Skip to content

spacemit: fix MoE row-map capacity for repeated expert IDs - #99

Merged
alex-spacemit merged 1 commit into
spacemit-com:mtmd-backendfrom
co-seven:pr/nomtp-moe-20261203
Dec 4, 2026
Merged

alex-spacemit merged 1 commit into
spacemit-com:mtmd-backendfrom
co-seven:pr/nomtp-moe-20261203

Conversation

@co-seven

@co-seven co-seven commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Problem and behavior

Correctness fix, not a new MoE compute optimization. MUL_MAT_ID may receive the same expert ID in several slots for one token. Sizing each expert's row map only to the token count allows repeated-slot entries to overwrite the next expert's map.

Size and index each expert's map for the full number of ID slots and move subsequent M4 scratch beyond the larger table. Each selected activation slot then retains its own output mapping.

Change and design

Only ime.cpp changes: row-map workspace sizing, per-expert indexing and the following M4 scratch offset. The arithmetic kernels and the existing M8 tail-padding policy from #89 remain unchanged.

Worst-case workspace increases in proportion to the number of selected slots. This supports the operator's repeated-ID input semantics; ordinary top-k routing need not generate duplicates for the bug to be valid.

Scope is limited to ggml/src/ggml-spacemit/. Impact classification: execution-path change. No changes to the retired CPU backend, model code, public API or test sources. Local validation fixtures are excluded. This independently based module commit preserves the target branch's common MTP graph/rollback paths; experimental noMTP-wide reversions are not submitted. No new external dependency is added.

Validation

Base: mtmd-backend at 3f5ce5fd84f4dc6e7e621642cfef0143d49e7c24. Candidate: 797ff0fe303e55e1063f963a66676a6aa46ad5d3; source tree 4c9f5d84895e5190139ee4277ae90ab6a38bb948.

The exact submitted production source passed a RISC-V Release cross-build of ggml-spacemit using the SpacemiT v1.1.2 toolchain (GCC 14.3), cmake/riscv64-spacemit-linux-gnu-gcc.cmake, GGML_SPACEMIT=ON, GGML_RV_ZBA=ON, GGML_OPENMP=OFF, Spert 0.6.3 and SpacemiT ORT 2.0.6. Build target: cmake --build <build> --target ggml-spacemit --parallel 24. Backend DSO SHA-256: faa2032c0d053af501bb5d8f8e429f389ed8dd5e38c36d68adb431412e6d1da7. Source hashes were checked before/after the build and against the committed files.

Reproduction: SPACEMIT0, Q4_0 weights with K=512, N=2048, 16 experts; one token, eight distinct F32 activation slots and IDs [0,1,2,3,0,1,2,3]. Compare MUL_MAT_ID against an independent CPU reference using NMSE <= 5e-4.

The original backend failed this input at NMSE 1.802669. The archived corrected K3-179 package passed 15/15 cases with the default schedule and 60/60 across four experimental schedules at the same threshold. Cases cover repeated IDs, all slots selecting one expert, unique IDs, one/two tokens and broadcast/nonbroadcast activations. Optional grouping/scheduling experiments are outside this PR.

Run labels: mmid-duplicate-v18-repro-board179-r1 and mmid-groups-v25-board179-r1. These are historical operator results for the same capacity fix, not fresh board execution of this independent PR head.

Check Status Evidence / scope
Exact-source RISC-V backend build PASS Configuration and DSO identity above
Diff / scope / formatting checks PASS Backend-only; no test changes or new environment controls; git diff --check, UTF-8/LF and added-line whitespace
Duplicate-ID regression FAIL (historical baseline) NMSE 1.802669 versus 5e-4 limit
Corrected operator cases PASS (historical) Default 15/15; all schedules 60/60
Final-head model correctness / performance NOT RUN Only operator regression evidence is available
Final-head board / additional platform coverage NOT RUN Historical target results are carried forward; no new final-head K3 or K1 run

Performance

No throughput benefit is claimed. The change corrects workspace capacity and indexing; it increases worst-case scratch allocation. Final-head model correctness and a model-level performance comparison are NOT RUN. This PR does not reuse the performance numbers for #89's separate M8-padding change.

Risks and limits

Worst-case workspace is larger. Historical cases establish the duplicate-slot correction, not broad end-to-end model coverage or a throughput improvement. The final independent head needs target revalidation.

The historical module comparisons used the common noMTP experimental baseline on top of 3f5ce5fd; this PR instead preserves upstream common MTP behavior. Historical results are not claimed as new measurements of the final independent head. Raw build/test/benchmark archives are retained privately and are not publicly attached; the cases, results, artifact identities and limits above are the reviewable record here. Exact-input model replay is not provided by these summaries. Required final-head target evidence remains pending; this submission requests review, not a waiver or a claim of merge readiness. No maintainer exception has been granted. CI status is separate from the local results above.

AI assistance and contributor responsibility

Codex assisted with source preparation, static review, local build/check execution, historical evidence analysis and this PR description. The contributor discussed the module design and explicitly requested publication. No unrecorded personal review, maintainer approval or target execution is asserted. The contributor remains responsible for reviewing the submitted code and claims and addressing review feedback.

@alex-spacemit
alex-spacemit merged commit 75b1485 into spacemit-com:mtmd-backend Dec 4, 2026
13 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants