| 257 | self.has_moe_params = True |
| 258 | |
| 259 | def check_using_norm(self, norm_group, reduce_overflow=True): |
| 260 | # TODO: I don't think reduce_overflow is needed if mpu is None |
| 261 | overflow = any(is_invalid_grad_norm(norm) for norm in norm_group) |
| 262 | overflow_gpu = get_accelerator().FloatTensor([overflow]) |
| 263 | if self.has_moe_params: |
| 264 | # In this case, we need to do an all_reduce across |
| 265 | # the expert_parallel_group, so that if there was |
| 266 | # an overflow due to expert weights, we detect it |
| 267 | |
| 268 | # Only need to check groups.get_largest_expert_parallel_group() |
| 269 | dist.all_reduce(overflow_gpu, op=dist.ReduceOp.MAX, group=groups._get_max_expert_parallel_group()) |
| 270 | if self.mpu is not None: |
| 271 | dist.all_reduce(overflow_gpu, op=dist.ReduceOp.MAX, group=self.mpu.get_model_parallel_group()) |
| 272 | elif reduce_overflow: |
| 273 | dist.all_reduce(overflow_gpu, op=dist.ReduceOp.MAX) |
| 274 | dist.barrier() |
| 275 | overflow = overflow_gpu[0].item() |
| 276 | return bool(overflow) |
| 277 | |
| 278 | def check(self, param_groups=None): |
| 279 | params = [] |