Skip to content

Fix gradients through routing indices - #1856

Merged
zcbenz merged 9 commits into
ml-explore:mainfrom
dogukanveziroglu:fix/stop-gradient-routing
Sep 9, 2026
Merged

zcbenz merged 9 commits into
ml-explore:mainfrom
dogukanveziroglu:fix/stop-gradient-routing

Conversation

@dogukanveziroglu

Copy link
Copy Markdown
Contributor

I noticed a few related issues after mlx#3820. This fixes the backpropagation errors by adding mx.stop_gradient to selection indices while preserving gradients through scores and model outputs.

I used ai for the tests.

@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.

The test is over-complicated for such small change, a simple test like the one in #1787 would be preferred but it is not really meaningful adding the same test for all the models. Since this is a trivial change, I think we should just ignore the tests.

@michalk8
michalk8 requested a review from zcbenz September 9, 2026 15:49
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.

3 participants