TensorId
PythonTensorId = strTensorId = strAIR tensor representation.
AirTensor()AIR tensor representation.
id: TensorId = Field(..., description='Unique tensor identifier')kind: AirTensorKind = Field(AirTensorKind.SCRATCH, description='The kind of tensor')quantization: AirQuantizationParameters | None = Field(default_factory=AirQuantizationParameters, description='Quantization parameters for the tensor')sparsity: AirSparsityParameters | None = Field(default_factory=AirSparsityParameters, description='Sparsity parameters for the tensor')buffer_index: int | None = Field(None, description='Index of the buffer this tensor is mapped to')local_name: str | None = Field(None, description='Local name for the tensor')shape_signature: tuple[int, ...] | None = Field(None, description='Shape signature of the tensor')has_rank: bool = Field(False, description='Indicates if the tensor has a rank')alias_of: TensorId | None = Field(None, description='Optional alias for this tensor')alignment_hint: int | None = Field(None, description='Alignment hint for the tensor in bytes')shape: tuple[int, ...]dtype: np.dtypeReturn the data of the tensor.
data: npt.NDArray | NoneReturn the data of the tensor.
Quantization parameters, which must carry a scale.
quant: AirQuantizationParametersQuantization parameters, which must carry a scale.
quantization is Optional so a tensor can carry none; kernels that
require quantized inputs read through this view and get a typed error
naming the tensor instead of an attribute access on None. A tensor
with no scale, such as one with only a min/max range, is unquantized,
as LiteRT’s kernels read it.
Whether kernels read this tensor through its quantization.
is_quantized: boolWhether kernels read this tensor through its quantization.
Only an int8, uint8 or int16 tensor with a scale is. Any other tensor, such as a float tensor carrying a calibration range or a scale and zero point, is unquantized whatever it carries, as LiteRT’s kernels read it.
The stored value of a real 0: the first zero point of a quantized tensor, and 0 for any other.
stored_zero_point: intThe stored value of a real 0: the first zero point of a quantized tensor, and 0 for any other.
Return the size of the tensor.
size: intReturn the size of the tensor.
Return the number of bytes in the tensor.
nbytes: intReturn the number of bytes in the tensor.
Return the number of dimensions of the tensor.
ndim: intReturn the number of dimensions of the tensor.
Check if the tensor is a constant.
is_constant: boolCheck if the tensor is a constant.
Check if the tensor is a persistent variable.
is_persistent: boolCheck if the tensor is a persistent variable.
Check if the tensor is a scratch tensor.
is_scratch: boolCheck if the tensor is a scratch tensor.
Id that memory.tensors rules match: the source id for a repacked copy.
placement_id: TensorIdId that memory.tensors rules match: the source id for a repacked copy.
name: strReturn the C type of the tensor.
ctype: strReturn the C type of the tensor.
This is used for generating C code that operates on the tensor. For example, if the tensor is of type int16, the C type will be int16_t.
Return the alignment floor based on the tensor's dtype.
dtype_alignment_floor: intReturn the alignment floor based on the tensor’s dtype.
The zero point at index of a quantized tensor, and 0 for any other tensor or a missing entry.
quantized_zero_point(index: int = 0) -> intThe zero point at index of a quantized tensor, and 0 for any other tensor or a missing entry.
Reject a scale without a zero point, which LiteRT refuses to load whatever the dtype.
require_zero_point() -> NoneReject a scale without a zero point, which LiteRT refuses to load whatever the dtype.
Raises
| Type | Description |
|---|---|
MissingQuantizationError | If the tensor carries a scale and no zero point. |
Return a NHWC padded shape tuple, padding missing axes with 1.
get_shape_nhwc(pre: bool = True) -> tuple[int, int, int, int]Return a NHWC padded shape tuple, padding missing axes with 1.
Raises
| Type | Description |
|---|---|
ConfigValueError | If the tensor has more than four dimensions. |
get_shape_with_axis_expanded(axis: int) -> tuple[int, ...]