From 92a005883a18a0026161d933aa27a08d0ef68af2 Mon Sep 17 00:00:00 2001 From: Mikayla Gawarecki Date: Fri, 12 Aug 2022 23:14:13 +0000 Subject: [PATCH] [easy] Fix .sizes() call in saved_variable.cpp for nested tensor (#83356) Small fix so that TestMultipleDispatch in the above PR will throw the correct error when using an inplace operation on a saved nested input Pull Request resolved: https://github.com/pytorch/pytorch/pull/83356 Approved by: https://github.com/albanD --- torch/csrc/autograd/saved_variable.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/torch/csrc/autograd/saved_variable.cpp b/torch/csrc/autograd/saved_variable.cpp index c6ca8eda13d19..de375cd194764 100644 --- a/torch/csrc/autograd/saved_variable.cpp +++ b/torch/csrc/autograd/saved_variable.cpp @@ -159,7 +159,12 @@ Variable SavedVariable::unpack(std::shared_ptr saved_for) const { message << "one of the variables needed for gradient computation has been " "modified by an inplace operation: [" - << data_.toString() << " " << data_.sizes() << "]"; + << data_.toString() << " "; + if (data_.is_nested()) { + message << data_._nested_tensor_size() << "]"; + } else { + message << data_.sizes() << "]"; + } if (grad_fn) { message << ", which is output " << output_nr_ << " of " << grad_fn->name() << ",";