Repository navigation
Cache post-lowering ATen graphs to skip decomp on warm compiles. - #4540
micwill755 wants to merge 4 commits into
Conversation
narendasan
left a comment
There was a problem hiding this comment.
Here can we use the same caching interface as engine caching? In theory users could provide their own implementation for things like remote cache or mem cache. We should use the same cache object for both engine and graph cache if possible
b287f3a to
af86293
Compare
8da3124 to
a6ec762
Compare
Done, lowered graphs now use BaseEngineCache.save/load as bytes, and custom_engine_cache is reused for both engines and graphs. Let me know if you want any further changes. |
579e79f to
64a6f93
Compare
4933c1b to
70b20cf
Compare
64a6f93 to
7e0b391
Compare
70b20cf to
488038d
Compare
7e0b391 to
d9e1735
Compare
488038d to
666c1b1
Compare
|
@zewenli98 Can you review this? |
d9e1735 to
622fcd6
Compare
666c1b1 to
d2be6d3
Compare
e9ada9a to
149d075
Compare
a2c9200 to
9c130ab
Compare
149d075 to
b3608de
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:34:49.970188+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py 2026-10-06 21:35:19.290872+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:34:49.968083+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py 2026-10-06 21:35:23.569487+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)9c130ab to
148fd1e
Compare
b3608de to
37b8702
Compare
| cache_lowered_graphs: bool = _defaults.CACHE_LOWERED_GRAPHS, | ||
| reuse_cached_lowered_graphs: bool = _defaults.REUSE_CACHED_LOWERED_GRAPHS, | ||
| lowering_cache_dir: str = _defaults.LOWERING_CACHE_DIR, |
There was a problem hiding this comment.
Do we need to add the same args in cross_compile_for_windows?
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _CACHE_FORMAT_VERSION = 5 |
There was a problem hiding this comment.
Why does it start from 5?
There was a problem hiding this comment.
Updated and set to 1, let me know if you want further changes here.
| _NON_SEMANTIC_SETTINGS = { | ||
| "cache_built_engines", | ||
| "reuse_cached_engines", | ||
| "cache_lowered_graphs", | ||
| "reuse_cached_lowered_graphs", | ||
| "dryrun", | ||
| "lazy_engine_init", | ||
| "timing_cache_path", | ||
| } |
There was a problem hiding this comment.
Is it same as
TensorRT/py/torch_tensorrt/dynamo/_settings.py
Lines 309 to 334 in 5d6bdb2
There was a problem hiding this comment.
No. The engine cache list covers settings that change the TensorRT engine. This cache stores the graph before the engine is built, so it must also include settings that change decomposition and lowering. Only settings that cannot change that graph are excluded.
| def _canonical_graph(gm: torch.fx.GraphModule) -> Tuple[str, ...]: | ||
| return tuple(node.format_node() for node in gm.graph.nodes) |
There was a problem hiding this comment.
Can this method promise isomorphism? In engine caching, I did something like
TensorRT/py/torch_tensorrt/dynamo/_engine_cache.py
Lines 75 to 94 in 5d6bdb2
The idea here is that if two graphs are isomorphic (with the same structure but different names), they should reuse the same cache.
There was a problem hiding this comment.
Also, do you think if we can put the common util methods into utils.py instead of repeat?
There was a problem hiding this comment.
Good catch, the old key included the node names a renamed export would miss. Each node is now numbered in order, and each operation records the numbers it reads, so add_1(x, y) and add_7(input, bias) produce the same key. An add of a different pair does not. The engine-cache helper only numbers the inputs and drops those connections, so I kept this key separate.
There was a problem hiding this comment.
Also, do you think if we can put the common util methods into utils.py instead of repeat?
Good idea, moved canonicalize_setting_value into dynamo/utils.py, updated both the engine cache and lowering cache to use it, and existing tests import the shared function.
37b8702 to
2aa0679
Compare
76e7c24 to
8820d25
Compare
8820d25 to
ada13a8
Compare
Serialize the live FX node list and state_dict with torch.save so a hit can skip decomposition and post_lowering without retracing generated Python.
Reuse save/load so custom engine caches can hold post-lowering GraphModules without a separate disk format.
A re-export that only renames nodes was a cache miss. Number every node in order and keep its arguments, so renamed graphs match and swapped inputs do not.
ada13a8 to
7b0b8db
Compare
Summary
GraphModule, keyed from the exported program before decomposition.run_decompositionsandpost_loweringand rebuild the FX graph from a node list +state_dict(torch.save), nottorch.export.saveor FX__reduce__retrace.Test plan
tests/py/dynamo/models/test_lowering_cache.py