Forbid inplace modification of a saved tensor's pack_hook input (#62717)
authorVictor Quach <quach@fb.com>
Thu, 12 Aug 2021 19:36:38 +0000 (12:36 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 12 Aug 2021 19:40:10 +0000 (12:40 -0700)
commited7ece389daa980a03a2f09848a6439a90af9782
treeecb9c6139371ae15ade1289bfcbc058cfc4caed8
parentaa5141f2044e851e43e12ae33fc4e601369012e6
Forbid inplace modification of a saved tensor's pack_hook input (#62717)

Summary:
When using saved tensors hooks (especially default hooks),
if the user defines a `pack_hook` that modifies its input,
it can cause some surprising behavior.

The goal of this PR is to prevent future user headache by catching
inplace modifications of the input of `pack_hook` and raising an error if
applicable.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62717

Reviewed By: albanD

Differential Revision: D30255243

Pulled By: Varal7

fbshipit-source-id: 8d73f1e1b50b697a59a2849b5e21cf0aa7493b76
test/test_autograd.py
torch/_C/_autograd.pyi
torch/autograd/__init__.py
torch/autograd/graph.py
torch/csrc/autograd/init.cpp
torch/csrc/autograd/saved_variable.cpp