Profiles PyTorch models on Intel XPU using torch.profiler and Kineto to capture CPU+XPU timelines, export Chrome traces, and identify kernel bottlenecks and async-overlap gaps.
Ships in torch-xpu-profile. 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.
None: SKILL.md is the whole skill.
torch.profiler with ProfilerActivity.XPU captures CPU + XPU op
timeline on Kineto. Use for "which aten::* op is slow?", "is
the GPU idle?", "is decode kernel-bound?". For server-side
profiling use vllm-xpu-profile; for SYCL kernel level use
xpu-profile-unitrace.
| CUDA | XPU |
|---|---|
ProfilerActivity.CPU, ProfilerActivity.CUDA | ProfilerActivity.CPU, ProfilerActivity.XPU |
prof.export_chrome_trace("trace.json") | identical |
record_shapes=True, with_stack=True | identical |
prof.key_averages().table(sort_by="cuda_time_total") | sort_by="xpu_time_total" |
import torch
from torch.profiler import profile, ProfilerActivity, schedule
from transformers import AutoModelForCausalLM, AutoTokenizer
mid = "Qwen/Qwen2.5-1.5B-Instruct"
tok = AutoTokenizer.from_pretrained(mid)
model = AutoModelForCausalLM.from_pretrained(
mid, dtype=torch.bfloat16, device_map="xpu"
).eval()
inp = tok("Tell me a joke.", return_tensors="pt").to("xpu")
# Warmup so first-run kernel compile doesn't pollute the trace
with torch.no_grad():
model.generate(**inp, max_new_tokens=8, do_sample=False,
pad_token_id=tok.eos_token_id)
with profile(
activities=[ProfilerActivity.CPU, ProfilerActivity.XPU],
record_shapes=True,
profile_memory=True,
with_stack=False,
) as prof:
with torch.no_grad():
model.generate(**inp, max_new_tokens=64, do_sample=False,
pad_token_id=tok.eos_token_id)
print(prof.key_averages().table(sort_by="xpu_time_total", row_limit=20))
prof.export_chrome_trace("trace.json")
Output: trace.json (drag into https://ui.perfetto.dev) plus a
top-20 ops table sorted by XPU time.
key_averages table — first 5 rows are usually
70–90% of XPU time. Top = matmul/attention -> GPU-bound (good).
Top = aten::copy_ / H2D-D2H transfers -> bandwidth-bound or
paying for unnecessary moves.profile_memory=True) — peak before
first generated token is prefill; subsequent peaks are KV
growth. Compare against model-can-it-fit prediction.scheduleFor multi-step capture without giant files:
sched = schedule(skip_first=2, wait=1, warmup=1, active=3, repeat=1)
with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.XPU],
schedule=sched,
on_trace_ready=lambda p: p.export_chrome_trace(
f"trace_step_{p.step_num}.json")) as prof:
for step in range(10):
with torch.no_grad():
model.generate(**inp, max_new_tokens=16, do_sample=False,
pad_token_id=tok.eos_token_id)
prof.step()
One trace per repeat -> easier to diff than one giant file.
ProfilerActivity.XPU not supported -> torch build doesn't
include XPU profiler. Confirm torch.__version__ ends in
+xpu and is recent enough.torch.xpu.synchronize() at end of with profile(...).schedule form above for short active
windows.PYTORCH_ENABLE_XPU_FALLBACK=0 so unsupported ops
error loudly.| Variable | Purpose |
|---|---|
ZE_AFFINITY_MASK | Pin to one XPU. |
PYTORCH_ENABLE_XPU_FALLBACK=0 | Error on CPU fallbacks instead of hiding them. |
KINETO_LOG_LEVEL=INFO | Diagnose incomplete traces. |
torch.profiler API: https://docs.pytorch.org/docs/stable/profiler.htmlWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/torch-xpu-profile:torch-xpu-profilefrom torch-xpu-profile
npx claudepluginhub intel/gpu-ai-skills --plugin torch-xpu-profileOther plugins' skills for the same job