| 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)) |