lfm3: round 6 - GPTQ INT4 baked (INT4 lm_head + INT8 embedding)

- quant/gptq_baked/: llm-compressor GPTQ W4A16 body (sequential pipeline, verified
  equal to the plain forward), B65-style GPTQ INT4 lm_head bake with a small
  damp/act-order/clipping grid, INT8 per-row embedding, assembly into one
  compressed-tensors checkpoint (1.155 GB vs 3.46 GB BF16)
- plugin: pass quant_config to the token embedding so vLLM's compressed-tensors
  INT8 embedding path is used; BF16/FP8 greedy output unchanged
- tests: INT8 embedding kernel check, quant method dump, head timing, round-6 driver
- NOTES: round 6 results (PPL +8.1%, decode 217 t/s = FP8 pc +14%, head bake
  gives no measurable decode gain on this stack), llama-swap snippet (not applied)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-30 14:48:48 +01:00
1 parent 1115927570
commit 38b0e9a345
110 files changed
+118917 -3

No files matched your search

+174
View File
@@ -982,3 +982,177 @@ Phase 2 (video) not started — waiting for your OK.
Backup of the previous config: /etc/llama-swap/config.yaml.bak-pre-lfm3-vl. Verified via :8080: watch-reload clean,
cold start 2m46s, `XPUW8A16FP8LinearKernel` for `Fp8PtpcOnlineLinearMethod`, weights 2.24 GiB, newspaper photo →
"The New York Times", "MEN WALK ON MOON"; alias `lfm3-1.7b` → "17*23" = 391.
## Round 6 — GPTQ INT4 baked + INT8 embed (2026-10-30)
Goal: `LFM3-1.7B-GPTQ-Int4-baked-v1-embed-int8` after the recipe of Wrapzii/Swift-1.5-Qwen3.8-27b-GPTQ-Int4-baked-v1-embed-int8
(itself after Launch80/Qwen3.8-27B-GPTQ-Int4-baked): GPTQ INT4 body, GPTQ INT4 lm_head stored on disk, INT8 embedding.
Branch `lfm3-round6-gptq-baked`, scripts in `quant/gptq_baked/`, image `lfm3-vllm-xpu:v0.32.0-lfm3-baked`.
Checkpoint: `/models/LFM3-1.7B-GPTQ-Int4-baked-v1-embed-int8` (the model library is mounted read-only, see the end of this section).
### Step 0 — reference recipe
| | Launch80 (v1/v2) | Wrapzii (Swift 1.5) |
|---|---|---|
| body | GPTQ INT4 (GPTQModel 7.3.2: sym, g128, desc_act false, act_group_aware, damp 0.05), from SergiioB / MikeCaldera | **AutoRound** INT4 g128 sym (UkisAI), GPTQ metadata + g_idx added |
| lm_head + 8 MTP linears | GPTQ INT4 sym g128, no act-order, damp 1%, Hessian Σxᵀx of the lm_head input captured *in vLLM* with the INT4 body (256 wikitext prompts × 128 generated tok), every 64th row held out | same tool (B65 `bake_gptq_resume.py`), 128 × 384-token wikitext prompts + 64 generated, TP2 |
| storage | GPTQ `qweight [K/8,N]`, fp16 scales, qzeros 0x77777777, g_idx k//128; separate `model-bake-int4.safetensors`; dense tensors removed; `lm_head: true` | same + `model-embed-int8.safetensors` side file |
| embedding | FP16 | INT8 per-row absmax/127, fp16 scales, loaded by a vLLM patch of `vocab_parallel_embedding.py` |
| head error GPTQ vs RTN | 3.6% vs 7.6% | 3.5% vs 7.6% |
### Step 1 — format and tools
- **vLLM 0.32 already has an INT8 embedding path, but only for compressed-tensors:** `CompressedTensorsEmbeddingWNA16Int`
(Triton gather that dequantizes only the looked-up rows; INT 2–8 bit, channel/group). GPTQ format has none. compressed-tensors
also handles `ParallelLMHead` as a linear (→ the same `XPUwNa16LinearKernel` as the body). → **Checkpoint in compressed-tensors
pack-quantized format** (body, head and embedding in one `model.safetensors`, stock vLLM loaders). The GPTQ algorithm is the
same as the references; only the file layout differs.
- **Body tool: llm-compressor 0.15.0** (+ compressed-tensors 0.20.1, `pip install --no-deps --target quant/gptq_baked/pylib`; the
image's own CT 0.17 loads the result). GPTQModel 7.7 has LFM2 but no LFM3 definition and replays layer-0 kwargs like AutoRound
(round-4 bug). llm-compressor's sequential pipeline traces `Lfm3Model.forward` with `Lfm3DecoderLayer` as targets, so every
layer gets its own RoPE table and mask: **no patch needed**. `quant/gptq_baked/check_body.py`: the 25 traced subgraphs run
in sequence give max |Δlogit| **0.0**, top-1 100% vs the plain forward over 1,000 tokens (sliding window included).
Only `trust_remote_code_model=True` was needed.
- Calibration: `quant/build_calib.py` re-run (the .pt is not in git) → identical per-source stats to round 4 (199/567/239/629
conversations, 237,340/105,303/78,660/106,397 tokens).
### Step 2 — quantization (logs: logs/gptq_body.log, logs/bake_head_embed.log)
- `quantize_body.py`: GPTQModifier W4A16 (sym, g128), `actorder=static` (no runtime g_idx), damp 0.05 (Launch80's body),
block 128; ignore `lm_head` + 11 × `self_attn.gate_proj` → 142 linears, as round 4. **8.3 min** on XPU.
- `bake_head_embed.py` (head after B65's `bake_quant.py`/`bake_gptq_resume.py`):
- Activations: final-norm output of the model with the body weights dequantized from the INT4 checkpoint, over the
calibration set. 516,096 Hessian rows, every 64th row held out (8,192).
- The B65 setting (damp 1%, natural order, absmax scales) gave only 5.96% vs RTN 7.52%. Grid run next:
damp {0.1, 0.3, 1, 3, 10}% × act-order {none, static} × scales {absmax, MSE-clipped}. Even held-out rows select,
odd rows report.
- Damping hardly matters (±0.1 pt). Static act-order −0.05 pt. **MSE-clipped scales −0.8 pt.**
- Chosen: damp 0.3%, static, MSE → **5.07% output error vs 7.49% RTN** (−32%); top-1 vs BF16 96.4% vs 94.1%.
- LFM3's head (K=2048) gains less from GPTQ than Qwen's (K=5120, −54% there).
- Scales are rounded to BF16 before the codes are chosen (the references chose codes with fp32 scales and stored fp16).
- Embedding INT8: weight rel. L2 1.01%, looked-up rows 0.87%. Total 1.5 min.
- `assemble.py`: body + head (+ embedding) → one `model.safetensors`, `tie_word_embeddings=false`, compressed-tensors config
groups `group_0` (Linear), `lm_head` (same args), `embed_tokens` (8 bit, channel). Non-weight files from the original.
Variants: target (GPTQ head + INT8 embed, 1.155 GB), RTN head + INT8 embed (1.155 GB), body-only tied (1.282 GB),
and for the decode analysis GPTQ head + BF16 embed (1.417 GB); all but the target in /models/scratch/.
- Round 4 re-quantized with the unchanged `quantize_autoround.py` (16.3 min) into /models/scratch/LFM3-1.7B-W4A16-autoround
(the round-4 checkpoint was no longer on disk).
### Step 3 — plugin (`vllm_lfm3/model.py`, two lines + comments)
- `VocabParallelEmbedding(..., quant_config=quant_config, prefix="model.embed_tokens")`. BF16 and online FP8 resolve to the
unquantized embedding as before (`Fp8*OnlineLinearMethod` / the online base return `None` for embeddings).
- Untied head: `ParallelLMHead` was already built with `quant_config` and only tied when `tie_word_embeddings`; nothing to change.
- No own embedding module: vLLM's is used. `tests/test_embed_int8.py` (XPU): vLLM's kernel is **bit-exact** to
F.embedding of the dequantized weight; vs the BF16 embedding rel. L2 1.01%, min row cosine 0.9996 (real weights).
- `tests/quant_methods.py` on the served target: lm_head `CompressedTensorsLinearMethod / XPUwNa16LinearKernel`,
embed_tokens `CompressedTensorsEmbeddingWNA16Int`, gate_proj `UnquantizedLinearMethod`, qkv `XPUwNa16LinearKernel`.
Weights **1.12 GiB** (BF16 3.24, FP8 1.88, INT4 tied 1.24).
- **Regression** (old image `:v0.32.0-lfm3-vl` vs new, greedy_variant.py, results/round6/greedy_old_*.json):
- BF16: 5/5 prompts bit-identical, tokens and logprobs.
- FP8 per-channel: new image = round 5 bit-identical (5/5 tokens, 5/5 logprob margins).
- Today's old-image FP8 run, however, differs from its own VL-day run (margins 1/5 identical) and from the new image at
one near-tie (raw_long_1500, position 56).
- → online FP8 has small run-to-run variation; the plugin change does not alter it.
### Step 4 — quality (eval/eval_quality.py → results/round6/eval/results_*.json, greedy: results/round6/greedy_*.json; all compile + graphs)
| variant | PPL (40,940 tok) | vs BF16 | 8 prompts | completion tok | e2e 8 prompts (tok ÷ decode t/s) |
|---|--:|--:|---|--:|--:|
| BF16 | 18.518 | — | 8/8 | 3,790 | 29.7 s |
| FP8 per-channel (round 5) | 18.523 | +0.03% | 8/8 | 3,803 | 20.0 s |
| AutoRound INT4 (round 4, requantized) | 19.835 | +7.1% | 8/8 | 4,274 | 18.8 s |
| GPTQ INT4 body only (tied BF16 head) | 19.861 | +7.3% | 8/8 | 3,248 | 14.9 s |
| GPTQ baked + RTN head + INT8 embed | 20.286 | +9.5% | 8/8 | 3,330 | 15.4 s |
| **GPTQ baked + GPTQ head + INT8 embed (target)** | **20.014** | **+8.1%** | 8/8 | 3,487 | 16.0 s |
- Both tool calls byte-identical to BF16 in all variants, JSON valid, needle found, math 30.90, Canberra.
- Head cost: GPTQ head +0.15 PPL over the body-only checkpoint, RTN head +0.43, so GPTQ roughly thirds the head's damage.
- The GPTQ body thinks *less* than AutoRound on these prompts (3.2–3.5k vs 4.3k tokens); AutoRound's longer reasoning (round 4)
is not inherent to INT4.
- Greedy 64 tokens vs BF16 eager: all INT4 variants diverge early (0–1/5 identical), at BF16 margins up to 1.375, as in round 4.
### Step 5 — benchmarks
BetterBench 0.6.1, `--config /srv/llm/bench/bench-standard/dev/config.json --quick --max-model-len 32768`, direct on :8001
(bench-standard moved its config into `dev/`; identical to round 5's except what --quick sets). results/round6/bb/*.json.
Real bytes per step = all stored weights except an untied embedding (only the gathered rows are read).
| variant | decode t/s | bytes/step | eff. BW | ITL 1% low t/s | TTFT p50 ms | aggregate @8 t/s | prefill @32k t/s |
|---|--:|--:|--:|--:|--:|--:|--:|
| BF16 | 127.6 | 3.458 GB | 441 GB/s | 106.3 | 60 | 763.7 | 16,618 |
| FP8 per-channel | 189.9 | 2.02 GB | 384 GB/s | 117.4 | 61 | 1,082.2 | 16,514 |
| AutoRound INT4 | 227.7 | 1.287 GB | 293 GB/s | 163.1 | 59 | 1,139.2 | 14,125 |
| GPTQ body only | 217.6 | 1.282 GB | 279 GB/s | 134.2 | 62 | 1,134.9 | 14,098 |
| GPTQ + RTN head + INT8 emb | 216.2 | 0.893 GB | 193 GB/s | 135.4 | 62 | 1,136.5 | 14,180 |
| **target** | **217.5*** | 0.893 GB | 194 GB/s | 134.4* | 61 | **1,156.6** | 14,284 |
\* BetterBench printed "update p99" (one coalesced SSE update); decode from its combined line, ITL via tests/itl_low.py.
**The smaller head did not speed up decode.**
- An interleaved TPOT check (tests/bench.py decode 128/512, three servers up at 0.3 share each, alternated 3×;
results/round6/ab_tpot.txt) measured c=1 TPOT:
- target 4.34 / 4.44 / 4.43 ms
- INT4 head + BF16 embedding 4.36 / 4.42 / 4.34 ms
- tied BF16 head 4.32 / 4.34 / 4.46 ms
- → identical within ±2%. Earlier single runs (4.49 vs 4.71 ms) were start-to-start noise.
- In isolation (tests/head_timing.py, eager) `compute_logits` drops from 0.99 to 0.42 ms with the INT4 head. The INT8 lookup
costs +0.12 ms eager (vLLM's Triton gather ≈ a torch-ops version, both bit-exact, ~0.12–0.16 ms launch-bound).
- So at ~4.4 ms/step the bottleneck is not weight bytes any more. Likely host/scheduling overhead or kernel launch latency:
- not proven, because xpu-smi utilization reads 0% inside this setup;
- consistent with AutoRound and the GPTQ body (same bytes) also landing at 4.3–4.5 ms.
- AutoRound's 227.7 vs GPTQ body 217.6 in BetterBench is within that noise (TPOT 4.34 vs 4.32–4.49 ms).
bench-standard 0.5.0 (`bench.sh`, unmodified), quick, target, `--quant gptq-w4a16-g128-head-int4-embed-int8 --kv bf16 --tp 1
--pp 1 --spec none --thinking default --server-cmd-file results/round6/server-cmd.txt --special-notes "…"`:
`/srv/llm/bench/results/261030_pascal_lfm3-1.7b_vllm_1x-arc-pro-b65_quick`.
- Decode 214.7 t/s, TTFT p50 65 ms.
- Concurrency 207 / 380 / 689 / 1,152 t/s at 1/2/4/8.
- Prefill 13,929 / 15,652 / 15,314 / 14,224 t/s at 2k/8k/16k/32k.
- 258 GB/s = 48% of the measured 533 GB/s (bench.sh uses the 1.20 GB vLLM reports as loaded, which includes the embedding).
- 0.67 J/tok decode, 0.113 J/tok @8. Greedy identical 3/3, no warnings.
- `model_file` reads `/model · hash not checked` (container path), not the expected "not a standard model" warning. By hand:
repo hash `e89c4a35083a…` — not in models.tsv, as expected.
`betterbench compare` round-5 FP8 pc (results/variants/bb/fp8pc.json) vs this run: decode +8.0% to +16.1% in all 8 categories,
all SIG (unpaired across files). results/round6/compare_fp8pc_vs_target.txt.
### Gotchas
- `/mnt/model-library` is a **read-only** CIFS mount on this host → the checkpoint, README.md (model card) and SHA256SUMS are in
`/models/LFM3-1.7B-GPTQ-Int4-baked-v1-embed-int8`; copy it into the library from a machine with write access.
- llm-compressor needs `trust_remote_code_model=True` in `oneshot()` even with a model object.
- `subgraph.forward` expects only the inputs that exist (`_kwargs` placeholder) — pass `{k: acts[k] for k in input_names if k in acts}`.
- Single server starts vary ±5% in decode; compare decode-speed variants interleaved, not run after run.
### Recommendation
**Not worth it vs FP8 per-channel for quality; worth it only for memory or throughput.**
- vs FP8 pc: +14% decode (217 vs 190), +7% aggregate @8, −13% prefill, 60% of the weight memory (1.12 vs 1.88 GiB, +1.5 GiB KV
at the same utilization). But +8.1% perplexity vs +0.03%, and greedy paths flip at confident tokens.
- vs round 4 (AutoRound, tied BF16 head): same decode, same quality (PPL +8.1 vs +7.1%), 10% smaller file, stock kernel path
(no `VLLM_XPU_INC_WNA16_BACKEND`, no ARK crash), shorter reasoning on our 8 prompts (e2e 16.0 s vs 18.8 s).
- The baked head/embedding itself (target vs GPTQ body only): −0.13 GB file, −0.39 GB per-step reads, but **no measurable
decode gain** on this stack, and +0.8% PPL. Keep it only if the memory matters.
- Default stays **FP8 per-channel**. If an INT4 is wanted, this checkpoint is the better INT4 than round 4.
llama-swap snippet (NOT applied):
```yaml
# ---------- vLLM 0.32 + lfm3 plugin – LFM3-1.7B GPTQ INT4 baked (INT4 head, INT8 embed) ----------
vllm/lfm3-1.7b-int4-baked:
useModelName: lfm3-1.7b-int4-baked
aliases:
- lfm3-1.7b-int4-baked
cmdStop: docker stop -t 30 vllm-lfm3-int4-baked
cmd: >
docker run --rm --name vllm-lfm3-int4-baked
--device /dev/dri --group-add 991
--ipc=host --shm-size=16g
-p 127.0.0.1:${PORT}:8000
-v /dev/dri:/dev/dri
-v /dev/dri/by-path:/dev/dri/by-path:ro
-v /models/LFM3-1.7B-GPTQ-Int4-baked-v1-embed-int8:/model:ro
-v /srv/llm/runtimes/vllm-xpu/lfm3-v032/.cache/vllm-lfm3-int4-baked:/root/.cache/vllm
-e HF_HUB_OFFLINE=1
-e TRANSFORMERS_OFFLINE=1
lfm3-vllm-xpu:v0.32.0-lfm3-baked
/model
--host=0.0.0.0
--port=8000
--served-model-name=lfm3-1.7b-int4-baked
--gpu-memory-utilization=0.5
--dtype=bfloat16
--max-model-len=32768
--enable-auto-tool-choice
--tool-call-parser=qwen3_coder
--reasoning-parser=qwen3
```
(quantization is read from config.json; cache dir to be created.)