Skip to main content

Quantize

Trait Quantize 

Source
pub trait Quantize<Q>: Send + Sync {
    // Required method
    fn quantize(&self, tensor: &Tensor, device: &Device) -> Result<Q>;
}
Expand description

Tensor quantization trait.

Converts full-precision tensors to quantized representation. Implementations may use various quantization schemes (NF4, FP4, ternary, etc.).

§Type Parameters

  • Q: The quantized tensor type (e.g., QuantizedTensor, TernaryVector)

§Example

use rust_ai_core::Quantize;

struct Nf4Quantizer;

impl Quantize<Nf4Tensor> for Nf4Quantizer {
    fn quantize(&self, tensor: &Tensor, device: &Device) -> Result<Nf4Tensor> {
        // Quantize to NF4 format
    }
}

Required Methods§

Source

fn quantize(&self, tensor: &Tensor, device: &Device) -> Result<Q>

Quantize a tensor.

§Arguments
  • tensor - Full-precision input tensor
  • device - Target device for the quantized output
§Returns

Quantized representation of the input tensor.

§Errors

May return errors for unsupported dtypes, shapes, or device issues.

Implementors§