Skip to content

Fix sharded-to-all bias and integer split positions on quantized layers - #4715

Merged
zcbenz merged 4 commits into
ml-explore:mainfrom
ronaldmannak:bias-quantized-integer
Oct 31, 2026
Merged

zcbenz merged 4 commits into
ml-explore:mainfrom
ronaldmannak:bias-quantized-integer

Conversation

@ronaldmannak

@ronaldmannak ronaldmannak commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR has three fixes:

  • ShardedToAllLinear ranks start with a different random bias, and the bias is added after the sum, resulting in different values being returned. Bias now starts at zeros.
  • Integer split positions on QuantizedShardedToAllLinear can split in wrong places. Fix converts integer positions to exact fractions of the input size, raises ValueError when segment can't be split correctly
  • Same fix for shard_inplace for quantized layers

The first two fixes are already fixed in MLX-Swift. I'll open a separate PR for the third issue on MLX-Swift.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: Issues found and fixed by Opus 5.5 while porting distributed to MLX-Swift. Code reviewed by Codex

@ronaldmannak ronaldmannak changed the title Initialize ShardedToAllLinear bias to zeros and integer split position in QuantizedShardedToAllLinear Fix sharded-to-all bias and integer split positions on quantized layers Oct 17, 2026
@zcbenz zcbenz added low priority await verification This pull request is non-trivial and requires a human expert to verify its correctness. labels Oct 19, 2026
@zcbenz zcbenz removed the await verification This pull request is non-trivial and requires a human expert to verify its correctness. label Oct 29, 2026

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response, can you take a look at the failed cpu tests?

And btw way please consider creating PRs from personal accounts, we are unable to rebase this branch when it is in org account even when you enabled it on GitHub.

@ronaldmannak

Copy link
Copy Markdown
Contributor Author

@zcbenz It only fails on Linux CPU. Linux doesn't use MacOS' Accelerate SIMD kernel and a rounding error seems to push one output just over the tolerance. The sharding itself is exact (checked in float64).

I can change the two new checks to use exactly representable values and compare with array_equal, so they don’t depend on summation order. Or would you rather I just loosen the tolerance for these checks?

Re: personal account, Ronan mentioned that as well yesterday. I can reopen the PR from my personal fork.

@zcbenz

zcbenz commented Oct 29, 2026

Copy link
Copy Markdown
Member

Thanks for looking into it, either fix sounds good to me. We can just use this PR, please do a rebase though.

@ronaldmannak
ronaldmannak force-pushed the bias-quantized-integer branch from 2b8c7ca to cdda3e1 Compare October 29, 2026 15:41
@ronaldmannak

Copy link
Copy Markdown
Contributor Author

@zcbenz done. Verified on macOS but not on Linux.
FYI: changes made by Opus 5.5

@zcbenz zcbenz closed this Oct 31, 2026
@zcbenz zcbenz reopened this Oct 31, 2026
@zcbenz

zcbenz commented Oct 31, 2026

Copy link
Copy Markdown
Member

Can you rebase the PR for CI changes?

ronaldmannak and others added 4 commits October 30, 2026 20:44
Power-of-two scales, offsets in eighths and integer inputs keep every sum exact, so the sharded layers must match bit for bit regardless of summation order. The tolerance-based checks failed on Linux CPU, where the scalar quantized matmul kernel accumulates in a different order than the sharded sum.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ronaldmannak
ronaldmannak force-pushed the bias-quantized-integer branch from cdda3e1 to 5dc07e6 Compare October 31, 2026 03:49
@ronaldmannak

Copy link
Copy Markdown
Contributor Author

@zcbenz done

@zcbenz
zcbenz merged commit 3392795 into ml-explore:main Oct 31, 2026
24 checks passed
rcfa pushed a commit to cubiculum-ai/mlx that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants