contract(trace-moe-gpu-sub-stages-v1): v1.0.0 PROPOSED scaffold for M-GPU-MOE-1.4 bisection#1498
Merged
Merged
Conversation
4 tasks
Sibling contract to trace-attn-sub-stages-v1; pins the SaveTensorStage extensions needed for M-GPU-MOE-1.4 NaN/Inf bisection per qwen3-moe-forward-gpu-v1 v1.4.0 amendment. WHY THIS CONTRACT: After M-GPU-MOE-1.3 partial fix (PR #1491 squash f0cbe37 MERGED), heavy `qwen3_moe_gpu_parity` test on lambda-vector RTX 4090 produces 100% NaN logits. Steps 1-9 are CPU-shared with finite output; step 10 (GPU MoE FFN — moe_ffn_forward_layer_cuda → expert_swiglu_cuda → q4k_matvec/q6k_gemv) is the only candidate. Per qwen3-moe-forward-gpu-v1 v1.4.0 bisection plan step (a), apr trace needs new SaveTensorStage variants for MoE GPU stages. WHAT IT DEFINES: * 2 mandatory new SaveTensorStage variants: - MoeRouter — top-k weights post-softmax/renormalize - MoeFfnOut — aggregated MoE FFN output (Σ w_e * expert_out_e) * 4 optional per-expert variants (with expert_id qualifier): - MoeExpertGate, MoeExpertUp, MoeExpertSwigl, MoeExpertOut - Promoted to mandatory only if 2-stage bisection isn't precise enough. * Bisection chain CPU-vs-GPU: cos_sequence = [ cos(CPU.ffn_norm, GPU.ffn_norm), # parent enum cos(CPU.moe_router, GPU.moe_router), # NEW cos(CPU.moe_ffn_out, GPU.moe_ffn_out), # NEW ] FALSIFICATION TESTS (4): FALSIFY-MOE-SUB-001: New variants exist + parse correctly FALSIFY-MOE-SUB-002: Existing 20-stage byte-identity preserved FALSIFY-MOE-SUB-003: Bisection identifies first NaN-producing stage FALSIFY-MOE-SUB-004: Fix PR cites bisected stage by name IMPLEMENTATION_STAGES (4): M-MOE-SUB-0: This contract scaffold (SHIPPED) M-MOE-SUB-1: Add MoeRouter + MoeFfnOut variants (PENDING) M-MOE-SUB-2: Wire MoeRouter into both CPU + GPU forward (PENDING) M-MOE-SUB-3: Wire MoeFfnOut + run heavy bisection (PENDING) M-MOE-SUB-4: OPTIONAL per-expert promotion (PENDING) VALIDATION: pv validate exits 0 errors, 0 warnings. Per CLAUDE.md "NEVER write code before writing a provable contract" — this PR pins the trace-stage architecture before code lands. M-MOE-SUB-1 follows in a separate PR. Refs: M-GPU-MOE-1.4, R10, qwen3-moe-forward-gpu-v1 v1.4.0, trace-attn-sub-stages-v1 (sibling pattern). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
0a18b9d to
c2afb5a
Compare
noahgift
added a commit
that referenced
this pull request
May 5, 2026
…-MOE-SUB-1 Per `contracts/trace-moe-gpu-sub-stages-v1.yaml` v1.0.0 (PR #1498), M-MOE-SUB-1 implementation: extend the parent SaveTensorStage enum with the 2 new mandatory MoE-GPU bisection variants. WHAT THIS PR ADDS: * `MoeRouter` — top-k expert weights post-softmax + renormalize, per-layer, captured AFTER FfnNorm and BEFORE per-expert SwiGLU. * `MoeFfnOut` — aggregated MoE FFN output Σ w_e * expert_out_e, per-layer, captured AFTER all per-expert computations. CHANGES: * `SaveTensorStage` enum: 2 new variants between `PostFfnResidual` and `FinalNorm`. * `ALL` array: 20 → 22 entries; new variants in canonical position. * `canonical_name()`: 2 new arms returning "moe_router" + "moe_ffn_out". * `FromStr::from_str()` lowercase match: 2 new accepted strings. * `is_per_layer_count_matches_contract` test: per_layer 18 → 20, total 20 → 22. * `canonical_names_match_contract_enumeration` test: expected[] grows to 22 with new entries in canonical order. * 5 new `falsify_moe_sub_001_*` tests: - `moe_router_round_trip` - `moe_ffn_out_round_trip` - `2_new_stages_in_canonical_order` (ALL position assertions) - `parse_list_accepts_2_new_stages_together` - `parse_list_accepts_full_moe_block_chain` (3-stage bisection chain `ffn_norm,moe_router,moe_ffn_out`) DISCHARGES: FALSIFY-MOE-SUB-001 (per contract). NOT DISCHARGED YET (separate follow-up scope per contract): * FALSIFY-MOE-SUB-002 (byte-identity preservation) — needs the instrumentation PR (M-MOE-SUB-2 + 3) that wires MoeRouter + MoeFfnOut capture into both forward bodies. * FALSIFY-MOE-SUB-003 (live bisection on lambda-vector RTX 4090). * FALSIFY-MOE-SUB-004 (fix PR cites bisected stage by name). VERIFICATION: cargo test -p aprender-serve --lib save_tensor_stage → 29 passed; 0 failed; 0 ignored rustfmt --check → exit 0 DEPENDS ON: PR #1498 (`trace-moe-gpu-sub-stages-v1` v1.0.0 contract scaffold) being on aprender main first. The contract pinned the new variants' names + semantics; this PR implements them. Refs: M-GPU-MOE-1.4 step (a) instrumentation, R10, qwen3-moe-forward-gpu-v1 v1.4.0, trace-moe-gpu-sub-stages-v1 v1.0.0, FALSIFY-MOE-SUB-001 (DISCHARGED). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
noahgift
added a commit
that referenced
this pull request
May 5, 2026
…-MOE-SUB-1 Per `contracts/trace-moe-gpu-sub-stages-v1.yaml` v1.0.0 (PR #1498), M-MOE-SUB-1 implementation: extend the parent SaveTensorStage enum with the 2 new mandatory MoE-GPU bisection variants. WHAT THIS PR ADDS: * `MoeRouter` — top-k expert weights post-softmax + renormalize, per-layer, captured AFTER FfnNorm and BEFORE per-expert SwiGLU. * `MoeFfnOut` — aggregated MoE FFN output Σ w_e * expert_out_e, per-layer, captured AFTER all per-expert computations. CHANGES: * `SaveTensorStage` enum: 2 new variants between `PostFfnResidual` and `FinalNorm`. * `ALL` array: 20 → 22 entries; new variants in canonical position. * `canonical_name()`: 2 new arms returning "moe_router" + "moe_ffn_out". * `FromStr::from_str()` lowercase match: 2 new accepted strings. * `is_per_layer_count_matches_contract` test: per_layer 18 → 20, total 20 → 22. * `canonical_names_match_contract_enumeration` test: expected[] grows to 22 with new entries in canonical order. * 5 new `falsify_moe_sub_001_*` tests: - `moe_router_round_trip` - `moe_ffn_out_round_trip` - `2_new_stages_in_canonical_order` (ALL position assertions) - `parse_list_accepts_2_new_stages_together` - `parse_list_accepts_full_moe_block_chain` (3-stage bisection chain `ffn_norm,moe_router,moe_ffn_out`) DISCHARGES: FALSIFY-MOE-SUB-001 (per contract). NOT DISCHARGED YET (separate follow-up scope per contract): * FALSIFY-MOE-SUB-002 (byte-identity preservation) — needs the instrumentation PR (M-MOE-SUB-2 + 3) that wires MoeRouter + MoeFfnOut capture into both forward bodies. * FALSIFY-MOE-SUB-003 (live bisection on lambda-vector RTX 4090). * FALSIFY-MOE-SUB-004 (fix PR cites bisected stage by name). VERIFICATION: cargo test -p aprender-serve --lib save_tensor_stage → 29 passed; 0 failed; 0 ignored rustfmt --check → exit 0 DEPENDS ON: PR #1498 (`trace-moe-gpu-sub-stages-v1` v1.0.0 contract scaffold) being on aprender main first. The contract pinned the new variants' names + semantics; this PR implements them. Refs: M-GPU-MOE-1.4 step (a) instrumentation, R10, qwen3-moe-forward-gpu-v1 v1.4.0, trace-moe-gpu-sub-stages-v1 v1.0.0, FALSIFY-MOE-SUB-001 (DISCHARGED). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
noahgift
added a commit
that referenced
this pull request
May 5, 2026
…-MOE-SUB-1 (#1499) Per `contracts/trace-moe-gpu-sub-stages-v1.yaml` v1.0.0 (PR #1498), M-MOE-SUB-1 implementation: extend the parent SaveTensorStage enum with the 2 new mandatory MoE-GPU bisection variants. WHAT THIS PR ADDS: * `MoeRouter` — top-k expert weights post-softmax + renormalize, per-layer, captured AFTER FfnNorm and BEFORE per-expert SwiGLU. * `MoeFfnOut` — aggregated MoE FFN output Σ w_e * expert_out_e, per-layer, captured AFTER all per-expert computations. CHANGES: * `SaveTensorStage` enum: 2 new variants between `PostFfnResidual` and `FinalNorm`. * `ALL` array: 20 → 22 entries; new variants in canonical position. * `canonical_name()`: 2 new arms returning "moe_router" + "moe_ffn_out". * `FromStr::from_str()` lowercase match: 2 new accepted strings. * `is_per_layer_count_matches_contract` test: per_layer 18 → 20, total 20 → 22. * `canonical_names_match_contract_enumeration` test: expected[] grows to 22 with new entries in canonical order. * 5 new `falsify_moe_sub_001_*` tests: - `moe_router_round_trip` - `moe_ffn_out_round_trip` - `2_new_stages_in_canonical_order` (ALL position assertions) - `parse_list_accepts_2_new_stages_together` - `parse_list_accepts_full_moe_block_chain` (3-stage bisection chain `ffn_norm,moe_router,moe_ffn_out`) DISCHARGES: FALSIFY-MOE-SUB-001 (per contract). NOT DISCHARGED YET (separate follow-up scope per contract): * FALSIFY-MOE-SUB-002 (byte-identity preservation) — needs the instrumentation PR (M-MOE-SUB-2 + 3) that wires MoeRouter + MoeFfnOut capture into both forward bodies. * FALSIFY-MOE-SUB-003 (live bisection on lambda-vector RTX 4090). * FALSIFY-MOE-SUB-004 (fix PR cites bisected stage by name). VERIFICATION: cargo test -p aprender-serve --lib save_tensor_stage → 29 passed; 0 failed; 0 ignored rustfmt --check → exit 0 DEPENDS ON: PR #1498 (`trace-moe-gpu-sub-stages-v1` v1.0.0 contract scaffold) being on aprender main first. The contract pinned the new variants' names + semantics; this PR implements them. Refs: M-GPU-MOE-1.4 step (a) instrumentation, R10, qwen3-moe-forward-gpu-v1 v1.4.0, trace-moe-gpu-sub-stages-v1 v1.0.0, FALSIFY-MOE-SUB-001 (DISCHARGED). Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sibling contract to
trace-attn-sub-stages-v1; pins theSaveTensorStageextensions needed for M-GPU-MOE-1.4 NaN/Inf bisection perqwen3-moe-forward-gpu-v1v1.4.0 (PR #1492).Why now
After M-GPU-MOE-1.3 partial fix (PR #1491
f0cbe37f9MERGED), heavy test produces 100% NaN logits on lambda-vector RTX 4090. Steps 1-9 are CPU-shared with finite output; step 10 (GPU MoE FFN) is the only candidate. The bisection plan needs trace-stage instrumentation, which requires the new SaveTensorStage variants pinned here.What this contract pins
MoeRouter(top-k weights),MoeFfnOut(aggregated)MoeExpertGate/Up/Swigl/Out(promoted to mandatory only if 2-stage bisection isn't precise enough)Validation
Stacks on
PR #1492 (
fe8877424v1.4.0 amendment) which is already on main.Test plan
🤖 Generated with Claude Code