Skip to content

Commit 1768d55

Browse files
committed
Fix format
1 parent e57c525 commit 1768d55

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: deepspeed/runtime/zero/stage_1_and_2.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,11 @@ def get_grad_norm_direct(self, gradients, params, norm_type=2):
17251725

17261726
total_norm = total_norm.pow(1. / norm_type)
17271727

1728-
if total_norm.isinf() or total_norm.isnan():
1729-
total_norm = torch.tensor(-1.0, device=self.device, dtype=torch.float)
1728+
norm_is_inf = total_norm.isinf()
1729+
norm_is_nan = total_norm.isnan()
1730+
1731+
if norm_is_inf or norm_is_nan:
1732+
total_norm = torch.tensor(-1.0, device=self.device, dtype=torch.float)
17301733

17311734
return total_norm
17321735

0 commit comments

Comments
 (0)