veloxquant_mlx.core.context module¶
Data-carrying types shared across the quantization handler chain and quantizers.
QuantizationContext is the mutable payload passed between
QuantizationHandler stages (see veloxquant_mlx.handlers) as it is
encoded or decoded; EncodedVector is the typed, memory-accountable output
of Quantizer.encode(); TransformResult carries the per-level angles and
radius produced by a recursive polar transform. These dataclasses decouple the
handler pipeline and quantizer implementations from MLX’s array type via
lazy import.
- class veloxquant_mlx.core.context.QuantizationContext(x_original, mode, x_current, norm=None, rotated=None, indices=None, signs=None, residual_norm=None, angles=None, final_radius=None, outlier_idx=None, packed_bits=None, metadata=<factory>)[source]¶
Bases:
objectMutable payload flowing through a QuantizationHandler chain.
- Variables:
x_original – Original input vectors, shape (batch, d).
mode – Whether the chain is encoding or decoding.
x_current – Working copy mutated by each handler.
norm – L2 norm stored by NormalizationHandler, shape (batch,).
rotated – Vector after RotationHandler, shape (batch, d).
indices – Codebook indices, shape (batch, d) uint8.
signs – QJL sign bits, shape (batch, m) int8.
residual_norm – Residual L2 norm for QJL stage, shape (batch,).
angles – Per-level polar angles from PolarTransformHandler.
final_radius – Scalar radius after all polar levels, shape (batch,).
outlier_idx – Channel positions of outlier channels.
packed_bits – Bit-packed index array from BitPackingHandler.
metadata – Arbitrary stage-specific metadata.
- Parameters:
- class veloxquant_mlx.core.context.EncodedVector(quantizer_type, batch_size, dim, indices=None, norm=None, signs=None, residual_norm=None, angles=None, final_radius=None, outlier_idx=None, outlier_encoded=None, inlier_encoded=None)[source]¶
Bases:
objectTyped output of Quantizer.encode().
Different quantizer types populate different subsets of fields.
- Variables:
quantizer_type – Registry key of the producing quantizer.
batch_size – Number of vectors encoded.
dim – Original vector dimensionality.
indices – Scalar codebook indices, shape (batch, d) uint8.
norm – Per-vector L2 norm, shape (batch,) fp16.
signs – QJL sign bits, shape (batch, m) int8.
residual_norm – QJL residual norm, shape (batch,) fp16.
angles – PolarQuant level angles, list of (batch, d/2^ℓ) arrays.
final_radius – PolarQuant scalar radius, shape (batch,) fp16.
outlier_idx – Outlier channel indices for CompositeQuantizer.
outlier_encoded – Nested EncodedVector for outlier channels.
inlier_encoded – Nested EncodedVector for inlier channels.
- Parameters:
- outlier_encoded: EncodedVector | None = None¶
- inlier_encoded: EncodedVector | None = None¶
- class veloxquant_mlx.core.context.TransformResult(angles, final_radius, n_levels)[source]¶
Bases:
objectOutput of RecursivePolarTransform.forward().
- Variables:
angles – List of angle arrays, one per polar level. angles[0] has shape (batch, d/2), angles[ℓ] has shape (batch, d/2^(ℓ+1)).
final_radius – Scalar radius at the end of recursion, shape (batch,).
n_levels – Number of polar recursion levels applied.
- Parameters: