Guides profiling NKI kernels on Trainium/Inferentia hardware using Neuron tools to generate NEFF+NTFF profile pairs for performance analysis.
Ships in neuron. 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.
This skill provides a complete workflow for profiling NKI kernel execution on Trainium/Inferentia hardware using Neuron profiling tools.
Minimal workflow to profile a kernel:
# 1. Set environment variables in Python before kernel execution
os.environ['NEURON_RT_INSPECT_ENABLE'] = '1'
os.environ['NEURON_RT_INSPECT_DEVICE_PROFILE'] = '1'
os.environ['NEURON_RT_INSPECT_OUTPUT_DIR'] = './output'
# 2. Run kernel to generate NEFF
python my_kernel.py
# 3. Find the NKI kernel NEFF (skip XLA-generated NEFFs)
NEFF_PATH=$(python3 scripts/identify-neffs.py ./output my_kernel_func_name)
# 4. Capture profile with neuron-explorer
neuron-explorer capture -n $NEFF_PATH -s profile.ntff --profile-nth-exec=2 --enable-dge-notifs
# 5. View results with neuron-explorer
neuron-explorer view --output-format summary-json -n $NEFF_PATH -s profile.ntff
The workflow generates two key artifacts:
$NEURON_PROJECT_ROOT names the PROJECT directory this analysis belongs to; everything this
skill generates lands under <root>/agent_artifacts/, and it defaults to the cwd, so an ordinary
interactive run needs no extra input. It is the SAME input the rest of this family takes — the
parallelism-planner and hardware-entitlement skills accept it as --project-root, the
vllm-neuron profiling skill writes its profiles under it — which is what lets one run's plan,
per-operator floor, profile and ingested parquet sit in a single evidence trail instead of four
unrelated directories.
an explicit `-s` / output path you pass to neuron-explorer (if given)
else $NEURON_PROJECT_ROOT/agent_artifacts/data/profiles/<run-name>/ (NEFF, NTFF, summary JSON)
else $PWD/agent_artifacts/data/profiles/<run-name>/ (NEFF, NTFF, summary JSON)
The relative paths in the examples below (./profiles/run_001/profile.ntff) are relative to the project root. Capture must run on the Trainium box that owns the device, so when that box is not your project directory, pass the output path explicitly and copy the pair back into <root>/agent_artifacts/data/profiles/ — the querying skill then finds it where every other skill looks.
Before profiling kernels, resolve the NKI virtual environment path:
echo $NKI_VENV_PATH.claude/nki-dev-suite.local.md and extract nki_venv_path from YAML frontmatterActivate before running any profiling commands:
source $NKI_VENV_PATH/bin/activate
Hardware requirement: Profiling requires execution on actual Trainium/Inferentia hardware.
Add these environment variables in your Python script before kernel execution:
import os
# Enable runtime inspection and device profiling
os.environ['NEURON_RT_INSPECT_ENABLE'] = '1'
os.environ['NEURON_RT_INSPECT_DEVICE_PROFILE'] = '1'
os.environ['NEURON_RT_INSPECT_OUTPUT_DIR'] = './output'
# Compiler flags for target hardware
os.environ['NEURON_CC_FLAGS'] = '--target trn2 --lnc 1' # use lnc=2 if explicitely told to.
# Pin to a specific neuron core(s) to avoid conflicts with concurrent sessions
os.environ['NEURON_RT_VISIBLE_CORES'] = '0' # '0,1', '0-1'
| Environment Variable | Description |
|---|---|
NEURON_RT_INSPECT_ENABLE | Enable runtime inspection |
NEURON_RT_INSPECT_DEVICE_PROFILE | Enable device-level profiling |
NEURON_RT_INSPECT_OUTPUT_DIR | Directory for NEFF output |
NEURON_RT_VISIBLE_CORES | Pin to specific core(s) — prevents contention when multiple agents profile concurrently |
Run your kernel script. This compiles and executes the kernel, generating the NEFF file in the output directory.
python my_kernel.py
Important: Compute references on CPU. If the test script computes a reference result (e.g., torch.matmul for comparison), do it on CPU — not on the XLA device. Every XLA graph compiled on-device generates a separate NEFF. Running reference operations on-device creates extra NEFFs that make it hard to identify the NKI kernel's NEFF.
# CORRECT: Reference on CPU — generates only the NKI kernel NEFF
expected = torch.relu(torch.matmul(lhs.cpu(), rhs.cpu()))
result = my_nki_kernel(lhs, rhs) # Only this generates a NEFF
# WRONG: Reference on device — generates an extra NEFF
expected = torch.relu(torch.matmul(lhs, rhs)) # Compiles to its own NEFF!
result = my_nki_kernel(lhs, rhs) # Another NEFF
The runtime creates a subdirectory with instance and process ID naming:
./output/
└── i-0823210096b01e7ec_pid_1187583/
└── neff_*_vnc_0.neff
Create a dedicated folder for this profiling iteration. This prevents confusion when comparing multiple optimization attempts:
mkdir -p ./profiles/run_001
Organize profile iterations:
./profiles/
├── run_001/ # Baseline profiling
│ ├── profile.ntff
│ └── metrics.json
├── run_002/ # After first optimization
│ ├── profile.ntff
│ └── metrics.json
└── run_003/ # After second optimization
Locate the NKI kernel NEFF and capture execution profile:
# Find NKI kernel NEFF by function name (skips XLA-generated NEFFs)
NEFF_PATH=$(python3 scripts/identify-neffs.py ./output my_kernel_func_name)
# Capture profile trace
neuron-explorer capture \
-n $NEFF_PATH \
-s ./profiles/run_001/profile.ntff \
--profile-nth-exec=2 \
--enable-dge-notifs
| Flag | Description |
|---|---|
-n | Path to NEFF file |
-s | Output path for NTFF trace file |
--profile-nth-exec=2 | Profile the 2nd execution (skip warmup) |
--enable-dge-notifs | Enable DMA engine notifications for detailed analysis |
Generate a JSON summary of the profile results:
neuron-explorer view \
--output-format summary-json \
-n $NEFF_PATH \
-s ./profiles/run_001/profile.ntff
This outputs structured JSON with all metrics. Parse for specific values:
neuron-explorer view \
--output-format summary-json \
-n $NEFF_PATH \
-s ./profiles/run_001/profile.ntff | jq '.latency'
Common JSON queries:
# Get latency in milliseconds
jq '.latency'
# Get all engine utilizations
jq '{tensor: .tensor_engine_active_time_percent, vector: .vector_engine_active_time_percent}'
# Get memory metrics
jq '{hbm_read: .hbm_read_bytes, hbm_write: .hbm_write_bytes}'
# Check if memory-bound or compute-bound
jq '{intensity: .mm_arithmetic_intensity, peak_ratio: .peak_flops_bandwidth_ratio}'
Save the full JSON output for later comparison:
neuron-explorer view \
--output-format summary-json \
-n $NEFF_PATH \
-s ./profiles/run_001/profile.ntff > ./profiles/run_001/metrics.json
For detailed analysis of the kernel profile, use the /neuron-nki-profile-querying skill. It allows for high level performance bounds analysis, as well as zoomed in, instruction level investigation of specific inefficiencies through python on parquet.
Understanding the generated file structure:
./output/ # NEURON_RT_INSPECT_OUTPUT_DIR
└── i-0823210096b01e7ec_pid_1187583/ # Instance ID + process ID
├── neff_307444798579300_vnc_0.neff # One NEFF per compiled XLA graph
├── neff_324387526933418_vnc_0.neff # (may include non-NKI NEFFs)
├── 307444798579300_vnc_0.ntff # Matching execution traces
├── 324387526933418_vnc_0.ntff
└── ntrace.pb # System trace metadata
./profiles/ # Organized profile iterations
├── run_001/
│ ├── profile.ntff # Execution trace
│ └── metrics.json # Summary metrics
├── run_002/
│ └── ...
The instance/pid subdirectory naming (i-xxx_pid_xxx) is automatic and includes the EC2 instance ID and process ID for traceability.
When the output directory contains multiple NEFFs (from multiple on-device operations), use the included identify-neffs.py script to identify which NEFF belongs to which kernel:
# List all NEFFs with identification
python3 scripts/identify-neffs.py ./output/i-*_pid_*/
# Output:
# [NKI:matmul_relu] ./output/.../neff_389250674131083_vnc_0.neff
# inputs: ['lhs_T', 'rhs', 'tmp.4'] outputs: ['output.51']
# ntff: ./output/.../389250674131083_vnc_0.ntff
# [XLA:broadcast,dot,maximum] ./output/.../neff_418708643727628_vnc_0.neff
# Find a specific kernel by name (useful with multiple NKI kernels)
NEFF_PATH=$(python3 scripts/identify-neffs.py ./output/i-*_pid_*/ matmul_relu)
How it works: Each NEFF embeds its compile workdir path (/tmp/.../neuroncc_compile_workdir/<uuid>/). The script reads the HLO module in that workdir. NKI kernels appear as custom-call ops with AwsNeuronCustomNativeKernel and carry a base64-encoded JSON blob containing func_name, input_names, and output_names.
Limitation: Depends on compile workdirs in /tmp/ still existing. Run promptly after kernel execution.
| Metric | Description | Target |
|---|---|---|
latency | Total kernel execution time (ms) | Lower is better |
tensor_engine_active_time_percent | TensorE utilization | >90% for compute-bound |
hbm_read_bytes | HBM read traffic | Minimize |
hbm_write_bytes | HBM write traffic | Minimize |
mm_arithmetic_intensity | FLOPs per byte of memory traffic | Compare to peak ratio |
When optimizing a kernel, compare metrics across iterations:
# Baseline measurement
neuron-explorer view --output-format summary-json \
-n $NEFF -s ./profiles/baseline/profile.ntff > ./profiles/baseline/metrics.json
# After optimization
neuron-explorer view --output-format summary-json \
-n $NEFF -s ./profiles/optimized/profile.ntff > ./profiles/optimized/metrics.json
# Compare latencies
echo "Baseline: $(jq .latency ./profiles/baseline/metrics.json)"
echo "Optimized: $(jq .latency ./profiles/optimized/metrics.json)"
Optimization tracking table:
| Iteration | Change | Latency (ms) | TensorE (%) |
|---|---|---|---|
| Baseline | - | 1.23 | 45% |
| Larger tiles | Increased tile 64→128 | 0.95 | 72% |
| Double buffer | Added prefetching | 0.78 | 89% |
Keep notes on what changed between iterations to correlate optimizations with metric improvements.
See examples/basic-profiling-workflow.py for a complete end-to-end profiling script demonstrating all steps: environment setup, kernel execution, NEFF identification, profile capture, and JSON metric extraction.
Required settings:
| Setting | Source | Description |
|---|---|---|
nki_venv_path | .claude/nki-dev-suite.local.md or NKI_VENV_PATH | Python venv with neuronx packages |
Environment variables (set in kernel script):
| Variable | Value | Purpose |
|---|---|---|
NEURON_RT_INSPECT_ENABLE | 1 | Enable runtime inspection |
NEURON_RT_INSPECT_DEVICE_PROFILE | 1 | Enable device profiling |
NEURON_RT_INSPECT_OUTPUT_DIR | Path | NEFF output directory |
| Skill | Purpose |
|---|---|
/neuron-nki-profile-querying | Detailed profile querying and analysis |
/neuron-explorer-profile-schema | Reference for the parquet schema produced by neuron-explorer |
/neuron-nki-debugging | Debug compilation errors |
/neuron-nki-docs | Look up API documentation |
/neuron-nki-writing | Write NKI kernels |
Multiple NEFFs generated (can't tell which is the NKI kernel):
torch.matmul) on CPU, not on the XLA device. Each on-device XLA graph generates its own NEFF.python3 scripts/identify-neffs.py ./output to list all NEFFs with their type (NKI vs XLA) and kernel names. See the NEFF Identification section for details.neff_<ID>_vnc_0.neff has a matching trace <ID>_vnc_0.ntff in the same directory.No NEFF file generated:
NEURON_RT_INSPECT_ENABLE=1 is set before importsNEURON_RT_INSPECT_OUTPUT_DIR path exists and is writableneuron-lsneuron-explorer capture fails:
ls -la <path>Empty or minimal profile data:
--profile-nth-exec=2 to skip warmup execution--enable-dge-notifs for detailed DMA analysisls -lh profile.ntffLatency varies between runs:
--profile-nth-exec=2 or higher to skip warmupWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
neuron-profiling, nki-kernel, trainium, inferentia, neuron-explorer
/neuron:neuron-nki-profiling [kernel file]from neuron
neuron@tsvikas is listed by tsvikas/skills — review the source before installing
npx claudepluginhub tsvikas/skills --plugin neuron13 skills in this plugin
/neuron-explorer-profile-schemaReference for the neuron-explorer profile schema (the parquet tables produced
when `neuron-explorer view`/`ingest` processes a profile). Use when the user
asks "what tables are in the profile", "what fields are in <Table>", "where
does this field come from", "where can I find matmul/source-line info in the
schema", or wants to fetch the canonical schema YAML matching the installed
neuron-explorer version. Companion to /neuron-nki-profile-querying — that
skill writes SQL; this skill explains what the columns mean and where the
data originates.
/neuron-framework-autoportPort a HuggingFace model to NeuronX Distributed Inference for AWS Trainium/Inferentia.
Use when the user says "port model", "autoport", "convert to neuron",
"compile for trainium", or invokes /neuron-framework-autoport. Handles the full workflow:
knowledge base analysis, architecture analysis, NeuronX implementation,
compilation, inference testing, and accuracy validation (95%+ token match).
/neuron-framework-autoport-vllm-neuronPort a HuggingFace model architecture to the vLLM-Neuron Trainium2 backend. Handles architecture research, code generation, and validation./neuron-framework-equivalenceVerifies functional equivalence between two implementations of the same model using a hierarchical 8-stage algorithm. Orchestrates model tree comparison, component-level R-ratio testing, E2E logit comparison, and distributional checks. Use when porting models between frameworks, hardware targets, or precision regimes — e.g., HuggingFace to NxDI, PyTorch to ONNX, GPU to Neuron, FP32 to BF16, or any source-target pair./neuron-framework-profile-analysis-vllm-neuronIngests vllm-neuron model execution artifacts into parquet using
neuron-explorer and guides profile analysis: identifies
prefill/decode NEFFs, segments by collective boundaries,
computes per-engine bounds and DMA efficiency, and produces
structured workload reports.
Use when encountering "analyze profile", "ingest profile",
"query system trace", "what's the bottleneck",
"decode step time", "prefill breakdown",
"segment by layer", "DMA efficiency".
/neuron-framework-profiling-vllm-neuronGuides profiling vllm-neuron models on Trainium: capturing device (NTFF) and
system traces from a live server via vLLM's /start_profile and /stop_profile
endpoints (the primary method), or offline via `vllm bench throughput` +
`neuron-explorer capture` (fallback). Covers the neuron_profiler config,
steady-state decode capture, and the common traps.
Use when encountering "profile model", "benchmark vllm-neuron",
"profile running server", "start_profile", "stop_profile",
"profile live vllm serve", "capture NEFF from vllm", "get system trace",
"capture NTFF from model run", "get profiling artifacts", "profile decode step",
"profile MoE model", "per-rank profiling".
Other plugins' skills for the same job