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

Add to_grad option to F.assign #577

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

takuseno
Copy link
Contributor

@takuseno takuseno commented Jan 23, 2020

Hi, @TE-AkioHayakawa san , @TE-TakuyaNarihira san.

I've added to_grad option to F.assign function. This will be useful to build original your own gradient manipulation with use of nn.grad.

x = nn.Variable((2, 3), need_grad=True)
y = nn.Variable((2, 3))

l = F.mean(F.squared_error(x, y))

# backward
grad = nn.grad([l], [x], bind_grad_output=True)[0]

# clip gradients by norm
clipped_grad = F.clip_by_norm(grad, 0.5)

# apply clipped gradients to x
assign = F.assign(x, clipped_grad, to_grad=True)

assign.forward(clear_buffer=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant