Repository navigation
Fix floor_divide for integers - #4515
Merged
Merged
Conversation
zcbenz
force-pushed
the
floor_divide
branch
from
September 28, 2026 08:25
423ea6e to
2e383e8
Compare
zcbenz
approved these changes
Sep 28, 2026
dgrauet
added a commit
to dgrauet/mlx-arsenal
that referenced
this pull request
Sep 28, 2026
ml-explore/mlx#4515 makes integer floor_divide floor toward -inf in the next MLX release, which would fail the assertion that it truncates. The right_shift helper stays correct on every version; the docstring now says so. MLX argsort stability is documented since 0.32.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WpxsXyNmLskVHUCzfNu59g
9 tasks done
davidtai
added a commit
to Layr-Labs/mlx
that referenced
this pull request
Oct 1, 2026
The signed-integer CPU Divide computed x / y before it checked y != 0. C++ does not define integer division by 0, so the compiler could remove the check. It also always computed q - 1, which overflows for min // 1. Now the functor divides by 1 where y == 0 or where min is divided by -1, returns 0 for x // 0 and min for min // -1 (the values arm64 gave before), and subtracts 1 only in the lanes that need it. Add tests with 40 elements, so the 16-lane int8 and int16 SIMD path runs, and CPU tests for x // 0 and min // -1. State the upstream ml-explore#4515 risk, the CUDA functor and the mlx-swift generated copies in fork.yaml. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 6, 2026
ronaldmannak
added a commit
to PicoMLX/mlx-swift
that referenced
this pull request
Oct 16, 2026
In MLX v0.32.3, integer floor_divide (ml-explore/mlx#4515) built its logical_and on the calling thread's own default stream. When the result was evaluated on any other thread, the process stopped with "There is no Stream(gpu, N) in current thread". mlx-swift-lm's MoE gather sort calls floorDivide on integer indices and evaluates on its generation thread, so every MoE generation in PicoCore crashed. The mlx submodule now points at PicoMLX/mlx pico/0.32.3: v0.32.3 plus the one-line fix that passes the stream through. CMake fetches the same commit. v0.32.4 replaces this code with a FloorDivide primitive (ml-explore/mlx#4642). StreamTests.testIntegerFloorDivideEvaluatesOnAnotherThread builds an integer floorDivide on one thread and reads it on another. Without the fix it stops the process with that error. Co-Authored-By: Claude Opus 5.5 <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.
Fixes [BUG] Inconsistent behaviour of the floot_divide integer arrays truncates towards 0 #4450 , making quotient for integer division floor towards -inf
None