Repository navigation
Description
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) forrms_normandlayer_normreturn an emptydxand zerodw/dbwithout a HIP error; fails on main. - A row count above
INT_MAXeither works or throws the new error, in a documented#[ignore]test like those intests/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 * colsorbatch * rowsexceedsINT_MAXmatches 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_qmmwithM = 0and withN = 0(affine, and nvfp4 where its layout checks accept the shape) returns an empty array; fails or crashes on main.
Common
- New
LOCAL_FIXES.mditem naminglayer_norm.hip,rms_norm.hip,gemms/gemv.hipandquantized/qmm.hip;CORE_RESIDUAL.diffonly if a core file changes.
scripts/rocm_gpu_guard.sh --hold -- make verify-rocm
Activity
fix(rocm): guard empty and 64-bit sizes in norm VJP, gemv, GatherQMM (l…