Skip to content

fix(olmoe): apply q_norm/k_norm before the head reshape - #317

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-316-olmoe-qk-norm
Jun 16, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-316-olmoe-qk-norm

Conversation

@inureyes

Copy link
Copy Markdown
Member

OLMoE normalizes Q/K over the full num_heads*head_dim projection (the q_norm/k_norm weights are hidden-sized, 2048 for OLMoE-1B-7B), matching the upstream order where the RMSNorm runs on the q_proj/k_proj output before the head split. The code applied the norm after reshaping to [batch, seq_len, heads, head_dim], so rms_norm received a 2048-element weight against a head_dim-wide (128) last dimension and aborted with std::invalid_argument; OLMoE-1B-7B was non-functional as a result. This moves q_norm/k_norm ahead of the head reshape. Validated on mlx-community/OLMoE-1B-7B-0125-Instruct-4bit: loads and generates coherent greedy temp-0 output (e.g. "What is the capital of France? Paris, France.") with no crash. The change is confined to olmoe.rs attention; no other model is affected. Found while validating epic #307 (#302 wires olmoe to the fused decode-MoE kernel, which could not be runtime-validated until this crash was fixed). Closes #316

OLMoE normalizes Q/K over the full num_heads*head_dim projection (the q_norm/k_norm weights are hidden-sized, 2048 for OLMoE-1B-7B), matching the upstream order where the RMSNorm runs on the q_proj/k_proj output before splitting into heads. The code applied the norm after reshaping to [batch, seq_len, heads, head_dim], so rms_norm received a 2048-element weight against a head_dim-wide (128) last dimension and aborted with std::invalid_argument. OLMoE-1B-7B was non-functional as a result.

Move q_norm/k_norm ahead of the head reshape. Validated on mlx-community/OLMoE-1B-7B-0125-Instruct-4bit: loads and generates coherent greedy temp-0 output with no crash. The change is confined to olmoe.rs attention.

Closes #316
@inureyes inureyes added type:bug Bug fixes, error corrections, or issue resolutions priority:high High priority area:models Model architectures, weights, loading, metadata platform:macos macOS (Apple Silicon) specific status:done Completed labels Jun 16, 2026
@inureyes
inureyes merged commit 6d56776 into main Jun 16, 2026
5 checks passed
@inureyes
inureyes deleted the fix/issue-316-olmoe-qk-norm branch June 16, 2026 14:20
@inureyes inureyes added this to the 0.3 milestone Jun 21, 2026
@inureyes inureyes self-assigned this Aug 31, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
OLMoE normalizes Q/K over the full num_heads*head_dim projection (the q_norm/k_norm weights are hidden-sized, 2048 for OLMoE-1B-7B), matching the upstream order where the RMSNorm runs on the q_proj/k_proj output before splitting into heads. The code applied the norm after reshaping to [batch, seq_len, heads, head_dim], so rms_norm received a 2048-element weight against a head_dim-wide (128) last dimension and aborted with std::invalid_argument. OLMoE-1B-7B was non-functional as a result.

Move q_norm/k_norm ahead of the head reshape. Validated on mlx-community/OLMoE-1B-7B-0125-Instruct-4bit: loads and generates coherent greedy temp-0 output with no crash. The change is confined to olmoe.rs attention.

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

Labels

area:models Model architectures, weights, loading, metadata platform:macos macOS (Apple Silicon) specific priority:high High priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(olmoe): q_norm/k_norm applied after head reshape crashes OLMoE-1B-7B (rms_norm dim mismatch)

1 participant