Add RAISE_VARARGS 0

ghstack-source-id: 6136b37665
Pull Request resolved: https://github.com/pytorch/pytorch/pull/146493
This commit is contained in:
Guilherme Leobas 2025-02-07 16:46:22 -03:00
parent 1d05cc9a8f
commit 8b1b8ab952
2 changed files with 27 additions and 1 deletions

View file

@ -11912,6 +11912,27 @@ fn
self.assertFalse(ne)
self.assertEqual(len(counters["graph_break"]), 1)
@unittest.skipIf(sys.version_info < (3, 11), "Python 3.11+")
def test_RAISE_VARARGS_0(self):
def foo():
try:
raise ValueError
except:
raise
@torch.compile(backend="eager", fullgraph=True)
def fn(t):
try:
foo()
except ValueError:
return t.sin()
except Exception:
return t.cos()
t = torch.randn(2)
y = fn(t)
self.assertEqual(y, t.sin())
def test_overridden_getattribute(self):
class Foo:
attribute_map = {}

View file

@ -1488,7 +1488,12 @@ class InstructionTranslatorBase(
def RAISE_VARARGS(self, inst):
if inst.arg == 0:
unimplemented("re-raise")
# duplicate the top of the stack and re-raise it
if sys.version_info < (3, 11):
unimplemented("re-raise")
assert isinstance(self.stack[-1], ExceptionVariable)
self.stack.append(self.stack[-1])
self._raise_exception_variable(inst)
elif inst.arg == 1:
self._raise_exception_variable(inst)
else: