Ferret frozen-gate kernel system — how to invoke + why
The problem it solves (read first)
The OLD ferret wrote its OWN correctness test. It once shipped a DeepSeek-V3
attention kernel with SIMPLIFIED math (theta-10000 rope not YaRN, 1/sqrt(576) not
the YaRN mscale scale, head-sum o_proj skipping W_UV, no kv_a_layernorm) and
self-reported cosine 1.0 — against its own simplified reference. Marking its
own homework. The refactor takes judging + constraints OUT of the optimizer.
The 3 agents (in .claude/agents/)
| Agent |
Role |
You invoke? |
| ferret-kernel-agent (L1 dispatcher) |
The ENTRY POINT. Pins ALL constraints, freezes the gate via the test-writer, runs the optimizer in-session, drives Codex review each round, does in-MPK faithful acceptance. |
YES — this is the only one you invoke directly. |
| ferret-test-writer (L2a) |
Writes the FROZEN, hash-locked gate vs a CANONICAL reference (never re-derived), checking INTERMEDIATE tensors. Spawned by L1, before the optimizer. |
No (L1 spawns it) |
| ferret-optimizer (L2b) |
In-session optimizer (replaces claude -p), judged ONLY by the frozen gate, can't simplify. Spawned by L1 each round. |
No (L1 spawns it) |
How to invoke (the main-thread → subagent contract)
Invoke the ferret-kernel-agent subagent (via the Agent tool) with a COMPLETE
constraint contract — this is where nothing gets missed and no simplification slips
in. Give it, explicitly:
- TARGET — the exact MPK op + what it replaces; the baseline = the kernel being
replaced, benched the way MPK calls it (not an external SOTA unless it's the consumer).
- REAL-MATH CONTRACT — enumerate EVERY step the kernel must compute, NO
simplification (the test-writer turns this into intermediate checks).
- SHAPES — exact (M,K,N) at the real TP/EP regime (derive from the builder/weights).
- PRODUCTION COMPILE FLAGS —
-rdc=true / MPK_FORCE_RDC_TRUE=1, arch sm_100a,
single-stream / no-CUDA-graph / no-cta_group::2. State that FINAL acceptance is the
in-MPK faithful build; standalone -rdc=true is diagnostic only.
- ABI — the
__device__ task_impl signature + NS/NE.
- CANONICAL REFERENCE SOURCE — the already-trusted oracle to compare against
(the in-MPK task-chain output; the official HF model; an in-tree faithful test).
NEVER "let the agent derive it."
If the gate already exists (hash-locked in the workspace), tell L1 to reuse it
(hash-verify) and go straight to the optimizer loop.
The invariants that make it trustworthy (Codex-hardened — gate fidelity is load-bearing)
- The gate is built by the independent test-writer, not the optimizer.
- The reference is CANONICAL (validated against a trusted source), never re-derived.
- The gate checks INTERMEDIATES (golden vectors per stage), not just a final cosine
— a deep simplification (a dropped layernorm, a wrong rope base) is caught at the
first diverging stage (
first_failing_stage), not washed out.
- Multiple metrics + edge cases (long-context, boundary positions).
- The gate is sha256 hash-locked; L1 re-verifies the hash before EVERY round
(tamper = abort).
- The optimizer is judged ONLY by
gate/check.py. Codex reviews each round on two
axes — Integrity (did it simplify to pass?) + Plan (is the lever sound?).
- FINAL acceptance = in-MPK faithful build (
MPK_FORCE_RDC_TRUE=1, compiled into
the real megakernel). A standalone number never ships.
- Early stop = round incomplete, never success.
Proof it works
Re-run on the simplified attention: the optimizer (judged by the frozen gate) built a
CORRECT real-DSv3 fused attention in round 1 — GATE_RESULT {pass:true} on all 5
cases / all intermediates, gate untouched, dump provenance verified (W_UV BMM present,
real mscale²/sqrt(192) scale), all 4 simplifications fixed, Codex Integrity+Plan PASS.
The old simplified-kernel failure is now structurally impossible.
Reference
Full design + the /cd-mechanics + the hardening rationale: DESIGN.md (bundled
alongside this skill). The ferret runtime itself lives at
~/ferret/ (its CLAUDE.md is the optimizer's methodology). Pre-authored task specs:
~/ferret/tasks/.
1---2name: ferret-kernel-system3description: Ferret frozen-gate kernel system — how to invoke + why4---56# Ferret frozen-gate kernel system — how to invoke + why78## The problem it solves (read first)9The OLD ferret wrote its OWN correctness test. It once shipped a DeepSeek-V310attention kernel with SIMPLIFIED math (theta-10000 rope not YaRN, 1/sqrt(576) not11the YaRN mscale scale, head-sum o_proj skipping W_UV, no kv_a_layernorm) and12self-reported **cosine 1.0** — against its own simplified reference. Marking its13own homework. The refactor takes judging + constraints OUT of the optimizer.1415## The 3 agents (in `.claude/agents/`)16| Agent | Role | You invoke? |17|---|---|---|18| **ferret-kernel-agent** (L1 dispatcher) | The ENTRY POINT. Pins ALL constraints, freezes the gate via the test-writer, runs the optimizer in-session, drives Codex review each round, does in-MPK faithful acceptance. | **YES — this is the only one you invoke directly.** |19| **ferret-test-writer** (L2a) | Writes the FROZEN, hash-locked gate vs a CANONICAL reference (never re-derived), checking INTERMEDIATE tensors. Spawned by L1, before the optimizer. | No (L1 spawns it) |20| **ferret-optimizer** (L2b) | In-session optimizer (replaces `claude -p`), judged ONLY by the frozen gate, can't simplify. Spawned by L1 each round. | No (L1 spawns it) |2122## How to invoke (the main-thread → subagent contract)23Invoke the **ferret-kernel-agent** subagent (via the Agent tool) with a COMPLETE24constraint contract — this is where nothing gets missed and no simplification slips25in. Give it, explicitly:261. **TARGET** — the exact MPK op + what it replaces; the baseline = the kernel being27 replaced, benched the way MPK calls it (not an external SOTA unless it's the consumer).282. **REAL-MATH CONTRACT** — enumerate EVERY step the kernel must compute, NO29 simplification (the test-writer turns this into intermediate checks).303. **SHAPES** — exact (M,K,N) at the real TP/EP regime (derive from the builder/weights).314. **PRODUCTION COMPILE FLAGS** — `-rdc=true` / `MPK_FORCE_RDC_TRUE=1`, arch sm_100a,32 single-stream / no-CUDA-graph / no-cta_group::2. State that FINAL acceptance is the33 in-MPK faithful build; standalone `-rdc=true` is diagnostic only.345. **ABI** — the `__device__ task_impl` signature + NS/NE.356. **CANONICAL REFERENCE SOURCE** — the already-trusted oracle to compare against36 (the in-MPK task-chain output; the official HF model; an in-tree faithful test).37 NEVER "let the agent derive it."38If the gate already exists (hash-locked in the workspace), tell L1 to reuse it39(hash-verify) and go straight to the optimizer loop.4041## The invariants that make it trustworthy (Codex-hardened — gate fidelity is load-bearing)42- The gate is built by the **independent test-writer**, not the optimizer.43- The reference is **CANONICAL** (validated against a trusted source), never re-derived.44- The gate checks **INTERMEDIATES** (golden vectors per stage), not just a final cosine45 — a deep simplification (a dropped layernorm, a wrong rope base) is caught at the46 first diverging stage (`first_failing_stage`), not washed out.47- Multiple metrics + edge cases (long-context, boundary positions).48- The gate is **sha256 hash-locked**; L1 re-verifies the hash before EVERY round49 (tamper = abort).50- The optimizer is judged ONLY by `gate/check.py`. **Codex** reviews each round on two51 axes — Integrity (did it simplify to pass?) + Plan (is the lever sound?).52- **FINAL acceptance = in-MPK faithful build** (`MPK_FORCE_RDC_TRUE=1`, compiled into53 the real megakernel). A standalone number never ships.54- **Early stop = round incomplete, never success.**5556## Proof it works57Re-run on the simplified attention: the optimizer (judged by the frozen gate) built a58CORRECT real-DSv3 fused attention in round 1 — `GATE_RESULT {pass:true}` on all 559cases / all intermediates, gate untouched, dump provenance verified (W_UV BMM present,60real mscale²/sqrt(192) scale), all 4 simplifications fixed, Codex Integrity+Plan PASS.61The old simplified-kernel failure is now structurally impossible.6263## Reference64Full design + the /cd-mechanics + the hardening rationale: `DESIGN.md` (bundled65alongside this skill). The ferret runtime itself lives at66`~/ferret/` (its `CLAUDE.md` is the optimizer's methodology). Pre-authored task specs:67`~/ferret/tasks/`.