Using Tensor Compiler Engineering
Overview
A tensor compiler is a semantics-preserving transformation, and the compiler cannot be the witness to its own preservation.
That sentence is the whole pack. A compiler for tensor programs exists to change how a computation runs — schedule, layout, fusion, kernel, memory plan — while leaving what it computes untouched. Every serious failure in this domain is the same failure wearing a different hat: something in the pipeline changed meaning, and the thing that would have noticed was the pipeline itself.
Four load-bearing properties follow, and every sheet here designs one or more of them:
- Semantic identity is an input, not an output. The compiler receives a canonical IR that already carries a semantic hash, and carries that hash through untouched. A compiler that mints its own identity has no way to prove the artifact matches what was approved — and the approval was of the semantics, not the binary.
- Conformance is proven by a gate independent of the compiler. Reference-versus-compiled execution on declared inputs, gradient conformance, cross-device and cross-layout agreement. If the same code that chose the fusion also decides the fusion was safe, a wrong fusion produces a green test.
- Numerics are a contract declared before compilation. Dtype, accumulation order, which kernels may be nondeterministic, and the per-op tolerance budget are stated up front. A tolerance widened after a test fails is not a tolerance; it is the removal of a test.
- Every optimisation earns an entry in the manifest. The manifest is what answers "why does this artifact behave differently from the one we shipped last week." An optimisation that fired but was not recorded makes that question permanently unanswerable.
Key tensions the sheets resolve: speed vs. provability, aggressive fusion vs. numerical contract, cache hit rate vs. identity correctness, compile latency vs. artifact freshness.
When to Use
Use this pack when:
- You are lowering a graph IR — your own DSL, an ONNX-ish import, a generated architecture, a serialised subgraph — into something executable, and the lowered thing must mean what the IR meant.
- You are writing or composing
torch.fx passes and need them to be legal, ordered, and auditable rather than a pile of graph.erase_node calls.
- You are driving
torch.compile / dynamo / inductor / AOTAutograd and need to reason about guards, recompilation, graph breaks, and joint forward+backward capture.
- Compiled output differs from eager and you need to know whether that is a miscompile, a legitimate numerical difference, or a broken test.
- Gradients disagree after compilation — the forward matches and the backward does not, which is the single most under-tested failure in this domain.
- Someone is about to raise
atol to make CI green.
- A compilation cache is returning artifacts you do not trust, or is keyed on something that is not the program's identity.
- You need reproducible model builds: same input, same toolchain, same artifact, with a manifest that proves it.
Do not use this pack when:
- You want to make an existing model faster and no IR transformation is involved — profiling, memory, kernel-level tuning →
/pytorch-engineering. This pack builds the compiler; that pack tunes the program.
- You are debugging NaN/Inf at the tensor level in normal training →
yzmir-pytorch-engineering:debug-nan.
- You need distributed training throughput (FSDP, mixed precision schedules, FP8) →
/training-optimization.
- Your problem is run-versus-replay divergence — the same program run twice disagrees →
/determinism-and-replay. That pack owns divergence between executions. This pack owns divergence between a reference and its compilation. The distinction matters: see miscompile-taxonomy-and-debugging.md.
- You are reading source and emitting verdicts about it without running it →
/static-analysis-engineering (the producer-side sibling; see Pipeline Position).
- You are packaging and serving a model in production — versioning, drift, rollout →
/ml-production.
Start Here
If your input is "we need to lower this IR to something executable" and you have not run this pack before:
- Read compiler-architecture-for-tensor-programs.md — fix the pipeline stages and, more importantly, fix where the conformance gate sits relative to the compiler. Emit a pipeline diagram naming who certifies.
- Read ir-contracts-and-semantic-identity.md — write down the may-change / must-not-change list for your IR, and how the semantic hash is carried. Emit an IR contract.
- Read numerical-contracts-and-tolerances.md — declare the numerics before you write a pass. Emit a numerical contract with per-op tolerance budgets.
- Read conformance-testing.md — build the gate, failing-first, before the pipeline it will judge exists.
- Then implement: torch-fx-capture-and-transformation.md for the pass infrastructure, operator-lowering-and-kernel-selection.md and fusion-and-memory-planning.md for the optimisations.
- Use the Routing table for everything else.
Steps 1–4 are the spike, and they are in that order for a reason. The gate must exist before the compiler does, because a gate written after the compiler is written against the compiler's behaviour — it will encode the bugs as expectations. This is the same reason you write a failing test first.
How to Access Reference Sheets
All reference sheets live in the same directory as this SKILL.md. When you see a link like [conformance-testing.md](conformance-testing.md), read that file from this directory.
Pipeline Position
axiom-static-analysis-engineering axiom-tensor-compiler-engineering
READS code → emits VERDICTS ←-sibling-→ TRANSFORMS IR → emits EXECUTABLES
AST visitation, abstract domains, lowering, fusion, kernel choice,
inference, suppressions manifests, conformance gates
────────────────────────────────────────────────────────────────────────────
↑ ↓
the gate that says "this IR is legal" the artifact that runs; verified by
is a verdict producer — that pack a conformance gate independent of
the compiler (this pack)
/pytorch-engineering → tunes a program you already have
/determinism-and-replay → same program, two runs, why do they differ
THIS PACK → two *programs* (reference and compiled), why do they differ
The boundary with the static-analysis pack is sharp, and it is the same producer/consumer split stated from the other side:
| Question |
Pack |
| "Is this graph legal / well-typed / shape-correct?" |
/static-analysis-engineering — that is a verdict |
| "Turn this legal graph into something that runs" |
this pack |
| "Does the thing that runs still mean what the graph meant?" |
this pack (conformance) |
| "Why did rerunning the same artifact give a different answer?" |
/determinism-and-replay |
| "Why is this artifact slow?" |
/pytorch-engineering |
| "Why is this artifact wrong?" |
this pack (miscompile-taxonomy-and-debugging.md) |
Specialist Skills Catalog
Twelve sheets, grouped by concern. Sheets are named rather than numbered because a compiler is designed, not assembled from a fixed sequence — but the Foundations group is genuinely read-first.
Foundations (read first, in this order):
| Sheet |
Concern |
compiler-architecture-for-tensor-programs |
Pipeline stages; separating semantic identity from execution strategy; why the compiler must not certify itself |
ir-contracts-and-semantic-identity |
What a compiler may change vs. must never change; carrying the semantic hash; contract-violation detection |
numerical-contracts-and-tolerances |
Declaring dtype, accumulation, nondeterminism, and per-op tolerance budgets before compiling |
conformance-testing |
The core sheet — reference execution, gradient conformance, zero-influence and identity checks, cross-device/cross-layout agreement |
Capture and transformation:
| Sheet |
Concern |
torch-fx-capture-and-transformation |
Symbolic tracing, fx.Graph surgery, pass composition, round-trips, control-flow/dynamic-shape/in-place pitfalls |
torch-compile-and-aotautograd |
Dynamo guards and recompilation, graph breaks, inductor lowering, joint forward+backward capture; why eager-mode compilation is usually the right first implementation |
Optimisation:
| Sheet |
Concern |
operator-lowering-and-kernel-selection |
Decompositions, dtype/device dispatch, choosing kernels under a numerical contract, fallback paths |
fusion-and-memory-planning |
Fusion legality, layout optimisation, constant folding, memory planning, and how each earns a manifest entry |
Artifact discipline:
| Sheet |
Concern |
compilation-manifests-and-reproducibility |
Recording every pass, kernel, version, flag and pin; deterministic recompilation; the manifest as audit trail |
artifact-identity-and-caching |
Content-addressed artifacts keyed on canonical hash + device + dtype + compiler version; invalidation; safe reuse |
cost-estimation-and-compilation-budgets |
Static and measured cost models, calibration, compile-time budgets, staleness |
miscompile-taxonomy-and-debugging |
Four distinct failure classes; graph bisection; per-node comparison; minimal reproducers |
Routing
| Symptom or question |
Primary sheet |
| "Lower this graph to something executable" |
compiler-architecture-for-tensor-programs, then ir-contracts-and-semantic-identity |
| "What is my compiler allowed to change?" |
ir-contracts-and-semantic-identity |
| "Where should the conformance check live?" |
compiler-architecture-for-tensor-programs |
| "Write a torch.fx transform / pass" |
torch-fx-capture-and-transformation |
| "symbolic_trace fails on my model" |
torch-fx-capture-and-transformation (control flow, dynamic shapes) |
| "torch.compile keeps recompiling" |
torch-compile-and-aotautograd (guards) |
| "What is dynamo/inductor actually doing?" |
torch-compile-and-aotautograd |
| "I need forward and backward captured together" |
torch-compile-and-aotautograd (AOTAutograd) |
| "Which kernel should this op lower to?" |
operator-lowering-and-kernel-selection |
| "Is this fusion legal?" |
fusion-and-memory-planning |
| "Compiled output differs from eager" |
conformance-testing, then miscompile-taxonomy-and-debugging |
| "Gradient mismatch after compilation" |
conformance-testing (gradient conformance section) |
| "What tolerance should I use?" |
numerical-contracts-and-tolerances |
| "Test fails at 1e-5, passes at 1e-3 — ship it?" |
numerical-contracts-and-tolerances (tolerance inflation) |
| "Results differ between CPU and GPU" |
conformance-testing (cross-device agreement) |
| "Reproducible builds for models" |
compilation-manifests-and-reproducibility |
| "Why does this artifact behave differently?" |
compilation-manifests-and-reproducibility |
| "Compilation cache returns the wrong thing" |
artifact-identity-and-caching |
| "Can I reuse this artifact for another run?" |
artifact-identity-and-caching |
| "Compilation takes longer than the thing is useful for" |
cost-estimation-and-compilation-budgets |
| "Predicted cost does not match measured cost" |
cost-estimation-and-compilation-budgets |
| "Miscompile — where?" |
miscompile-taxonomy-and-debugging |
| "Same artifact, two runs, different results" |
→ /determinism-and-replay |
| "Artifact is correct but slow" |
→ /pytorch-engineering |
Specialist Agents
agent: tensor-compiler-architect — Forward-design SME. Given a compilation problem (IR shape, target device/dtype, constraints), designs the IR contract, pass pipeline, manifest schema, and conformance-gate placement. Invoked via Task tool.
agent: compiler-conformance-reviewer — Critic SME. Audits a compiler or its artifacts for semantic-drift risk, self-certification, tolerance abuse, manifest gaps, and cache-identity bugs. A zero-findings run is treated as a defect of the audit, not a clean bill of health. Invoked via Task tool.
Specialist Commands
/scaffold-tensor-compiler — Given an IR spec and a target, scaffolds the lowering pipeline, manifest emission, and an independent conformance harness with failing-first tests.
/verify-artifact-conformance — Runs or authors the full conformance suite for one artifact: reference execution, gradient conformance, cross-device agreement, manifest completeness. Severity-rated report.
/diagnose-miscompile — Given "compiled differs from reference", bisects the pass pipeline and the graph to the first divergent node and classifies against the taxonomy.
Agents vs. skills: Skills design the compiler and its discipline. Agents audit one that exists. Load a skill when building; dispatch an agent when reviewing.
Common Multi-Skill Scenarios
Scenario: Greenfield — new IR, new backend
compiler-architecture-for-tensor-programs — stages, and where the gate sits
ir-contracts-and-semantic-identity — the may-change / must-not-change list
numerical-contracts-and-tolerances — declare numerics before writing a pass
conformance-testing — build the gate, failing-first
torch-fx-capture-and-transformation — pass infrastructure
compilation-manifests-and-reproducibility — manifest from the first pass, not retrofitted
operator-lowering-and-kernel-selection, then fusion-and-memory-planning — optimise only now
Command: /scaffold-tensor-compiler does steps 1, 4, and 6 as code.
Scenario: "Compiled output differs from eager"
numerical-contracts-and-tolerances — is there a declared contract? If not, the question is unanswerable; write one first.
miscompile-taxonomy-and-debugging — classify: compile failure / semantic drift / conformance failure / performance regression
conformance-testing — is the test right? Wrong dtype in gradcheck produces false miscompiles
torch-fx-capture-and-transformation or fusion-and-memory-planning — localise to the offending pass
compilation-manifests-and-reproducibility — the manifest should already name the passes that fired
Command: /diagnose-miscompile runs this as a bisection.
Scenario: Gradients disagree, forward agrees
conformance-testing — gradient conformance section; check dtype and requires_grad in the harness first
torch-compile-and-aotautograd — is the backward captured jointly or re-derived?
operator-lowering-and-kernel-selection — a decomposition with a correct forward and a wrong backward is a classic
miscompile-taxonomy-and-debugging — per-node backward comparison
Scenario: Adopting torch.compile on an existing model
torch-compile-and-aotautograd — guards, graph breaks, recompilation limits
numerical-contracts-and-tolerances — inductor changes accumulation order; declare what you accept
conformance-testing — reference-vs-compiled before you trust throughput numbers
cost-estimation-and-compilation-budgets — is compile time paid back?
Scenario: Compilation cache is suspect
artifact-identity-and-caching — what is the key? If it includes a file path, mtime, or source text, that is the bug
ir-contracts-and-semantic-identity — is a canonical hash even available to key on?
compilation-manifests-and-reproducibility — can you prove two artifacts came from the same inputs?
Scenario: Auditing someone else's compiler
- Dispatch
agent: compiler-conformance-reviewer
conformance-testing — is the gate independent of the compiler?
numerical-contracts-and-tolerances — check the git history of the tolerances, not just their values
artifact-identity-and-caching — key composition
compilation-manifests-and-reproducibility — manifest completeness against passes actually present in the code
Decision Tree
Building a compiler / lowering pipeline from scratch?
├─ Yes → compiler-architecture → ir-contracts → numerical-contracts
│ → conformance-testing (gate first!) → fx/compile sheets
│ → lowering → fusion → manifests → caching
└─ No → continue
Compiled output differs from reference? → miscompile-taxonomy (classify first)
→ conformance-testing (is the test right?)
Gradients differ, forward agrees? → conformance-testing (gradient section)
→ torch-compile-and-aotautograd
Arguing about a tolerance? → numerical-contracts-and-tolerances
torch.compile recompiling constantly? → torch-compile-and-aotautograd (guards)
symbolic_trace throws on control flow? → torch-fx-capture-and-transformation
Is this fusion safe? → fusion-and-memory-planning
Cache returning wrong/stale artifacts? → artifact-identity-and-caching
"Why does this artifact behave differently?"→ compilation-manifests-and-reproducibility
Compile time exceeds the artifact's useful life? → cost-estimation-and-compilation-budgets
Same artifact, two runs, different results? → /determinism-and-replay (not this pack)
Artifact correct but slow? → /pytorch-engineering (not this pack)
Rationalization Resistance
This is the anti-pattern catalogue. Each row is a real thing engineers say, the reason it is wrong, and where the fix lives.
| Rationalization |
Reality |
Counter-guidance |
| "The compiler checks its own output, that's the conformance step" |
The code that chose the fusion cannot be the authority on whether the fusion was legal. A wrong fusion and a wrong legality check share a root cause and fail together. |
Gate independent of the compiler — conformance-testing, compiler-architecture-for-tensor-programs |
"It only fails at atol=1e-6, so use 1e-3" |
You did not fix anything; you deleted the test. A tolerance chosen to make a failure disappear encodes the failure as the specification. |
Declare tolerances before compiling; changing one is a contract change with a written justification — numerical-contracts-and-tolerances |
| "The compiler can add a node here, it's mathematically equivalent" |
If the compiler may invent semantic nodes, the approved thing and the deployed thing are different objects, and the approval means nothing. Equivalence claimed by the party that benefits is not equivalence. |
ir-contracts-and-semantic-identity — may change execution strategy, never topology |
| "Forward matches, so the compile is correct" |
Backward is a different program, often produced by a different code path. A decomposition with a right forward and a wrong backward passes every forward test you have. |
Gradient conformance is mandatory — conformance-testing |
| "We cache on the source file hash" |
Two different programs can have identical source (different config, dtype, device); one program can have many source spellings. Syntax is not identity. |
Key on canonical semantic hash + device + dtype + compiler version — artifact-identity-and-caching |
| "We'll pin the toolchain at release time" |
The artifact you validated was built with whatever was installed that afternoon. Without a pin recorded at build time, "reproduce it" is a research project. |
Pin and record in the manifest — compilation-manifests-and-reproducibility |
| "This pass only fires on CUDA, so CPU tests still cover us" |
A device-specific pass that changes semantics on one target produces a system that is correct in CI and wrong in production. |
Cross-device agreement in the gate — conformance-testing |
| "That optimisation is internal, no need to log it" |
The manifest is the only answer to "why does this artifact behave differently from the last one". An unlogged optimisation makes every future regression permanently un-bisectable. |
Every optimisation earns a manifest entry — fusion-and-memory-planning, compilation-manifests-and-reproducibility |
| "gradcheck is flaky, it fails randomly" |
gradcheck on float32 fails essentially always — finite differences need float64. It is not flaky; the harness is wrong, and "flaky" is how a wrong harness gets ignored. |
conformance-testing — gradcheck harness in float64 |
| "The compiler failed, so reject the candidate" |
Compilation failure means this backend could not build it. Structural rejection means the graph is illegal. Task rejection means the graph is legal and useless. Collapsing them silently discards good programs and hides backend bugs. |
Three distinct outcomes — miscompile-taxonomy-and-debugging |
| "Compile it aggressively, we can always verify later" |
Verification you have not budgeted does not happen, and an unverified artifact in a cache is indistinguishable from a verified one. |
Gate before cache insertion — artifact-identity-and-caching |
| "torch.compile is the compiler, we don't need our own IR" |
torch.compile is a backend, not a contract. Without your own canonical IR you have nothing to hash, nothing to approve, and nothing to compare the artifact against. |
ir-contracts-and-semantic-identity |
Red Flags Checklist
Signs a tensor-compilation pipeline is not trustworthy:
Integration with Other Skillpacks
Static analysis engineering (axiom-static-analysis-engineering)
The producer-side sibling. That pack builds tools that read a program and emit verdicts; this pack builds tools that transform a program and emit executables. They meet at the gate: a structural verifier that says "this graph is legal and canonical" is a verdict producer (that pack), and the artifact it approves is compiled and conformance-checked here.
Determinism and replay (axiom-determinism-and-replay)
Adjacent and easy to confuse. That pack owns divergence between executions — same program, two runs, why do they differ — and ships bisection tooling for exactly that. This pack owns divergence between a reference and its compilation — two programs, same inputs. Both use bisection; the bisection axis is different (time/step vs. pass/node). miscompile-taxonomy-and-debugging cross-links rather than re-deriving.
PyTorch engineering (yzmir-pytorch-engineering)
That pack makes a program you already have faster and less memory-hungry. This pack builds the thing that produces the program. When conformance passes and performance is the problem, leave.
Audit pipelines (axiom-audit-pipelines)
A compilation manifest is a provenance record. If manifests must be tamper-evident, signed, or externally attestable — regulated deployment, supply-chain requirements — that pack owns the evidence discipline; this pack owns the content.
Other packs
| Request |
Primary pack |
| Make an existing model faster |
yzmir-pytorch-engineering |
| Debug NaN in training |
yzmir-pytorch-engineering:debug-nan |
| Distributed training throughput |
yzmir-training-optimization |
| Serve and version a model in production |
yzmir-ml-production |
| Design the architecture being compiled |
yzmir-neural-architectures |
| Reproduce a run, not an artifact |
axiom-determinism-and-replay |
| CI/CD for the compiler itself |
axiom-devops-engineering |
Quick Reference
| Need |
Use this |
| Pipeline stages and where the gate sits |
compiler-architecture-for-tensor-programs |
| May-change / must-not-change list |
ir-contracts-and-semantic-identity |
| Declare numerics before compiling |
numerical-contracts-and-tolerances |
| Prove the artifact preserves semantics |
conformance-testing |
| Write and compose fx passes |
torch-fx-capture-and-transformation |
| Guards, graph breaks, joint fwd+bwd |
torch-compile-and-aotautograd |
| Decompositions and kernel choice |
operator-lowering-and-kernel-selection |
| Fusion legality and memory planning |
fusion-and-memory-planning |
| Reproducible builds and audit trail |
compilation-manifests-and-reproducibility |
| Content-addressed artifacts and cache keys |
artifact-identity-and-caching |
| Cost models and compile budgets |
cost-estimation-and-compilation-budgets |
| Classify and localise a miscompile |
miscompile-taxonomy-and-debugging |
| Scaffold a pipeline + gate |
command: /scaffold-tensor-compiler |
| Verify one artifact end-to-end |
command: /verify-artifact-conformance |
| Bisect "compiled differs from reference" |
command: /diagnose-miscompile |
| Design an IR contract and pass pipeline |
agent: tensor-compiler-architect |
| Audit a compiler for drift risk |
agent: compiler-conformance-reviewer |
The Bottom Line
A tensor compiler may change how a program runs and may never change what it computes. Because it cannot be trusted to judge its own preservation, the discipline is four things: an IR contract that says what is off-limits, a numerical contract declared before the first pass, a conformance gate independent of the compiler that checks forward and backward across devices and layouts, and a manifest complete enough that any behavioural difference between two artifacts can be traced to a specific decision. Skip any one and you will eventually ship an artifact that is fast, green, and wrong — with no way to find out which pass did it.
Reference Sheets
Foundations (read first, in order):
- compiler-architecture-for-tensor-programs.md — Stages; identity vs. execution strategy; who certifies
- ir-contracts-and-semantic-identity.md — May-change / must-not-change; carrying the semantic hash
- numerical-contracts-and-tolerances.md — Dtype, accumulation, nondeterminism, tolerance budgets
- conformance-testing.md — Reference execution, gradient conformance, cross-device/cross-layout agreement
Capture and transformation:
- torch-fx-capture-and-transformation.md — Tracing, graph surgery, pass composition, pitfalls
- torch-compile-and-aotautograd.md — Guards, recompilation, inductor, joint forward+backward
Optimisation:
- operator-lowering-and-kernel-selection.md — Decompositions, dispatch, kernel choice, fallbacks
- fusion-and-memory-planning.md — Fusion legality, layout, constant folding, memory planning
Artifact discipline:
- compilation-manifests-and-reproducibility.md — Recording every decision; deterministic recompilation
- artifact-identity-and-caching.md — Content-addressed artifacts, cache keys, invalidation
- cost-estimation-and-compilation-budgets.md — Cost models, calibration, budgets, staleness
- miscompile-taxonomy-and-debugging.md — Four failure classes, bisection, minimal reproducers
1---2name: using-tensor-compiler-engineering3description: Use when building or auditing a compiler for tensor programs — lowering a graph IR to executable PyTorch, writing torch.fx passes, driving torch.compile/dynamo/inductor/AOTAutograd, selecting kernels, fusing operators, or planning memory. Use when compiled output differs from eager, gradients mismatch after compilation, a numerical tolerance is being argued about, a compilation cache returns a stale or wrong artifact, or model builds must be reproducible. Covers semantic identity vs execution strategy, conformance gates independent of the compiler (reference execution, gradcheck, cross-device and cross-layout agreement), compilation manifests, content-addressed artifacts, compile-time budgets and staleness, and miscompile bisection. Producer-side pack — it transforms IR and emits executables. To read code and produce verdicts use `/static-analysis-engineering`; for run-versus-replay divergence use `/determinism-and-replay`.4---56# Using Tensor Compiler Engineering78## Overview910**A tensor compiler is a semantics-preserving transformation, and the compiler cannot be the witness to its own preservation.**1112That sentence is the whole pack. A compiler for tensor programs exists to change *how* a computation runs — schedule, layout, fusion, kernel, memory plan — while leaving *what it computes* untouched. Every serious failure in this domain is the same failure wearing a different hat: something in the pipeline changed meaning, and the thing that would have noticed was the pipeline itself.1314Four load-bearing properties follow, and every sheet here designs one or more of them:1516- **Semantic identity is an input, not an output.** The compiler receives a canonical IR that already carries a semantic hash, and carries that hash through untouched. A compiler that mints its own identity has no way to prove the artifact matches what was approved — and the approval was of the *semantics*, not the binary.17- **Conformance is proven by a gate independent of the compiler.** Reference-versus-compiled execution on declared inputs, gradient conformance, cross-device and cross-layout agreement. If the same code that chose the fusion also decides the fusion was safe, a wrong fusion produces a green test.18- **Numerics are a contract declared before compilation.** Dtype, accumulation order, which kernels may be nondeterministic, and the per-op tolerance budget are stated up front. A tolerance widened after a test fails is not a tolerance; it is the removal of a test.19- **Every optimisation earns an entry in the manifest.** The manifest is what answers "why does this artifact behave differently from the one we shipped last week." An optimisation that fired but was not recorded makes that question permanently unanswerable.2021Key tensions the sheets resolve: *speed vs. provability*, *aggressive fusion vs. numerical contract*, *cache hit rate vs. identity correctness*, *compile latency vs. artifact freshness*.2223## When to Use2425Use this pack when:2627- You are lowering a graph IR — your own DSL, an ONNX-ish import, a generated architecture, a serialised subgraph — into something executable, and the lowered thing must mean what the IR meant.28- You are writing or composing `torch.fx` passes and need them to be legal, ordered, and auditable rather than a pile of `graph.erase_node` calls.29- You are driving `torch.compile` / dynamo / inductor / AOTAutograd and need to reason about guards, recompilation, graph breaks, and joint forward+backward capture.30- Compiled output differs from eager and you need to know whether that is a miscompile, a legitimate numerical difference, or a broken test.31- Gradients disagree after compilation — the forward matches and the backward does not, which is the single most under-tested failure in this domain.32- Someone is about to raise `atol` to make CI green.33- A compilation cache is returning artifacts you do not trust, or is keyed on something that is not the program's identity.34- You need reproducible model builds: same input, same toolchain, same artifact, with a manifest that proves it.3536Do **not** use this pack when:3738- You want to make an *existing* model faster and no IR transformation is involved — profiling, memory, kernel-level tuning → `/pytorch-engineering`. This pack builds the compiler; that pack tunes the program.39- You are debugging NaN/Inf at the tensor level in normal training → `yzmir-pytorch-engineering:debug-nan`.40- You need distributed training throughput (FSDP, mixed precision schedules, FP8) → `/training-optimization`.41- Your problem is *run-versus-replay* divergence — the same program run twice disagrees → `/determinism-and-replay`. That pack owns divergence between executions. **This pack owns divergence between a reference and its compilation.** The distinction matters: see [miscompile-taxonomy-and-debugging.md](miscompile-taxonomy-and-debugging.md).42- You are reading source and emitting verdicts about it without running it → `/static-analysis-engineering` (the producer-side sibling; see Pipeline Position).43- You are packaging and serving a model in production — versioning, drift, rollout → `/ml-production`.4445## Start Here4647If your input is "we need to lower this IR to something executable" and you have not run this pack before:48491. Read [compiler-architecture-for-tensor-programs.md](compiler-architecture-for-tensor-programs.md) — fix the pipeline stages and, more importantly, fix where the conformance gate sits relative to the compiler. Emit a pipeline diagram naming who certifies.502. Read [ir-contracts-and-semantic-identity.md](ir-contracts-and-semantic-identity.md) — write down the may-change / must-not-change list for your IR, and how the semantic hash is carried. Emit an IR contract.513. Read [numerical-contracts-and-tolerances.md](numerical-contracts-and-tolerances.md) — declare the numerics **before** you write a pass. Emit a numerical contract with per-op tolerance budgets.524. Read [conformance-testing.md](conformance-testing.md) — build the gate, failing-first, before the pipeline it will judge exists.535. Then implement: [torch-fx-capture-and-transformation.md](torch-fx-capture-and-transformation.md) for the pass infrastructure, [operator-lowering-and-kernel-selection.md](operator-lowering-and-kernel-selection.md) and [fusion-and-memory-planning.md](fusion-and-memory-planning.md) for the optimisations.546. Use the **Routing** table for everything else.5556Steps 1–4 are the spike, and they are in that order for a reason. The gate must exist before the compiler does, because a gate written after the compiler is written against the compiler's behaviour — it will encode the bugs as expectations. This is the same reason you write a failing test first.5758## How to Access Reference Sheets5960All reference sheets live in the same directory as this `SKILL.md`. When you see a link like `[conformance-testing.md](conformance-testing.md)`, read that file from this directory.6162## Pipeline Position6364```65axiom-static-analysis-engineering axiom-tensor-compiler-engineering66 READS code → emits VERDICTS ←-sibling-→ TRANSFORMS IR → emits EXECUTABLES67 AST visitation, abstract domains, lowering, fusion, kernel choice,68 inference, suppressions manifests, conformance gates69 ────────────────────────────────────────────────────────────────────────────70 ↑ ↓71 the gate that says "this IR is legal" the artifact that runs; verified by72 is a verdict producer — that pack a conformance gate independent of73 the compiler (this pack)7475 /pytorch-engineering → tunes a program you already have76 /determinism-and-replay → same program, two runs, why do they differ77 THIS PACK → two *programs* (reference and compiled), why do they differ78```7980The boundary with the static-analysis pack is sharp, and it is the same producer/consumer split stated from the other side:8182| Question | Pack |83|----------|------|84| "Is this graph legal / well-typed / shape-correct?" | `/static-analysis-engineering` — that is a verdict |85| "Turn this legal graph into something that runs" | **this pack** |86| "Does the thing that runs still mean what the graph meant?" | **this pack** (conformance) |87| "Why did rerunning the same artifact give a different answer?" | `/determinism-and-replay` |88| "Why is this artifact slow?" | `/pytorch-engineering` |89| "Why is this artifact *wrong*?" | **this pack** ([miscompile-taxonomy-and-debugging.md](miscompile-taxonomy-and-debugging.md)) |9091## Specialist Skills Catalog9293Twelve sheets, grouped by concern. Sheets are named rather than numbered because a compiler is designed, not assembled from a fixed sequence — but the Foundations group is genuinely read-first.9495**Foundations** (read first, in this order):9697| Sheet | Concern |98|-------|---------|99| `compiler-architecture-for-tensor-programs` | Pipeline stages; separating semantic identity from execution strategy; why the compiler must not certify itself |100| `ir-contracts-and-semantic-identity` | What a compiler may change vs. must never change; carrying the semantic hash; contract-violation detection |101| `numerical-contracts-and-tolerances` | Declaring dtype, accumulation, nondeterminism, and per-op tolerance budgets *before* compiling |102| `conformance-testing` | The core sheet — reference execution, gradient conformance, zero-influence and identity checks, cross-device/cross-layout agreement |103104**Capture and transformation:**105106| Sheet | Concern |107|-------|---------|108| `torch-fx-capture-and-transformation` | Symbolic tracing, `fx.Graph` surgery, pass composition, round-trips, control-flow/dynamic-shape/in-place pitfalls |109| `torch-compile-and-aotautograd` | Dynamo guards and recompilation, graph breaks, inductor lowering, joint forward+backward capture; why eager-mode compilation is usually the right first implementation |110111**Optimisation:**112113| Sheet | Concern |114|-------|---------|115| `operator-lowering-and-kernel-selection` | Decompositions, dtype/device dispatch, choosing kernels under a numerical contract, fallback paths |116| `fusion-and-memory-planning` | Fusion legality, layout optimisation, constant folding, memory planning, and how each earns a manifest entry |117118**Artifact discipline:**119120| Sheet | Concern |121|-------|---------|122| `compilation-manifests-and-reproducibility` | Recording every pass, kernel, version, flag and pin; deterministic recompilation; the manifest as audit trail |123| `artifact-identity-and-caching` | Content-addressed artifacts keyed on canonical hash + device + dtype + compiler version; invalidation; safe reuse |124| `cost-estimation-and-compilation-budgets` | Static and measured cost models, calibration, compile-time budgets, staleness |125| `miscompile-taxonomy-and-debugging` | Four distinct failure classes; graph bisection; per-node comparison; minimal reproducers |126127## Routing128129| Symptom or question | Primary sheet |130|---------------------|---------------|131| "Lower this graph to something executable" | `compiler-architecture-for-tensor-programs`, then `ir-contracts-and-semantic-identity` |132| "What is my compiler allowed to change?" | `ir-contracts-and-semantic-identity` |133| "Where should the conformance check live?" | `compiler-architecture-for-tensor-programs` |134| "Write a torch.fx transform / pass" | `torch-fx-capture-and-transformation` |135| "symbolic_trace fails on my model" | `torch-fx-capture-and-transformation` (control flow, dynamic shapes) |136| "torch.compile keeps recompiling" | `torch-compile-and-aotautograd` (guards) |137| "What is dynamo/inductor actually doing?" | `torch-compile-and-aotautograd` |138| "I need forward *and* backward captured together" | `torch-compile-and-aotautograd` (AOTAutograd) |139| "Which kernel should this op lower to?" | `operator-lowering-and-kernel-selection` |140| "Is this fusion legal?" | `fusion-and-memory-planning` |141| "Compiled output differs from eager" | `conformance-testing`, then `miscompile-taxonomy-and-debugging` |142| "Gradient mismatch after compilation" | `conformance-testing` (gradient conformance section) |143| "What tolerance should I use?" | `numerical-contracts-and-tolerances` |144| "Test fails at 1e-5, passes at 1e-3 — ship it?" | `numerical-contracts-and-tolerances` (tolerance inflation) |145| "Results differ between CPU and GPU" | `conformance-testing` (cross-device agreement) |146| "Reproducible builds for models" | `compilation-manifests-and-reproducibility` |147| "Why does this artifact behave differently?" | `compilation-manifests-and-reproducibility` |148| "Compilation cache returns the wrong thing" | `artifact-identity-and-caching` |149| "Can I reuse this artifact for another run?" | `artifact-identity-and-caching` |150| "Compilation takes longer than the thing is useful for" | `cost-estimation-and-compilation-budgets` |151| "Predicted cost does not match measured cost" | `cost-estimation-and-compilation-budgets` |152| "Miscompile — where?" | `miscompile-taxonomy-and-debugging` |153| "Same artifact, two runs, different results" | → `/determinism-and-replay` |154| "Artifact is correct but slow" | → `/pytorch-engineering` |155156### Specialist Agents157158- **`agent: tensor-compiler-architect`** — Forward-design SME. Given a compilation problem (IR shape, target device/dtype, constraints), designs the IR contract, pass pipeline, manifest schema, and conformance-gate placement. Invoked via `Task` tool.159- **`agent: compiler-conformance-reviewer`** — Critic SME. Audits a compiler or its artifacts for semantic-drift risk, self-certification, tolerance abuse, manifest gaps, and cache-identity bugs. A zero-findings run is treated as a defect of the audit, not a clean bill of health. Invoked via `Task` tool.160161### Specialist Commands162163- **`/scaffold-tensor-compiler`** — Given an IR spec and a target, scaffolds the lowering pipeline, manifest emission, and an independent conformance harness with failing-first tests.164- **`/verify-artifact-conformance`** — Runs or authors the full conformance suite for one artifact: reference execution, gradient conformance, cross-device agreement, manifest completeness. Severity-rated report.165- **`/diagnose-miscompile`** — Given "compiled differs from reference", bisects the pass pipeline and the graph to the first divergent node and classifies against the taxonomy.166167**Agents vs. skills:** Skills *design* the compiler and its discipline. Agents *audit* one that exists. Load a skill when building; dispatch an agent when reviewing.168169## Common Multi-Skill Scenarios170171### Scenario: Greenfield — new IR, new backend1721731. `compiler-architecture-for-tensor-programs` — stages, and where the gate sits1742. `ir-contracts-and-semantic-identity` — the may-change / must-not-change list1753. `numerical-contracts-and-tolerances` — declare numerics before writing a pass1764. `conformance-testing` — build the gate, failing-first1775. `torch-fx-capture-and-transformation` — pass infrastructure1786. `compilation-manifests-and-reproducibility` — manifest from the first pass, not retrofitted1797. `operator-lowering-and-kernel-selection`, then `fusion-and-memory-planning` — optimise only now180181Command: `/scaffold-tensor-compiler` does steps 1, 4, and 6 as code.182183### Scenario: "Compiled output differs from eager"1841851. `numerical-contracts-and-tolerances` — is there a declared contract? If not, the question is unanswerable; write one first.1862. `miscompile-taxonomy-and-debugging` — classify: compile failure / semantic drift / conformance failure / performance regression1873. `conformance-testing` — is the *test* right? Wrong dtype in gradcheck produces false miscompiles1884. `torch-fx-capture-and-transformation` or `fusion-and-memory-planning` — localise to the offending pass1895. `compilation-manifests-and-reproducibility` — the manifest should already name the passes that fired190191Command: `/diagnose-miscompile` runs this as a bisection.192193### Scenario: Gradients disagree, forward agrees1941951. `conformance-testing` — gradient conformance section; check dtype and `requires_grad` in the harness first1962. `torch-compile-and-aotautograd` — is the backward captured jointly or re-derived?1973. `operator-lowering-and-kernel-selection` — a decomposition with a correct forward and a wrong backward is a classic1984. `miscompile-taxonomy-and-debugging` — per-node backward comparison199200### Scenario: Adopting `torch.compile` on an existing model2012021. `torch-compile-and-aotautograd` — guards, graph breaks, recompilation limits2032. `numerical-contracts-and-tolerances` — inductor changes accumulation order; declare what you accept2043. `conformance-testing` — reference-vs-compiled before you trust throughput numbers2054. `cost-estimation-and-compilation-budgets` — is compile time paid back?206207### Scenario: Compilation cache is suspect2082091. `artifact-identity-and-caching` — what is the key? If it includes a file path, mtime, or source text, that is the bug2102. `ir-contracts-and-semantic-identity` — is a canonical hash even available to key on?2113. `compilation-manifests-and-reproducibility` — can you prove two artifacts came from the same inputs?212213### Scenario: Auditing someone else's compiler2142151. Dispatch `agent: compiler-conformance-reviewer`2162. `conformance-testing` — is the gate independent of the compiler?2173. `numerical-contracts-and-tolerances` — check the git history of the tolerances, not just their values2184. `artifact-identity-and-caching` — key composition2195. `compilation-manifests-and-reproducibility` — manifest completeness against passes actually present in the code220221## Decision Tree222223```224Building a compiler / lowering pipeline from scratch?225├─ Yes → compiler-architecture → ir-contracts → numerical-contracts226│ → conformance-testing (gate first!) → fx/compile sheets227│ → lowering → fusion → manifests → caching228└─ No → continue229230Compiled output differs from reference? → miscompile-taxonomy (classify first)231 → conformance-testing (is the test right?)232Gradients differ, forward agrees? → conformance-testing (gradient section)233 → torch-compile-and-aotautograd234Arguing about a tolerance? → numerical-contracts-and-tolerances235torch.compile recompiling constantly? → torch-compile-and-aotautograd (guards)236symbolic_trace throws on control flow? → torch-fx-capture-and-transformation237Is this fusion safe? → fusion-and-memory-planning238Cache returning wrong/stale artifacts? → artifact-identity-and-caching239"Why does this artifact behave differently?"→ compilation-manifests-and-reproducibility240Compile time exceeds the artifact's useful life? → cost-estimation-and-compilation-budgets241Same artifact, two runs, different results? → /determinism-and-replay (not this pack)242Artifact correct but slow? → /pytorch-engineering (not this pack)243```244245## Rationalization Resistance246247This is the anti-pattern catalogue. Each row is a real thing engineers say, the reason it is wrong, and where the fix lives.248249| Rationalization | Reality | Counter-guidance |250|-----------------|---------|------------------|251| "The compiler checks its own output, that's the conformance step" | The code that chose the fusion cannot be the authority on whether the fusion was legal. A wrong fusion and a wrong legality check share a root cause and fail together. | Gate independent of the compiler — `conformance-testing`, `compiler-architecture-for-tensor-programs` |252| "It only fails at `atol=1e-6`, so use `1e-3`" | You did not fix anything; you deleted the test. A tolerance chosen to make a failure disappear encodes the failure as the specification. | Declare tolerances before compiling; changing one is a contract change with a written justification — `numerical-contracts-and-tolerances` |253| "The compiler can add a node here, it's mathematically equivalent" | If the compiler may invent semantic nodes, the approved thing and the deployed thing are different objects, and the approval means nothing. Equivalence claimed by the party that benefits is not equivalence. | `ir-contracts-and-semantic-identity` — may change execution strategy, never topology |254| "Forward matches, so the compile is correct" | Backward is a *different program*, often produced by a different code path. A decomposition with a right forward and a wrong backward passes every forward test you have. | Gradient conformance is mandatory — `conformance-testing` |255| "We cache on the source file hash" | Two different programs can have identical source (different config, dtype, device); one program can have many source spellings. Syntax is not identity. | Key on canonical semantic hash + device + dtype + compiler version — `artifact-identity-and-caching` |256| "We'll pin the toolchain at release time" | The artifact you validated was built with whatever was installed that afternoon. Without a pin recorded *at build time*, "reproduce it" is a research project. | Pin and record in the manifest — `compilation-manifests-and-reproducibility` |257| "This pass only fires on CUDA, so CPU tests still cover us" | A device-specific pass that changes semantics on one target produces a system that is correct in CI and wrong in production. | Cross-device agreement in the gate — `conformance-testing` |258| "That optimisation is internal, no need to log it" | The manifest is the only answer to "why does this artifact behave differently from the last one". An unlogged optimisation makes every future regression permanently un-bisectable. | Every optimisation earns a manifest entry — `fusion-and-memory-planning`, `compilation-manifests-and-reproducibility` |259| "gradcheck is flaky, it fails randomly" | `gradcheck` on float32 fails essentially always — finite differences need float64. It is not flaky; the harness is wrong, and "flaky" is how a wrong harness gets ignored. | `conformance-testing` — gradcheck harness in float64 |260| "The compiler failed, so reject the candidate" | Compilation failure means *this backend could not build it*. Structural rejection means *the graph is illegal*. Task rejection means *the graph is legal and useless*. Collapsing them silently discards good programs and hides backend bugs. | Three distinct outcomes — `miscompile-taxonomy-and-debugging` |261| "Compile it aggressively, we can always verify later" | Verification you have not budgeted does not happen, and an unverified artifact in a cache is indistinguishable from a verified one. | Gate before cache insertion — `artifact-identity-and-caching` |262| "torch.compile is the compiler, we don't need our own IR" | `torch.compile` is a backend, not a contract. Without your own canonical IR you have nothing to hash, nothing to approve, and nothing to compare the artifact against. | `ir-contracts-and-semantic-identity` |263264### Red Flags Checklist265266Signs a tensor-compilation pipeline is not trustworthy:267268- [ ] **Self-certified conformance** — the conformance check imports, or is written by, the compiler it judges269- [ ] **No declared numerical contract** — tolerances live as literals inside test files270- [ ] **Tolerance drift** — `git log` shows `atol`/`rtol` only ever increasing271- [ ] **Forward-only conformance** — no gradient check anywhere in the suite272- [ ] **gradcheck in float32** — the harness cannot pass, so it was disabled or its failures normalised273- [ ] **Semantic hash minted by the compiler** — instead of received from the IR producer and carried through274- [ ] **Syntax-keyed cache** — cache key includes source text, file path, or mtime rather than canonical identity275- [ ] **Manifest gaps** — passes exist in the code that cannot appear in any manifest276- [ ] **Unpinned toolchain** — no recorded versions for torch, CUDA/cuDNN, the compiler itself277- [ ] **Device-conditional passes with single-device testing**278- [ ] **Collapsed failure classes** — compile failure, semantic drift, and performance regression share one error type279- [ ] **No compile-time budget** — no one knows whether artifacts arrive before they are needed280281## Integration with Other Skillpacks282283### Static analysis engineering (`axiom-static-analysis-engineering`)284285The producer-side sibling. That pack builds tools that *read* a program and emit verdicts; this pack builds tools that *transform* a program and emit executables. They meet at the gate: a structural verifier that says "this graph is legal and canonical" is a verdict producer (that pack), and the artifact it approves is compiled and conformance-checked here.286287### Determinism and replay (`axiom-determinism-and-replay`)288289Adjacent and easy to confuse. That pack owns *divergence between executions* — same program, two runs, why do they differ — and ships bisection tooling for exactly that. This pack owns *divergence between a reference and its compilation* — two programs, same inputs. Both use bisection; the bisection axis is different (time/step vs. pass/node). `miscompile-taxonomy-and-debugging` cross-links rather than re-deriving.290291### PyTorch engineering (`yzmir-pytorch-engineering`)292293That pack makes a program you already have faster and less memory-hungry. This pack builds the thing that produces the program. When conformance passes and performance is the problem, leave.294295### Audit pipelines (`axiom-audit-pipelines`)296297A compilation manifest is a provenance record. If manifests must be tamper-evident, signed, or externally attestable — regulated deployment, supply-chain requirements — that pack owns the evidence discipline; this pack owns the content.298299### Other packs300301| Request | Primary pack |302|---------|--------------|303| Make an existing model faster | `yzmir-pytorch-engineering` |304| Debug NaN in training | `yzmir-pytorch-engineering:debug-nan` |305| Distributed training throughput | `yzmir-training-optimization` |306| Serve and version a model in production | `yzmir-ml-production` |307| Design the architecture being compiled | `yzmir-neural-architectures` |308| Reproduce a run, not an artifact | `axiom-determinism-and-replay` |309| CI/CD for the compiler itself | `axiom-devops-engineering` |310311## Quick Reference312313| Need | Use this |314|------|----------|315| Pipeline stages and where the gate sits | `compiler-architecture-for-tensor-programs` |316| May-change / must-not-change list | `ir-contracts-and-semantic-identity` |317| Declare numerics before compiling | `numerical-contracts-and-tolerances` |318| Prove the artifact preserves semantics | `conformance-testing` |319| Write and compose fx passes | `torch-fx-capture-and-transformation` |320| Guards, graph breaks, joint fwd+bwd | `torch-compile-and-aotautograd` |321| Decompositions and kernel choice | `operator-lowering-and-kernel-selection` |322| Fusion legality and memory planning | `fusion-and-memory-planning` |323| Reproducible builds and audit trail | `compilation-manifests-and-reproducibility` |324| Content-addressed artifacts and cache keys | `artifact-identity-and-caching` |325| Cost models and compile budgets | `cost-estimation-and-compilation-budgets` |326| Classify and localise a miscompile | `miscompile-taxonomy-and-debugging` |327| Scaffold a pipeline + gate | command: `/scaffold-tensor-compiler` |328| Verify one artifact end-to-end | command: `/verify-artifact-conformance` |329| Bisect "compiled differs from reference" | command: `/diagnose-miscompile` |330| Design an IR contract and pass pipeline | agent: `tensor-compiler-architect` |331| Audit a compiler for drift risk | agent: `compiler-conformance-reviewer` |332333## The Bottom Line334335**A tensor compiler may change how a program runs and may never change what it computes. Because it cannot be trusted to judge its own preservation, the discipline is four things: an IR contract that says what is off-limits, a numerical contract declared before the first pass, a conformance gate independent of the compiler that checks forward *and* backward across devices and layouts, and a manifest complete enough that any behavioural difference between two artifacts can be traced to a specific decision. Skip any one and you will eventually ship an artifact that is fast, green, and wrong — with no way to find out which pass did it.**336337---338339## Reference Sheets340341**Foundations** (read first, in order):3423431. [compiler-architecture-for-tensor-programs.md](compiler-architecture-for-tensor-programs.md) — Stages; identity vs. execution strategy; who certifies3442. [ir-contracts-and-semantic-identity.md](ir-contracts-and-semantic-identity.md) — May-change / must-not-change; carrying the semantic hash3453. [numerical-contracts-and-tolerances.md](numerical-contracts-and-tolerances.md) — Dtype, accumulation, nondeterminism, tolerance budgets3464. [conformance-testing.md](conformance-testing.md) — Reference execution, gradient conformance, cross-device/cross-layout agreement347348**Capture and transformation:**3493505. [torch-fx-capture-and-transformation.md](torch-fx-capture-and-transformation.md) — Tracing, graph surgery, pass composition, pitfalls3516. [torch-compile-and-aotautograd.md](torch-compile-and-aotautograd.md) — Guards, recompilation, inductor, joint forward+backward352353**Optimisation:**3543557. [operator-lowering-and-kernel-selection.md](operator-lowering-and-kernel-selection.md) — Decompositions, dispatch, kernel choice, fallbacks3568. [fusion-and-memory-planning.md](fusion-and-memory-planning.md) — Fusion legality, layout, constant folding, memory planning357358**Artifact discipline:**3593609. [compilation-manifests-and-reproducibility.md](compilation-manifests-and-reproducibility.md) — Recording every decision; deterministic recompilation36110. [artifact-identity-and-caching.md](artifact-identity-and-caching.md) — Content-addressed artifacts, cache keys, invalidation36211. [cost-estimation-and-compilation-budgets.md](cost-estimation-and-compilation-budgets.md) — Cost models, calibration, budgets, staleness36312. [miscompile-taxonomy-and-debugging.md](miscompile-taxonomy-and-debugging.md) — Four failure classes, bisection, minimal reproducers