(self, check_using_norm)
| 464 | world_size = 2 |
| 465 | |
| 466 | def test(self, check_using_norm): |
| 467 | groups._create_expert_and_data_parallel(2) |
| 468 | |
| 469 | param1 = torch.nn.Parameter(torch.Tensor([0])) |
| 470 | param1.grad = torch.Tensor([1]) |
| 471 | param2 = torch.nn.Parameter(torch.Tensor([0])) |
| 472 | if dist.get_rank() == 0: |
| 473 | param2.grad = torch.Tensor([1]) |
| 474 | else: |
| 475 | param2.grad = torch.Tensor([float("inf")]) |
| 476 | param2.allreduce = False |
| 477 | # param2 is now MoE parameter |
| 478 | parameters = [param1, param2] |
| 479 | if check_using_norm: |
| 480 | grads_group_flat = [_flatten_dense_tensors([p.grad for p in parameters])] |
| 481 | norm = ds_utils.get_weight_norm(grads_group_flat) |
| 482 | overflow_checker = ds_utils.CheckOverflow([parameters]) |
| 483 | overflow = overflow_checker.check_using_norm([norm], reduce_overflow=False) |
| 484 | else: |
| 485 | overflow_checker = ds_utils.CheckOverflow([parameters]) |
| 486 | overflow = overflow_checker.check() |
| 487 | assert overflow |
| 488 | |
| 489 | |
| 490 | @pytest.mark.skipif(not hasattr(torch.autograd.graph, "_get_grad_fn_or_grad_acc"), |
nothing calls this directly
no test coverage detected