Files
xpu-llm-ports/lfm3/quant/gptq_baked/check_body.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

30 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Check that llm-compressor's traced sequential pipeline (what quantize_body.py calibrates with) is the
same function as the plain LFM3 forward: trace the BF16 model with the same sequential targets and
tracing_ignore, run the 25 subgraphs one after another on a 1000-token calibration sample (as
quant/check_patch.py in round 4) and compare the logits with model(x).logits.
python3 check_body.py MODEL_DIR CALIB.pt [DEVICE=xpu]
"""
import sys
import torch
from llmcompressor.args.dataset_arguments import DatasetArguments
from llmcompressor.pipelines.sequential.helpers import trace_subgraphs
from transformers import AutoModelForCausalLM
model_dir, calib = sys.argv[1:3]
dev = sys.argv[3] if len(sys.argv) > 3 else "xpu"
model = AutoModelForCausalLM.from_pretrained(model_dir, dtype=torch.bfloat16, trust_remote_code=True).to(dev).eval()
x = torch.load(calib)[3][:, :1000].to(dev)
inputs = {"input_ids": x}
with torch.no_grad():
ref = model(**inputs).logits.float()
subgraphs = trace_subgraphs(model, inputs, ["Lfm3DecoderLayer"],
DatasetArguments().tracing_ignore + ["create_masks_by_layer_type"])
acts = dict(inputs)
for sg in subgraphs:
acts.update(sg.forward(model, **{k: acts[k] for k in sg.input_names if k in acts}))
out = next(v for v in acts.values() if torch.is_tensor(v) and v.shape[-1] == ref.shape[-1]).float()
print(f"{len(subgraphs)} subgraphs; max |dlogit| {(out - ref).abs().max().item()}, "
f"top1 agree {(out.argmax(-1) == ref.argmax(-1)).float().mean().item()}")