Files
xpu-llm-ports/lfm3/NOTES.md
T
Pascal LinxweilerandClaude Opus 5.5 3b85c03761 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>
2026-10-29 07:43:09 +01:00

490 lines
34 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LFM3-1.7B on vLLM 0.32.0 / Intel XPU — working notes
## Environment (verified 2026-10-28)
- Image `vllm/vllm-openai-xpu:latest`: vLLM 0.32.0+xpu, torch 2.14.0+xpu, transformers 5.19.0,
triton-xpu 3.8.0, vllm-xpu-kernels 0.1.15.4, Python 3.12.
- transformers 5.19 ≥ 5.12.1 (config.json) → Liquid's remote code imports and builds fine inside the
image; **no separate reference venv needed**. transformers 5.19 does *not* ship `lfm3` natively
(only lfm2, lfm2_moe, lfm2_vl).
- vLLM sources relevant to this work are copied (read-only reference) into `./ref/`.
## Step 1 — architecture: LFM3 vs. vLLM's LFM2 (source of truth: modeling_lfm3.py)
Checkpoint: 286 tensors, single `model.safetensors`, BF16, **no `lm_head.weight`** (tied to
`model.embed_tokens.weight`). Key patterns:
```
model.embed_tokens.weight (128000, 2048)
model.embedding_norm.weight (2048,)
model.layers.N.operator_norm / ffn_norm / post_operator_norm / post_ffn_norm .weight (2048,)
model.layers.N.feed_forward.{w1,w3}.weight (7680, 2048) w2 (2048, 7680)
conv layers: model.layers.N.conv.conv.weight (2048, 1, 7)
model.layers.N.conv.in_proj.weight (6144, 2048) out_proj (2048, 2048) (no bias)
attn layers: model.layers.N.self_attn.{q,o}_proj (2048,2048) {k,v}_proj (512,2048)
q_norm/k_norm (128,) gate_proj (16, 2048)
```
| Aspect | vLLM LFM2 (lfm2.py) | LFM3 (modeling_lfm3.py) | Impact |
|---|---|---|---|
| Layer types | `conv`, `full_attention` | `conv`(13), `full_attention`(6), `sliding_attention`(5) | new layer kind; per-layer `per_layer_sliding_window=256` on `Attention` |
| Conv width | `conv_L_cache=3` | **7** | state shape `(dim, 6)`; vLLM Triton kernels can't do it (see below) |
| Conv block | in_proj → B,C,x → conv(B·x) → C·y → out_proj | identical (chunk order B, C, x; no bias) | reuse ShortConv logic |
| Conv dim config | `conv_dim`, `block_dim` | not present → `hidden_size` | adapt |
| MLP | `block_auto_adjust_ff_dim` etc. | plain SwiGLU, `intermediate_size=7680` used as-is | no ff-dim auto adjust |
| Norm layout | pre-norm (operator_norm, ffn_norm), fused residual add | **sandwich**: `post_operator_norm` on operator output and `post_ffn_norm` on FFN output *before* residual add | cannot use vLLM's fused add+norm residual trick the LFM2 way; explicit residual |
| Final norm | `embedding_norm` after last layer | **also after the last layer** (line 760) — the brief's "right after the token embedding" is wrong; the name is a historical LFM2 misnomer | final norm only |
| Attention out proj name | `out_proj` | `o_proj` | weight mapping |
| QK norm | q_layernorm/k_layernorm | `q_norm`/`k_norm`, per-head RMSNorm, before RoPE | same math, new names |
| Output gate | none | `o = o * sigmoid(gate_proj(x_normed))` per head (16 scalars/token), before o_proj | new |
| head_dim | hidden/heads | explicit 128 (= 2048/16) | |
| RoPE | single, neox | per layer type. sliding: theta 1e4, full rotation. full: theta 1e6, **"zero-tail" partial 0.5** | custom RoPE (see below) |
| RoPE precision | model dtype | q/k rotated in **fp32**, cast back | do it in fp32 too |
| Norm eps | norm_eps | `norm_eps = 1e-5` everywhere (incl. q/k norm) | |
| RMSNorm | x·rsqrt(mean x²+eps) · w | same (weight multiply after cast back to input dtype) | vLLM RMSNorm ok |
| Embedding pad idx | — | `padding_idx=124893` (only matters for training) | ignore |
### Zero-tail partial RoPE (full_attention layers) — NOT vLLM's standard partial rotary
HF computes `inv_freq[i] = theta^(-2i/128)` for i < 32 and `inv_freq[i] = 0` for 32 ≤ i < 64, then applies
neox-style `rotate_half` over the **full** 128-dim head. Consequences:
- dims 0..31 pair with 64..95 and rotate with frequencies of the *full* head-dim progression;
- dims 32..63 and 96..127 are untouched (cos=1, sin=0).
vLLM's `partial_rotary_factor=0.5` instead rotates dims 0..63 (pairs i ↔ i+32) with `theta^(-2i/64)`.
That would be silently wrong. → implement a RoPE with rotary_dim=128 and the zero-tail inv_freq
(subclass of vLLM's `RotaryEmbedding` overriding `_compute_inv_freq`), so the cos/sin cache is exact.
### Conv / hybrid state machinery in vLLM 0.32
- `ShortConv` (layers/mamba/short_conv.py) is generic in `config.conv_L_cache`; state shape from
`MambaStateShapeCalculator.short_conv_state_shape(conv_kernel=7)` → `(6, dim)` per slot in the
default "SD" layout (viewed as `(dim, 6)` via transpose). State dtype = model dtype.
- On non-CPU platforms (XPU included) it calls Triton `causal_conv1d_fn` / `causal_conv1d_update`
(ops/causal_conv1d.py). **Those kernels are hand-unrolled: prefill supports KERNEL_WIDTH 2–5
(loads/updates written for ≤4/5), decode ≤6. Width 7 is unsupported** → must ship our own conv.
- The CPU path uses a per-sequence torch `F.conv1d` loop (`causal_conv1d_fn_cpu`) — usable as a
model for a correct PyTorch fallback.
- The model class needs the `IsHybrid`/`HasInnerState` interface:
`get_mamba_state_shape_from_config`, `get_mamba_state_dtype_from_config`,
`get_mamba_state_copy_func` (copy from LFM2 with `intermediate_size=hidden_size`, `conv_kernel=7`).
- Prefix caching on hybrids → `mamba_cache_mode="align"` (state indices become per-block). The
ShortConv path doesn't pass APC block indices; plan: start with prefix caching disabled, revisit.
### Plan decisions
- Out-of-tree plugin `vllm_lfm3` with `vllm.general_plugins` entry point; registers
`Lfm3ForCausalLM` and `AutoConfig.register("lfm3", Lfm3Config)` (vendored copy of Liquid's
configuration, so `--trust-remote-code` is not required).
- Own `Lfm3ShortConv` (subclass of vLLM `ShortConv`) with width-7 conv: PyTorch reference first,
then a Triton-XPU kernel if it's correct and faster.
- Reference comparison uses Liquid's remote code inside the same image (fp32 on CPU).
## Steps 2–4 — plugin, packaging, weight loading
Layout of `./`:
```
vllm_lfm3/__init__.py register(): ModelRegistry ("vllm_lfm3.model:Lfm3ForCausalLM", lazy) +
AutoConfig.register("lfm3", Lfm3Config)
vllm_lfm3/configuration_lfm3.py vendored verbatim from the model dir (no --trust-remote-code needed)
vllm_lfm3/model.py Lfm3ForCausalLM / Lfm3Model / layers
vllm_lfm3/conv_ops.py width-agnostic causal conv1d: Triton (default) + torch fallback
pyproject.toml entry point [vllm.general_plugins] lfm3 = vllm_lfm3:register
Dockerfile FROM vllm/vllm-openai-xpu:latest + pip install --no-deps . -> lfm3-vllm-xpu
run_server.sh docker run … vllm serve (see "Serving" below)
tests/ test_conv_kernel.py, ref_compare.py, test_api.py
```
- **Packaging decision:** derived image `lfm3-vllm-xpu` (`docker build -t lfm3-vllm-xpu .`, ~1 s on top
of the base image). A pip-installed entry point is picked up by every vLLM process (API server,
EngineCore, workers) with no per-start install step; a bind-mounted source + `pip install` at
container start would also work but adds a step per start and a writable site-packages.
Verified in the log: `Resolved architecture: Lfm3ForCausalLM` in the API process and the model is
built in the spawned EngineCore.
- **Model design:**
- `Lfm3ShortConv` subclasses vLLM's `ShortConv` (projections, state shape/dtype, metadata, the
`torch.ops.vllm.short_conv` custom op are inherited) and only replaces `forward_cuda` (the path
XPU takes) with calls into `conv_ops`. Spec decode raises `NotImplementedError`.
- Hybrid state: `get_mamba_state_shape_from_config` → `short_conv_state_shape(hidden_size, conv_kernel=7)`
→ conv state `(6, 2048)` per slot; dtype = model dtype; copy func = vLLM's conv copy spec.
- Attention: `QKVParallelLinear` + `q_norm/k_norm` (vLLM RMSNorm per head) + RoPE + `Attention(
per_layer_sliding_window=256 if sliding else None)` + `sigmoid(gate_proj(x))` per head + `o_proj`.
vLLM 0.32 never copies the model-level `sliding_window` into `cache_config`, so full-attention
layers get no window. Flash-attn window is `(255, 0)` = 256 keys incl. self = HF's mask.
- RoPE: `Lfm3RotaryEmbedding(RotaryEmbedding)` with rotary_dim=128 and zero-tail `inv_freq`; one
instance per layer type, shared by its layers; cache sized to `max_model_len`.
- Sandwich norm with vLLM's fused add+RMSNorm: each layer returns the post-normed FFN output and
the un-added residual; `operator_norm(h, res)` / `ffn_norm(h, res)` do the residual adds,
`embedding_norm(h, res)` is the final norm.
- **Weight loading:** HF→vLLM mapping `.conv.`→`.short_conv.`, `q/k/v_proj`→`qkv_proj`, `w1/w3`→`w13`.
Unknown checkpoint tensors make `AutoWeightsLoader` raise; after loading, every model parameter
must have been loaded or `load_weights` raises with the missing names. All 286 tensors load.
(Caveat inherited from vLLM: AutoWeightsLoader silently ignores unexpected `*.bias` tensors —
irrelevant here, the checkpoint has no biases.)
- vLLM picks the hybrid KV layout automatically: 6 KV-cache groups of 6 layers (full / sliding /
conv); log says "Add 2 / 4 padding layers, may waste at most 15–67% KV cache memory" — harmless
for a 1.7B model at 0.5 GPU utilization.
- Prefix caching stays ON by default; vLLM switches the conv state to `mamba_cache_mode='align'`
(state copied between blocks by the framework). Our kernels only touch the current slot, which is
exactly what align mode expects → works (see step 7 for repeated-prefix test).
## Step 6 — XPU conv kernel, tested in isolation (`tests/test_conv_kernel.py`, log: logs/conv_kernel_test.log)
Reference: independent per-sequence `F.conv1d` in fp32. Cases: 5 sequences (lengths 37, 3, 1, 300, 6;
some with initial state, i.e. continued chunked prefill, some shorter than the 6-token state), then
5 decode steps with an extra padded row (slot -1); both conv-state layouts (SD default, DS).
| implementation | result |
|---|---|
| vLLM stock `causal_conv1d_fn`, width 7 | **Triton CompilationError** (kernel is unrolled for widths ≤ 5) |
| vLLM stock `causal_conv1d_update`, width 7 | runs, **wrong**: max abs err 19.6 |
| `conv_ops` torch | PASS (out err ≤ 1.5e-2 = bf16 rounding, states bit-exact) |
| `conv_ops` triton | PASS (same) |
Speed on the B65 (bf16, dim 2048, per layer call):
| | torch | triton |
|---|---|---|
| prefill 1×2048 tokens | 3.51 ms | 0.43 ms |
| prefill 16×512 tokens | 13.35 ms | 0.57 ms |
| decode batch 1 | 0.378 ms | 0.066 ms |
| decode batch 16 | 0.378 ms | 0.068 ms |
→ Triton is the default; `LFM3_CONV_IMPL=torch` switches to the fallback.
## Step 5 — correctness vs. Liquid's Transformers code (`tests/ref_compare.py`)
Reference = `modeling_lfm3.py` via trust_remote_code in the same image (transformers 5.19), on **CPU**
(independent of the XPU stack; fp32 ground truth + bf16 noise floor). vLLM side: XPU, enforce_eager,
all 5 prompts in one batch, prefix caching on (align mode). Compared at **every** position
(prompt_logprobs + 64 greedy tokens, top-20), teacher-forced; plus HF's own greedy `generate`.
Prompts: raw_short (5 tok), raw_code (13), chat_short (22), chat_long_600 (590), raw_long_1500 (1423).
Logs: logs/ref_hf_vllm_{fp32,bf16}.log, reports: results/*_report.json.
**vLLM fp32 (XPU, Triton attention) vs HF fp32 (CPU)** — the strict implementation check:
| prompt | positions | top-1 agree | mean |Δlogp| top-1 | max |Δlogp| top-5 | greedy 64 tok identical |
|---|---|---|---|---|---|
| raw_short | 68 | 68/68 | 1.4e-4 | 0.004 | 64/64 |
| raw_code | 76 | 76/76 | 1.0e-4 | 0.008 | 64/64 |
| chat_short | 85 | 85/85 | 3.1e-4 | 0.010 | 64/64 |
| chat_long_600 | 653 | 653/653 | 4.6e-4 | 0.069 | 64/64 |
| raw_long_1500 | 1486 | 1486/1486 | 0.8e-4 | 0.012 | 64/64 |
→ The port is numerically exact to fp32 tolerance, including positions > 256 (sliding window,
zero-tail RoPE on full attention, conv state across chunked prefill/decode).
**vLLM bf16 (XPU, Flash attention) vs HF fp32**, with HF bf16 (CPU) vs HF fp32 as noise floor:
| prompt | vLLM-bf16 mean Δ top-1 | HF-bf16 mean Δ top-1 (noise) | vLLM-bf16 top-1 agree | HF-bf16 top-1 agree | greedy identical (vs HF fp32) |
|---|---|---|---|---|---|
| raw_short | 0.0068 | 0.0086 | 68/68 | 67/68 | 64/64 |
| raw_code | 0.0100 | 0.0073 | 75/76 | 75/76 | 50/64 (near-tie, margin 0.017) |
| chat_short | 0.0108 | 0.0141 | 85/85 | 85/85 | 64/64 |
| chat_long_600 | 0.0171 | 0.0204 | 645/653 | 644/653 | 64/64 |
| raw_long_1500 | 0.0040 | 0.0042 | 1475/1486 | 1478/1486 | 28/64 (near-tie, margin 0.014) |
→ vLLM bf16 is as close to fp32 as HF's own bf16. Every top-1 disagreement is a near-tie
(fp32 logprob margin ≤ 0.23, mostly < 0.1); the two greedy divergences happen at ties of 0.014/0.017.
Gotcha found on the way: `generation_config.json` sets `repetition_penalty: 1.1`, which HF `generate`
applies even with `do_sample=False` — the first run's HF greedy outputs diverged after 2 tokens because
of that, not because of the port. The script now forces `repetition_penalty=1.0`.
## Upstream check (2026-10-28, requested mid-way; done after step 5 because work had already progressed)
- vLLM `main` shallow clone in `./vllm-main` (HEAD c105af4, 2026-10-28 11:31 -0700): no match for
`lfm3` / `Lfm3ForCausalLM` anywhere; registry only has Lfm2 / Lfm2Moe / Lfm2Vl / Lfm2Bidirectional /
ColBERTLfm2.
- Main's Triton `causal_conv1d` is still unrolled for widths ≤ 5 (prefill) / ≤ 6 (decode) → width 7
still unsupported upstream; our kernels are still needed.
- GitHub search (API, no `gh` installed): 0 PRs and 0 issues for "LFM3", "LFM3 liquid",
"Lfm3ForCausalLM". (Related open issue #52887: causal_conv1d kernels round bf16 products before fp32
accumulation — our kernels accumulate in fp32.)
- Docker Hub `vllm/vllm-openai-xpu`: newest tag `nightly` = `nightly-edad8b0…` (2026-10-28 05:32),
built from a main commit older than the clone above → no LFM3 either. `latest` = v0.32.0.
- **Conclusion: neither main nor an open PR supports LFM3 → the plugin route (step 2) stands.**
## Step 7 — serving + API tests (`run_server.sh`, `tests/test_api.py`, log: logs/api_test_eager.log)
Server: `./run_server.sh -d` (= `vllm serve /models/LFM3-1.7B --served-model-name lfm3-1.7b --dtype bfloat16
--max-model-len 32768 --gpu-memory-utilization 0.5 --enforce-eager --reasoning-parser qwen3
--enable-auto-tool-choice --tool-call-parser qwen3_coder`, port 8000). Ready in ~85 s.
KV cache: 541,313 tokens (16.5× concurrency at 32k). Flash Attention backend, prefix caching on (align).
Sampling for chat tests: temperature 0.1, top_k 50, repetition_penalty 1.1.
| test | result |
|---|---|
| chat "17*23?" | reasoning split into `reasoning` (62 tokens), content `'391'`, no think tags in content |
| `chat_template_kwargs: {enable_thinking: false}` | no reasoning, direct answer |
| streaming | reasoning deltas then content deltas (383 events) |
| tool call (get_weather) | `finish_reason=tool_calls`, `{"city": "Berlin"}`, content None; follow-up turn with tool result → "light rain, 14°C" |
| long prompt (701 tokens, fact in first sentence) | answers `1817` → full-attention layers see past the 256 window |
| prefix caching (align mode) | 2nd identical request: 1280 tokens from cache, greedy output identical to cold run |
13/13 checks pass. Notes:
- The qwen3 reasoning parser works even though the template puts `<think>` into the prompt (the
model only emits `</think>`). vLLM 0.32 returns the field as `reasoning` (not `reasoning_content`).
- First request after start takes ~10 s extra (Triton JIT of the conv kernels; cached afterwards).
## Step 8 — without --enforce-eager (torch.compile + XPU graphs)
`EAGER=0 ./run_server.sh -d`: works out of the box. torch.compile 38 s (cached in-container), graph
capture FULL_AND_PIECEWISE (51 piecewise + 35 FULL decode sizes) ~17 s, server ready in ~145 s
(eager: ~85 s). Our Triton conv kernels are captured inside the FULL decode graphs.
Correctness re-checked, not assumed:
- API tests 13/13 (logs/api_test_compiled.log).
- **fp32 + graphs vs HF fp32** (results/vllm_fp32_graphs_report.json): top-1 68/68, 76/76, 85/85,
652/653 (one 0.002-margin tie), 1486/1486; mean |Δlogp| 1e-4–5e-4; greedy 64/64 on all 5 prompts.
- bf16 server vs eager bf16 run (tests/compare_greedy_server.py): divergences only at the known
near-ties (pos 47/50/49/28), same with 5 concurrent requests.
- Gotcha: `vllm serve` applies generation_config.json (repetition_penalty 1.1, temperature 0.1,
top_k 50) as *default* sampling params. Any greedy comparison through the API must pass
`repetition_penalty: 1.0` explicitly. (Handy for production: those are Liquid's recommended defaults.)
## Step 9 — benchmarks (`tests/bench.py`, wraps `vllm bench serve`, random dataset, --ignore-eos)
Files: results/bench_eager.md, results/bench_compiled.md (+ raw JSON in results/bench_<label>/).
Each run uses a fresh random seed; prefix-cache hits are tracked per row (all 0.0%).
| scenario | metric | eager | compiled + graphs |
|---|---|---|---|
| decode 128/512, c=1 | median TPOT | 34.3 ms (28.8 tok/s) | **7.8 ms (126 tok/s)** |
| decode 128/512, c=16 | output tok/s | 444 | **1593** |
| prefill 4096/1, c=1 | median TTFT | 227 ms (≈18k tok/s) | 234 ms (17.5k tok/s) |
| prefill 4096/1, c=16 | prefill tok/s | 22.0k | 22.3k |
- Decode in eager mode is launch-overhead bound (TPOT flat from batch 1 to 16); graphs give 4.3×
at c=1 and 3.6× at c=16. Prefill is compute bound and unaffected. → **Run without --enforce-eager.**
- Pitfalls hit while benchmarking (fixed in tests/bench.py): (1) a fixed `--seed` re-sends identical
random prompts → served from prefix cache (one bogus run showed 228k prefill tok/s); (2) the first
run after server start includes ~10 s Triton JIT (eager prefill c=1 throughput showed 3.1k tok/s
while its TTFT said 18k) → script now warms up first. An earlier eager prefill c=16 figure of 31k
was cache-contaminated and is superseded.
- Initial mixed 1k/256 run (eager, `vllm bench serve` default): c=1 29.7 tok/s out, TPOT 33.2 ms;
c=16 424 tok/s out, TPOT 36.0 ms (logs/bench_eager_c{1,16}.log).
- BetterBench: see below.
## Deployment
Build once: `docker build -t lfm3-vllm-xpu .`
Ready-to-use `docker run` (recommended: graphs on, i.e. no --enforce-eager):
```bash
docker run -d --rm --name lfm3-serve \
--device /dev/dri -v /dev/dri/by-path:/dev/dri/by-path --ipc=host --shm-size=16g \
-p 127.0.0.1:8000: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
```
(`./run_server.sh -d` = same with --enforce-eager; `EAGER=0 ./run_server.sh -d` = the above.)
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 — 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
# ---------- 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 vllm-lfm3
--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:/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.
## Known limitations
- Speculative decoding not supported by the short-conv path (raises NotImplementedError).
- TP > 1 is structurally supported (parallel linears, sharded conv dim) but untested (single GPU).
- Requests that override `repetition_penalty` etc. work as usual; generation_config defaults apply otherwise.
### Sanity check of the benchmark numbers against measured hardware limits (`tests/hw_roofline.py`)
B65 measured: decode-like bf16 GEMV ≈ 428 GB/s (raw copy 956 GB/s read+write), bf16 GEMM ≈ 92–94 TFLOPS.
- Decode reads all weights per step: ~1.73 B params (incl. tied lm_head) = 3.45 GB → floor ≈ 8.1 ms at
428 GB/s. Measured 7.8 ms (≈ 440 GB/s effective) → **at the bandwidth roofline**; only weight
quantization would speed up single-stream decode further. c=16 TPOT only +10% → still weight-bound.
- Prefill: 2 × 1.47 B FLOP/token (+ attention) → 4096 tokens ≈ 12.4 TFLOP; 227 ms ≈ 55 TFLOPS (58% of
GEMM peak), c=16 at 22.3k tok/s ≈ 65 TFLOPS (70%). Remainder = norms/conv/rope/attention/gating. Reasonable.
- Eager decode 34 ms = ~26 ms launch/dispatch overhead above the floor (~1 ms per layer), consistent with
TPOT being flat across batch sizes.
### BetterBench 0.6.1 (github.com/GGZ14/BetterBench @ f72bb90), compiled mode, `--quick --decode --prefill`
Installed in ./.venv-bench, BETTERBENCH_HOME=./.betterbench, `--no-update-check`.
Report: results/betterbench/compiled.html (+ compiled.json), log: logs/betterbench_compiled.log.
- Single stream, 8 real-prompt categories × 5 passes: decode **128.4 tok/s** median (all categories
128.2–129.1, CV ≤ 0.6%), inter-token p50 7.8 ms / p99 8.6 ms, TTFT p50 ≈ 64 ms.
- Prefill sweep (cold cache): 1.5k tok → 15.2k tok/s, 5.9k → 18.4k, 11.8k → 18.0k, 23.5k → 16.7k tok/s
(TTFT 1.41 s at 23.5k tokens); 64k skipped (context 32k).
- Agrees with tests/bench.py (7.8 ms TPOT, ~17.5k prefill tok/s at 4k).
- Caveats: BetterBench labels the stream "speculative decoding" because 1 of 40 runs delivered a
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 .`).