Skip to content

Prefix grouper test: give extracted llama.py functions a package for relative imports - #17853

Merged
danielhanchen merged 1 commit into
mainfrom
fix-gated-method-harness
Nov 15, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-gated-method-harness

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

tests/test_grpo_prefix_grouper_capability.py::test_pre_patch_gate_applies_only_on_marked_modules has failed in Repo tests (CPU, rest) on main since #17830 ("keep layer gradient checkpointing on transformers 5.23+"). Seen on the staging run of #12384, base 57d9d1de:

unsloth/models/llama.py:3456: in _gated_method
    from ._block_compile import _checkpointing, _is_hf_checkpoint_wrapper
E   KeyError: "'__name__' not in globals"

#17830 is correct: _gated_method now re-applies transformers' layer checkpoint wrapper. The test's _top_level helper pulls functions out of llama.py with ast and execs them in a bare namespace, to avoid importing unsloth (GPU init). A relative import has no package to resolve against in that namespace.

Change (test only)

_top_level now gives the namespace a __name__ and __package__ under a stand-in package (_unsloth_models_under_test), registered once with __path__ = [unsloth/models]. A relative import inside an extracted function then loads the real sibling file (_block_compile.py here) as _unsloth_models_under_test._block_compile. It does not run unsloth/models/__init__.py, so the harness still avoids the GPU stack, and the test exercises the shipped _checkpointing / _is_hf_checkpoint_wrapper rather than stubs.

Verification

tests/test_grpo_prefix_grouper_capability.py
main (57d9d1de) 1 failed, 19 passed
this branch 20 passed

…for relative imports

#17830 made _gated_method import _checkpointing and _is_hf_checkpoint_wrapper from ._block_compile.
_top_level execs extracted functions in a bare namespace, so the relative import raised
KeyError: '__name__' not in globals and test_pre_patch_gate_applies_only_on_marked_modules failed on
main. The namespace now names a stand-in package whose __path__ is unsloth/models, so the real sibling
module loads without running unsloth/models/__init__.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T16:57:01.957077Z 331a20a 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. 🚀

Reviewed commit: 331a20a080

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

@danielhanchen
danielhanchen merged commit 51fe1fc into main Nov 15, 2026
@danielhanchen
danielhanchen deleted the fix-gated-method-harness branch November 15, 2026 16:59
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