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

step18: fix AttributeError: NoneType object has no attribute generation #41

Open
wants to merge 1 commit into
base: master
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
12 changes: 10 additions & 2 deletions steps/step18.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def add_func(f):
seen_set.add(f)
funcs.sort(key=lambda x: x.generation)

add_func(self.creator)

if self.creator is not None: # skip the first variable, whose creator is none
add_func(self.creator)

while funcs:
f = funcs.pop()
Expand Down Expand Up @@ -148,4 +150,10 @@ def add(x0, x1):

with no_grad():
x = Variable(np.array(2.0))
y = square(x)
y = square(x)

with using_config('enable_backprop', False):
x = Variable(np.ones((100, 100, 100)))
y = square(square(square(x)))
y.backward()
print(x.grad)