Fix conv_general output offset overflow in Metal writeback#3320
Closed
Aristide021 wants to merge 2 commits intoml-explore:mainfrom
Closed
Fix conv_general output offset overflow in Metal writeback#3320Aristide021 wants to merge 2 commits intoml-explore:mainfrom
Aristide021 wants to merge 2 commits intoml-explore:mainfrom
Conversation
0085a3b to
0b12f2c
Compare
zcbenz
requested changes
Mar 26, 2026
Collaborator
zcbenz
left a comment
There was a problem hiding this comment.
The added test passes without the change.
Contributor
Author
I tried to build the e2e test but found a blocker unrelated to this fix. I've filed a separate issue: #3327. I'm closing this PR for now since I can't meaningfully verify the fix with a reliable regression test. Once #3327 is resolved, this can be revisited with proper coverage. |
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.
Fixes incorrect output writes in Metal
conv_generalwhen output offsets exceed signed 32-bit range.Root cause
In Metal steel conv writeback paths, output pointer offset arithmetic used 32-bit
intintermediates. For large outputs, this can overflow and corrupt writes.What this changes
size_t) in:mlx/backend/metal/kernels/steel/conv/kernels/steel_conv.hmlx/backend/metal/kernels/steel/conv/kernels/steel_conv_general.hTests
tests/ops_tests.cpp:test conv2d output offset uses 64-bit arithmeticint32maxValidation run
cmake --build build --target mlx-metallibcmake --build build --target testsbuild/tests/tests --test-case "test conv2d output offset uses 64-bit arithmetic"conv_generalvs matmul) now pass for cases above2^31Closes #3248.