MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / assert_device_binding

Function assert_device_binding

tests/unit/comm/test_dist.py:551–566  ·  view source on GitHub ↗

A device is bound for multi-rank jobs, and not for a single-rank one (#8248).

(expect_bound)

Source from the content-addressed store, hash-verified

549
550
551def assert_device_binding(expect_bound):
552 """A device is bound for multi-rank jobs, and not for a single-rank one (#8248)."""
553 if get_accelerator().communication_backend_name() != 'nccl':
554 pytest.skip("device_id is only bound for the nccl backend")
555
556 deepspeed.init_distributed(dist_backend='nccl', auto_mpi_discovery=False)
557 default_pg = torch.distributed.distributed_c10d._get_default_group()
558 assert (default_pg.bound_device_id is not None) == expect_bound
559
560 # The eager split new_group() makes when a device is bound is the call that fails in #8248.
561 device = get_accelerator().device(int(os.environ["LOCAL_RANK"]))
562 default_backend = default_pg._get_backend(device)
563 if hasattr(default_backend, "comm_split_count"):
564 splits_before = default_backend.comm_split_count()
565 torch.distributed.new_group(ranks=list(range(dist.get_world_size())))
566 assert (default_backend.comm_split_count() > splits_before) == expect_bound
567
568
569class TestSingleRankDeviceId(DistributedTest):

Callers 2

testMethod · 0.85
testMethod · 0.85

Calls 5

get_acceleratorFunction · 0.90
get_world_sizeMethod · 0.80
deviceMethod · 0.45
new_groupMethod · 0.45

Tested by

no test coverage detected