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

Class Tensor

tensorrt_llm/functional.py:107–602  ·  view source on GitHub ↗

The class to represent dense tensors. A dense tensor is named, has a shape and contains typed elements. Each dimension of a tensor can either be static or dynamic. Static dimensions are known at engine compilation by TensorRT. Dynamic dimensions can take values determined at ru

Source from the content-addressed store, hash-verified

105
106
107class Tensor(object):
108 '''
109 The class to represent dense tensors.
110
111 A dense tensor is named, has a shape and contains typed elements. Each
112 dimension of a tensor can either be static or dynamic. Static dimensions
113 are known at engine compilation by TensorRT. Dynamic dimensions can take
114 values determined at runtime. The tensor can be located on the host (CPU)
115 or the device (GPU).
116 '''
117
118 def __init__(self,
119 name=None,
120 dtype=None,
121 shape=None,
122 dim_range=None,
123 is_network_input=True,
124 location=trt.TensorLocation.DEVICE,
125 network=None,
126 trt_tensor=None):
127 '''
128 Parameters:
129 name : str
130 The name of the tensor.
131
132 dtype : tensorrt.DataType
133 The type of the elements of the tensor. See the TensorRT
134 documentation for list of supported data types.
135
136 shape : tensorrt.Dims
137 The dimensions of the tensor. In TensorRT-LLM, tensors can have
138 static or dynamic dimensions (it is possible to mix static and
139 dynamic dimensions). A static dimension is known when the
140 TensorRT engine is built. A dynamic dimension can be set when
141 the engine is executed. Use -1 for dynamic dimensions.
142
143 dim_range : OrderedDict
144 An ordered dictionary (the positions of the elements matter)
145 that associates a name and a range of values to the dimensions.
146 For a static dimension, the range must be limited to a single
147 value. For a dynamic dimension, the range is defined by three
148 values [min, opt, max] where min and max are, respectively, the
149 smallest and largest possible values of that dimension. The
150 opt value is used by TensorRT to optimize the engine for the
151 most common case.
152
153 Assume there is N optimization profiles, each item dim_range dict is ordered by:
154 (dynamic dimension name : [profile 0 (min, opt, max), profile 1 (min, opt, max), ... profile N(min, opt, max)])
155 or it's following when the dimension is static (can think as min==opt==max):
156 (static dimension name : [profile 0 value, profile 1 value, ... profile N value])
157 For static dimension the profile 0-N value must be same, (TODO: can it be simplified to be only 1 value?)
158 And number of keys is equal to number of optimization profiles.
159
160 is_network_input : bool
161 A boolean indicating if that tensor is an input of the network.
162 Inputs must be provided by the user to run the engine.
163
164 location : tensorrt.TensorLocation

Callers 15

_construct_executionMethod · 0.90
_construct_executionMethod · 0.90
_construct_executionMethod · 0.90
build_engineMethod · 0.90
_construct_executionMethod · 0.90
_sq_gemmMethod · 0.90
_fp8_rowwise_gemmMethod · 0.90
test_mlp_smooth_quantMethod · 0.90

Calls

no outgoing calls

Tested by 15

_construct_executionMethod · 0.72
_construct_executionMethod · 0.72
_construct_executionMethod · 0.72
build_engineMethod · 0.72
_construct_executionMethod · 0.72
_sq_gemmMethod · 0.72
_fp8_rowwise_gemmMethod · 0.72
test_mlp_smooth_quantMethod · 0.72