lfm3: online FP8 (W8A16) support, graph-mode and FP8 benchmarks

- load_weights: run the strict missing-parameter check only for unquantized
  models; vLLM's loader checks quantized ones and knows the params a
  checkpoint cannot carry (online-FP8 weight_scale). BF16 output unchanged.
- tests: variant launcher, greedy and quality comparisons, BetterBench
  table + ITL 1% low recompute, Discord notify helper.
- NOTES: round 2 (eager vs default vs FULL_DECODE_ONLY, default kept) and
  round 3 (FP8 W8A16: +49% decode, +35% @8, answers unchanged); llama-swap
  snippet now FP8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-29 07:43:09 +01:00
1 parent 4e7a7ce903
commit 3b85c03761
29 files changed
+87117 -18

No files matched your search

+180 -16
View File
@@ -273,26 +273,41 @@ docker run -d --rm --name lfm3-serve \
Startup ~145 s with graphs (compile cache lives inside the container and is lost with --rm; mounting
a host dir at /root/.cache/vllm would make restarts faster). No --trust-remote-code needed.
llama-swap model entry (snippet only — the real config was not touched):
llama-swap model entry — as live in /etc/llama-swap/config.yaml. Since 2026-10-29: W8A16 (online FP8
weights, round 3, +49% decode) on the `:v0.32.0-lfm3-fp8fix` image, with the vLLM default compile +
FULL_AND_PIECEWISE graphs confirmed in round 2. Previous BF16 entry: same without `--quantization=fp8`, image `:v0.32.0-lfm3`.
```yaml
models:
"lfm3-1.7b":
# ---------- vLLM 0.32 + lfm3 plugin – LFM3-1.7B (W8A16: online FP8 weights) ----------
vllm/lfm3-1.7b:
useModelName: lfm3-1.7b
aliases:
- lfm3-1.7b
cmdStop: docker stop -t 30 vllm-lfm3
cmd: >
docker run --rm --name lfm3-swap
--device /dev/dri -v /dev/dri/by-path:/dev/dri/by-path --ipc=host --shm-size=16g
docker run --rm --name vllm-lfm3
--device /dev/dri --group-add 991
--ipc=host --shm-size=16g
-p 127.0.0.1:${PORT}:8000
-v /models/LFM3-1.7B:/models/LFM3-1.7B:ro
lfm3-vllm-xpu
/models/LFM3-1.7B --served-model-name lfm3-1.7b --dtype bfloat16
--max-model-len 32768 --gpu-memory-utilization 0.5
--reasoning-parser qwen3 --enable-auto-tool-choice --tool-call-parser qwen3_coder
--host 0.0.0.0 --port 8000
cmdStop: docker stop lfm3-swap
proxy: http://127.0.0.1:${PORT}
checkEndpoint: /v1/models
# graph capture + torch.compile: allow a slow first start
healthCheckTimeout: 300
-v /dev/dri:/dev/dri
-v /dev/dri/by-path:/dev/dri/by-path:ro
-v /models/LFM3-1.7B:/model:ro
-v /srv/llm/runtimes/vllm-xpu/lfm3-v032/.cache/vllm-lfm3:/root/.cache/vllm
-e HF_HUB_OFFLINE=1
-e TRANSFORMERS_OFFLINE=1
lfm3-vllm-xpu:v0.32.0-lfm3-fp8fix
/model
--host=0.0.0.0
--port=8000
--served-model-name=lfm3-1.7b
--gpu-memory-utilization=0.5
--dtype=bfloat16
--quantization=fp8
--max-model-len=32768
--enable-auto-tool-choice
--tool-call-parser=qwen3_coder
--reasoning-parser=qwen3
```
(The global `healthCheckTimeout: 1800` covers the ~140 s cold start; warm start with the cache mount ~80 s.)
Defaults applied by the server from generation_config.json: temperature 0.1, top_k 50,
repetition_penalty 1.1 (Liquid's recommendation) — clients don't need to send them.
@@ -323,3 +338,152 @@ Report: results/betterbench/compiled.html (+ compiled.json), log: logs/betterben
multi-token chunk; tok/update is 1.00 everywhere, there is no spec decode. In --quick mode all runs
hit max_tokens while still thinking (reasoning on by default), so TTFA (time to first answer token)
is not measurable; decode/prefill speeds are unaffected.
## Round 2 — graphs/compile tuning
### Step 1 — baseline config (confirmed 2026-10-28)
Baseline = bench-standard run `/srv/llm/bench/results/20261028-231853-pascal-vllm-lfm3-1.7b-vllm-arc-pro-b65`
(decode 127.6 t/s, ITL 1% low 102.3, TTFT p50 60 ms, aggregate @8 764.4 t/s, prefill @32k 16,670 t/s).
It did **not** use `--enforce-eager`: torch.compile (`CompilationMode.VLLM_COMPILE`) + vLLM default
graphs `FULL_AND_PIECEWISE`, capture sizes 1,2,4,8,16,24,…,512 (51 PIECEWISE + 35 FULL decode graphs;
the 2-graph FULL pass before them is the memory-profiling run). Same config as "compiled" in step 8/9.
Exact serve command (llama-swap `/running`, also in the result's `server-cmd.txt`):
```
docker run --rm --name vllm-lfm3 --device /dev/dri --group-add 991 --ipc=host --shm-size=16g
-p 127.0.0.1:5800:8000 -v /dev/dri:/dev/dri -v /dev/dri/by-path:/dev/dri/by-path:ro
-v /models/LFM3-1.7B:/model:ro
-v /srv/llm/runtimes/vllm-xpu/lfm3-v032/.cache/vllm-lfm3:/root/.cache/vllm
-e HF_HUB_OFFLINE=1 -e TRANSFORMERS_OFFLINE=1
lfm3-vllm-xpu:v0.32.0-lfm3 /model --host=0.0.0.0 --port=8000 --served-model-name=lfm3-1.7b
--gpu-memory-utilization=0.5 --dtype=bfloat16 --max-model-len=32768
--enable-auto-tool-choice --tool-call-parser=qwen3_coder --reasoning-parser=qwen3
```
Baseline BetterBench invocation (from the result's `meta.json`): BetterBench 0.6.1,
`--config /srv/llm/bench/bench-standard/config.json --quick --max-model-len 32768`, endpoint
`http://localhost:8080/v1`, model `vllm/lfm3-1.7b` (decode + concurrency + prefill, all defaults).
### Step 2 — variants (same image `lfm3-vllm-xpu:v0.32.0-lfm3`, same serve flags as the baseline)
Scripts: `tests/variant.sh NAME [--fresh] [vllm args]` (container `lfm3-var-NAME` on :8001, own compile
cache `./.cache/NAME`, server log `logs/variant_NAME.log`, startup/VRAM in `results/variants_startup.tsv`);
`tests/greedy_variant.py` (64 greedy tokens for the 5 ref_compare prompts, rep. penalty 1.0, prints the
reference's top-2 logprob margin at the first difference). Outputs: results/variants/greedy_*.json.
| variant | flags | starts | cold startup | torch.compile | graph capture | KV cache | VRAM used | greedy 64 tok vs eager (sequential) |
|---|---|---|---|---|---|---|---|---|
| a) eager | `--enforce-eager` | yes | 75 s | — | — | 541k tok | 15.75 GB | reference |
| b) default = baseline | — (FULL_AND_PIECEWISE, sizes 1…512) | yes | 138 s | 38.9 s | 7 s, 0.11 GiB | 506k tok | 15.67 GB | 3/5 identical; diffs at pos 47 / 50, margins 0.25 / 0.125 |
| d) FULL_DECODE_ONLY | `--compilation-config={"cudagraph_mode":"FULL_DECODE_ONLY","cudagraph_capture_sizes":[1,2,4,8]}` | yes | 128 s | 38.2 s | 1 s, ~0 GiB | 533k tok | 16.07 GB | 2/5 identical; diffs at pos 47 / 50 / 49, margins 0.25 / 0.125 / 0.000 |
| c) compile, no graphs | — | not run (b works) | | | | | | |
- "Cold startup" = `docker run` → `/v1/models` answers, with an empty compile cache. VRAM is ~fixed by
`--gpu-memory-utilization=0.5` (≈16 GB of 32), the variants only shift it between KV cache and graphs.
- **Noise floor:** eager vs *eager itself* run with all 5 prompts concurrently is also only 3/5 identical
(diffs at pos 47 margin 0.25, pos 49 margin 0.000). Batch composition changes bf16 reductions, so
"64 tokens identical" fails at near-ties even without any compile/graph change.
- Every divergence in every variant (sequential and concurrent) is at a top-2 margin ≤ 0.25 and at the
same positions as round 1's known near-ties (raw_short 47, chat_short 49, raw_code 50, raw_long_1500
28). No variant diverges at a confident token → all three are numerically equivalent to eager.
### Step 3 — BetterBench per variant
Invocation identical to the baseline (BetterBench 0.6.1, `--config /srv/llm/bench/bench-standard/config.json
--quick --max-model-len 32768`), endpoint `http://127.0.0.1:8001/v1` directly (no llama-swap), model
`lfm3-1.7b`. Results: results/variants/bb/{eager,default,fdo1248}.{json,html}, logs: logs/bb_*.log.
Table: `tests/bb_table.sh`; ITL column via `tests/itl_low.py` (see note). Bandwidth = 3.47 GB × decode t/s,
% of the B65's 608 GB/s spec.
| variant | decode t/s | eff. bandwidth | ITL 1% low t/s | TTFT p50 ms | aggregate @8 t/s | prefill @32k t/s | warm / cold startup |
|---|--:|--:|--:|--:|--:|--:|--:|
| baseline (= b, via llama-swap) | 127.6 | 443 GB/s (73%) | 102.3 | 60 | 764.4 | 16,670 | — |
| a) eager | 29.5 | 102 GB/s (17%) | 22.9* | 125 | 190.9 | 16,502 | 60 s / 75 s |
| **b) default (FULL_AND_PIECEWISE)** | **128.4** | **446 GB/s (73%)** | **105.1** | 67 | **768.2** | 16,626 | 83 s / 138 s |
| d) FULL_DECODE_ONLY [1,2,4,8] | 128.7 | 447 GB/s (73%) | 107.7* | 85 | 744.3 | 16,691 | 69 s / 128 s |
\* BetterBench printed "update p99" instead of ITL for these runs: one or more stream updates carried
2 tokens (SSE coalescing; tok/update is 1.00, no spec decode), which flips it into its "speculative"
view. `tests/itl_low.py` recomputes the number with BetterBench's own `itl_to_rate_samples` +
`summarize(rate_like=True)` per category and the config weights; it reproduces the baseline's 102.3 and
b's 105.1 exactly.
Findings:
- b and d decode identically (128.4 vs 128.7 t/s, within noise). Both sit at the measured GEMV
bandwidth of this card (~428–440 GB/s, tests/hw_roofline.py); the 608 GB/s spec is not reachable for
decode-shaped reads. **Graph mode is no longer a lever for decode** — only fewer bytes (quantization) are.
- d is worse where piecewise graphs matter: TTFT p50 +18 ms (85 vs 67 ms; short prefills run without
graphs in FULL_DECODE_ONLY), concurrency TTFT p50 at @8 105 vs 77 ms, aggregate @8 −3% (744 vs 768).
Its only gains are ~14 s faster warm startup and ~0.1 GiB less graph memory — irrelevant at 0.5 util.
- Eager is 4.3× slower at decode (launch-bound, flat ~29 t/s per request at every concurrency level).
- Prefill is compute-bound and identical across all variants (16.5–16.7k t/s at 23.5k tokens).
- Baseline vs b (llama-swap vs direct): equal within noise → the proxy costs nothing measurable.
### Step 4 — recommendation
**Keep b) the vLLM default (no `--enforce-eager`, no `--compilation-config`)**: best or tied on every
metric except a ~14 s slower warm start. That is exactly what the live llama-swap entry already runs, so
the snippet below only changes to match the live entry (no flag changes).
## Round 3 — W8A16 (online FP8 weights, BF16 compute)
### Step 1 — quant_config plumbing
All big linears are vLLM linear classes with `quant_config` passed through: attention `qkv_proj`
(QKVParallelLinear) and `o_proj` (RowParallelLinear), MLP `w13` (MergedColumnParallelLinear) and `w2`
(RowParallelLinear), conv `in_proj` / `out_proj` (built by vLLM's `ShortConv`, which passes quant_config).
Deliberately unquantized: `gate_proj` (16×2048 output gate, 0.002% of weights), the conv kernel weight
(read directly by our Triton conv kernel), embedding / tied `lm_head` (vLLM's online FP8 never quantizes
VocabParallelEmbedding), norms.
**Bug found when serving FP8:** `Lfm3ForCausalLM.load_weights` raised on parameters missing from the
checkpoint — online FP8 adds `weight_scale` params that a BF16 checkpoint can't contain (96 of them).
Fix: run our strict check only when `quant_config is None`; for quantized models vLLM's DefaultModelLoader
does the check itself and knows which params a checkpoint cannot carry. BF16 path unchanged. Built as
`lfm3-vllm-xpu:v0.32.0-lfm3-fp8fix` (the live llama-swap image `:v0.32.0-lfm3` is untouched).
### Step 2 — serving with `--quantization=fp8` (log: logs/variant_fp8.log)
- vLLM 0.32 maps it to online per-tensor FP8 (`fp8` is a deprecated alias of `fp8_per_tensor`), and on XPU
selects **`XPUW8A16FP8LinearKernel` for `Fp8PerTensorOnlineLinearMethod`** → `torch.ops._xpu_C.fp8_gemm_w8a16`:
FP8 (e4m3) weights + per-tensor scale, BF16 activations, i.e. real W8A16 (the W8A8 kernel is only the
fallback).
- **Model weight memory 1.88 GiB vs 3.24 GiB BF16** (−42%). Matches all linears in FP8 (~1.47 B params →
1.47 GB) + BF16 embedding/lm_head (0.52 GB) + small rest. Bytes read per decode step: ~2.02 GB vs 3.47 GB
→ ideal bandwidth-bound speedup ≤ 1.72×.
- KV cache memory 11.69 GiB (BF16: 10.61 GiB) at the same 0.5 utilization; graph capture 0.54 GiB
(BF16 0.12); cold start 144 s (torch.compile 38 s).
### Step 3 — quality vs BF16 (greedy, `tests/quality_prompts.py`, results/w8a16/quality_{bf16,fp8}.json)
| prompt | first token divergence (BF16 top-2 margin there) | BF16 answer | FP8 answer | correct? |
|---|---|---|---|---|
| math (train minutes) | 13 of 1166 (0.000) | 201 | 201 (613 tokens of reasoning instead of 1166) | both |
| code (is_palindrome) | 26 of 315 (0.375) | `cleaned = ''.join(ch.lower() … isalnum())` | same, variable named `filtered` | both |
| German (blue sky) | 33 of 332 (0.125) | correct, 2 sentences (one grammar slip "das kurzwelliges") | correct, 2 sentences (one awkward clause) | both |
| tool call (weather Hamburg) | 33 of 90 (0.25), inside reasoning | `get_weather{"city":"Hamburg","unit":"celsius"}` | identical call | both |
| summary (council vote) | 110 of 386 (0.25) | one sentence, all facts | one sentence, all facts, reordered | both |
64-token raw-prompt check vs eager BF16 (`tests/greedy_variant.py`, results/w8a16/greedy_fp8.json): 2/5
identical; raw_short diverges at token 1 (margin 0.31), chat_short at 4 (0.25), raw_code at 50 (0.125).
→ FP8 changes greedy paths much earlier than BF16 batch noise does (always at near-ties ≤ 0.375, never at a
confident token), but every final answer stayed correct and the tool call is byte-identical.
BF16 regression check after the load_weights fix: `:v0.32.0-lfm3-fp8fix` without quantization gives
greedy output bit-identical to the pre-fix default image (5/5 prompts, 64/64 tokens,
results/w8a16/greedy_bf16fix.json).
### Step 4 — BetterBench (same invocation as step 3; results/variants/bb/fp8.{json,html}, logs/bb_fp8.log)
| variant | decode t/s | eff. bandwidth (3.47 GB × t/s) | real bytes/step × t/s | ITL 1% low t/s | TTFT p50 ms | aggregate @8 t/s | prefill @32k t/s |
|---|--:|--:|--:|--:|--:|--:|--:|
| b) BF16 default | 128.4 | 446 GB/s (73%) | 446 GB/s (3.47 GB) | 105.1 | 67 | 768.2 | 16,626 |
| **FP8 W8A16 (`--quantization=fp8`)** | **191.3** | 664 GB/s (109%) | **386 GB/s** (2.02 GB) | **122.5** | 59 | **1,036.5** | 16,744 |
| Δ | **+49%** | | | +17% | −8 ms | **+35%** | +0.7% |
- The 3.47 GB column is a "BF16-equivalent" number and exceeds the 608 GB/s spec, which only shows that
fewer bytes are read. Real traffic is ~2.02 GB/step → 386 GB/s, ~88–90% of the measured BF16 GEMV
bandwidth (428–440 GB/s), so the FP8 GEMV kernel is slightly less bandwidth-efficient than BF16, and
we get 1.49× of the ideal 1.72×.
- Concurrency per-request decode: 192 / 186 / 176 / 160 t/s at 1/2/4/8 (BF16: 128 / 126 / 121 / 116).
- Prefill unchanged (compute-bound; `fp8_gemm_w8a16` dequantizes to BF16 compute).
- Next lever if wanted: the BF16 tied embedding/lm_head is now 0.52 of the 2.02 GB read per step (26%).
vLLM's online FP8 does not quantize `ParallelLMHead`; an FP8/INT8 lm_head would need an offline
checkpoint or plugin work. Step 5 (offline INT8 route) not needed: online FP8 works and is +49%.
### Recommendation / deployed (2026-10-29)
FP8 W8A16 is the new default: llama-swap `vllm/lfm3-1.7b` switched to image `lfm3-vllm-xpu:v0.32.0-lfm3-fp8fix`
+ `--quantization=fp8` (backup of the previous config: /etc/llama-swap/config.yaml.bak-pre-lfm3-fp8).
Verified through llama-swap: reload clean, cold start 2m26s, kernel `XPUW8A16FP8LinearKernel`, weights 1.88 GiB,
"17*23" → 391. For a manual `docker run` (Deployment section above), add `--quantization=fp8` and use the
`:v0.32.0-lfm3-fp8fix` image (rebuild from this repo: `docker build -t lfm3-vllm-xpu:v0.32.0-lfm3-fp8fix .`).