Fix vmap + floor_divide: preserve integer dtype#3292
Merged
zcbenz merged 4 commits intoml-explore:mainfrom Mar 24, 2026
Merged
Conversation
Divide::vmap called divide() which promotes integers to float via at_least_float. But floor_divide creates a Divide primitive with integer dtype for integer division. The vmap of this primitive should preserve integer semantics. Fix: in Divide::vmap, check if inputs are integer type and construct the Divide primitive directly (preserving dtype) instead of calling the high-level divide() which promotes to float. Before: vmap(floor_divide(12, 5)) → 2.4 (float32) After: vmap(floor_divide(12, 5)) → 2 (int32) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zcbenz
requested changes
Mar 22, 2026
Collaborator
zcbenz
left a comment
There was a problem hiding this comment.
I think this would make vmap + divide output wrong dtype for integers? Adding a flag in Divide might be a better solution?
angeloskath
requested changes
Mar 24, 2026
angeloskath
approved these changes
Mar 24, 2026
zcbenz
approved these changes
Mar 24, 2026
robert-johansson
pushed a commit
to robert-johansson/genmlx
that referenced
this pull request
Mar 27, 2026
node-mlx now pins mlx at origin/main which contains latest upstream (0ff1115a) + 6 GenMLX-only patches. The vmap/floor_divide fix was dropped (merged upstream as ml-explore/mlx#3292). git submodule update --init --recursive now works without needing to know about any special branches. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Divide::vmapcallsdivide(a, b)which promotes integers to float viaat_least_float. Butfloor_dividecreates aDivideprimitive with integer dtype for integer division. Under vmap, the integer dtype is lost.Before:
After:
Fix
In
Divide::vmap, check if inputs are integer type and construct theDivideprimitive directly (preserving dtype) instead of calling the high-leveldivide()which promotes to float.Test plan
test vmap floor_divide integerwith 3 sub-tests:floor_dividepreserves int32 dtype under vmapremainderpreserves int32 dtype under vmapfloor_divide + remainderreconstructs original values under vmap