Skip to content

Fix the loss initialization in intermediate_source/char_rnn_generation_tutorial.py #2380

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

Merged
merged 8 commits into from
Jun 2, 2023
2 changes: 1 addition & 1 deletion intermediate_source/char_rnn_generation_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def train(category_tensor, input_line_tensor, target_line_tensor):

rnn.zero_grad()

loss = 0
loss = torch.tensor([0]) # in PyTorch 2.0 and later can be don't need to initialize as tensor, can be ``loss = 0``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is true for any pytorch version, it's not related to 2.0


for i in range(input_line_tensor.size(0)):
output, hidden = rnn(category_tensor, input_line_tensor[i], hidden)
Expand Down