Skip to content

Commit

Permalink
Update optim.py (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinZr authored Oct 9, 2023
1 parent ce08230 commit fefffc0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion egs/librispeech/ASR/zipformer/optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ def _get_clipping_scale(
if self.show_dominant_parameters:
assert p.shape[0] == len(param_names)
self._show_gradient_dominating_parameter(tuples, tot_sumsq)
if ans != ans: # e.g. ans is nan
ans = 0.0
if ans == 0.0:
for p, state, param_names in tuples:
p.grad.zero_() # get rid of infinity()

return ans

def _show_gradient_dominating_parameter(
Expand Down Expand Up @@ -573,7 +579,7 @@ def _step_one_batch(

grad = p.grad
if clipping_scale != 1.0:
grad = grad * clipping_scale
grad *= clipping_scale
step = state["step"]
delta = state["delta"]

Expand Down

0 comments on commit fefffc0

Please sign in to comment.