From 7a2a2f675a031b54ce2e1e3b302c0120a3c45da5 Mon Sep 17 00:00:00 2001 From: "Colin L. Rice (Meta Employee)" Date: Fri, 17 Jan 2025 11:49:24 -0800 Subject: [PATCH] dynamo: Don't crash with internal error if getattr on a tensor fails (#144817) Summary: This prevents crashes when getattr is called on a tensor for something which doesn't exist. X-link: https://github.com/pytorch/pytorch/pull/144817 Approved by: https://github.com/williamwen42, https://github.com/jansel Reviewed By: kit1980 Differential Revision: D68304676 Pulled By: c00w fbshipit-source-id: aabd53d950a19e2837ff15e11a39cc1771ac4ec5 --- userbenchmark/dynamo/dynamobench/_dynamo/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/userbenchmark/dynamo/dynamobench/_dynamo/utils.py b/userbenchmark/dynamo/dynamobench/_dynamo/utils.py index 05adae716d..f3630cfebc 100644 --- a/userbenchmark/dynamo/dynamobench/_dynamo/utils.py +++ b/userbenchmark/dynamo/dynamobench/_dynamo/utils.py @@ -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 @@ -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__