Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix distributed all_to_sharded bias shard axis from -2 to -1#2987

Merged
awni merged 2 commits intoml-explore:mainfrom
gufengc:patch-1
Jan 17, 2026
Merged

fix distributed all_to_sharded bias shard axis from -2 to -1#2987
awni merged 2 commits intoml-explore:mainfrom
gufengc:patch-1

Conversation

@gufengc
Copy link
Contributor

@gufengc gufengc commented Jan 12, 2026

Proposed changes

Please include a description of the problem or feature this PR is addressing. If there is a corresponding issue, include the issue #.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)


def _shard_fn(path, weight):
if path.endswith("bias"):
return -1, segments
Copy link
Member

Choose a reason for hiding this comment

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

The axis will be 0 max(1 - 2, 0) = 0 which is the same as -1 for the bias since it's 1D.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, thank you for review. The broken test case is I am tring add gpt-oss tensor parallelism on mlx-lm.
See ml-explore/mlx-lm#757.

When shard_inplace mlp.experts.gate_proj, the bias shape is 2D due to multi local expert.
Apply this change, I can run mlx-lm pr success.

@awni
Copy link
Member

awni commented Jan 13, 2026

I don't think this fix is doing anything. But if there is a broken test case you observed then please share and we can revisit it.

@awni awni closed this Jan 13, 2026
@awni awni reopened this Jan 16, 2026
Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

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

LGTM

@awni awni merged commit d2bef3c into ml-explore:main Jan 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants