Fix error message of autograd (#123154)

This PR updates the error message in autograd when an input tensor does not set to `require_grad`. The original message does not contain the index info, making users hard to debug.
The error message style consists with that on line 105-109.
Co-authored-by: Jeffrey Wan <soulitzer@gmail.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/123154
Approved by: https://github.com/soulitzer
This commit is contained in:
Chun Cai
2024-04-03 19:07:15 +00:00
committed by PyTorch MergeBot
parent 700917c361
commit 691054eeef
2 changed files with 7 additions and 3 deletions

View File

@ -1661,7 +1661,7 @@ TEST(TestAutogradNotImplementedFallback, TensorlistOp) {
ASSERT_THROWS_WITH(
torch::autograd::grad({out}, {vec[0]}),
"One of the differentiated Tensors does not require grad");
"element 0 of the input tensors does not require grad");
ASSERT_THROWS_WITH(
torch::autograd::grad({out}, {vec[1]}), "is not implemented");