Raise exception in Dynamo if op fails in the interpreter (#158661)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/158661
Approved by: https://github.com/williamwen42
ghstack dependencies: #158660
This commit is contained in:
Guilherme Leobas
2025-07-23 10:03:18 -03:00
committed by PyTorch MergeBot
parent b67f97c166
commit 0204099762
31 changed files with 59 additions and 13 deletions

View File

@ -577,7 +577,14 @@ class BuiltinVariable(VariableTracker):
def create_cmp_op_handlers(op):
def compare_by_value(tx: "InstructionTranslator", a, b):
return ConstantVariable(op(a.value, b.value))
try:
return ConstantVariable(op(a.value, b.value))
except TypeError as exc:
raise_observed_exception(
type(exc),
tx,
args=list(map(ConstantVariable.create, exc.args)),
)
result: list[
tuple[