What to build
Extract the four-step routed-expert FFN (expert_gate_up → siluf → e8_rot_rows → matmul_qt) into ONE shared helper, and replace the ~6 inlined copies in moe() with calls. Pure refactor: byte-identical output (token-exact oracle green before AND after), one file, no new knobs.
Two things this forces, worth doing now:
- Resolve an existing inconsistency. Two of the inlined copies apply the fmt=6 down-rotation (
if(d.fmt==6) e8_rot_rows); four don't (CPU-resident, Vulkan dev0/dev2 device-lost fallbacks, CUDA-take fallback). Determine whether the non-rotating fallback paths can ever see a fmt=6 expert, and settle the canonical behavior. This is either harmless (those paths never reach fmt=6) or a latent bug — decide and document it.
- Shape the helper for reuse. It must operate on (gate/up/down tensors + input rows + count), not on
moe()'s locals, so the distributed worker can call the same helper later instead of carrying a parallel copy. This is the seam that removes the maintainer's "re-implemented core kernel" objection at the root.
This change is a self-contained, independently-submittable refactor: single concern, byte-identical, no new knobs — the exact shape the maintainer has praised — and should go upstream as its own PR, separate from the distributed-workers PR.
Acceptance criteria
Environment: codegraph-indexed — run codegraph explore first; refs in /home/eli/dev/_reference-docs-and-repos/colibri.
What to build
Extract the four-step routed-expert FFN (
expert_gate_up → siluf → e8_rot_rows → matmul_qt) into ONE shared helper, and replace the ~6 inlined copies inmoe()with calls. Pure refactor: byte-identical output (token-exact oracle green before AND after), one file, no new knobs.Two things this forces, worth doing now:
if(d.fmt==6) e8_rot_rows); four don't (CPU-resident, Vulkan dev0/dev2 device-lost fallbacks, CUDA-take fallback). Determine whether the non-rotating fallback paths can ever see a fmt=6 expert, and settle the canonical behavior. This is either harmless (those paths never reach fmt=6) or a latent bug — decide and document it.moe()'s locals, so the distributed worker can call the same helper later instead of carrying a parallel copy. This is the seam that removes the maintainer's "re-implemented core kernel" objection at the root.This change is a self-contained, independently-submittable refactor: single concern, byte-identical, no new knobs — the exact shape the maintainer has praised — and should go upstream as its own PR, separate from the distributed-workers PR.
Acceptance criteria
moe()call sites route through it (no remaining inlined four-step sequence).make checkgreen, 0 warnings.moe()locals).devtarget), independent of the distributed-workers PR.Environment: codegraph-indexed — run
codegraph explorefirst; refs in/home/eli/dev/_reference-docs-and-repos/colibri.