Skip to content

Commit fabff45

Browse files
Lluo/cherry pick 4342 (#4410)
Co-authored-by: cehongwang <wangcehong@gmail.com>
1 parent 16d94f3 commit fabff45

14 files changed

Lines changed: 79 additions & 689 deletions

File tree

docsrc/tutorials/runtime_opt/python_runtime.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ produced outside Torch-TensorRT):
130130
``settings`` (:class:`~torch_tensorrt.dynamo._settings.CompilationSettings`, optional)
131131
Device and runtime options (must match how the engine was built).
132132

133-
``weight_name_map`` (``dict``, optional)
134-
Mapping of TRT weight names to PyTorch state dict names. Required for refit
135-
support via :func:`~torch_tensorrt.dynamo.refit_module_weights`.
136-
137133
``requires_output_allocator`` (``bool``, default ``False``)
138134
Set to ``True`` if the engine contains data-dependent-shape ops (``nonzero``,
139135
``unique``, etc.) that require TRT's output allocator.

docsrc/tutorials/weight_refit/refit.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ API
8888
arg_inputs=None,
8989
kwarg_inputs=None,
9090
verify_output=False,
91-
use_weight_map_cache=True,
9291
in_place=False,
9392
)
9493
@@ -114,12 +113,6 @@ API
114113
PyTorch on the provided sample inputs. Useful for catching silent refit failures
115114
during development.
116115

117-
``use_weight_map_cache`` (``bool``, default ``True``)
118-
When torch-tensorrt programs are compiled, the TRTIntpereter builds a map of which
119-
exported program nodes correspond to which TensorRT layers. This mapping is stored as metadata in serialized
120-
torch-tensorrt programs. This cache is not gaurenteed to be an exact match but to a new
121-
unseen exported program but when it does, it reduces refit time by ~50%.
122-
123116
``in_place`` (``bool``, default ``False``)
124117
If ``True``, modify the compiled module in-place rather than returning a copy.
125118
Not supported for ``ExportedProgram`` inputs (use the returned module instead).

examples/dynamo/refit_engine_example.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,15 @@
114114
#
115115
# There are a number of settings you can use to control the refit process
116116
#
117-
# Weight Map Cache
117+
# Output Verification
118118
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119119
#
120120
# Weight refitting works by matching the weights of the compiled module with the new weights from
121-
# the user supplied ExportedProgram. Since 1:1 name matching from PyTorch to TensorRT is hard to accomplish,
122-
# the only gaurenteed way to match weights at *refit-time* is to pass the new ExportedProgram through the
123-
# early phases of the compilation process to generate near identical weight names. This can be expensive
124-
# and is not always necessary.
121+
# the user supplied ExportedProgram. To do this, the new ExportedProgram is passed through the early
122+
# phases of the compilation process to generate near identical weight names, which are then used to
123+
# refit the existing TensorRT engine in place without rebuilding it.
125124
#
126-
# To avoid this, **At initial compile**, Torch-TensorRt will attempt to cache a direct mapping from PyTorch
127-
# weights to TensorRT weights. This cache is stored in the compiled module as metadata and can be used
128-
# to speed up refit. If the cache is not present, the refit system will fallback to rebuilding the mapping at
129-
# refit-time. Use of this cache is controlled by the ``use_weight_map_cache`` parameter.
130-
#
131-
# Since the cache uses a heuristic based system for matching PyTorch and TensorRT weights, you may want to verify the refitting. This can be done by setting
125+
# You may want to verify the refitting. This can be done by setting
132126
# ``verify_output`` to True and providing sample ``arg_inputs`` and ``kwarg_inputs``. When this is done, the refit
133127
# system will run the refitted module and the user supplied module on the same inputs and compare the outputs.
134128
#

py/torch_tensorrt/dynamo/_engine_cache.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
List[str],
2525
Sequence[Input],
2626
CompilationSettings,
27-
Optional[Dict[str, Any]],
2827
bool,
2928
bool,
3029
]
@@ -108,19 +107,17 @@ def pack(
108107
output_names: List[str],
109108
input_specs: Sequence[Input],
110109
compilation_settings: CompilationSettings,
111-
weight_name_map: Optional[Dict[Any, Any]],
112110
requires_output_allocator: bool,
113111
requires_native_multidevice: bool,
114112
) -> bytes:
115-
"""Pack serialized engine, input names, output names, and weight map into a single blob
113+
"""Pack serialized engine, input names, and output names into a single blob
116114
117115
Args:
118116
serialized_engine (bytes): serialized TRT engine
119117
input_names (List[str]): input names of TRT engine
120118
output_names (List[str]): output names of TRT engine
121119
input_specs (Sequence[Input]): input specs of TRT engine
122120
compilation_settings (CompilationSettings): compilation settings of TRT engine
123-
weight_name_map (Optional[Dict[Any, Any]]): weight name map for refitting
124121
requires_output_allocator (bool): Boolean flag indicating if the converter creates operators which require an Output Allocator to run (e.g. data dependent operators)
125122
requires_native_multidevice (bool): Boolean flag indicating if the converter creates operators which require multiple devices to run (e.g. multi-device collective operations)
126123
Returns:
@@ -135,21 +132,20 @@ def pack(
135132
"output_names": output_names,
136133
"input_specs": input_specs,
137134
"compilation_settings": settings,
138-
"weight_name_map": weight_name_map,
139135
"requires_output_allocator": requires_output_allocator,
140136
"requires_native_multidevice": requires_native_multidevice,
141137
}
142138
)
143139

144140
@staticmethod
145141
def unpack(packed_obj: bytes) -> UnpackedCacheHit:
146-
"""Unpack packed blob into serialized engine, input names, output names, and weight map
142+
"""Unpack packed blob into serialized engine, input names, and output names
147143
148144
Args:
149145
packed_obj (bytes): packed blob
150146
151147
Returns:
152-
Tuple[bytes, List[str], List[str], Sequence[Input], CompilationSettings, Optional[Dict[str, Any]]]: serialized engine, input names, output names, input specs, CompilationSettings, weight name map
148+
Tuple[bytes, List[str], List[str], Sequence[Input], CompilationSettings, bool, bool]: serialized engine, input names, output names, input specs, CompilationSettings, requires_output_allocator, requires_native_multidevice
153149
"""
154150
unpacked = pickle.loads(packed_obj)
155151
return (
@@ -158,7 +154,6 @@ def unpack(packed_obj: bytes) -> UnpackedCacheHit:
158154
unpacked["output_names"],
159155
unpacked["input_specs"],
160156
unpacked["compilation_settings"],
161-
unpacked["weight_name_map"],
162157
unpacked["requires_output_allocator"],
163158
unpacked.get("requires_native_multidevice", False),
164159
)

0 commit comments

Comments
 (0)