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

Automatic differentiation with autograd · Machine-learning #2

Open
utterances-bot opened this issue Jul 9, 2020 · 2 comments
Open

Comments

@utterances-bot
Copy link

Automatic differentiation with autograd · Machine-learning

https://westgrid-ml.netlify.app/schoolremake/pt-13-autograd.html

Copy link

vickeybu commented Jul 9, 2020

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 "", line 3
print(manual_gradient_predicted)
^
SyntaxError: invalid syntax

@prosoitos
Copy link
Member

prosoitos commented Jul 9, 2020

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.

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

No branches or pull requests

3 participants