MCPcopy
hub / github.com/NVIDIA/TensorRT-LLM / _set_layer_name

Method _set_layer_name

tensorrt_llm/network.py:253–299  ·  view source on GitHub ↗
(self, layer)

Source from the content-addressed store, hash-verified

251 return self._named_parameters
252
253 def _set_layer_name(self, layer):
254 original_layer_name = layer.name
255 layer_name = str(layer.type).split('.')[-1]
256 current_module = self._module_call_stack.get_current_module()
257
258 func_stack = []
259 frame = inspect.currentframe().f_back.f_back
260 while frame:
261 func_name = frame.f_code.co_name
262 line_num = frame.f_lineno
263 if func_name == "forward":
264 break
265 func_stack.insert(0, f"{func_name}_L{line_num}")
266 if len(func_stack) >= 10:
267 # NOTE: TRT error messages has a character limit.
268 # Limiting to only 10 levels helps retain
269 # the true error message from TRT.
270 break
271 frame = frame.f_back
272 current_module = f"{current_module}.{'.'.join(func_stack)}"
273
274 if layer.type == trt.LayerType.PLUGIN_V2:
275 layer_name = '_'.join(
276 [layer_name,
277 str(layer.plugin.plugin_type).split('.')[-1]])
278 elif layer.type in [
279 trt.LayerType.UNARY, trt.LayerType.REDUCE,
280 trt.LayerType.ELEMENTWISE
281 ]:
282 layer_name = '_'.join([layer_name, str(layer.op).split('.')[-1]])
283
284 layer.name = self._name_generator(layer_name, current_module)
285 for idx in range(layer.num_outputs):
286 # TRT initializes tensor names from the initial layer's name when the layer is created,
287 # and does not update tensor names when layer name changed by application, needs to
288 # change the tensor name to align with the new layer name for better debugging
289 layer.get_output(idx).name = f"{layer.name}_output_{idx}"
290 if original_layer_name != layer.name:
291 if layer.type == trt.LayerType.PLUGIN_V2:
292 plugin_info = get_plugin_info(self.trt_network,
293 original_layer_name)
294 if plugin_info is not None:
295 set_plugin_info(self.trt_network, layer.name, plugin_info)
296 delete_plugin_info(self.trt_network, original_layer_name)
297
298 # Set layer metadata to the same as the layer name so that it can show up in NVTX.
299 layer.metadata = layer.name
300
301 def register_ndarray(self, ndarray: np.ndarray) -> None:
302 ''' When the functional APIs need to create local numpy array and use as weights for constant or other layers,

Callers 1

_create_tensorFunction · 0.80

Calls 6

get_plugin_infoFunction · 0.85
set_plugin_infoFunction · 0.85
delete_plugin_infoFunction · 0.85
get_current_moduleMethod · 0.80
splitMethod · 0.45
get_outputMethod · 0.45

Tested by

no test coverage detected