Open utterances-bot opened 4 years ago
when I was trying to run one of the statements, it gave me an error message (see below). I am so new to python and am not sure why.
with torch.no_grad():
... manual_gradient_predicted = 2.0 * (predicted - real)
... print(manual_gradient_predicted)
File "
Your problem is a wrong indentation.
Python uses indentation to delineate blocks instead of parentheses, braces, or other syntax as is common in other languages. So the indentation in Python is not just a question of readability. It is really part of the code.
The print
statement should be aligned on the left-most side as it is a statement independent from what came above.
The way you indented it, you included it within the with torch.no_grad():
statement.
I added a blank line above that print
statement to make it more obvious that it is independent from what precedes.
Automatic differentiation with autograd · Machine-learning
https://westgrid-ml.netlify.app/schoolremake/pt-13-autograd.html