Skip to content

Fixing Tensor.backward's function signature #1376

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 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Releases, starting with 9/2/2021, are listed with the most recent release at the

# NuGet Version 0.103.1

__Breaking Changes__:
#1376 `torch.Tensor.backward`'s function signature has been updated to match PyTorch's implementation. Previously, passing `create_graph` or `retain_graph` by position would work like PyTorch's `torch.Tensor.backward`, but not if passing by name (`create_graph`'s value was swapped with `retain_graph`). This has been corrected; however, this means any code that passes `create_graph` or `retain_graph` by name needs to be updated to reflect the intended functionality.<br/>

__Bug Fixes__:

#1383 `torch.linalg.vector_norm`: Make `ord`-argument optional, as specified in docs<br/>
Expand Down
4 changes: 2 additions & 2 deletions src/TorchSharp/Tensor/Tensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ public bool is_sparse {
}
}

public void backward(IList<Tensor>? grad_tensors = null, bool create_graph = false, bool retain_graph = false, IList<Tensor>? inputs = null) =>
torch.autograd.backward(new[] { this }, grad_tensors, create_graph, retain_graph, inputs);
public void backward(IList<Tensor>? grad_tensors = null, bool retain_graph = false, bool create_graph = false, IList<Tensor>? inputs = null) =>
torch.autograd.backward(new[] { this }, grad_tensors, retain_graph, create_graph, inputs);

/// <summary>
/// Creates a tensor by loading it from a file.
Expand Down