Skip to content

PrefixGrouper compile check test: keep the throwaway package importable for Dynamo - #19034

Merged
danielhanchen merged 1 commit into
mainfrom
fix/prefix-grouper-check-keeps-pkg-registered
Nov 23, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/prefix-grouper-check-keeps-pkg-registered

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, rest-2) fails on PR runs rebased past #18975 (for example the staging run for #19000), and the same two tests fail on a local checkout of current main:

tests/test_prefix_grouper_compile_check.py::test_rocm_new_padded_length_inside_a_fullgraph_compile[grad]
tests/test_prefix_grouper_compile_check.py::test_rocm_new_padded_length_inside_a_fullgraph_compile[no_grad]
E   torch._dynamo.exc.InternalTorchDynamoError: ModuleNotFoundError: No module named '_pg_check_pkg_under_test'

Both tests were added by #18975 and already fail at its merge commit (03c989b0a7) with torch 2.10 CPU, the same as CI.

Root cause

The test, not the kernel. _load() imports prefix_grouper.py under a throwaway package and removes it from sys.modules straight away. These two tests are the only ones in the file that wrap the kernel in torch.compile(fullgraph=True), and Dynamo resolves a traced function's globals by importing its module by name (symbolic_convert._import_module), so the compile dies on the missing package before reaching the code under test.

Keeping the package registered exposed a second problem: _import_module is functools.cached for the process, so with one fixed package name the [no_grad] compile resolved the [grad] test's kernel module and guarded on its _COMPILE_CHECKED (Guard failed on the same frame it was created). Each parametrization passes on its own.

Fix

tests/test_prefix_grouper_compile_check.py only:

  • _load(monkeypatch) registers the package and both modules through monkeypatch, so they stay importable for the whole test and are removed at teardown.
  • Each load uses its own package name (_pg_check_pkg_under_test_<n>), so Dynamo's import cache can never hand one test another test's kernel state.

No change to unsloth/utils/prefix_grouper_kernel.py.

Testing

  • tests/test_prefix_grouper_compile_check.py: 18 passed (was 2 failed), also under -n 3.
  • All tests/test_prefix_grouper*.py: 100 passed, 3 skipped.
  • No _pg_check_pkg_under_test* module is left in sys.modules after the file runs.
  • Sabotage: removing the kernel's in-graph reuse (if in_graph_reuse: needs_check = False) makes both tests fail, so they now check the kernel instead of failing before it.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 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-23T08:59:25.404310Z 220f0a0 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. Delightful!

Reviewed commit: 220f0a060a

ℹ️ 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 fefbdff into main Nov 23, 2026
@danielhanchen
danielhanchen deleted the fix/prefix-grouper-check-keeps-pkg-registered branch November 23, 2026 09:00
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