Skip to content

[staging CI] unslothai/unsloth_zoo#1128 - #181

Closed
danielhanchen wants to merge 7 commits into
mainfrom
pr-1128-ci
Closed

danielhanchen wants to merge 7 commits into
mainfrom
pr-1128-ci

Conversation

@danielhanchen

Copy link
Copy Markdown
Owner

Disposable CI run for unslothai#1128. Do not merge; closed after CI.

Lyxot and others added 2 commits August 28, 2026 17:42
…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.
@danielhanchen danielhanchen added the mlx Run MLX Apple Silicon CI label Sep 1, 2026
danielhanchen 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.
@danielhanchen
danielhanchen deleted the pr-1128-ci branch September 1, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlx Run MLX Apple Silicon CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants