Skip to content

fix: Guard empty and 64-bit sizes in ROCm norm VJP, gemv, GatherQMM #2633

Closed

Description

@inureyes

Problem

Three ROCm overlay launch paths (under src/lib/mlxcelverse/overlays/rocm/mlx/backend/rocm/) narrow 64-bit sizes to int or divide before an empty-output check. Implement all three in one PR with one verification pass at the end and as few pushes as possible.

(a) Norm VJP row count and empty input

layer_norm.hip:409-410 and rms_norm.hip:395-396 shape gw_temp as {static_cast<int>(n_rows), ...}, and the gw ReductionPlan narrows n_rows the same way (layer_norm.hip:509, rms_norm.hip:484), though n_rows is int64_t since #2627. Separately, row_grid(0, ...) (layer_norm.hip:266-269, rms_norm.hip:243-246) returns dim3(1, 0, 1), an invalid launch; no forward or VJP path checks for zero rows. Fix: return early when n_rows == 0 in both forward and VJP of both files, after allocating outputs and filling gw and gb with zeros (the sum over zero rows), and pass n_rows without the int cast where the shape and plan types allow, otherwise throw a clear error above INT_MAX.

  • Zero-row forward and VJP (all wrt) for rms_norm and layer_norm return an empty dx and zero dw/db without a HIP error; fails on main.
  • A row count above INT_MAX either works or throws the new error, in a documented #[ignore] test like those in tests/rocm_hip_grid_clamp/row_grid.rs.

(b) gemv offsets

gemms/gemv.hip:96 computes mat + row * cols and :154, :179 compute out + batch_idx * rows, all in int. Widen to int64_t as #2624 did for the gather paths.

  • A gemv or batched gemv whose rows * cols or batch * rows exceeds INT_MAX matches a host reference, as a documented #[ignore] test if it exceeds the default memory budget; fails on main.

(c) GatherQMM empty output

quantized/qmm.hip:6230 computes B = out.size() / M / N before the only out.size() == 0 check (:6256, inside the nvfp4 branch), so M == 0 or N == 0 divides by zero. Move if (out.size() == 0) return; above that line, after the set_input_array/set_output_array calls, covering every mode.

  • gather_qmm with M = 0 and with N = 0 (affine, and nvfp4 where its layout checks accept the shape) returns an empty array; fails or crashes on main.

Common

  • New LOCAL_FIXES.md item naming layer_norm.hip, rms_norm.hip, gemms/gemv.hip and quantized/qmm.hip; CORE_RESIDUAL.diff only if a core file changes.
scripts/rocm_gpu_guard.sh --hold -- make verify-rocm

Activity

  1. added
    status:ready
    type:bug
    priority:medium
    platform:linux
    status:in-progress
    status:review
    status:done
    and removed
    status:ready
    status:in-progress
    status:review
    on Oct 26, 2026
  2. added a commit that references this issue on Nov 3, 2026
    5610f8f
  3. added this to the 0.8 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform:linuxpriority:mediumstatus:donetype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions