Repository navigation
Description
Problem
After the q_norm/k_norm crash fix (#316), OLMoE-1B-7B loads and runs, but its greedy temp-0 output is corrupted/degenerate: it starts plausibly then drifts into non-sequiturs, stray non-Latin tokens, and refusals. Example for mlx-community/OLMoE-1B-7B-0125-Instruct-4bit with the chat template: "What is the capital of France?" yields "Paris, France" (correct) then "...is a city or politician's home to all 3.6K EPILE13 defense"; "List three primary colors." yields "I'm sorry, but I'm unable to explain... protect the document". A healthy OLMoE-1B-7B-Instruct should answer these cleanly. The "starts coherent then degrades" pattern points at a position- or context-dependent defect.
What it is NOT
Not the q_norm/k_norm crash (fixed in #316; verified our order now matches ml-explore/mlx-lm mlx_lm/models/olmoe.py, which applies q_norm/k_norm to the full n_heads*head_dim projection before the head reshape). Not the fused decode-MoE kernel: the corruption is present with MLXCEL_FUSED_MOE=0 (the gather_qmm baseline), and fused-on differs from off only within the documented f16 jitter class. So this is a separate, pre-existing attention/model defect.
Evidence
With MLXCEL_FUSED_MOE=0, output is already corrupted, so the MoE path is not the cause. Short factual prompts produce a correct first clause before degrading, consistent with a RoPE / KV-cache / attention-scale issue rather than a weight-loading error.
Likely areas to investigate
Compare against https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/olmoe.py.
- RoPE configuration in
src/models/olmoe.rsattention:rope_dims,rope_traditional,rope_basevs mlx-lm (rope overhead_dim, traditional=false, base=rope_theta=10000). - Attention scale (
head_dim ** -0.5). - KV-cache offset / masking across decode steps (degradation grows with position).
- norm_topk_prob handling (config sets it false) and router scoring.
Repro
mlxcel download mlx-community/OLMoE-1B-7B-0125-Instruct-4bit
mlxcel generate -m <path> -p "What is the capital of France?" -n 30 -t 0
Acceptance Criteria
- Root-cause the corruption by diffing
src/models/olmoe.rsattention/RoPE/cache against ml-explore/mlx-lmmlx_lm/models/olmoe.py. - OLMoE-1B-7B generates coherent greedy temp-0 output (correct, on-topic answers) with no degeneration over a few hundred tokens.
- Greedy temp-0 stays within the f16 jitter class of mlx-lm for the same prompt where feasible.
- Confirm
MLXCEL_FUSED_MOE=1(fused decode-MoE, wired in perf(moe): wire olmoe to the fused decode-MoE kernel #302) remains within the jitter class of the gather_qmm baseline on the now-healthy model.
Notes
Discovered while validating epic #307 (#302 wired olmoe to the fused decode-MoE kernel). The fused wiring is correct and parity-preserving but perf-neutral for olmoe (top_k=8, Dff 1024); it does not cause this corruption.
Activity
docs(olmoe): note router scoring fix (#318) in M1 Ultra benchmark table
fix(olmoe): score MoE router with full softmax then gather, not top-k…
fix(olmoe): score MoE router with full softmax then gather, not top-k…