course-v3
course-v3 copied to clipboard
Can't call numpy() on Variable that requires grad
Hi,
In lesson2-sgd.ipynb there are a few lines that are giving the error
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.
fastai - 1.0.60 pytorch - 1.3.1
Accordingly I made the following changes
plt.scatter(x[:,0],y)
plt.scatter(x[:,0],x@a);
to
plt.scatter(x[:,0],y)
with torch.no_grad():
plt.scatter(x[:,0],x@a);
and also
fig = plt.figure()
plt.scatter(x[:,0], y, c='orange')
line, = plt.plot(x[:,0], x@a)
plt.close()
def animate(i):
update()
line.set_ydata(x@a)
return line,
to
fig = plt.figure()
plt.scatter(x[:,0], y, c='orange')
with torch.no_grad():
line, = plt.plot(x[:,0], x@a)
plt.close()
def animate(i):
update()
with torch.no_grad():
line.set_ydata(x@a)
return line,
Thank you!
Thanks. This solved my problem.