Benchmarks Hugging Face models on Intel XPU GPUs using pure PyTorch, measuring tokens/sec, TTFT, decode latency, and peak memory. Use after model-can-it-fit to validate memory predictions.
Ships in torch-xpu-bench. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Pure-PyTorch benchmarks of HF models on XPU. Measures bare
model.generate() with no scheduler, no continuous batching, no
API overhead. For serving-shape numbers (TTFT/TPOT/ITL under
concurrency) use vllm-xpu-bench.
Important: This skill provides a ready-to-use benchmark script at
{base_dir}/scripts/bench.py. Do not write your own benchmark script;
use the provided one.
Use cases:
--enforce-eager is worth adding in vLLM for a
problem model (graphs are on by default from v0.31.0).max_memory_allocated.For diffusion and encoder-only models, see
references/non-llm-snippets.md.
| CUDA | XPU |
|---|---|
torch.cuda.synchronize() | torch.xpu.synchronize() |
torch.cuda.Event(enable_timing=True) | torch.xpu.Event(enable_timing=True) |
torch.cuda.max_memory_allocated() | torch.xpu.max_memory_allocated() |
torch.cuda.reset_peak_memory_stats() | torch.xpu.reset_peak_memory_stats() |
torch.cuda.empty_cache() | torch.xpu.empty_cache() |
Two gotchas:
torch.xpu.synchronize() you measure launch latency.If nvidia-smi or rocm-smi reports hardware, bench code that
doesn't pin a device may silently land on CUDA/ROCm. Defences:
export CUDA_VISIBLE_DEVICES= # hide all NVIDIA
export HIP_VISIBLE_DEVICES= # hide all AMD ROCm
export ZE_AFFINITY_MASK=0 # pick a specific Intel device
scripts/bench.py asserts model parameters land on xpu after
from_pretrained; replicate in your own benches. Cross-check with
xpu-smi dump -d 0 -m 5 — if XPU memory doesn't climb, the bench
is on the wrong device.
These all load onto xpu:0 when only an Intel XPU is visible:
device_map="xpu" / "xpu:0" / 0 / "auto" / {"": "xpu"} / {"": 0}.
hf_device_map is empty for whole-model placement; populates only
on multi-GPU splits.
Always use the provided benchmark script at {base_dir}/scripts/bench.py:
python3 {base_dir}/scripts/bench.py \
--model Qwen/Qwen2.5-1.5B-Instruct \
--dtype bfloat16 \
--prompt-tokens 512 --gen-tokens 128 \
--warmup 2 --runs 5
--revision pins the Hugging Face repo revision (branch, tag, or commit sha;
default main). Pass a commit sha when a benchmark number has to stay
reproducible — otherwise the run silently follows whatever main points at.
Output:
Run TTFT (ms) Decode (ms/tok) Total (s) Throughput (tok/s)
1 ... ... ... ...
...
Median: TTFT ... ms, decode ... ms/tok, throughput ... tok/s
Peak XPU memory: ... GiB
Use this relative: capture a baseline median, change one knob, re-run. Throughput won't match anyone else's; the delta between two runs on your hardware is the signal.
generate() entry to first token,
dominated by prefill.gen_tokens / Total_s.torch.xpu.max_memory_allocated().Median across runs is robust to jitter; mean isn't. Median delta within ~3% is noise; >5% is signal; >10% is a clear win/regression.
python3 {base_dir}/scripts/bench.py --model "$M" --dtype bfloat16 --runs 5 > bench-bf16.txt
python3 {base_dir}/scripts/bench.py --model "$M" --dtype float16 --runs 5 > bench-fp16.txt
diff -u <(grep Median bench-bf16.txt) <(grep Median bench-fp16.txt)
Same shape for --compile on/off, model A vs B.
torch.compile actually helpsvLLM v0.31.0+ captures XPU graphs by default, so the compiled path is
already what you serve. Use this to confirm the pattern on Battlemage
before you consider adding --enforce-eager back for a model that
misbehaves under capture:
python3 {base_dir}/scripts/bench.py --model "$M" --runs 5 # eager
python3 {base_dir}/scripts/bench.py --model "$M" --compile --runs 5 # compiled
If compiled wins on decode (ms/tok) and content is correct, leave
graphs on in vllm-xpu-run — emit no --enforce-eager. Only if
eager measures faster, or compiled output is wrong, is the flag
justified for that model.
Compile gain scales with model size — sub-1B models see little win because launch overhead and kernel work are similar in magnitude. First compiled run includes graph capture cost; default warmup is post-capture. If a 0.5B sees no win, retest at 7B+ before concluding "compile doesn't help."
Run against the model you tested with model-can-it-fit. Compare the bench's "Peak XPU memory" against the calculator's "Total" line:
max_seq_len; rerun with longer --gen-tokens.device_map="xpu"); verify
next(model.parameters()).device.reset_peak_memory_stats(0) + empty_cache() once.torch.xpu.synchronize(); t = time.perf_counter()
<work>
torch.xpu.synchronize(); times.append(time.perf_counter() - t)
xpu-smi dump -d 0 -m 5,18 -i 1 from host.Cannot find any XPU devices → check xpu-container-run /
xpu-discover before running.XPU out of memory → reduce --prompt-tokens / --gen-tokens,
use float16, or quantize. Run model-can-it-fit first.--compile first run much slower → graph capture cost; raise
--warmup.| Variable | Purpose |
|---|---|
ZE_AFFINITY_MASK | Pin to one XPU. |
TRITON_CACHE_DIR | Persist XPU Triton kernels across runs. |
PYTORCH_ENABLE_XPU_FALLBACK=0 | Make CPU fallbacks loud during a bench. |
HF_TOKEN | Gated checkpoints. |
references/non-llm-snippets.md — diffusion + encoder-onlytorch.xpu API: https://docs.pytorch.org/docs/stable/xpu.htmlgenerate(): https://huggingface.co/docs/transformers/main_classes/text_generationtorch.compile: https://docs.pytorch.org/docs/stable/torch.compiler.htmlWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/torch-xpu-bench:torch-xpu-benchfrom torch-xpu-bench
npx claudepluginhub intel/gpu-ai-skills --plugin torch-xpu-benchOther plugins' skills for the same job