Repository navigation
Description
Problem / Background
Four lib tests fail on a local Metal run (Mac Studio, Apple M3 Ultra, 512 GB, rustc 1.97.1) with make verify-test, i.e. cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1:
vision::dense::sam3::linear::tests::biased_bf16_projection_matches_mlx_addmm_rounding(src/vision/dense/sam3/linear.rs:76)vision::dense::sam3d_body::layers::tests::sam3d_body_linear_preserves_bf16_and_authentic_addmm_rounding(src/vision/dense/sam3d_body/layers_tests.rs:17)vision::dense::sapiens2::weights::tests::sapiens2_bf16_linear_uses_fused_bias_epilogue(src/vision/dense/sapiens2/weights.rs:239)vision::encoders::dinov2_layers::policy::tests::objects_dino_linear_matches_authentic_bf16_addmm_oracle(src/vision/encoders/dinov2_policy_tests.rs:66)
They fail in isolation too (cargo test -p mlxcel --lib --profile test-fast --features metal,accelerate -- --test-threads=1 <name>), so this is not test ordering. It is pre-existing: the same four tests fail identically at 8d3e16ad (main before PRs #2904..#2913). GitHub CI does not catch it because there is no Metal test job, and CI on 897852de was green.
Current Behavior
Every failure is the single-row assertion (for example src/vision/dense/sam3/linear.rs:118): left (actual) [1.296875, -0.50390625, 1.9296875], right (expected) [1.296875, -0.50390625, 1.9375]. The actual value is the fused (single rounding) result. The tests expect the separate-add (double rounding) result because single_row_addmm_rounds_twice() in src/vision/addmm_oracle_test_support.rs:51 returns true for any Metal GPU default device. The two-row ROUTING_ROWS assertions pass.
The module doc in src/vision/addmm_oracle_test_support.rs (lines 18-27) says Metal routes min(M, N) == 1 to gemv_axbpy, which casts the F32 accumulator to the output type before adding the bias, and records that behaviour as observed with upstream mlx 0.32.4 on an Apple M1 Ultra (from #2631). On this M3 Ultra, the single-row result is fused instead.
Proposed Solution
Candidate causes, all unconfirmed:
- The MLX pin bump to
9f806b36(PR update: advance MLX pin to 9f806b36 and refresh backend overlays #2876, 2026-11-07) changed which kernel a single-row BF16 addmm selects, or changed the gemv epilogue. - A mlxcel Metal overlay (for example the
MLXCEL_QMV_WIDEor gemv changes) routes the single-row case differently. - The kernel choice differs by Apple GPU generation (M3 vs M1).
Determine which applies, then either re-key single_row_addmm_rounds_twice() (and its docs) to the real routing, or fix the routing if a vision layer now rounds differently from upstream mlx.nn.Linear at one row.
Acceptance Criteria
- Identify which Metal kernel a 1x4 @ 4x3 BF16
addmmwith bias selects on the current MLX pin on M3 Ultra, and whether it rounds once or twice, with evidence (kernel name, upstream mlx Python comparison on the same host). - If the kernel choice changed (pin or overlay), decide whether that change is intended. If it is, update
single_row_addmm_rounds_twice()and its docs so the key reflects the actual routing (per pin or per GPU generation), never a blanket expectation flip. - If the change is unintended (a vision layer now rounds differently from upstream
mlx.nn.Linearat one row), fix the routing instead. - The four tests pass under
make verify-teston M3 Ultra; record which hosts were checked.
Activity
fix(vision): expect fused bf16 addmm at one row on Metal (lablup#2927)