Repository navigation
Description
Summary
Report the small-axis CUDA RMSNorm regression to upstream ml-explore/mlx and track dropping the local rms_norm.cu overlay once upstream fixes it. This is the follow-up noted in #829 (which fixed #824 by overlaying the pre-regression kernel while keeping the MLX pin at the latest commit).
The upstream problem
MLX #3792 ("Fix CUDA RMSNorm small-row dispatch", commit a5a684d, first shipped in the 0.32.1 pin) regressed the small-axis CUDA RMSNorm. For the dispatch config dispatch_group_dim selects when axis_size falls in the (n_per_thread*32, n_per_thread*32*2] band (with N_READS == 8 for half-precision, that band is (256, 512]), #3792 changed groups_per_block from 2 to 1 with block_dim == n_groups*group_dim == 64 (a multi-warp block). The result is a numerically-wrong normalizer for that config.
DeepSeek-V2's MLA kv_a_layernorm normalizes over kv_lora_rank == 512, which lands exactly on that band, so DeepSeek-V2 text generation degenerated into repeated tokens on CUDA. Models whose RMSNorm axis is larger (qwen3 hidden_size 1024+, etc.) take a different dispatch path and are unaffected. compute-sanitizer initcheck and memcheck are both clean, so it is a numerical kernel error, not a memory-safety bug. The later #3850 rewrite ("RMSNorm forward speed up") kept the same axis broken (with a different, alignment-dependent symptom).
Pinned by a deterministic bisect on our side: 1700b39 (the commit before #3792) is coherent, a5a684d (#3792) is garbage, using an MLX_DISABLE_COMPILE=1 MLX_USE_CUDA_GRAPHS=0 probe to remove the graph-capture nondeterminism that masked the determinism.
What to file upstream
An issue (and ideally a minimal repro + fix) on ml-explore/mlx: CUDA RMSNorm produces incorrect output for axis_size in the small multi-warp dispatch band (e.g. 512 with fp16, block_dim == 64), regressed by #3792 and still wrong after the #3850 rewrite. Include the dispatch config, the deepseek-v2-lite repro, and the bisect boundary.
Definition of done
- Upstream issue/PR filed on ml-explore/mlx and linked here.
- When an upstream fix lands and mlxcel bumps its MLX pin past it, delete the
src/lib/mlx-cpp/patches/mlx/backend/cuda/rms_norm.cuoverlay (added in fix(cuda): restore DeepSeek-V2 output by reverting the regressed RMSNorm kernel #829) and re-verify deepseek-v2-lite stays coherent with the upstream fast kernel, restoring the #3850 speedup. The overlay header comment already flags this.
Refs
Follow-up to #824 / #829. Sibling to #821 (the analogous upstream tracking for the CUDA graph-cache abort).
Activity
inureyes commentedon Aug 5, 2026
Do not file this upstream. Verifying the attribution against real MLX source inverted it, so #1033 lands a corrected report instead of an upstream bug report.
Measured on GB10 with the three kernel bodies copied verbatim from
1700b39(the direct parent of #3792),a5a684d(#3792) andb7c3dd6d(#3850, which is the actual pin, not0.32.1), each launched with its own commit's dispatch configuration and diffed against a per-row float64 reference:a5a684dand the pinned kernel are correct at every axis from 8 to 8192 for row counts 1 to 17.patches/mlx/backend/cuda/rms_norm.cu, is wrong at all 34 swept axis sizes in[257, 512]with 16-bit activations, andcompute-sanitizermemcheck flags an out-of-bounds__shared__read for its launch geometry only.At that band the pre-#3792 dispatch pairs
block_dim == 64withgroups_per_block == 2, so a 128-thread block runs a reduction whose shared scratch is sized for 64 threads:TempStorageholds 2 floats whilemeta_group_size()is 4. It indexes past the end and folds in the other row's partials. At one row the exiting threads never write their partials, so the normalizer picks up residual shared memory (seeding that window with 0 / 1 / 100 / 10000 gives 99.99% / 92.79% / 24.19% / 2.49% of the reference). #3792 changed that value to 1 and added astatic_assertpinning the invariant.The band, the config, the changed value and DeepSeek-V2's
kv_lora_rank == 512landing on it were all correct in this issue. Only the direction was backwards.Open thread: #829's 0/4 to 4/4 deepseek-v2-lite result is not reconciled by these measurements, and settling it needs a build with the overlay removed. #1033 changes no runtime behavior and records that explicitly rather than acting on it.
docs(upstream): correct the CUDA RMSNorm small-axis attribution (#1033)
chore(deps): bump the MLX pin to 2c46b953 and re-derive three overlays (
docs(upstream): correct the CUDA RMSNorm small-axis attribution (labl…
chore(deps): bump the MLX pin to 2c46b953 and re-derive three overlays (