profile: execute the MoE region terminator, and stop shared work inheriting pair labels - #107
Merged
Merged
Conversation
qichao-arlo-wang
force-pushed
the
feat/moe-stage-terminator-exec
branch
from
August 9, 2026 12:13
8634933 to
29c2e8b
Compare
…k inheriting pair labels Companion to PLENA_Compiler's terminator change; the pin moves onto it here. `StageKind::NonMoe` resolves the compiler's `@stage=non_moe`. Markers are sticky and a program does not stop where its MoE region does, so without a terminator the last MoE marker ran to the end of the file and the epilogue -- an lm_head, the next sublayer -- was billed to a MoE stage. Measured end to end on a shared-expert program followed by an lm_head projection: 29 of 219 instructions move out of `shared_expert_projection` once the terminator is emitted. A distinct variant rather than resolving `other`: a large `Other` is a coverage problem and a large `NonMoe` is just a long epilogue, and being unable to tell those apart is how the original bug stayed invisible. The pair-label reset now covers the three `shared_expert_*` stages and `NonMoe`. They have no experts at all, so there is no `(token, expert)` pair for their work to belong to, and without the reset their cost merged into whichever routed pair ran last. The list is a named `PAIRLESS_STAGES` constant so the test asserts against the classifier rather than restating the match arm. Three new reported fields make an unterminated region visible without reading the source that produced it: `moe_region_terminated`, `trailing_stage` and `trailing_labels`. All three are recorded when the marker is applied, from the same place, so they cannot contradict one another -- an earlier version took `trailing_stage` from the last label instead and disagreed with the other two. `trailing_labels` counts from the last marker rather than from the last change of stage, so adjacent regions marked with the same name are not merged, and it is named for labels because it counts emitted ASM like `label_count`, not executions. When no marker ever resolves it is 0, not `label_count`: a legacy-classified file has no final marker for anything to ride on. `test_branch_split.py` classifies `non_moe` explicitly, in its own tuple rather than folded into PLUMBING_STAGES -- plumbing is MoE cost both branches share and this is not MoE cost at all. The exhaustiveness assertion forced the decision rather than letting a new stage drop out of the split and read as free. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
qichao-arlo-wang
force-pushed
the
feat/moe-stage-terminator-exec
branch
from
August 9, 2026 12:28
29c2e8b to
07bed8e
Compare
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.
Companion to AICrossSim/PLENA_Compiler#72; the submodule pin moves onto it here.
1. The MoE region now has an end
StageKind::NonMoeresolves the compiler's@stage=non_moe. Demonstrated end to end — a shared-expert program followed by an lm_head projection, classified with the emulator's own sticky-marker rule:29 instructions of pure non-MoE work stop being billed to the shared branch, and that number feeds
shared_branch_fraction.A distinct variant, not
other. Resolvingotherwould have worked mechanically, but a largeOtheris a coverage problem and a largeNonMoeis just a long epilogue. Being unable to tell those apart is how the original bug stayed invisible.2. Shared work no longer inherits a pair label
The three
shared_expert_*stages have no experts — there is no(token, expert)pair for their work to belong to. Without a reset their cost merged into whichever routed pair ran last, and in a shared-only program it invented pairs outright.The reset list is now
PAIRLESS_STAGES, a named constant, so the test asserts membership instead of restating the match arm — the two could previously drift.3. An unterminated region is now visible in the JSON
classification.trailing_stageandclassification.trailing_instructions.The per-stage totals still add up when a region is left open — that is precisely what made this class of bug invisible. A large trailing count against a MoE stage now says so, without anyone having to read the source that emitted it. A properly terminated program shows
non_moehere and the count is simply how long the epilogue is.On
test_branch_split.pynon_moeis classified explicitly, in its ownNON_MOE_STAGEStuple rather than folded intoPLUMBING_STAGES. Plumbing is MoE cost that both branches share; this is not MoE cost at all. The exhaustiveness assertion is what forced the decision rather than letting a new stage drop out of the split and read as free — working as intended.Validation
cargo test --workspace --release— 181 passed, 0 failed (3 new: terminator resolution, trailing attribution both ways, and pairless-stage membership including the negative case that a routed stage keeps its label).just test-moe-shared-allpasses with 3 bit-exact comparisons; all six routed-MoE suites pass.cargo fmt --check,ruff format --check,ruff checkclean.🤖 Generated with Claude Code