torch_to_nnef.compress
Compression module mostly used as demonstration purpose.
Examplify: how to implement quantization
Functions:
| Name | Description |
|---|---|
dynamic_load_registry |
Load a registry dynamically based on it's module path + dict name. |
offloaded_tensor_qtensor |
Maintains a QTensor offloaded if original tensor is offloaded. |
quantize_weights_ggml_IQ2_S |
Example of quantization function for a model to IQ2_S. |
quantize_weights_ggml_Q4_K |
Example of quantization function for a model to Q4_K. |
quantize_weights_ggml_Q5_K |
Example of quantization function for a model to Q5_K. |
quantize_weights_ggml_Q6_K |
Example of quantization function for a model to Q6_K. |
quantize_weights_min_max_Q4_0 |
Example of quantization function for a model to Q40. |
quantize_weights_min_max_Q4_0_with_experts |
Q4_0 for Linear and Embedding weights and for fused MoE experts. |
quantize_weights_min_max_Q8_0 |
Example of quantization function for a model to Q8_0. |
quantize_weights_min_max_Q8_1 |
Example of quantization function for a model to Q8_1. |
dynamic_load_registry
Load a registry dynamically based on it's module path + dict name.
offloaded_tensor_qtensor
Maintains a QTensor offloaded if original tensor is offloaded.
quantize_weights_ggml_IQ2_S
Example of quantization function for a model to IQ2_S.
Uses the ggml reference quantizer (grid nearest neighbour search with
a weighted scale fit, no importance matrix).
tract only supports IQ2_S weights for embedding/gathering operations
so only nn.Embedding (or subclasses) can be quantized.
quantize_weights_ggml_Q4_K
Example of quantization function for a model to Q4_K.
Uses the ggml reference quantizer (make_qkx2_quants search per
sub-block, no importance matrix).
tract only supports Q4_K weights for embedding/gathering operations
so only nn.Embedding (or subclasses) can be quantized.
quantize_weights_ggml_Q5_K
Example of quantization function for a model to Q5_K.
Uses the ggml reference quantizer (make_qkx2_quants search per
sub-block, no importance matrix).
tract only supports Q5_K weights for embedding/gathering operations
so only nn.Embedding (or subclasses) can be quantized.
quantize_weights_ggml_Q6_K
Example of quantization function for a model to Q6_K.
Uses the ggml reference quantizer (make_qx_quants search per
sub-block, no importance matrix).
tract only supports Q6_K weights for embedding/gathering operations
so only nn.Embedding (or subclasses) can be quantized.
quantize_weights_min_max_Q4_0
Example of quantization function for a model to Q40.
quantize_weights_min_max_Q4_0_with_experts
Q4_0 for Linear and Embedding weights and for fused MoE experts.
Linear and Embedding weights are quantized as in
min_max_q4_0_with_embeddings, except MoE routers (including shared
expert gates), whose weights stay in floating point. Fused expert weights
are not nn.Linear modules, so every MoE block handled by the
tract_moe_ffn extractor is marked instead: its experts are quantized
to Q4_0 min-max during extraction, in the linear layout. Q4_0 blocks
run along the reduction axis as tract's matmul kernels expect. A model
without such a block gets the min_max_q4_0_with_embeddings result.
quantize_weights_min_max_Q8_0
Example of quantization function for a model to Q8_0.
tract only supports Q8_0 weights for embedding/gathering operations
so only nn.Embedding (or subclasses) can be quantized.
Requires tract >= 0.23.10.