Skip to content

tools: requantization script and perplexity harness - #685

Merged
inureyes merged 1 commit into
mainfrom
tools/683-requant-and-perplexity
Jul 7, 2026
Merged

inureyes merged 1 commit into
mainfrom
tools/683-requant-and-perplexity

Conversation

@inureyes

@inureyes inureyes commented Jul 7, 2026

Copy link
Copy Markdown
Member

Lands the two tools behind issue #683 steps 2 and 3 (refs #683, does not close it).

scripts/requantize_mlp.py: rewrites a checkpoint's 8-bit affine module overrides down to 4-bit with pure-numpy raw safetensors I/O (bf16 as uint16, u32 low-first packing, q computed against bf16-rounded scales/biases so the stored triples are self-consistent). Supports --target-group-size 32 and a --match regex to requantize only selected modules (e.g. keep down_proj at 8-bit), updating config quantization overrides accordingly. The uniform 4-bit gemma-4-12b variant it produced measured 1.59 to 1.62x decode with 3.6 GB lower peak on GB10 (numbers on the issue).

examples/perplexity.rs: exact teacher-forced next-token NLL over a fixed text file, chunked with fresh KV caches, for comparing quantization variants of the same model (the quality gate the greedy smoke prompts cannot provide).

Tool-only change: no library or runtime code is touched.

Refs #683

scripts/requantize_mlp.py rewrites a checkpoint's 8-bit affine module overrides to 4-bit (optional group_size 32 and module-name regex filter) with pure-numpy raw safetensors I/O, enabling quantization variants for the #683 quality/throughput frontier; the uniform 4-bit gemma-4-12b variant it produced measured 1.59 to 1.62x decode on GB10. examples/perplexity.rs computes exact teacher-forced next-token NLL over a fixed text so those variants can be quality-gated beyond greedy smoke prompts.
@inureyes inureyes added type:performance Performance improvements area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Jul 7, 2026
@inureyes
inureyes merged commit fcd60cf into main Jul 7, 2026
4 checks passed
@inureyes
inureyes deleted the tools/683-requant-and-perplexity branch July 7, 2026 06:21
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added the status:done Completed label Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…lup#685)

scripts/requantize_mlp.py rewrites a checkpoint's 8-bit affine module overrides to 4-bit (optional group_size 32 and module-name regex filter) with pure-numpy raw safetensors I/O, enabling quantization variants for the lablup#683 quality/throughput frontier; the uniform 4-bit gemma-4-12b variant it produced measured 1.59 to 1.62x decode on GB10. examples/perplexity.rs computes exact teacher-forced next-token NLL over a fixed text so those variants can be quality-gated beyond greedy smoke prompts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:inference Generation, sampling, decoding (incl. speculative, DRY) status:done Completed type:performance Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant