TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay.functional.quantize_per_tensor_dynamic

tensorplay.functional.quantize_per_tensor_dynamic(input, dtype, reduce_range) → Tensor[source]

Converts a float tensor to a quantized tensor with scale and zero_point calculated dynamically based on the input.

Parameters:
  • input (Tensor) – float tensor or list of tensors to quantize

  • dtype (tensorplay.dtype) – the desired data type of returned tensor. Has to be one of the quantized dtypes: tensorplay.quint8, tensorplay.qint8

  • reduce_range (bool) – a flag to indicate whether to reduce the range of quantized

  • bit (data by 1)

  • hardwares (it's required to avoid instruction overflow for some)

Returns:

A newly (dynamically) quantized tensor

Return type:

Tensor

Example:

>>> t = tensorplay.quantize_per_tensor_dynamic(tensorplay.tensor([-1.0, 0.0, 1.0, 2.0]), tensorplay.quint8, False)
>>> print(t)
tensor([-1.,  0.,  1.,  2.], size=(4,), dtype=tensorplay.quint8,
       quantization_scheme=tensorplay.per_tensor_affine, scale=0.011764705882352941,
       zero_point=85)
>>> t.int_repr()
tensor([  0,  85, 170, 255], dtype=tensorplay.uint8)

On this page

Ask DeepWiki