Views
No views yet
d ∈ {1, 2, 3, 4} (3, 9, 27, 81 levels per weight) with no calibration data and no per-model tuning. Output is dequantized FP16 safetensors that load into stock transformers and lm-eval without a custom loader.lm_head (output projection)embed_tokens)*_norm layers (RMSNorm, LayerNorm — these are 1D anyway)1pip install torch transformers safetensors numpy huggingface_hub
2git clone https://huggingface.co/Entrit/tritllm-codec
3cd tritllm-codec1# Quantize Qwen2.5-7B at uniform depth d=2 (3.47 bpw)
2python quantize_model_v2.py \
3 --model Qwen/Qwen2.5-7B \
4 --configs uniform-d2 \
5 --out ./out
6
7# Multi-config single pass (computes scales once, derives 6 configs)
8python quantize_model_v2.py \
9 --model Qwen/Qwen2.5-7B \
10 --configs uniform-d1,uniform-d2,uniform-d3,uniform-d4,d3scale-sens002,d3scale-sens003 \
11 --out ./outout/
uniform-d2/
model/
config.json
model.safetensors # dequantized FP16
tokenizer.json
...1from transformers import AutoModelForCausalLM, AutoTokenizer
2m = AutoModelForCausalLM.from_pretrained("./out/uniform-d2/model")
3t = AutoTokenizer.from_pretrained("./out/uniform-d2/model")| Parameter | Value | Notes |
|---|---|---|
Group size G | 16 | Per Section 6.1 of the paper, gs=64 is also viable; gs=16 gives best PPL |
Scale depth d_s | 3 | 27-entry log-spaced codebook per matrix |
| Power mapping | d1=1.0, d2=1.5, d3=1.2, d4=1.0 | Tuned once on Qwen2.5-7B, held fixed for all subsequent models |
| Scale candidates | indices [G-6, G-4, G-2, G-1] of sorted |w| | MSE-minimum over the 4 candidates is selected per group |
| Scale codebook range | log_min = 0.1th percentile of group |w|-maxes, log_max = max | Fixed in commit 0c16d24 (was 99.9th percentile, which clipped) |
lm_head, embeddings, norms | kept FP16 | See "What gets quantized" above |
bpw = (d * log2(3) + d_s * log2(3) / G) / 1 # weights + scales only
= d * 1.585 + 0.297 # for G=16, d_s=3--revision <git-sha> to pin the source model — without it the upstream HF repo can move under you between runs.(model, revision, codec version, group size, depth-power mapping) and the matrix shape. On resume, mismatched checkpoints are discarded and re-quantized rather than silently mixed.assembled config.json records the full fingerprint so you can verify which source model and codec version produced any given output.log_max = max(...) codebook upper bound. Both are intentional choices; the file explains the reasoning and what to look for in new model families.@article{stentzel2026ternaryptq,
title = {Balanced Ternary Post-Training Quantization for Large Language Models},
author = {Stentzel, Eric},
year = 2026,
note = {Entrit Systems}
}