Skip to content

tools: moe_expert_chunks.py gate --proj down crashes instead of emitting the down gate (it uses the hidden-state row for a 768-wide contraction) #1083

Closed

Description

@bong-water-water-bong

tools: moe_expert_chunks.py gate --proj down crashes instead of emitting the down gate (it uses the hidden-state row for a 768-wide contraction)

gate builds A from the layer's MoE input row (h, hidden 2048 on Qwen3-Coder-30B-A3B) and then does
codes.T @ a8. For --proj down the contraction is K = 768 (each expert's SwiGLU width), and down is
the one projection that does not share one A across experts: its input is each expert's own
silu(gate·x) * (up·x). --proj down is in the CLI's choices, so the path is advertised; it dies with a raw
numpy shape error after the full forward has already run:

File "tools/moe_expert_chunks.py", line 299, in gate
    exact = codes.astype(np.int32).T @ a8.astype(np.int32)      # [N]
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0,
            (size 2048 is different from 768)

So the one gate artifact the docs name for a decode layer (docs/npu.md, "Routed expert stacks" — down is
the projection whose A cannot be shared) cannot be produced by the tool that is supposed to produce it, and a
run wastes the whole forward (minutes on this model) before failing.

Reproducer (2026-11-05 05:4x AST, origin/main bd7d451a):

python3 tools/moe_expert_chunks.py gate ~/models/npu/qwen3-coder-30b-a3b-moe /tmp/g \
    --prompt "." --layer 0 --proj down --experts 8

Fix in the PR that references this: per-expert A (and per-expert ascale, since a different row has a different
maximum), plus the M=16 A matrix the chunk-list dispatch actually takes with expert j's row in row j
(docs/npu.md: "A chunk-list dispatch shares ONE A across its chunks"). The existing gate/up artifact is
unchanged — checked field by field against the frozen oracle ~/evidence/tmoe-npu/gate-L0-gate_proj-pad1024.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions