Fix conv_transpose maxBufferLength failures on Metal via tiled unfold#3845
Open
eyupcanakman wants to merge 1 commit into
Open
Fix conv_transpose maxBufferLength failures on Metal via tiled unfold#3845eyupcanakman wants to merge 1 commit into
eyupcanakman wants to merge 1 commit into
Conversation
conv_transpose on Metal allocated one full unfold buffer that could exceed the device maxBufferLength for large outputs. Unfold and run the GEMM in row tiles reusing a single buffer, so peak memory stays at one tile (ml-explore#3082).
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.
Proposed changes
conv_transpose1d/2d/3d(andconv_generalwithinput_dilation > 1) on Metal go through the explicit GEMM path, which allocates one full unfold buffer ofimplicit_Mbyimplicit_K. For large outputs that buffer exceeds the devicemaxBufferLengthand the allocation throws, even when the output itself fits in memory (#3082).The explicit GEMM now unfolds and runs in row tiles that each stay under
maxBufferLength, reusing a single unfold buffer so peak memory is one tile. Both the grouped and non-grouped paths are covered. The approach follows #3084.MLX_CONV_UNFOLD_TILE_ROWScaps the tile size so the tiled path can be exercised on small inputs, which the added test uses.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes