Skip to content

fix(vision): expect fused bf16 addmm at one row on Metal - #2927

Merged
inureyes merged 1 commit into
mainfrom
fix/issue-2916-bf16-addmm-oracle
Nov 10, 2026
Merged

inureyes merged 1 commit into
mainfrom
fix/issue-2916-bf16-addmm-oracle

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Four BF16 addmm oracle tests failed on Metal because they expected a single-row product to round twice. That expectation came from the old gemv.h epilogue, which cast the F32 accumulator to BF16 before adding the bias. Upstream ml-explore/mlx#4769 ("[Metal] Fix precision loss in addmm", commit 49366677, 2026-10-29) adds the bias to the accumulator first in both GEMVKernel and GEMVTKernel. That commit has been in our MLX pin since #2876 (9f806b36), so gemv_axbpy now rounds once like every other route. The kernel change is intended upstream and no vision layer diverges from upstream mlx.nn.Linear, so no routing change is needed.

Evidence (Mac Studio, Apple M3 Ultra)

1x4 @ 4x3 BF16 addmm with bias, expected fused [1.296875, -0.50390625, 1.9296875], separate add [..., 1.9375]:

MLX GPU, 1 row GPU, 2 rows CPU, 1 and 2 rows
released mlx 0.32.4 (PyPI) separate fused fused
upstream mlx built at 9f806b36 fused fused fused
mlxcel at main fused fused fused

Released 0.32.4 shows the old split on M3 Ultra too, so the change comes from the pin, not from the GPU generation.

Changes

  • src/vision/addmm_oracle_test_support.rs: remove single_row_addmm_rounds_twice, and rewrite the module doc around the pinned kernels and #4769.
  • The four oracles (sam3, sam3d_body, sapiens2, dinov2) assert the fused value at one row on every backend and keep the ROUTING_ROWS assertions. If a pin change brings the double rounding back, the one-row assertion fails.
  • The Sapiens2 oracle also asserts that plain matmul + add still gives the separate value at one row.

Verification

  • The four tests pass on M3 Ultra: cargo test -p mlxcel --lib --profile test-fast --features metal,accelerate -- --test-threads=1 filtered to them, 4 passed.
  • cargo clippy -p mlxcel --lib --tests --features metal,accelerate -- -D warnings is clean.
  • Hosts checked: M3 Ultra only. M1 Ultra, CUDA and ROCm were not run. CPU, ROCm and CUDA already expected the fused value, and the one-row assertion now expects the same value everywhere.

Fixes #2916

The four BF16 addmm oracle tests expected the double-rounded value for a single-row product on Metal, because the gemv epilogue used to cast the F32 accumulator to BF16 before adding the bias. Upstream ml-explore/mlx#4769 (commit 49366677), in the MLX pin since #2876, adds the bias to the accumulator first, so gemv_axbpy now rounds once like every other route.

On the M3 Ultra, released mlx 0.32.4 still gives the separate value at one row on the GPU, while upstream mlx built at the pin (9f806b36) gives the fused value at one and two rows on GPU and CPU, matching mlxcel. Remove single_row_addmm_rounds_twice, assert the fused value at one row in all four oracles, keep the two-row assertions, and rewrite the support module doc around the pinned kernels. The Sapiens2 oracle also checks that a plain matmul plus add still rounds twice at one row.

Fixes #2916
@inureyes inureyes added the type:bug Bug fixes, error corrections, or issue resolutions label Nov 10, 2026
@inureyes
inureyes merged commit ddd4a61 into main Nov 10, 2026
31 checks passed
@inureyes
inureyes deleted the fix/issue-2916-bf16-addmm-oracle branch November 10, 2026 04:35
@inureyes inureyes added status:done Completed priority:medium Medium priority platform:macos macOS (Apple Silicon) specific labels Nov 30, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform:macos macOS (Apple Silicon) specific priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(vision): BF16 single-row addmm oracles fail on M3 Ultra Metal

1 participant