Skip to content

Fix floor_divide for integers - #4515

Merged
zcbenz merged 2 commits into
ml-explore:mainfrom
aaishwarymishra:floor_divide
Sep 28, 2026
Merged

zcbenz merged 2 commits into
ml-explore:mainfrom
aaishwarymishra:floor_divide

Conversation

@aaishwarymishra

@aaishwarymishra aaishwarymishra commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

@zcbenz zcbenz changed the title fix floor_divide Fix floor_divide for integers Sep 28, 2026
@zcbenz
zcbenz merged commit 0a8e18e into ml-explore:main Sep 28, 2026
29 checks passed
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
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>
@aaishwarymishra
aaishwarymishra deleted the floor_divide branch October 6, 2026 07:10
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Inconsistent behaviour of the floot_divide integer arrays truncates towards 0

3 participants