Skip to content

Commit

Permalink
dynamo: Don't crash with internal error if getattr on a tensor fails …
Browse files Browse the repository at this point in the history
…(#144817)

Summary:
This prevents crashes when getattr is called on a tensor for something
which doesn't exist.

X-link: pytorch/pytorch#144817
Approved by: https://github.com/williamwen42, https://github.com/jansel

Reviewed By: kit1980

Differential Revision: D68304676

Pulled By: c00w

fbshipit-source-id: aabd53d950a19e2837ff15e11a39cc1771ac4ec5
  • Loading branch information
c00w authored and facebook-github-bot committed Jan 17, 2025
1 parent 68c5409 commit 7a2a2f6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3064,10 +3064,16 @@ def run_node(tracer, node, args, kwargs, nnmodule):
def make_error_message(e):
return f"Failed running {op} {node.target}(*{args}, **{kwargs}):\n" + str(e)

from .exc import Unsupported

try:
if op == "call_function":
return node.target(*args, **kwargs)
elif op == "call_method":
if not hasattr(args[0], node.target):
from .exc import unimplemented

unimplemented(make_error_message("attribute not defined"))
return getattr(args[0], node.target)(*args[1:], **kwargs)
elif op == "call_module":
assert nnmodule is not None
Expand All @@ -3083,6 +3089,8 @@ def make_error_message(e):
from .exc import unimplemented

unimplemented(make_error_message(e), from_exc=e)
except Unsupported:
raise
except Exception as e:
raise RuntimeError(make_error_message(e)).with_traceback(
e.__traceback__
Expand Down

0 comments on commit 7a2a2f6

Please sign in to comment.