Repository navigation
[staging CI] unslothai/unsloth_zoo#1128 - #181
Closed
danielhanchen wants to merge 7 commits into
Closed
danielhanchen wants to merge 7 commits into
danielhanchen wants to merge 7 commits into
Conversation
…n burst `_generation_cache_hygiene` cleared MLX's buffer pool on entry and again in its `finally` without first draining submitted GPU work. mlx-lm's batched generation submits the next step with `mx.async_eval` before yielding, and the stop-string scanner breaks out of that loop early, so a clear can run while command buffers are still in flight. MLX keeps buffers that an in-flight command buffer reads alive through that command buffer's completion handler, but it does not pin an output array dropped mid-flight. Draining first keeps the release independent of that. `mx.synchronize()` costs ~33us and runs twice per burst, never per token. The warning raised when cleanup fails while an exception is active now names both calls, since the `try` covers the synchronize as well.
added 5 commits
September 1, 2026 07:14
test_missing_clear_cache_is_rejected_before_any_work failed on every
non-Apple host. monkeypatch.delattr("mlx.core.clear_cache") does not make
the attribute missing under tests/mlx_simulation: the shim synthesises a
trampoline for any name it does not implement, so getattr() still returns
something callable, the "clear_cache missing" guard never fires, and the
shim raises its own not-implemented error instead.
Measured on this branch: tests/test_mlx_generate.py is 51 passed at the
merge base and 2 failed, 54 passed at the head, both failures being the
new parametrized case. The file only executes on the mlx-labelled macOS
job, so upstream CI never showed it, but the command this PR gives as its
own validation step reproduces it directly on Linux.
Setting the attribute to None is what the guard actually tests for, and it
reads the same on real MLX and on the shim.
…ve stream The drain sat in front of both clears with nothing catching it, and the entry one is outside every try, so anything it raised cancelled the entry clear_cache() that always ran before and killed the generation burst with it. That is a worse failure than the one the drain guards against: not draining is the behaviour we had until this branch, and no fault was ever reproduced against it. The calls can genuinely fail. mlx made command encoders thread local in 0.31.2 (ml-explore/mlx#3348), and at the mlx-vlm pin floor 0.4.4 generation_stream is still a plain mx.new_stream (mlx_vlm/generate.py:240), so synchronizing it from a thread that did not create it raises "There is no Stream(gpu, N) in current thread". A module-level __getattr__ can raise too; getattr's default only swallows AttributeError. Two other corrections found while checking the candidate list against the supported range: mlx_vlm/speculative/common.py:6 has owned a second generation_stream since 0.6.0, created on import and never routed through wired_limit, so nothing drained it. It cannot go in _VLM_STREAM_MODULES, which resolves wired_limit, so the drain now builds its own list. That list is a function because _VLM_STREAM_MODULES is defined further down the module. 0.6.x defines the stream once in mlx_vlm/generate/common.py and re-exports it from all three candidate names, so the drain was synchronizing one object three times. Dedupe on identity. Also drop the falsey-stream branch in the test recorder: it labelled a falsey stream "default", which made an over-drain of the default stream indistinguishable from a real hit. Five tests added, each mutation checked: removing the per-stream try, the identity dedupe, the speculative module, or the try around getattr fails exactly the test that covers it.
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.
Disposable CI run for unslothai#1128. Do not merge; closed after CI.