latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.quantize_per_tensor
- tensorplay.functional.quantize_per_tensor(input, scale, zero_point, dtype) Tensor[source]
Converts a float tensor to a quantized tensor with given scale and zero point.
- Parameters:
input (Tensor) – float tensor or list of tensors to quantize
scale (float or Tensor) – scale to apply in quantization formula
zero_point (int or Tensor) – offset in integer value that maps to float zero
dtype (
tensorplay.dtype) – the desired data type of returned tensor. Has to be one of the quantized dtypes:tensorplay.quint8,tensorplay.qint8,tensorplay.qint32
- Returns:
A newly quantized tensor or list of quantized tensors.
- Return type:
Example:
>>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, tensorplay.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.1, zero_point=10) >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), 0.1, 10, tensorplay.quint8).int_repr() tensor([ 0, 10, 20, 30], dtype=tensorplay.uint8) >>> tensorplay.quantize_per_tensor([tensorplay.tensor([-1.0, 0.0]), tensorplay.tensor([-2.0, 2.0])], >>> tensorplay.tensor([0.1, 0.2]), tensorplay.tensor([10, 20]), tensorplay.quint8) (tensor([-1., 0.], size=(2,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.1, zero_point=10), tensor([-2., 2.], size=(2,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.2, zero_point=20)) >>> tensorplay.quantize_per_tensor(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), tensorplay.tensor(0.1), tensorplay.tensor(10), tensorplay.quint8) tensor([-1., 0., 1., 2.], size=(4,), dtype=tensorplay.quint8, quantization_scheme=tensorplay.per_tensor_affine, scale=0.10, zero_point=10)
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

