Verifies functional equivalence between two model implementations using an 8-stage algorithm. Use when porting models between frameworks, hardware targets, or precision regimes.
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.
Verify and diagnose functional equivalence between a source (reference) and a target (ported) implementation of the same model.
The frozen criterion, reference method/precision, corpus and input/output lengths take precedence over the general pipeline and example tolerances below. Run only required comparisons. Do not add distributional checks to greedy-token matching or loosen a failed criterion. Probe logit capture capability before choosing a logit method; unsupported tooling and measured mismatch are different outcomes.
For criterion=greedy_token_match, reference_method=exact_tokens and explicit fp32, bf16
or fp16 reference precision, use the existing runner:
python3 {SCRIPTS_DIR}/run_stage1.py --model-path {SOURCE_MODEL_PATH} \
--correctness-contract {EXP_DIR}/correctness_contract.json \
--prompt-token-ids {EXP_DIR}/prompt_token_ids.json \
--target-results {EXP_DIR}/target_tokens.json \
--source-attempt-id {SOURCE_PROFILE_ATTEMPT_ID} \
--prepared-attempt {EXP_DIR}/prepared_equivalence.json \
--reference-cache {EXP_DIR}/reference_cache \
--output {EXP_DIR}/results/exact_tokens.json
prompt_token_ids.json is an array of token-ID arrays at the declared input length.
Its SHA256 uses compact JSON (sort_keys=True, separators=(",", ":")) and must match
reference_identity.tokenized_prompts_sha256. The native inference producer supplies
target_tokens.json with prompt_token_ids, generated_token_ids, observed_config,
execution_identity and source_attempt_id, backed by this attempt's native artifacts. The
runner verifies the prepared task's grant digest and compares the target identity/configuration
with that granted source. Generate it through the
existing serving lifecycle with the exact granted config. The comparison command does not
launch another server. Candidate inference runs again after compiler/source/config changes.
The runner collects tokens without logits or scores. The cache is limited to 16 entries and
64 MiB, keyed by checkpoint, actual prompt IDs/lengths, reference code/runtime, precision and
method. A busy cache returns a resumable error without launching a duplicate reference.
For a local checkpoint, set reference_identity.checkpoint to
reference_cache.checkpoint_identity(model_path): sha256: plus the digest of sorted
relative filenames and their SHA256 content hashes. The runner rehashes before cache lookup
and after generation and rejects a mismatch; budget this file-reading cost. For a remote HF
checkpoint use repo/id@<40-hex-commit> and pass --model-revision <commit>; the loader receives
that exact revision. Pin reference code separately. The runner writes <output-stem>_reference.json alongside
the report so eviction cannot erase admitted evidence. Persist these before cleanup.
The general 32-token smoke test is diagnostic.
Submit the report as a PRIMARY_MEASURED equivalence_report and its reference file as
PRIMARY_MEASURED reference_outputs; also submit the exact target_tokens.json as a
PRIMARY_MEASURED artifact so admission can verify its digest and token content.
Keep the unchanged correctness_contract,
source_attempt_id and current execution evidence in the payload. Use the report's
reference_cache_key (the campaign contract key) as reference artifact metadata.cache_key;
the helper's reference_cache.key additionally binds actual runtime/code. Never cache target
correctness. Return mismatches and required permission through the campaign's repair route;
an equivalence-only grant permits no source/monkey patches.
This entire pipeline (token/logit teacher-forcing, TARGET_CAUSAL_CLASS/ForCausalLM
wrapper, R-ratio on logits) is built around models with a sampler and a token-generation
output (decode-step models). It has no defined behavior for a pooling/embedding
model (--runner pooling in vLLM, no lm_head/sampler, output is a fixed-size embedding
vector, no next-token distribution to compare).
Do not force-fit a pooling model into this skill (e.g. by looking for a
ForCausalLM-shaped class that doesn't exist, or trying to compare "logits" that the
model never produces). Real incident: generic-encoder-only-model
(LlamaBidirectionalModel, mean-pool + L2-normalize head, prefill-only, no KV cache) has
no causal-LM class and no logits — attempting this skill's standard flow on it has no
valid inputs to provide for TARGET_CAUSAL_CLASS.
For a pooling/embedding model, use embedding cosine similarity against a trusted reference instead:
cos(embedding_target, embedding_reference) per prompt.This is a lighter-weight, model-specific script, not this skill's 8-stage pipeline — do
not attempt to route it through run_stage0.py/run_stage5.py/etc., which all assume a
ForCausalLM class exists.
Before starting, collect these from the user. Ask for any missing ones.
| Input | Description | Example |
|---|---|---|
SOURCE_MODEL_PATH | Path to source model weights (HF format) | /path/to/hf_models/Qwen3-0.6B |
COMPILED_MODEL_PATH | Path to compiled target model | /path/to/neuron_models/Qwen3-0.6B |
TARGET_MODELING_FILE | Path to target's modeling .py file | /path/to/modeling_qwen3.py |
TARGET_INNER_CLASS | Inner model class (extends NeuronBaseModel) | NeuronQwen3Model |
TARGET_CAUSAL_CLASS | ForCausalLM wrapper class | NeuronQwen3ForCausalLM |
TARGET_CONFIG_CLASS | InferenceConfig class | Qwen3InferenceConfig |
VENV | Path to Python venv with torch + neuronx | /opt/aws_neuronx_venv_pytorch_2_8_nxd_inference |
EXP_DIR | Experiment output directory | agent_artifacts/equiv_qwen3 |
VLLM_NEURON_DIR | vLLM-Neuron targets only. Project root of the vllm-neuron editable install | /path/to/vllm-neuron |
VLLM_CONFIG_SOURCE | vLLM-Neuron Stages 5+6 only. Exact server config JSON, config script, or vllm serve/bench script used for the target workload | /path/to/run_bench.sh |
For vLLM-Neuron, ask for VLLM_CONFIG_SOURCE before Stages 5+6. If it contains
multiple benchmark cells, ask which cell to validate. If a setting cannot be represented
by the accuracy debugger's server config, record it as a configuration gap; do not claim
equivalence for that setting.
Set SCRIPTS_DIR to the absolute path of this skill's scripts/ directory.
This skill's vllm_neuron adapter is pinned to vLLM 0.29.0 and the vLLM-Neuron plugin 0.29.0 line (two independently-versioned packages; the pins live in scripts/adapters/vllm_neuron.py as PINNED_VLLM_VERSION and PINNED_VLLM_NEURON_VERSION). When the target stack is vLLM-Neuron:
Version check is automatic. get_adapter() calls adapter.check_environment() immediately after construction. If the installed vllm or vllm-neuron plugin is not on the 0.29 line, or vllm_neuron is not importable, the run exits early with a clear message — no cryptic mid-stage AssertionError: Current vLLM config is not set.
Match kernel and compiler LNC before device stages. The 0.29 V2 runner reads
NEURON_LOGICAL_NC_CONFIG. When the selected QKV path in
functional/attention/qkv.py launches wrapped_kernel[2], export
NEURON_LOGICAL_NC_CONFIG=2 and remove conflicting LNC=1 compiler options from
NEURON_CC_FLAGS and neuron_config.compiler_args, including at TP=1.
Compiling that kernel at LNC=1 fails with NCC_ENKI003.
Editable install must be on PYTHONPATH. vllm_neuron is a local editable install, and vLLM's plugin entry point (vllm_neuron:register) imports it. Prepend VLLM_NEURON_DIR to PYTHONPATH on every stage command for vLLM-Neuron targets:
PYTHONPATH={VLLM_NEURON_DIR}:{SCRIPTS_DIR} python3 {SCRIPTS_DIR}/run_stage0.py ...
If the user does not provide test data, the bundled scripts (run_stage5.py, run_teacher_forced_comparison.py) use built-in defaults. For manual testing or other contexts, use these 5 prompts:
"The future of artificial intelligence is" — short, common topic"In a groundbreaking discovery, scientists at" — medium, factual"Once upon a time in a land far away, there" — narrative style"The mathematical proof demonstrates that for all" — technical/mathematical"def fibonacci(n):\n '''Return the nth" — code completionBefore proceeding past Stage 0, confirm:
torch and neuronx importablecomponent_mapping.json exists and covers all components| Stages | Mode | Needs compiled model + Neuron device? |
|---|---|---|
| 0, 2, 3, 4 | CPU (NXD_CPU_MODE=1, TP=1) | No |
| 1, 5, 6, 7 | Device | Yes |
Stage 1 is a device stage despite its low stage number — run_stage1.py calls the
adapter's device_inference() and requires COMPILED_MODEL_PATH. Do not plan on running
Stages 0–4 hardware-free as a contiguous block.
scripts/ directly.component_mapping.json (Step 1),
server_config.json when translating a user-provided vLLM config source (Step 4),
and test_NN_*.py test files (Step 3).num_hidden_layers for E2E tests — E2E means full modelExecute in this exact order. Each step has a single command to run.
vLLM-Neuron targets: prepend
{VLLM_NEURON_DIR}:to thePYTHONPATHof every command below (e.g.PYTHONPATH={VLLM_NEURON_DIR}:{SCRIPTS_DIR} python3 ...). The adapter's automatic version check will exit early ifvllmis off the pinned0.29line. See vLLM-Neuron Targets above.
source {VENV}/bin/activate
PYTHONPATH={SCRIPTS_DIR} python3 {SCRIPTS_DIR}/run_stage0.py \
--source-model-path {SOURCE_MODEL_PATH} \
--target-model-path {SOURCE_MODEL_PATH} \
--target-module-file {TARGET_MODELING_FILE} \
--target-inner-class {TARGET_INNER_CLASS} \
--target-config-class {TARGET_CONFIG_CLASS} \
--output-dir {EXP_DIR}/model_tree
Then compare the two printed trees and build {EXP_DIR}/component_mapping.json.
See STAGE0.md for mapping instructions and references/mapping_example.json for format.
Then run class divergence detection:
python3 {SCRIPTS_DIR}/detect_class_divergence.py \
--target-module-file {TARGET_MODELING_FILE} \
--output {EXP_DIR}/class_divergence_report.json
This identifies components that use different classes on CPU vs device (e.g., LlamaRMSNorm on CPU, CustomRMSNorm on device). These require dual tests in Stage 2.
PYTHONPATH={SCRIPTS_DIR} python3 {SCRIPTS_DIR}/run_stage1.py \
--model-path {SOURCE_MODEL_PATH} \
--compiled-model-path {COMPILED_MODEL_PATH} \
--model-class {TARGET_MODELING_FILE}:{TARGET_CAUSAL_CLASS} \
--config-class {TARGET_MODELING_FILE}:{TARGET_CONFIG_CLASS} \
--num-tokens 32 \
--output {EXP_DIR}/results/stage1.json
Decision: If token match < 30% → catastrophic failure, proceed to Step 3 for localization. Otherwise continue. (30% is the liveness gate — it matches run_stage1.py's --pass-threshold default of 0.30.)
{SCRIPTS_DIR}/tensor_compare.py into {EXP_DIR}/tests/{EXP_DIR}/tests/conftest.py from templates/conftest_template.py — fill in model constants from config.jsontest_NN_*.py files for each mapped component. See STAGE2.md for the pattern and templates/test_template.py for the template.NXD_CPU_MODE=1 python3 {SCRIPTS_DIR}/run_stage2.py \
--tests-dir {EXP_DIR}/tests \
--tau-r 1.2 \
--output {EXP_DIR}/results/stage2.json
Decision: If all R < 1.2 → proceed to Step 4. If any fail → run Stage 3:
python3 {SCRIPTS_DIR}/run_stage3.py \
--stage2-output {EXP_DIR}/results/stage2.json \
--output {EXP_DIR}/results/stage3.json
Then debug and patch (see STAGE4.md). Re-run Stage 2 until all pass.
This single script covers Stage 5 (E2E R-ratio), Stage 6 Condition B (cosine), and Stage 6 Condition C (KL) — all under proper teacher forcing.
For vLLM-Neuron, use the profiling run_spec.json as VLLM_CONFIG_SOURCE.
The script reads its serve_config object. See
run_spec.example.json.
The script maps tensor_parallel_size, max_model_len, max_num_seqs,
hf_overrides, and additional_config.neuron_config. It records other compile
fields as configuration gaps.
For a config script, translate one selected cell to the profiling serve_config
shape. Save it in {EXP_DIR}/server_config.json. Do not guess missing values.
PYTHONPATH={SCRIPTS_DIR} python3 {SCRIPTS_DIR}/run_teacher_forced_comparison.py \
--model-path {SOURCE_MODEL_PATH} \
--compiled-model-path {COMPILED_MODEL_PATH} \
--model-class {TARGET_MODELING_FILE}:{TARGET_CAUSAL_CLASS} \
--config-class {TARGET_MODELING_FILE}:{TARGET_CONFIG_CLASS} \
--num-tokens 32 \
--output {EXP_DIR}/results/teacher_forced.json
For vLLM-Neuron, add:
--target-stack vllm_neuron \
--server-config {VLLM_CONFIG_SOURCE}
python3 {SCRIPTS_DIR}/run_stage7.py \
--bench-config {EXP_DIR}/bench_config.yaml \
--output-dir {EXP_DIR}/results/stage7
See STAGE7.md for bench config format.
Aggregate all stage results into {EXP_DIR}/EQUIVALENCE_REPORT.md.
See references/report-template.md for the structure and completion gate.
Do NOT generate the report until all stages have concrete results. No "Pending" sections.
R = ||target - source_fp32||_F / (||source_lowprec - source_fp32||_F + ε)
| R | Meaning |
|---|---|
| ≈ 1.0 | Healthy — matches precision baseline |
| > 1.2 | Bug — excess divergence |
| < 1.0 | Over-precision — extra .float() calls |
PASS ⟺ Stage 1 acceptable ∧ Stage 2 all R < 1.2
∧ Stages 5+6 E2E R consistent ∧ Condition B(θ) ∧ Condition C(δ)
∧ Stage 7 no regressions
Step 4 runs Stages 5+6 together with run_teacher_forced_comparison.py (teacher-forced,
per-position). These are alternative implementations, not fallbacks:
scripts/run_stage5.py — Stage 5 as a standalone last-position 3-tensor comparison
instead of teacher-forced per-position. Goes through the stack adapter, so it supports both
NxDI and vLLM-Neuron targets. Useful for a fast E2E check on one prompt set.scripts/run_stage6.py — Stage 6 Condition B/C computed from an existing stage1.json.
Pure JSON post-processing, no adapter. Currently unusable: it requires an
enhanced_metrics block that no bundled script writes, so it exits immediately. Use
Step 4 for Stage 6.scripts/run_calibration.py — derive τ_R from the stage2.json files of known-good ports
instead of relying on the 1.2 default. The θ/δ calibration reads stage6.json, so it is
blocked by the same gap as run_stage6.py.STAGE0.md (opens in a new tab)STAGE1.md (opens in a new tab)STAGE2.md (opens in a new tab)STAGE3.md (opens in a new tab)STAGE4.md (opens in a new tab)STAGE5.md (opens in a new tab)STAGE6.md (opens in a new tab)STAGE7.md (opens in a new tab)references/adapter-contract.md (opens in a new tab)references/cpu-component-debugging.md (opens in a new tab)references/cpu-e2e-debugging.md (opens in a new tab)references/debug-orchestration.md (opens in a new tab)references/debugging-case-study-gptoss.md (opens in a new tab)references/device-component-debugging.md (opens in a new tab)references/device-e2e-debugging.md (opens in a new tab)references/dump-tensors.md (opens in a new tab)references/enable-model-run.md (opens in a new tab)references/equiv-concept.md (opens in a new tab)references/example_plots/negative_samples/M2304_K256_N4096_seed42_d2a166b27b5e5073e755ff9ead80243e_debug_cpu32_gpu_trn_diff_qqplot_hist.png (opens in a new tab)references/example_plots/negative_samples/M256_K128_N4096_seed42_916d411da0ea543e2d2afe79671115bb_debug_cpu32_gpu_trn_diff_qqplot_hist.png (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
/neuron:neuron-framework-equivalencefrom 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-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".
/neuron-hardware-entitlementComputes per-operator mandatory compute/HBM work and component-boundary activation HBM for a single transformer-LLM inference parallelism config on AWS Neuron (Trainium trn1/trn2/trn3), and attributes a deployed graph's actual resident HBM back to those operator floors. Use when localizing which operator or component binds on tensor-engine versus HBM work within a chosen {TP, PP, CP, bucket, bs, prefill} cell, auditing ideal component fusion, routing optimization effort to regions with real headroom, or diffing actual resident HBM against its floor. Builds on neuron-parallelism-planner (imports its analytic engine + meta-device oracle); driven by a run-spec (HF config.json + hardware constants), ships a worked example.Other plugins' skills for the same job