Torch Xpu Bench logo

Torch Xpu Bench

Organization
intel
torch-xpu-bench

Benchmark a Hugging Face model on an Intel GPU through pure PyTorch + Transformers, **single-process, no HTTP server**. Measures generate() throughput in tokens/sec, time-to-first-token, decode-step latency, and peak XPU memory. Also covers diffusion and encoder-only models via `references/non-llm-snippets.md`. Use after **model-can-it-fit** to validate predicted memory against `torch.xpu.max_memory_allocated()`.

Overview

Publisherintel
Repositoryskills
Skill nametorch-xpu-bench
Stars
31
Forks
14
Bundled files
2
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by intel on GitHub. Read the source before you install it.

Installation

Install the Torch Xpu Bench AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/intel/skills/tree/main/skills/torch-xpu-bench
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/intel/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/torch-xpu-bench .claude/skills/torch-xpu-bench
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Torch Xpu Bench in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Torch Xpu Bench on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Torch Xpu Bench is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

torch-xpu-bench

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:

  • TTFT and decode rate of a single sequence at a given dtype.
  • A/B dtypes (bf16 vs fp16), compile on/off, model size.
  • Decide whether --enforce-eager is worth adding in vLLM for a problem model (graphs are on by default from v0.31.0).
  • Validate model-can-it-fit predictions against max_memory_allocated.

For diffusion and encoder-only models, see references/non-llm-snippets.md.

CUDA → XPU translation

CUDAXPU
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:

  • Synchronise before timing. XPU kernels launch async; without torch.xpu.synchronize() you measure launch latency.
  • Warm up. First call compiles XPU Triton kernels; first compiled-graph call triggers capture. Discard the first 1–3 runs.

Hosts with non-Intel GPUs

If nvidia-smi or rocm-smi reports hardware, bench code that doesn't pin a device may silently land on CUDA/ROCm. Defences:

sh
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.

Quickstart

Always use the provided benchmark script at {base_dir}/scripts/bench.py:

sh
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.

Per-run metrics

  • TTFT — wall time from generate() entry to first token, dominated by prefill.
  • Decode (ms/tok) — per-token time for tokens 2..N, averaged.
  • Total (s) — full call wall time.
  • Throughput — gen_tokens / Total_s.
  • Peak XPU memory — 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.

A/B comparisons

sh
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.

When torch.compile actually helps

vLLM 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:

sh
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."

Feedback loop with model-can-it-fit

Run against the model you tested with model-can-it-fit. Compare the bench's "Peak XPU memory" against the calculator's "Total" line:

  • Decoder-only LLM, gap >20% -> calculator bug; file an issue.
  • VLM / diffusion -> gap is expected (the calculator covers decoder-only). Use the measurement to refine your headroom budget.
  • Lower than predicted -> KV cache may not have grown to the configured max_seq_len; rerun with longer --gen-tokens.

Bench-procedure checklist (any workload)

  1. Pin device (device_map="xpu"); verify next(model.parameters()).device.
  2. reset_peak_memory_stats(0) + empty_cache() once.
  3. Warm: 1–3 unmeasured iterations.
  4. Synchronise around the timer:
    python
    torch.xpu.synchronize(); t = time.perf_counter()
    <work>
    torch.xpu.synchronize(); times.append(time.perf_counter() - t)
  5. N=5 timed iterations (raise to 10–20 if >10% spread).
  6. Report median, not mean. Add p99 for latency-tail concerns.
  7. Cross-check with xpu-smi dump -d 0 -m 5,18 -i 1 from host.

Common errors

  • 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.
  • TTFT >> decode → expected on long prompts.
  • Suspiciously fast decode + non-language output → garbage generation. Validate sample output before trusting throughput.
  • --compile first run much slower → graph capture cost; raise --warmup.

Env vars

VariablePurpose
ZE_AFFINITY_MASKPin to one XPU.
TRITON_CACHE_DIRPersist XPU Triton kernels across runs.
PYTORCH_ENABLE_XPU_FALLBACK=0Make CPU fallbacks loud during a bench.
HF_TOKENGated checkpoints.

What this skill does NOT cover

  • vLLM serving benches → vllm-xpu-bench.
  • SGLang serving benches → sglang-xpu-bench.
  • Profiling → torch-xpu-profile.
  • Training throughput — out of scope.

References

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Torch Xpu Bench AI skill do?

Benchmark a Hugging Face model on an Intel GPU through pure PyTorch + Transformers, **single-process, no HTTP server**. Measures generate() throughput in tokens/sec, time-to-first-token, decode-step latency, and peak XPU memory. Also covers diffusion and encoder-only models via `references/non-llm-snippets.md`. Use after **model-can-it-fit** to validate predicted memory against `torch.xpu.max_memory_allocated()`.

Why use Torch Xpu Bench on TypingMind?

Because you install it once and use it with any model. Torch Xpu Bench is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Torch Xpu Bench in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/intel/skills/tree/main/skills/torch-xpu-bench. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Torch Xpu Bench?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Torch Xpu Bench?

As many as you like. As long as a model supports skills, you can use Torch Xpu Bench with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Torch Xpu Bench AI skill free?

Yes. It is published on GitHub by intel under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇