Repository navigation
Description
Problem
OLMoE aborts at the first decode step on mlx-community/OLMoE-1B-7B-0125-Instruct-4bit:
libc++abi: terminating due to uncaught exception of type std::invalid_argument: [rms_norm] (*weight) must have the same size as the last dimension of x but has 2048 elements.
The model loads, then crashes during generation. OLMoE is effectively non-functional for this checkpoint. This is pre-existing and unrelated to the fused decode-MoE wiring (epic #307); the crash is in the attention QK-norm path, not the MoE path.
Root cause
In src/models/olmoe.rs, Attention::forward reshapes Q/K to [batch, seq_len, n_heads, head_dim] (head_dim = 128 for this model) and then applies q_norm/k_norm to the reshaped tensors (see src/models/olmoe.rs:218-225). But OLMoE's QK-norm weights are full-projection sized (num_heads * head_dim = hidden = 2048), matching the HF OLMoE convention where the RMSNorm is applied to the flattened q/k projection before the head reshape. Applying a 2048-element norm weight to a tensor whose last dim is head_dim (128) is the dimension mismatch that aborts.
Repro
mlxcel download mlx-community/OLMoE-1B-7B-0125-Instruct-4bit
mlxcel generate -m <path> -p "Hello, my name is" -n 20 -t 0 --no-chat-template
Fix
Apply q_norm/k_norm to the flattened projection output ([batch, seq_len, num_heads*head_dim]) BEFORE the head reshape, then reshape. This matches the 2048-element weight and the upstream OLMoE order (norm over the full projection, then split into heads). RoPE and the transpose stay after the reshape as today. Reference: ml-explore/mlx-lm OLMoE attention (q_norm/k_norm precede the head reshape).
Acceptance Criteria
-
q_norm/k_normare applied before the[b, l, heads, head_dim]reshape, on the full projection, so the 2048-element norm weights match. - OLMoE-1B-7B (
mlx-community/OLMoE-1B-7B-0125-Instruct-4bit) loads and generates coherent greedy temp-0 output with no crash and no NaN/garbage. - No regression to other models (the change is confined to
olmoe.rsattention). - Add or extend a test where practical.
Notes
Found while validating epic #307 (#302 wires olmoe to the fused decode-MoE kernel). #302's MoE wiring cannot be runtime-validated until this attention crash is fixed.
Activity
fix(olmoe): score MoE router with full softmax then gather, not top-k…
fix(olmoe): apply q_norm/k_norm before the head reshape (lablup#317)
fix(olmoe): score MoE router with full softmax then gather, not top-k…