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

Fix bug in graph engine for shared variable #532

Merged
merged 5 commits into from
Oct 24, 2019

Conversation

KazukiYoshiyama-sony
Copy link
Contributor

Two bug fixes:

  1. no accumulation of gradients for any shared variable, of which grad.zero is called, into a same function instance
  2. no accumulation of a shared and leaf variable into any function instance when using nn.grad

With this bug fixes, the following examples works as expected.

Ex.1

x = nn.Variable.from_numpy_array(np.ones((2, 3))).apply(need_grad=True)
x.grad.zero()
y = x * x * x
y.forward()
y.backward()
print(x.g)  # 3 * x ** 2

Ex. 2

x = nn.Variable.from_numpy_array(np.ones((2, 3))).apply(need_grad=True)
y = x * x * x
x.grad.zero()
dy_dx = nn.grad([y], [x])
dy_dx[0].forward()
print(dy_dx[0].d)  # 3 * x ** 2
dy_dx[0].backward()
print(x.g)  # 6 * x

Fix bind data region.

Add cleanup.
Format.

Delete cleanup since it's already done in conftest.py#scope_function

Change features to pass tests.
@TakuyaNarihira TakuyaNarihira merged commit 9201440 into master Oct 24, 2019
@YukioOobuchi YukioOobuchi deleted the fix/20191015-leaf-shared branch January 20, 2020 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug release-note-bugfix Auto-release; Bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants