Repository navigation
Wrap the live ICudaEngine after compile instead of serialize/deserialize. - #4698
micwill755 wants to merge 2 commits into
Conversation
6bf067a to
5c19a17
Compare
7530ad3 to
89837ea
Compare
5c19a17 to
2f4ea21
Compare
89837ea to
2279546
Compare
2f4ea21 to
9ea49e1
Compare
2279546 to
f7d7e0d
Compare
9ea49e1 to
4373c3c
Compare
f7d7e0d to
262b042
Compare
|
This PR needs some work. I don't think it can be done before the branch cut. Can you do a benchmark for me first? Choose a few models and record:
I want to know the impact before moving forward with this PR. We meticulously designed the format of interpret_result and lowered the memory usage as much as possible, but this PR seems to mix it up. Also it mixes up the usage of Python Engine and C++ runtime engine as well. |
4373c3c to
4aba7b0
Compare
262b042 to
ca59adc
Compare
4aba7b0 to
9ad1869
Compare
ca59adc to
8f431ef
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.376567+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/moe.py 2026-10-06 21:35:33.397806+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.374567+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py 2026-10-06 21:35:37.467310+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)8f431ef to
5730e18
Compare
9ad1869 to
0a25deb
Compare
We still save the engine bytes for these three cases that need a copy outside this process: Windows cross-compile, torch.save, and engine caching. A normal compile only runs the engine here, so we keep the one TensorRT just built and skip the extra save-and-load. For the Klein NVFP4 cold compile, keeping the live engine instead of saving and reloading it at the end of convert_module cut the compile’s peak host memory from 13.42 GiB to 10.06 GiB, about 3.36 GiB less, while the peak GPU memory stayed at 11.38 GiB on both. |
5730e18 to
1555fdb
Compare
1555fdb to
6de7ef5
Compare
d05a422 to
9345e9d
Compare
6de7ef5 to
229c6f1
Compare
9345e9d to
b61b0d7
Compare
229c6f1 to
2ed7324
Compare
…ize. In-process convert_module keeps the builder engine and skips the bytes roundtrip. Cache, export, and save still serialize.
convert_module can keep the live engine, but the helper read serialize_engine without receiving it.
b61b0d7 to
37264fb
Compare
2ed7324 to
1c19630
Compare
| cuda_engine: Any = None | ||
|
|
||
|
|
||
| def _host_memory_to_bytes(serialized: Any) -> bytes: |
There was a problem hiding this comment.
A new function to just defer a call to plain bytes seems unnecessary.
Summary
build_engine_with_config, in-processconvert_modulewraps the liveICudaEngineinstead ofserialize()+ C++deserializeCudaEngine.interpret_module_to_result(..., serialize_engine=False)keepscuda_engineonSerializedInterpreterResult. Cache insert,convert_exported_program_to_serialized_trt_engine, andget_extra_state/ save still serialize from the live engine.TRTEngine.execute()until save/reload (C++ execute path needs bytes).ICudaEngine.serialize1.15s → 0,setup_engine2.40s → 0.001s, compile wall 36.95s → 33.17s. First image ~1.12s and steady ~0.43s unchanged.PR 10 of the compile-startup stack; based on #4693.
Type of change
Test plan
tests/py/dynamo/runtime/test_live_engine_wrap.py(compile tiny Add:serialized_engine is None, live wrap, cosine match,get_extra_stateserializes)torchtrt-213rc10): serialize 1.15s and setup_engine 2.40s gone; first image and steady unchangedChecklist
Stack created with GitHub Stacks CLI • Give Feedback 💬