Skip to content

Commit 5838b07

Browse files
anijain2305facebook-github-bot
authored andcommitted
Refactor the fetching of subgraph names (#152770)
Summary: X-link: pytorch/pytorch#152770 Approved by: https://github.com/jansel, https://github.com/zou3519 ghstack dependencies: #152772 Reviewed By: huydhn Differential Revision: D74226447 fbshipit-source-id: 57382bd4a35e54644c55d76f4f8489a8e3ffc73b
1 parent e53141f commit 5838b07

File tree

1 file changed

+20
-0
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+20
-0
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/testing.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ def bw_compiler(
312312
)
313313

314314

315+
class InductorAndRecordGraphs:
316+
def __init__(self) -> None:
317+
self.graphs: list[torch.fx.GraphModule] = []
318+
self.inductor_graphs: list[torch.fx.GraphModule] = []
319+
320+
def __call__(self, gm, example_inputs): # type: ignore[no-untyped-def]
321+
import torch._inductor.compile_fx as compile_fx_mod
322+
323+
self.graphs.append(gm)
324+
325+
old_compile_fx_inner = compile_fx_mod._compile_fx_inner
326+
327+
def patched(*args, **kwargs): # type: ignore[no-untyped-def]
328+
self.inductor_graphs.append(args[0])
329+
return old_compile_fx_inner(*args, **kwargs)
330+
331+
with patch.object(compile_fx_mod, "_compile_fx_inner", new=patched):
332+
return compile_fx_mod.compile_fx(gm, example_inputs)
333+
334+
315335
def strip_comment(code: str) -> str:
316336
return re.sub(r"(?m)^ *#.*\n?", "", code)
317337

0 commit comments

Comments
 (0)