Add missing attr access check for legacy autograd.Function (#155055)

Fixes https://github.com/pytorch/pytorch/issues/154981
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155055
Approved by: https://github.com/albanD
ghstack dependencies: #154509, #154852
This commit is contained in:
soulitzer
2025-06-10 16:30:37 -04:00
committed by PyTorch MergeBot
parent 5dd07c70e5
commit 1ed243f01c
2 changed files with 34 additions and 35 deletions

View File

@ -3725,6 +3725,18 @@ class TestAutograd(TestCase):
f.next_functions
with self.assertRaisesRegex(RuntimeError, "Attribute 'name' is invalid"):
f.name()
with self.assertRaisesRegex(
RuntimeError, "Attribute '_sequence_nr' is invalid"
):
f._sequence_nr()
with self.assertRaisesRegex(
RuntimeError, "Attribute '_set_sequence_nr' is invalid"
):
f._set_sequence_nr(2)
with self.assertRaisesRegex(
RuntimeError, "Attribute '_input_metadata' is invalid"
):
f._input_metadata
with self.assertRaisesRegex(
RuntimeError, "underlying PyNode has already been deallocated"
):