aws-neuron/neuron-agentic-development/neuron-nki-debugging
Claude Code and agent skill by aws-neuron/neuron-agentic-development
- community
Checking that the SKILL.md file is still in the repository.
This skill guides debugging NKI compilation errors on Neuron hardware. Use when encountering "compiler error on device", "debug NKI kernel", "test kernel on trn2/trn3", "neuronx-cc compilation failed", "validate kernel on hardware", "run kernel on trainium", or asking "how to debug NKI compilation errors on device".
Install
npx vskill@latest install aws-neuron/neuron-agentic-development/neuron-nki-debuggingSKILL.md
The same SKILL.md was published earlier as uw-syfi/vibe-serve/neuron-nki-debugging.
Debugging NKI on Neuron Hardware
This skill provides a workflow for debugging NKI kernel compilation and execution on Trainium/Inferentia hardware.
Quick Start
Minimal working example to test kernel compilation on device:
Prerequisites
Before running kernels on device, resolve the NKI virtual environment path:
- Check environment:
echo $NKI_VENV_PATH - If empty, read
.claude/nki-dev-suite.local.mdand extractnki_venv_pathfrom YAML frontmatter - If still not found, report: "NKI_VENV_PATH not configured. Set the environment variable or create .claude/nki-dev-suite.local.md with nki_venv_path in frontmatter."
Activate before running any device tests:
Platform Detection
Before compilation, detect the current hardware platform:
Current platform: !neuron-ls | head -3
Platform Target Mapping
| Hardware | Instance | Target Flag | Generation | |
|---|---|---|---|---|
| Trainium 1 | trn1 | --target trn1 | gen2 | |
| Trainium 1n | trn1n | --target trn1n | gen2 | |
| Inferentia 2 | inf2 | --target inf2 | gen2 | |
| Trainium 2 | trn2 | --target trn2 | gen3 | |
| Trainium 3 | trn3 | --target trn3 | gen4 |
Match the --target flag and platform_target decorator argument to your detected hardware.
Standard Debugging Workflow
Step 1: Set Environment Variables
| Flag | Purpose | |
|---|---|---|
--target | Hardware platform (trn1, trn2, trn3, inf2) | |
--lnc 1 | Single NeuronCore (simplifies debugging) | |
NEURON_RT_VISIBLE_CORES | Pin to specific core(s) — prevents contention when multiple agents run concurrently |
See references/compiler-flags.md for complete flag reference.
Step 2: Apply Matching Decorator
The platform_target environment variable MUST match the --target in NEURON_CC_FLAGS.
Step 3: Create Test Script
Step 4: Run and Observe
Compilation errors appear in the console output. The print() statement forces XLA compilation, which triggers the neuronx-cc compiler.
Step 5: Validate Numerically
Compare device output against a CPU-computed reference using multiple complementary checks — no single metric catches all issues:
- atol / rtol (
torch.allclose): Per-element pass/fail gate - Maximum absolute difference: Worst-case outlier check
- Norm of the difference tensor: Detects widespread small drift
- Cosine similarity: Catches directional errors in high-dimensional outputs
Important: Compute references on CPU, not on the XLA device. Every XLA graph compiled on-device generates a separate NEFF file. Running reference operations (e.g., torch.matmul, torch.softmax) on the XLA device creates extra NEFFs, making it hard to identify which NEFF belongs to the NKI kernel during profiling.
For complex kernels where the final output is wrong: decompose the kernel into logical stages and examine intermediate tensors at each boundary. Store intermediates to HBM temporarily, compare each against the matching reference stage, and binary-search for the stage that introduces the error. Once the failing stage is identified, test it with minimal input shapes (e.g., a single 128x128 tile) to isolate whether the issue is in the core logic or in tiling/boundary handling. Remove the debug stores once the issue is resolved.
Compiler Artifacts Mode
For advanced debugging that preserves compiler outputs for inspection, use when you need to understand detailed compilation behavior.
When to use: "compiler artifacts", "compiler flags", "inspect compiler log"
See references/compiler-artifacts.md for:
- Compiler debug flag configuration (
--verbose,--target,--lnc) - Finding the compiler temp folder
- Understanding generated artifacts (
*.neff,log-neuron-cc.txt)
Error Resolution
Error Categories
| Error Pattern | Category | Reference | |
|---|---|---|---|
NCC_EVRF* | Verification error | See references/ncc-verification-errors.md | |
NCC_EOOM* | Out of memory | See references/ncc-memory-resource-errors.md | |
NCC_E* (other) | Type/operation error | See references/ncc-type-operation-errors.md |
Quick Reference
See references/compiler-error-codes.md for the complete index of all 28 NCC_* error codes.
Common Error Quick Fixes
| Error Code | Category | Quick Fix | |
|---|---|---|---|
NCC_EVRF001 | Unsupported operator | Use alternative operator from neuronx-cc list-operators | |
NCC_EOOM001 | Memory exceeded | Reduce batch size, use tensor/pipeline parallelism | |
NCC_EVRF007 | Instruction limit | Apply model parallelism | |
NCC_EVRF005 | Unsupported FP8 type | Convert to float16/bfloat16 or use gen3+ hardware | |
NCC_EARG001 | LNC configuration | Use supported LNC count for target hardware | |
NCC_EVRF024 | Output tensor > 4GB | Reduce tensor size or use tensor parallelism |
Profiling (Optional)
To capture execution traces for profiling:
This captures NEFF (compiled binary) and NTFF (execution trace) files in the output directory.
Complete Example
Configuration
Required settings:
| Setting | Source | Description | |
|---|---|---|---|
nki_venv_path | .claude/nki-dev-suite.local.md or NKI_VENV_PATH | Python venv with neuronx packages |
Related skills:
| Skill | Use When | |
|---|---|---|
/neuron-nki-profiling | Profile kernel performance | |
/neuron-nki-docs | Look up API documentation and error codes |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/neuron-nki-debugging/SKILL.md
Popularity
- Repository stars
- 65
- Repository forks
- 10
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/aws-neuron/neuron-agentic-development/neuron-nki-debugging)