Skip to content

MLX backend tests: answer zoo's _fusion_modules in the inference stub - #12783

Merged
danielhanchen merged 2 commits into
mainfrom
ci-mlx-stub-fusion-modules
Oct 6, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ci-mlx-stub-fusion-modules

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The macOS MLX dispatch job fails on #12778 and on any PR running it against current zoo main:

FAILED tests/test_mlx_inference_backend.py::test_a_vision_reply_stopped_partway_reports_the_tokens_it_actually_used
  ImportError: cannot import name '_fusion_modules' from 'unsloth_zoo.mlx.inference' (unknown location)
E   AssertionError: zoo imports ['_fusion_modules'] from mlx.inference and the stub cannot answer them

The second line is the guard #12700 added, which caught this on Linux too.

Cause

unslothai/unsloth-zoo#1565 (reuse module discovery across generation fusion scopes) made mlx/generate.py import _fusion_modules from mlx.inference and call tuple(_fusion_modules(model, None)). That is correct in zoo. The test file replaces unsloth_zoo.mlx.inference with a stub whose __getattr__ answers public helpers with a neutral scope and refuses private names, so the real generate.py cannot import it. _fusion_modules is also not a scope but a plain function that returns modules, so the neutral scope would be the wrong stand-in even if it were allowed.

Change

  • PLAIN_HELPERS = {"_fusion_modules": ...} carries zoo's three-line body, and the stub sets each one explicitly. Private names stay refused otherwise.
  • The call-shape replay (test_the_stub_accepts_every_call_zoo_makes_to_an_inference_helper) calls a plain helper with the call's argument shape instead of entering it as a context manager.
  • New test_each_plain_helper_stub_matches_zoos_body compares the stub's body to zoo's by AST, so the copy cannot silently drift.

Verification

  • With zoo main ce57159 on the path, test_mlx_inference_backend.py on main has 2 failures (the guard and the replay); this branch: 289 passed, 111 skipped.
  • Changing the stub's body (named_modules to modules) fails the new body-match test.

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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 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-05T23:13:22.002947Z a9820a9 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32b61e9ddc

ℹ️ 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".

continue
ours = ast.parse(textwrap.dedent(inspect.getsource(helper))).body[0]
ours_body, zoo_body = (
[ast.dump(n) for n in f.body if not isinstance(n, ast.Expr)] for f in (ours, zoo[name])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compare non-docstring expression statements

If the upstream helper gains a bare call or other expression statement, this filter removes that statement from both AST bodies, so the new drift guard can pass even though the local copy omits upstream behavior. Ignore only the leading string-literal docstring rather than every ast.Expr, so changes such as validation, cache priming, or logging calls are detected.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in a9820a9: only a leading string-literal docstring is dropped. Adding a bare logger.debug(...) call to zoo's _fusion_modules now fails the body check.

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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: a9820a9950

ℹ️ 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".

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.

1 participant