Repository navigation
Conversation
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.
Summary
Fixes a Metal debug validation crash in
Gather::eval_gpuwhen gather/take uses scalar indices.Gatheralready has a scalar-index specialization (idx_ndim == 0), but the Metal encoder still receives empty index metadata vectors:With Metal API validation enabled, an empty vector reaches
setBytes:length:attributeStride:atIndex:as a nil bytes argument and aborts.Evidence
Observed downstream crash:
The abort was isolated to this line in
mlx/backend/metal/indexing.cpp:compute_encoder.set_vector_bytes(idx_shapes, 7);The same file already handles this exact Metal binding edge case in
Scatter::eval_gpuby pushing dummy metadata whenidx_ndim == 0:This PR applies the same guard to
Gather::eval_gpu.idx_ndimremains0, so the scalar-index specialization behavior does not change; the patch only ensures Metal receives non-nil metadata buffers.Existing public API coverage already includes scalar-index take:
Validation
Ran locally:
Downstream validation after applying the same patch in a SwiftPM MLX checkout:
Those builds passed and no longer hit the Metal nil-buffer assertion.