Trait burn_tensor::ops::QTensorOps

source ·
pub trait QTensorOps<B: Backend> {
    // Required methods
    fn q_from_data<const D: usize>(
        data: TensorData,
        device: &Device<B>,
    ) -> QuantizedTensor<B, D>;
    fn quantize<const D: usize>(
        tensor: FloatTensor<B, D>,
        scheme: &QuantizationScheme,
        qparams: QuantizationParametersPrimitive<B>,
    ) -> QuantizedTensor<B, D>;
    fn dequantize<const D: usize>(
        tensor: QuantizedTensor<B, D>,
    ) -> FloatTensor<B, D>;
    fn q_shape<const D: usize>(tensor: &QuantizedTensor<B, D>) -> Shape<D>;
    fn q_device<const D: usize>(tensor: &QuantizedTensor<B, D>) -> Device<B>;
    fn q_reshape<const D1: usize, const D2: usize>(
        tensor: QuantizedTensor<B, D1>,
        shape: Shape<D2>,
    ) -> QuantizedTensor<B, D2>;
    fn q_into_data<const D: usize>(
        tensor: QuantizedTensor<B, D>,
    ) -> impl Future<Output = TensorData> + Send;

    // Provided methods
    fn q_set_require_grad<const D: usize>(
        tensor: QuantizedTensor<B, D>,
        _require_grad: bool,
    ) -> QuantizedTensor<B, D> { ... }
    fn q_is_require_grad<const D: usize>(
        _tensor: &QuantizedTensor<B, D>,
    ) -> bool { ... }
}
Expand description

Quantized Tensor API for basic operations, see tensor for documentation on each function.

Required Methods§

source

fn q_from_data<const D: usize>( data: TensorData, device: &Device<B>, ) -> QuantizedTensor<B, D>

Creates a new tensor from the data structure.

§Arguments
  • data - The data structure.
  • device - The device to create the tensor on.
§Returns

The tensor with the given data.

source

fn quantize<const D: usize>( tensor: FloatTensor<B, D>, scheme: &QuantizationScheme, qparams: QuantizationParametersPrimitive<B>, ) -> QuantizedTensor<B, D>

Convert the tensor to a lower precision data type based on the quantization scheme and parameters.

source

fn dequantize<const D: usize>( tensor: QuantizedTensor<B, D>, ) -> FloatTensor<B, D>

Convert the tensor back to a higher precision data type.

source

fn q_shape<const D: usize>(tensor: &QuantizedTensor<B, D>) -> Shape<D>

Gets the shape of the tensor.

§Arguments
  • tensor - The tensor.
§Returns

The shape of the tensor.

source

fn q_device<const D: usize>(tensor: &QuantizedTensor<B, D>) -> Device<B>

Gets the device of the tensor.

§Arguments
  • tensor - The tensor.
§Returns

The device of the tensor.

source

fn q_reshape<const D1: usize, const D2: usize>( tensor: QuantizedTensor<B, D1>, shape: Shape<D2>, ) -> QuantizedTensor<B, D2>

Reshapes a tensor.

§Arguments
  • tensor - The tensor to reshape.
  • shape - The new shape of the tensor.
§Returns

The tensor with the new shape.

source

fn q_into_data<const D: usize>( tensor: QuantizedTensor<B, D>, ) -> impl Future<Output = TensorData> + Send

Converts the tensor to a data structure.

§Arguments
  • tensor - The tensor.
§Returns

The data structure with the tensor’s data.

Provided Methods§

source

fn q_set_require_grad<const D: usize>( tensor: QuantizedTensor<B, D>, _require_grad: bool, ) -> QuantizedTensor<B, D>

Sets the require_grad flag of a tensor.

source

fn q_is_require_grad<const D: usize>(_tensor: &QuantizedTensor<B, D>) -> bool

Returns the require_grad flag of a tensor.

Object Safety§

This trait is not object safe.

Implementors§