Skip to main content

quantize_weights

Function quantize_weights 

Source
pub fn quantize_weights(
    weight: &Tensor,
    config: &BitNetConfig,
) -> Result<TernaryWeight>
Expand description

Quantize a weight tensor to ternary using AbsMean quantization.

§Algorithm

For each group of weights:

  1. Compute scale = mean(|W|)
  2. Compute W_q = round(W / scale) clamped to {-1, 0, +1}

§Arguments

  • weight - Input weight tensor [out_features, in_features]
  • config - BitNet configuration

§Errors

Returns error if weight has wrong shape or quantization fails.