Repository navigation
Skip rebuilding FX forward after post-lowering and before adjacency split. - #4599
micwill755 wants to merge 2 commits into
Conversation
9529f21 to
2ab2bab
Compare
d976ba1 to
17b63ed
Compare
2ab2bab to
79252a6
Compare
17b63ed to
c722fbb
Compare
79252a6 to
963be70
Compare
c722fbb to
6339d3b
Compare
6339d3b to
caed6cf
Compare
c174fe9 to
6034d33
Compare
caed6cf to
141e926
Compare
6034d33 to
c92404f
Compare
141e926 to
7762e49
Compare
| gm: torch.fx.GraphModule, | ||
| settings: CompilationSettings = CompilationSettings(), | ||
| *, | ||
| recompile: bool = False, |
There was a problem hiding this comment.
Check out torch.fx._lazy_graph_module._LazyGraphModule.
AI:
Defaulting recompile=False assumes the lowered module is never run as Python. But compile_module returns it unconverted when a graph has fewer supported ops than min_block_size, and the torch.compile backend then runs its stale forward.
backends.py:367 calls post_lowering(gm, settings) with the default, then compile_module. _compiler.py:1381 returns gm when num_supported_ops < min_block_size, which happens often with small Dynamo graph-break fragments. That gm.forward was generated before lowering. It still runs pre-lowering code, and it can refer to attributes that constant_fold deleted.
This PR already had to pass recompile=True in harness.py and test_static_cache.py for this reason. The same applies to compile(..., dryrun=True) at :1415. There's no test for the early-return path. I found this by inspection and haven't run it.
The fix is to convert to torch.fx._lazy_graph_module._LazyGraphModule instead of adding the flag. Its recompile() only marks the code dirty, and code generation runs on first access to forward. I measured 56.75 ms for GraphModule.recompile() against 0.01 ms for the lazy version on a 2000-node graph. That's the same saving, with no stale-module risk.
There was a problem hiding this comment.
Addressed by converting the lowered module to _LazyGraphModule. Recompilation now marks forward as dirty and regenerates it only when Python execution requires it. I also added regression coverage for the compile_module() early return path.
c92404f to
907decb
Compare
7762e49 to
949a239
Compare
907decb to
292ccf4
Compare
949a239 to
78b03f6
Compare
There was a problem hiding this comment.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py 2026-10-06 21:35:06.314583+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py 2026-10-06 21:35:38.389795+00:00
@@ -94,11 +94,13 @@
ctx, offs, torch.int32, f"{name}_offs_i32", target, source_ir
)
offs_row = impl.shuffle.reshape(
ctx, target, source_ir, f"{name}_offs_row", offs_i32, (1, -1)
)
- passed = impl.elementwise.le(ctx, target, source_ir, f"{name}_passed", offs_row, rows)
+ passed = impl.elementwise.le(
+ ctx, target, source_ir, f"{name}_passed", offs_row, rows
+ )
group = impl.reduce.sum(
ctx,
target,
source_ir,
f"{name}_group",
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py 2026-10-06 21:35:06.312815+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py 2026-10-06 21:35:42.883629+00:00
@@ -4640,13 +4640,11 @@
if key in kwargs and kwargs[key] is not None:
return kwargs[key]
return args_bounds_check(args, index, default)
-def histc_validator(
- node: Node, settings: Optional[CompilationSettings] = None
-) -> bool:
+def histc_validator(node: Node, settings: Optional[CompilationSettings] = None) -> bool:
bins = _arg_or_kwarg(node.args, node.kwargs, 1, "bins", 100)
lo = _arg_or_kwarg(node.args, node.kwargs, 2, "min", 0)
hi = _arg_or_kwarg(node.args, node.kwargs, 3, "max", 0)
if not all(
isinstance(v, (int, float)) and not isinstance(v, bool) for v in (bins, lo, hi)292ccf4 to
6ef979f
Compare
c6f9a51 to
a6afa53
Compare
ae0c5d4 to
c08fee9
Compare
c693a4b to
7a6ca3d
Compare
216ddd1 to
3688b2c
Compare
7a6ca3d to
0693ab4
Compare
3688b2c to
286ea9f
Compare
0fdefb3 to
2ff330e
Compare
Addressed: lowered module is now converted to _LazyGraphModule (no stale forward), and the compile_module() early-return path has regression coverage.
…plit. TRTInterpreter and AccNodesFinder walk graph.nodes; split still rebuilds forward when it constructs the runtime GraphModules.
2ff330e to
542aabb
Compare
Summary
gm.recompile()in the post-lowering flush (defaultrecompile=False) and infast_partitionbeforesplit(). Conversion (TRTInterpreter) and the adjacency splitter walkgraph.nodesand do not callgm.forward().post_lowering(..., recompile=True)(converter harness, LLM static-cache).split()still rebuildsforward()when it constructs_run_on_acc_*/_run_on_gpu_*GraphModules.fast_partitionwall is 118 ms (was ~155–171 ms).split()still reprints the full ACC child twice (~37 ms each) plus an expensive 9-node wrapper reprint (~36 ms).PR 8 of the compile-startup stack; based on #4598.
Test plan
tests/py/dynamo/lowering/test_skip_conversion_recompile.py(post_lowering does not recompile; DCE still runs; Interpreter still correct;recompile=Truerebuilds forward; fast_partition does not recompile the input module)tests/py/dynamo/models/test_lowering_cache.py(roundtrip still executes after explicit recompile of the in-memory module)tests/py/dynamo/partitioning/test_000_fast_partitioning.pyStack created with GitHub Stacks CLI • Give Feedback 💬