Skip to content

Commit

Permalink
adding support for assigning gpu ids based on host (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyce-yuan authored Nov 11, 2024
1 parent ca21cd7 commit b220027
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/algos/base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,16 @@ def setup_logging(self, config: Dict[str, ConfigType]) -> None:
def setup_cuda(self, config: Dict[str, ConfigType]) -> None:
"""add docstring here"""
# Need a mapping from rank to device id
device_ids_map = config["device_ids"]
node_name = f"node_{self.node_id}"
self.device_ids = device_ids_map[node_name]
if (config.get("assign_based_on_host", False)):
device_ids_map = config["device_ids"]
node_name = f"node_{self.node_id}"
self.device_ids = device_ids_map[node_name]
else:
hostname_to_device_ids = config["hostname_to_device_ids"]
hostname = os.uname().nodename
# choose a random one of the available devices
ind = self.node_id % len(hostname_to_device_ids[hostname])
self.device_ids = [hostname_to_device_ids[hostname][ind]]
gpu_id = self.device_ids[0]

if isinstance(gpu_id, int) and torch.cuda.is_available():
Expand Down
8 changes: 8 additions & 0 deletions src/configs/sys_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ def get_digit_five_support(num_users: int, domains: List[str] = DIGIT_FIVE):
"exp_keys": [],
"dropout_dicts": dropout_dicts,
"test_samples_per_user": 200,
"log_memory": True,
"assign_based_on_host": True,
"hostname_to_device_ids": {
"matlaber1": [2, 3, 4, 5, 6, 7],
"matlaber12": [0, 1, 2, 3],
"matlaber3": [0, 1, 2, 3],
"matlaber4": [0, 2, 3, 4, 5, 6, 7],
}
}


Expand Down

0 comments on commit b220027

Please sign in to comment.