Files
xpu-llm-ports/lfm3/tests/head_timing.py
T
Pascal LinxweilerandClaude Opus 5.5 38b0e9a345 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>
2026-10-30 14:48:48 +01:00

32 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""Time the logits step alone (compute_logits = lm_head GEMM + logits processor) and the embedding
lookup of a served LFM3 checkpoint at decode shape (1 token) and batch 8, eager, XPU-synchronized median.
python3 tests/head_timing.py MODEL_DIR (inside the image, VLLM_ALLOW_INSECURE_SERIALIZATION=1)
"""
import sys, time
import torch
from vllm import LLM
def bench(m):
out = {}
for n in (1, 8):
h = torch.randn(n, m.config.hidden_size, dtype=torch.bfloat16, device="xpu")
ids = torch.randint(0, m.config.vocab_size, (n,), device="xpu")
for name, fn in {"compute_logits": lambda: m.compute_logits(h),
"embed": lambda: m.model.embed_input_ids(ids)}.items():
for _ in range(20):
fn()
ts = []
for _ in range(200):
torch.xpu.synchronize(); t0 = time.perf_counter(); fn(); torch.xpu.synchronize()
ts.append(time.perf_counter() - t0)
out[f"{name} n={n}"] = f"{sorted(ts)[len(ts) // 2] * 1e3:.3f} ms"
return out
if __name__ == "__main__":
llm = LLM(sys.argv[1], enforce_eager=True, gpu_memory_utilization=0.3, max_model_len=4096)
with torch.no_grad():
print(llm.apply_model(bench)[0])