Skip to content

Commit 5197457

Browse files
Skip allow_in_graph if torch >= 2.8 (#394)
Starting from PyTorch 2.8, einops no longer needs to rely on `allow_in_graph` for its own ops. PyTorch follows the same approach internally, and I'd like to remove this usage from the PyTorch codebase as well. Dynamo is now mature enough to trace through the einops codebase, and we have tests in place to catch any regressions early.
1 parent 3bd7454 commit 5197457

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

einops/_torch_specific.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def allow_ops_in_compiled_graph():
104104
if hasattr(torch, "__version__") and torch.__version__[0] < "2":
105105
# torch._dynamo and torch.compile appear in pytorch 2.0
106106
return
107+
108+
if hasattr(torch, "__version__") and torch.__version__ >= "2.8":
109+
# einops don't need to use allow_in graph for torch 2.8 and above
110+
return
111+
107112
try:
108113
from torch._dynamo import allow_in_graph
109114
except ImportError:

0 commit comments

Comments
 (0)