Skip to content

Commit eb07d41

Browse files
nelyahuloadamstjruwasejomayeri
authored
Allow accelerator to instantiate the device (#5255)
when instantiating torch.device for HPU it cannot be fed with HPU:1 annotation, but only "HPU". moving the logic to accelerator will allow to solve this issue, with single line change. --------- Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Olatunji Ruwase <[email protected]> Co-authored-by: Joe Mayer <[email protected]>
1 parent 4ba49dd commit eb07d41

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

.github/workflows/hpu-gaudi2.yml

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ jobs:
6868
(test_flops_profiler.py and test_flops_profiler_in_inference)
6969
test_get_optim_files.py
7070
test_groups.py
71-
test_init_on_device.py
7271
test_partition_balanced.py
7372
(test_adamw.py and TestAdamConfigs)
7473
test_coalesced_collectives.py

accelerator/hpu_accelerator.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ def handles_memory_backpressure(self):
4242
return True
4343

4444
def device_name(self, device_index=None):
45-
if device_index is None:
46-
return 'hpu'
47-
return 'hpu:{}'.format(device_index)
45+
# ignoring device_index.
46+
return 'hpu'
4847

4948
def device(self, device_index=None):
5049
return torch.device(self.device_name(device_index))

deepspeed/runtime/engine.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1009,13 +1009,13 @@ def _set_distributed_vars(self, args):
10091009
device_rank = args.device_rank if args is not None and hasattr(args, 'device_rank') else self.local_rank
10101010
if device_rank >= 0:
10111011
get_accelerator().set_device(device_rank)
1012-
self.device = torch.device(get_accelerator().device_name(), device_rank)
1012+
self.device = torch.device(get_accelerator().device_name(device_rank))
10131013
self.world_size = dist.get_world_size()
10141014
self.global_rank = dist.get_rank()
10151015
else:
10161016
self.world_size = 1
10171017
self.global_rank = 0
1018-
self.device = torch.device(get_accelerator().device_name())
1018+
self.device = get_accelerator().device()
10191019

10201020
# Configure based on command line arguments
10211021
def _configure_with_arguments(self, args, mpu):

deepspeed/runtime/zero/utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def get_lst_from_rank0(lst: List[int]) -> None:
6868
lst_tensor = torch.tensor(
6969
lst if dist.get_rank() == 0 else [-1] * len(lst),
7070
dtype=int,
71-
# device=get_accelerator().current_device_name(),
7271
device=torch.device(get_accelerator().device_name(os.environ["LOCAL_RANK"])),
7372
requires_grad=False,
7473
)

0 commit comments

Comments
 (0)