Better error messages for impl_abstract_pystub (#120959)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/120959
Approved by: https://github.com/drisspg
This commit is contained in:
rzou
2024-03-01 11:17:16 -08:00
committed by PyTorch MergeBot
parent ce2903080c
commit 3ef0befdc9
6 changed files with 24 additions and 10 deletions

View File

@ -42,7 +42,7 @@ class TestCustomOperators(TestCase):
def f(x):
return torch.ops.custom.asin(x)
with self.assertRaisesRegex(RuntimeError, r'unsupported operator: .* \(you may need to `import nonexistent`'):
with self.assertRaisesRegex(RuntimeError, r'unsupported operator: .* you may need to `import nonexistent`'):
f(x)
def test_abstract_impl_pystub_faketensor(self):
@ -64,7 +64,7 @@ def forward(self, arg0_1):
def test_abstract_impl_pystub_meta(self):
x = torch.randn(3, device="meta")
self.assertNotIn("my_custom_ops2", sys.modules.keys())
with self.assertRaisesRegex(NotImplementedError, r"import the 'my_custom_ops2'"):
with self.assertRaisesRegex(NotImplementedError, r"'my_custom_ops2'"):
y = torch.ops.custom.sin.default(x)
torch.ops.import_module("my_custom_ops2")
y = torch.ops.custom.sin.default(x)