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

Method test

tests/unit/runtime/zero/test_zero_context.py:356–373  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

354 world_size = 2
355
356 def test(self):
357 with deepspeed.zero.Init():
358 l = torch.nn.Linear(4, 2)
359 assert l.weight.ds_status == ZeroParamStatus.NOT_AVAILABLE
360
361 # Gather and make a change
362 with deepspeed.zero.GatheredParameters(l.weight, modifier_rank=1):
363 assert l.weight.ds_status == ZeroParamStatus.AVAILABLE
364 if dist.get_rank() == 1:
365 with torch.no_grad():
366 l.weight.zero_()
367
368 # should now be scattered again
369
370 # Now gather again and ensure the change is global
371 with deepspeed.zero.GatheredParameters(l.weight):
372 # all ranks compare
373 assert torch.equal(l.weight, torch.zeros_like(l.weight))

Callers

nothing calls this directly

Calls 1

get_rankMethod · 0.45

Tested by

no test coverage detected