MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT-LLM / _create_constant_tensor

Method _create_constant_tensor

tensorrt_llm/parameter.py:103–132  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

101 return self._tensor
102
103 def _create_constant_tensor(self) -> Tensor:
104 if (self._value is not None and isinstance(self._value, np.ndarray)
105 and self._value.flags['C_CONTIGUOUS']):
106 lower_type = None
107 lower_shape = None
108 # workaround for reinterpreted data type
109 dtype = self._value.dtype
110 if (self.dtype == trt.fp4 or self.dtype
111 == trt.fp8) and (dtype == np.uint8 or dtype == np.int8
112 or dtype == np.int32 or dtype == np.int64):
113 lower_type = self.dtype
114 lower_shape = self.shape
115
116 self._value = constant(self._value, lower_type, lower_shape)
117 return self._value
118 elif self._value is None or isinstance(self._value, np.ndarray):
119 if self._dtype == trt.fp4:
120 shape = list(self._shape)
121 assert shape[
122 -1] % 16 == 0, "For FP4, the last dimension of the shape should be multiple of 16"
123 shape[-1] = shape[-1] // 16
124 dtype = np.int64
125 else:
126 shape = self._shape
127 dtype = trt_dtype_to_np(self._dtype)
128 ndarray = np.empty(shape, dtype)
129 tensor = constant(ndarray, self._dtype, self._shape)
130 default_net()._register_unfilled_weights(tensor.producer.name,
131 ndarray, self._value)
132 return tensor
133
134 def get_constant_tensor(self, network: Network) -> Tensor:
135 if self._network is None or self._network() != network:

Callers 1

get_constant_tensorMethod · 0.95

Calls 5

constantFunction · 0.85
trt_dtype_to_npFunction · 0.85
default_netFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected