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

support for stop_gradient? #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 3 additions & 1 deletion agc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ def adaptive_clip_grad(parameters, gradients, clip_factor=0.01,
eps=1e-3):
new_grads = []
for (params, grads) in zip(parameters, gradients):
if grads is None:
continue
p_norm = unitwise_norm(params)
max_norm = tf.math.maximum(p_norm, eps) * clip_factor
grad_norm = unitwise_norm(grads)
clipped_grad = grads * (max_norm / tf.math.maximum(grad_norm, 1e-6))
new_grad = tf.where(grad_norm < max_norm, grads, clipped_grad)
new_grads.append(new_grad)
return new_grads
return new_grads