Hi I have the following code: https://gist.github.com/vorlkets/f38c91aa52cb4e68976e1f638d251a85. When run, I get the following error:
python hw2main.py
Using device: cpu
Traceback (most recent call last):
File “hw2main.py”, line 142, in
main()
File “hw2main.py”, line 76, in main
loss.backward()
File “C:\Users\Cliff\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\tensor.py”, line 195, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File “C:\Users\Cliff\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\autograd_init_.py”, line 97, in backward
Variable._execution_engine.run_backward(
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
What does the error tell me? and how to fix this?