Skip to content

MLX inference test stub: accept any arguments a zoo helper is called with - #12700

Merged
danielhanchen merged 1 commit into
mainfrom
ci/mlx-stub-any-arity
Oct 4, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/mlx-stub-any-arity

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

MLX CI on Mac M1 fails on PRs based on current main (seen on #12699):

FAILED tests/test_mlx_inference_backend.py::test_a_vision_reply_stopped_partway_reports_the_tokens_it_actually_used
  - TypeError: nullcontext.__init__() takes from 1 to 2 positional arguments but 3 were given
unsloth_zoo/mlx/generate.py:961: in generation_mode

unsloth-zoo #1546 (merged 10:27 UTC today) changed generation_mode to enter nax_quantized_linear(model, int8_prefill). The zoo call is correct; this is a new argument on a zoo helper. The Studio test stub, _neutral_zoo_helper from #12548, answered every unknown unsloth_zoo.mlx.inference helper with contextlib.nullcontext, and that takes one argument, so the stub broke on the second one.

Fix

tests/test_mlx_inference_backend.py only:

  • _neutral_scope(model=None, *args, **kwargs) returns nullcontext(model). The stub hands it out for unknown helpers and for the explicit fused_* names, so a scope still yields the model and an added argument is ignored. Deleted fusions still raise ImportError as before.
  • test_every_stub_scope_takes_any_arguments_and_yields_the_model calls every stub scope with no arguments, (model), (model, flag) and (model, int8_prefill=...).
  • test_the_stub_accepts_every_call_zoo_makes_to_an_inference_helper parses zoo's mlx/*.py, finds each call to a helper zoo imports from mlx.inference, and replays the same positional and keyword shape against the stub. The next argument zoo adds then fails on the Linux backend job too, not only on the Mac job.

Verification

  • Against zoo main (573813f), the new tests pass. With the stub reverted to nullcontext they fail in 3 cases, including the zoo-call replay that hits nax_quantized_linear(model, int8_prefill).
  • The whole file passes on Linux: 280 passed, 113 skipped. The skips are Metal-only.
  • The Metal test that failed in CI cannot run here; staging CI's Mac M1 job covers it.

…with

unsloth_zoo #1546 calls nax_quantized_linear(model, int8_prefill) inside
generation_mode. The stub answered unknown helpers with contextlib.nullcontext,
which takes one argument, so every real-model vision batch test on the Mac
MLX job raised TypeError in nullcontext.__init__.

The stub now hands out a scope that accepts any arguments and yields the
model, for the fused_* names too. Two new tests pin it: one calls every stub
scope with the shapes zoo uses, and one reads zoo's own calls to its
mlx.inference helpers and replays each one's arguments against the stub, so
the next added argument fails on Linux as well.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T19:13:38.508438Z 4279b13 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 4279b13277

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 4, 2026
@danielhanchen
danielhanchen merged commit 2d5863c into main Oct 4, 2026
@danielhanchen
danielhanchen deleted the ci/mlx-stub-any-arity branch October 4, 2026 20:10
danielhanchen added a commit that referenced this pull request Oct 6, 2026
…#12783)

* MLX backend tests: answer zoo's _fusion_modules in the inference stub

unsloth_zoo #1565 made mlx/generate.py import _fusion_modules from mlx.inference
and call tuple(_fusion_modules(model, None)). The stub refuses private names, so the
guard added in #12700 failed on Linux (the stub cannot answer _fusion_modules) and
every macOS vision test raised ImportError in the dispatch job (#12778).

It is a plain function, not a scope, so the stub carries zoo's three-line body in
PLAIN_HELPERS, the call-shape replay calls it instead of entering it, and a new test
fails if the copy drifts from zoo's body.

* MLX stub body check: drop only a leading docstring before comparing

Filtering every ast.Expr also hid bare calls, so zoo adding a log line or other
call to _fusion_modules would have passed. Only a leading string literal is
ignored now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant