Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast grad_scale in whiten to float #1663

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions egs/librispeech/ASR/zipformer/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,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 @@ -1074,7 +1074,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
Loading