You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[2.16] Consolidate C++ TRTEngine construction on the zero-copy path #4883
Follow-up to the compile-memory stack (#4794, #4795, #4796), scheduled for 2.16.
#4794 added a zero-copy way to build the C++ runtime engine: torch.classes.tensorrt.Engine.from_engine_tensor(info, plan_tensor) reads the TensorRT plan in place from a uint8 CPU tensor. The older construction paths are still there, so we now have several ways to create a TRTEngine that differ only in how the plan is passed in:
C++ constructors (core/runtime/TRTEngine.h)
TRTEngine(const std::string& serialized_engine, const RTDevice&, in/out binding names, ...): used by the TorchScript path (core/compiler.cpp:44)
TRTEngine(std::vector<std::string> serialized_info): TorchBind __init__ and the pickle __setstate__ (core/runtime/register_jit_hooks.cpp:220)
TRTEngine(const std::vector<std::string>& serialized_info, std::string_view serialized_engine): used by from_engine_tensor
TRTEngine(const std::string& mod_name, std::string_view serialized_engine, const RTDevice&, ...): the one the others delegate to
Engine(info): plan inside the std::vector<std::string>, copied twice on the way in
Engine.from_engine_tensor(info, plan_tensor): zero copy
Python (py/torch_tensorrt/dynamo/runtime/_serialized_engine_layout.py, create_cpp_engine) chooses between the two: Engine(info) when the plan is a str or empty, from_engine_tensor otherwise.
Since the zero-copy path covers every case, the other paths only add surface area and a way to reintroduce plan-sized copies.
Proposal
Make the std::string_view constructor the single real constructor, and have every caller (TorchScript compiler.cpp, pickle __setstate__, ExecuTorch backend) pass a view of a plan it already holds.
Expose one TorchBind constructor that takes the plan as a tensor (or make __init__ accept it) and remove the copying Engine(info) path from create_cpp_engine, keeping backward compatibility for serialized artifacts that store the plan inside serialized_info.
Activity