Repository navigation
Chunked mask test: unwrap every layer, including unsloth_zoo's mask wrapper - #13248
Conversation
…rapper unsloth-zoo#1656 copied the original signature onto patch_transformers_masks' wrappers. Before it, the zoo wrapper on create_chunked_causal_mask read as (*args, **kwargs), so these tests skipped. Now they run, and the 'unpatched' fixture only unwrapped the outermost function: that is the zoo wrapper, which wraps Unsloth's fix (kept on _unsloth_original_create_chunked_causal_mask) and sets no __wrapped__, while LAYER_PATTERN_TO_MASK_FUNCTION_MAPPING still points at the fix. So the unpatched static-cache generate went through the fix and test_static_cache_generate_matches_dynamic failed with DID NOT RAISE TypeError. The fixture now walks the whole chain to the stock transformers function and points every reference at it through monkeypatch, so teardown restores each one.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47bd2e80a1
ℹ️ 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".
| elif is_wrapper(value): | ||
| monkeypatch.setitem(mapping, key, original) | ||
| monkeypatch.setattr(masking_utils, "create_chunked_causal_mask", original) | ||
| for name, module in list(sys.modules.items()): |
There was a problem hiding this comment.
Restore wrappers in modules imported during the test
This scan only registers modules that exist before the fixture yields. In test_static_cache_generate_matches_dynamic, _tiny_llama4() subsequently imports transformers.models.llama4.modeling_llama4; the call to fix_transformers_chunked_mask_block_sequence_ids() then rewrites that module's reference directly to the new per-test wrapper, but monkeypatch never recorded its previous value. Teardown therefore restores the module attribute and mapping while leaving modeling_llama4.create_chunked_causal_mask pointing at the test wrapper, so later tests can bypass the restored unsloth-zoo wrapper chain and become order-dependent. The fixture needs teardown logic that also restores references created or rewritten after setup.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct. When modeling_llama4 is first imported inside the test, monkeypatch never recorded it, so teardown left it on the per-test wrapper. The fixture now records which modules existed at setup and, on teardown, rebinds any module imported afterwards whose reference resolves to the stock function or a test-made wrapper to the restored outer function. Checked by dropping Llama-4 from sys.modules before the file and asserting afterwards that modeling_llama4 points at masking_utils.create_chunked_causal_mask: fails on the previous head, passes now.
…g the test monkeypatch only records modules that existed at setup. When modeling_llama4 is first imported inside the test it binds the stock function, and the fix rewrites it to a wrapper this test made, which teardown left in place. Rebind such modules to the function a normal import would have seen.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Problem
Repo tests (CPU, rest)fails on every PR since unslothai/unsloth-zoo#1656 landed (for example #13219, #13222, #13230, #13231):Bisected with transformers 5.17.0 (the CI pin): unsloth-zoo at
94e2429~1gives 2 passed and 2 skipped, and at94e2429(#1656, "Keep the original signature on the patched mask builders") gives 1 failed. The unsloth commit makes no difference: a8ff841, 554eb6b and main all fail against zoo main.Both products are correct. The test fixture is what broke:
import unslothstacks two wrappers. Unsloth'sblock_sequence_idsfix wraps the stockcreate_chunked_causal_mask, and unsloth_zoo'spatch_transformers_masksthen wraps the fix. The zoo wrapper keeps the fix on_unsloth_original_create_chunked_causal_maskand sets no__wrapped__.LAYER_PATTERN_TO_MASK_FUNCTION_MAPPING["chunked_attention"]still points at the fix.(*args, **kwargs), so_chunked_mask_rejects_block_sequence_idsreturned False and these tests skipped.unpatchedfixture only unwrapped when the outermost function carried Unsloth's flag. The outermost function is the zoo wrapper, so the fixture changed nothing, generate still went through the fix, and the expected TypeError never came.Llama-4 static-cache generate itself works under the stacked wrappers, so the product needs no change.
Fix
The fixture now follows the whole chain down to the stock transformers function: the outermost function, the zoo stash if present, then each Unsloth
__wrapped__. Every place_swap_function_referencestouches (the module attribute, the mask mapping including nested dicts and partials, andtransformers.*/ compiled-cache module globals) is pointed at that function throughmonkeypatch, so teardown restores each one exactly.Verification
kwargs.getinstead ofkwargs.popforblock_sequence_idsmakes 2 tests fail.create_chunked_causal_maskand the same Unsloth fix in the mapping.