Repository navigation
fix(vision): expect fused bf16 addmm at one row on Metal - #2927
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four BF16
addmmoracle tests failed on Metal because they expected a single-row product to round twice. That expectation came from the oldgemv.hepilogue, which cast the F32 accumulator to BF16 before adding the bias. Upstream ml-explore/mlx#4769 ("[Metal] Fix precision loss in addmm", commit49366677, 2026-10-29) adds the bias to the accumulator first in bothGEMVKernelandGEMVTKernel. That commit has been in our MLX pin since #2876 (9f806b36), sogemv_axbpynow rounds once like every other route. The kernel change is intended upstream and no vision layer diverges from upstreammlx.nn.Linear, so no routing change is needed.Evidence (Mac Studio, Apple M3 Ultra)
1x4 @ 4x3 BF16
addmmwith bias, expected fused[1.296875, -0.50390625, 1.9296875], separate add[..., 1.9375]:mlx0.32.4 (PyPI)mlxbuilt at9f806b36mainReleased 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: removesingle_row_addmm_rounds_twice, and rewrite the module doc around the pinned kernels and #4769.ROUTING_ROWSassertions. If a pin change brings the double rounding back, the one-row assertion fails.matmul + addstill gives the separate value at one row.Verification
cargo test -p mlxcel --lib --profile test-fast --features metal,accelerate -- --test-threads=1filtered to them, 4 passed.cargo clippy -p mlxcel --lib --tests --features metal,accelerate -- -D warningsis clean.Fixes #2916