Skip to content

Commit

Permalink
Cast grad_scale in whiten to float (#1663)
Browse files Browse the repository at this point in the history
* cast grad_scale in whiten to float

* fix cast in zipformer_lora
  • Loading branch information
teowenshen authored Jul 11, 2024
1 parent d65187e commit 19048e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions egs/librispeech/ASR/zipformer/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ def backward(ctx, x_grad: Tensor):
w.prob = w.max_prob
metric.backward()
penalty_grad = x_detached.grad
scale = w.grad_scale * (
scale = float(w.grad_scale) * (
x_grad.to(torch.float32).norm()
/ (penalty_grad.norm() + 1.0e-20)
)
Expand Down Expand Up @@ -1075,7 +1075,7 @@ def __init__(
super(Whiten, self).__init__()
assert num_groups >= 1
assert float(whitening_limit) >= 1
assert grad_scale >= 0
assert float(grad_scale) >= 0
self.num_groups = num_groups
self.whitening_limit = whitening_limit
self.grad_scale = grad_scale
Expand Down
4 changes: 2 additions & 2 deletions egs/librispeech/ASR/zipformer_lora/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def backward(ctx, x_grad: Tensor):
w.prob = w.max_prob
metric.backward()
penalty_grad = x_detached.grad
scale = w.grad_scale * (
scale = float(w.grad_scale) * (
x_grad.to(torch.float32).norm()
/ (penalty_grad.norm() + 1.0e-20)
)
Expand Down Expand Up @@ -1179,7 +1179,7 @@ def __init__(
super(Whiten, self).__init__()
assert num_groups >= 1
assert float(whitening_limit) >= 1
assert grad_scale >= 0
assert float(grad_scale) >= 0
self.num_groups = num_groups
self.whitening_limit = whitening_limit
self.grad_scale = grad_scale
Expand Down

0 comments on commit 19048e1

Please sign in to comment.