Skip to content

moe: the engine reads a moe_placement table only if it was written for this model (Refs #1702) - #2156

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl1077/1702-placement-reader
Nov 11, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl1077/1702-placement-reader

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #1702. This adds the reader that the issue's decision (11-11 01:12Z) named as the open task: "the splitter's reader for the table, gated as above." It does not add a splitter, and it does not add the NVMe write order; that order waits for the streamer, as the decision says.

What it does

app/moe_placement.h (header only) loads a tools/moe_placement.py table and checks it against what the caller is about to run. It returns group_of(layer, expert), or an error naming the check that failed. Every refusal below catches a table that is plausible but wrong. A table built for another model still places every expert of its own model exactly once, so a reader without these checks would adopt it without complaint.

refused message (from the test)
another schema schema "something/else" is not "1bit/moe-placement/1"
another device count the table splits into 4 groups, this run has 2
only share_in_sample no "share_held_out": the gate is the held-out share, not share_in_sample (51.1 %)
held-out share under the floor share_held_out 7.0 % is under the gate 15.0 %
a routed layer missing / an extra layer layer 3 is missing from the table / layer 2 is not a routed layer of this model
another expert count layer 1: the table was built for 16 experts, this model has 8
id out of range / placed twice / not placed expert 8 is outside 0..7 / expert 4 is placed twice / expert 5 is not placed

The 15 % floor is the decision's figure: "> ~15 % is the floor these traces support". A caller can change it through min_held_out.

Checked

  • ctest -R moe_placement: both rows pass. moe_placement_reader passes 22/22 checks, and the tool's own moe_placement self-test still passes.
  • Mutants: I removed three checks, one at a time: the held-out gate, the placed-twice check and the missing-layer check. Each one makes the test fail on the arm that covers it (rc 1).
  • A table written by the real tool: tools/moe_placement.py trace.tsv -g 2 -e 16 -o placement.json, run on a synthetic two-layer trace, is adopted with {1, 3}, 16, 2. The same file is refused for a 32-expert model with layer 1: the table was built for 16 experts, this model has 32.
  • copyright.py --check, ci_targets_check, tests_referenced_check and python_test_order_check all give rc 0.
  • Docs: a paragraph in docs/moe-streaming.md, in the placement-table section.

Nothing in the engine consumes the table yet, so this changes no served behaviour.

🤖 Generated with Claude Code

…r this model (Refs #1702)

app/moe_placement.h is the reader the #1702 decision named as the open task:
schema, group count, every routed layer, every expert id exactly once, and
the held-out share against a floor (15 %, never the in-sample share).
ctest moe_placement_reader: one adopted table and one arm per refusal.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at 6910a41

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 6910a41: READY

Reviewed head 6910a41 (refs #1702). This is the first verdict.

Checked

  • git merge-tree onto main: no conflicts.
  • ctest moe_placement_reader and moe_placement pass, built from this head. moe_placement_test is a build dependency of onebit, so CI actually runs it: the CI log at this head has #85: moe_placement_reader … Passed, 231/231. CI build, hrx_build and CodeQL green.
  • Mutants of app/moe_placement.h, on the checks the body's three mutants did not cover. Each was rebuilt and run:
check removed arm that fails
schema (schema != kPlacementSchema) "another schema (adopted)"
group count (p.groups != want.groups) "a table for 4 devices on a 2-device run (adopted)"
per-layer expert count "built for another expert count (adopted)"
an unplaced expert "an expert placed nowhere (adopted)"
a layer the model does not route "a layer this model routes nowhere (adopted)"
the upper id bound (id >= want.n_experts) refused, but by accident: see below

I restored the file (git status clean); "moe_placement_test: ok".

One observation, not blocking. With the upper bound removed, id 8 on an 8-expert model indexes pl.group_of[8], one past the vector, and the arm passes only because that out-of-bounds read happened to look like "placed twice". So the range check (:149) is also the memory-safety check for the two group_of[size_t(id)] accesses after it. Worth a word in its comment, so nobody "simplifies" it into the expert-count check at :135. That one only runs when the layer carries an experts key.

Not re-run by me: the round trip through tools/moe_placement.py on a synthetic trace.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1702 - Partially compliant

Compliant requirements:

  • Implement a reader for the tools/moe_placement.py table that checks the table against the model being run
  • The reader refuses tables that are for a different model, device count, or expert count
  • The reader validates that the table was built for the held-out share (not the in-sample share)
  • The reader validates that the held-out share is above a minimum threshold (15%)
  • The reader validates that all routed layers are present and correctly specified
  • The reader validates that all experts are placed exactly once
  • The reader validates that expert IDs are within the valid range
  • The reader validates that expert groups are correctly specified
  • The reader provides clear error messages indicating which check failed
  • Add tests to verify the reader's behavior with both valid and invalid tables
  • Update documentation to describe the new reader functionality

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Schema Validation

The schema validation checks for an exact match against "1bit/moe-placement/1", but the PR description mentions that the tool's own shape is used for validation. The implementation correctly enforces this, but it's worth noting that this is a strict validation that could prevent adoption of tables with slightly different schema versions.

if (schema != kPlacementSchema)
    refuse("schema \"" + schema + "\" is not \"" + kPlacementSchema + "\"");
Expert ID Validation

The validation for expert IDs ensures they are within the range 0..n_experts-1, but it doesn't validate that the expert IDs are unique within each group. While the code checks that each expert is placed exactly once across all groups, it doesn't explicitly validate that the IDs within each group are unique, which could lead to subtle issues if the input data is malformed.

if (id < 0 || id >= want.n_experts)
    refuse(at + "expert " + std::to_string(id) + " is outside 0.." + std::to_string(want.n_experts - 1));
Layer Key Validation

The layer key validation uses a decimal_key function that rejects keys with leading zeros. While this prevents some malformed inputs, it might be overly restrictive for future use cases where layer keys might legitimately have leading zeros. The validation should be reviewed to ensure it's appropriate for all expected inputs.

if (!detail::decimal_key(it.key(), layer)) refuse("layer key \"" + it.key() + "\" is not a layer number");
auto w = wanted.find(layer);
if (w == wanted.end()) refuse("layer " + it.key() + " is not a routed layer of this model");

@bong-water-water-bong
bong-water-water-bong merged commit 08cb7a4 into main Nov 11, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl1077/1702-placement-reader branch November 11, 2026 10:01
bong-water-water-bong pushed a commit that referenced this pull request Nov 12, 2026
…t prose (#1702)

The reader (app/moe_placement.h, #2156) refuses a table written for another
model, group count or expert count, and gates on the held-out share. It had
only synthetic tables to read. This adds the writer's actual output for the
Flash-Next decode trace -- 48 routed layers, 512 experts, 2 groups, in-sample
share 0.523 against a 0.2% contiguous control, held out 0.1892 over 5280
steps, every layer a permutation of 0..511 -- so the issue's headline is
reproduced through the shipped path rather than an analysis script.

Registered as a second arm, moe_placement_reader_fixture, because main already
registers moe_placement_reader without an argument. A second add_test with the
same NAME is a CMake configure error ('given test NAME ... which already
exists'), so the rebase had to give the arm its own name: verified with a
two-line project that duplicates fail (rc=1) and these two names do not (rc=0,
ctest lists both).
bong-water-water-bong added a commit that referenced this pull request Nov 12, 2026
…t prose (#1702) (#2286)

The reader (app/moe_placement.h, #2156) refuses a table written for another
model, group count or expert count, and gates on the held-out share. It had
only synthetic tables to read. This adds the writer's actual output for the
Flash-Next decode trace -- 48 routed layers, 512 experts, 2 groups, in-sample
share 0.523 against a 0.2% contiguous control, held out 0.1892 over 5280
steps, every layer a permutation of 0..511 -- so the issue's headline is
reproduced through the shipped path rather than an analysis script.

Registered as a second arm, moe_placement_reader_fixture, because main already
registers moe_placement_reader without an argument. A second add_test with the
same NAME is a CMake configure error ('given test NAME ... which already
exists'), so the rebase had to give the arm its own name: verified with a
two-line project that duplicates fail (rc=1) and these two names do not (rc=0,
ctest lists both).

Co-authored-by: bcloud <agent@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant