Skip to content

Commit 12edfb4

Browse files
committed
Update on "Add deprecation notice for allow_in_graph"
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx kadeng chauhang amjames Lucaskabela jataylo [ghstack-poisoned]
2 parents 482ee00 + 74c3084 commit 12edfb4

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

test/dynamo/test_decorators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ def fn(a):
221221
self.assertEqual(cnts.frame_count, 1)
222222
self.assertEqual(cnts.op_count, 5)
223223

224+
def test_allow_in_graph_deprecation_warning(self):
225+
with self.assertWarnsRegex(FutureWarning, "nonstrict_trace"):
226+
torch._dynamo.allow_in_graph(my_custom_function)
227+
torch._dynamo.disallow_in_graph(my_custom_function)
228+
224229
def test_allow_in_graph_no_id_reuse(self):
225230
cnts = torch._dynamo.testing.CompileCounter()
226231

torch/_dynamo/decorators.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
import functools
66
import inspect
7-
import warnings
87
import weakref
98
from collections.abc import Callable
109
from dataclasses import dataclass
1110
from types import TracebackType
1211
from typing import Any, overload, TYPE_CHECKING, TypeVar
13-
from typing_extensions import ParamSpec
12+
from typing_extensions import deprecated, ParamSpec
1413

1514
import torch
1615
import torch.utils._pytree as pytree
@@ -179,6 +178,11 @@ def assume_constant_result(fn): # type: ignore[no-untyped-def]
179178
return fn
180179

181180

181+
@deprecated(
182+
"torch._dynamo.allow_in_graph is deprecated and will be removed in a future version. "
183+
"Use torch._dynamo.nonstrict_trace instead.",
184+
category=FutureWarning,
185+
)
182186
def allow_in_graph(fn): # type: ignore[no-untyped-def]
183187
"""
184188
Tells the compiler frontend (Dynamo) to skip symbolic introspection of the function
@@ -188,12 +192,6 @@ def allow_in_graph(fn): # type: ignore[no-untyped-def]
188192
189193
WARNING: this API can be a footgun, please read the documentation carefully.
190194
"""
191-
warnings.warn(
192-
"torch._dynamo.allow_in_graph is deprecated and will be removed in a future version. "
193-
"Use torch._dynamo.nonstrict_trace instead.",
194-
FutureWarning,
195-
stacklevel=2,
196-
)
197195
if isinstance(fn, (list, tuple)):
198196
return [allow_in_graph(x) for x in fn]
199197
assert callable(fn), "allow_in_graph expects a callable"

0 commit comments

Comments
 (0)