Skip to content

Calibrated conversion, measured quantization, and release-integrity fixes - #1

Merged
classeve-public merged 1 commit into
mainfrom
calibrated-converter
Sep 8, 2026
Merged

classeve-public merged 1 commit into
mainfrom
calibrated-converter

Conversation

@classeve-public

Copy link
Copy Markdown
Contributor

Calibrated conversion, and the quantizer under measurement

rai convert --calibration-text <file> chooses each group's quantization
parameters from the activations a projection actually receives, not from the
range its weights span. Pure Rust, no GPU, no Python; same container and same
file size as the round-to-nearest path.

Measured on SmolLM2-1.7B (wikitext-2):

build perplexity agrees with the full model's next token
full precision 7.91 —
calibrated 4-bit 9.22 80.6%
round-to-nearest 4-bit (current) 10.30 75.4%

Greedy generations track the full model — same facts, coherent, no
degeneration; the round-to-nearest build's repetition and one wrong fact
(a city, a date) are gone. Details and the generations are in BENCHMARKS.md.

It reaches checkpoints the Python exporter refuses (projection biases among
them) and refuses, with a named reason, the ones it cannot yet reproduce
exactly (MoE routing, sandwich/post norms, per-head QK norms) rather than
quantizing against statistics from a model that behaves differently.

Also in this branch

  • rai perplexity and a paired top-K comparison against the full model; the
    first quantization-cost sweep in BENCHMARKS.md.
  • --group-size usable on 7B-class models (the kernel group cap became a
    validation bound); a dependency-free cargo bench --bench gemm.
  • Release integrity: archives build the inference product alone and a gate
    rejects any shipped binary carrying a TLS/HTTP stack; generated third-party
    attribution travels in every archive; the transformers-5 RoPE-base bug is
    fixed; the single conversion slot can no longer wedge; capacity limits are
    single-sourced and tested.

412 tests, clippy clean, byte-identity with the reference exporter preserved on
the uncalibrated path.

…ixes

Adds a calibrated path to `rai convert` and brings the quantizer's quality
under measurement for the first time, alongside a set of correctness and
release-integrity repairs found while doing so.

Calibrated conversion
- `rai convert --calibration-text <file>` chooses each group's quantization
  parameters from the activations the projection actually receives, not from
  the range its weights span. On SmolLM2-1.7B this is 9.22 perplexity against
  round-to-nearest's 10.30 at a byte-for-byte identical file, no GPU and no
  Python. It reaches architectures the Python exporter refuses (projection
  biases among them), and refuses — with a named reason — the ones it cannot
  yet reproduce exactly (MoE routing, sandwich/post norms, per-head QK norms)
  rather than quantizing against statistics from a model that behaves
  differently.

Measurement
- `rai perplexity`, a llama.cpp-compatible perplexity with per-token top-K
  records and standard errors; `scripts/reference_ppl.py` and
  `scripts/compare_topk.py` for a paired comparison against the full model.
- BENCHMARKS.md carries the sweep and the calibrated result, with generations
  shown so the behaviour is visible, not only the number.
- A dependency-free kernel benchmark, `cargo bench --bench gemm`.

Quantizer
- `--group-size` is usable on 7B-class models: the kernel group cap is a
  validation bound rather than a fixed working size, and per-row scratch scales
  with the group size the model uses.

Release integrity
- The archives build the inference product alone; a gate fails the build if any
  shipped binary carries a TLS or HTTP stack.
- Third-party attribution is generated from the shipped crate's own graph and
  travels in every archive; a license, advisory and source policy gates CI.
- The Python exporters read the RoPE base correctly on transformers 5 rather
  than defaulting it — a silent wrong-encoding bug on SmolLM2, Mistral and
  Llama-3.
- A conversion job can no longer wedge the single conversion slot; the
  container's capacity limits are single-sourced and tested; a yanked
  dependency is updated.
# throughout; see the TopKWriter doc comment in cli/perplexity.rs.
dump = None
if args.dump_topk:
dump = open(args.dump_path, "wb")
import json
import math
import struct
import sys
@classeve-public
classeve-public merged commit 2deb57f into main Sep 8, 2026
6 of 10 checks passed
@classeve-public
classeve-public deleted the calibrated-converter branch September 8, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants