mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
[dynamo][polyfills]Support getrecursionlimit (#145989)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/145989 Approved by: https://github.com/StrongerXi, https://github.com/jansel ghstack dependencies: #145986, #145987, #145994
This commit is contained in:
parent
e7bb608d02
commit
1e3d1738a4
|
|
@ -4505,6 +4505,14 @@ class DefaultsTests(torch._dynamo.test_case.TestCase):
|
|||
self.assertEqual(ref, res)
|
||||
self.assertTrue(isinstance(res, tuple))
|
||||
|
||||
def test_sys_recursionlimit(self):
|
||||
def fn(x):
|
||||
return x.sin() * sys.getrecursionlimit()
|
||||
|
||||
opt_fn = torch.compile(fn, backend="eager", fullgraph=True)
|
||||
x = torch.randn(4)
|
||||
self.assertEqual(fn(x), opt_fn(x))
|
||||
|
||||
|
||||
instantiate_parametrized_tests(FunctionTests)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,15 @@ from ..decorators import substitute_in_graph
|
|||
|
||||
__all__ = [
|
||||
"intern",
|
||||
"getrecursionlimit",
|
||||
]
|
||||
|
||||
|
||||
@substitute_in_graph(sys.intern, can_constant_fold_through=True)
|
||||
def intern(string: str, /) -> str:
|
||||
return string
|
||||
|
||||
|
||||
@substitute_in_graph(sys.getrecursionlimit, can_constant_fold_through=True)
|
||||
def getrecursionlimit() -> int:
|
||||
return sys.getrecursionlimit()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user