Skip to content

Commit fc489c3

Browse files
committed
adding epislon in nor division
1 parent 15c40c4 commit fc489c3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

makani/utils/training/training_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def clip_grads(model, max_grad_norm, norm_type=2.0):
9090
with torch.no_grad():
9191
total_gnorm = _compute_total_grad_norm(model, norm_type)
9292

93-
clip_factor = max_grad_norm / total_gnorm
93+
clip_factor = max_grad_norm / (total_gnorm + 1e-6) # add small epsilon to avoid division by zero
9494
clip_factor = torch.clamp(clip_factor, max=1.0)
9595

9696
for param in model.parameters():

0 commit comments

Comments
 (0)