Skip to content

chore(deps): report the CUDA RMSNorm small-axis regression upstream and drop the local overlay once fixed #830

Closed

Description

@inureyes

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.cu overlay (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

  1. added
    type:dependency
    priority:low
    area:inference
    status:backlog
    on Jul 20, 2026
  2. added
    status:in-progress
    status:done
    and removed
    status:backlog
    status:in-progress
    on Aug 5, 2026
  3. inureyes commented on Aug 5, 2026

    @inureyes
    MemberAuthor

    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) and b7c3dd6d (#3850, which is the actual pin, not 0.32.1), each launched with its own commit's dispatch configuration and diffed against a per-row float64 reference:

    • a5a684d and the pinned kernel are correct at every axis from 8 to 8192 for row counts 1 to 17.
    • The pre-#3792 kernel, which this repo ships as patches/mlx/backend/cuda/rms_norm.cu, is wrong at all 34 swept axis sizes in [257, 512] with 16-bit activations, and compute-sanitizer memcheck flags an out-of-bounds __shared__ read for its launch geometry only.

    At that band the pre-#3792 dispatch pairs block_dim == 64 with groups_per_block == 2, so a 128-thread block runs a reduction whose shared scratch is sized for 64 threads: TempStorage holds 2 floats while meta_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 a static_assert pinning the invariant.

    The band, the config, the changed value and DeepSeek-V2's kv_lora_rank == 512 landing 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.

  4. self-assigned this
    on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencepriority:lowstatus:donetype:dependency

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions