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

Method register_ndarray

tensorrt_llm/network.py:301–308  ·  view source on GitHub ↗

When the functional APIs need to create local numpy array and use as weights for constant or other layers, they need to register the ndarray objects to the TRT-LLM Network to prolong the lifetime of the ndarray, such that weights are still valid when functional API returned.

(self, ndarray: np.ndarray)

Source from the content-addressed store, hash-verified

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,
303 they need to register the ndarray objects to the TRT-LLM Network to prolong the lifetime of the ndarray, such that weights are
304 still valid when functional API returned.
305 All the weights referenced by the trt Network are weak referenced, it's TRT-LLM's responsibility to keep the weights alive
306 during the TRT network construction and TRT engine building process.
307 '''
308 self._registered_ndarrays.append(ndarray)
309
310 def _generate_optimization_profiles(self) -> List[trt.IOptimizationProfile]:
311 input_tensors = self._inputs

Callers 2

_fill_weightsMethod · 0.95
constantFunction · 0.80

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected