dynamo: Don't crash when someone tries to access a non existent list member (#156335)

dynamo: Don't crash when someone tries to access a non existent list member

Test added which reproduces the failure. Note that I'm using the new
unimplemented_v2 API. Let me know if people have a strong preference that I use
something else.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/156335
Approved by: https://github.com/jansel
This commit is contained in:
clr
2025-06-18 10:31:08 -07:00
committed by PyTorch MergeBot
parent ac86ec0e60
commit 9aaa184105
6 changed files with 15 additions and 1 deletions

View File

@ -116,7 +116,12 @@ class BaseListVariable(VariableTracker):
)
else:
assert isinstance(index, (int, torch.SymInt))
return self.items[index]
try:
return self.items[index]
except IndexError:
raise_observed_exception(
IndexError, tx, args=["list index out of range"]
)
def unpack_var_sequence(self, tx):
return list(self.items)