Skip to content

Flex mask graph-break patch: handle a positional call from the zoo wrapper above it (rest shard red on main) - #17952

Merged
danielhanchen merged 1 commit into
mainfrom
fix-flex-mask-positional-caller
Nov 16, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix-flex-mask-positional-caller

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Repo tests (CPU, rest) fails on current main (seen on #17921, #17934 and the staging run of #17904) in:

tests/test_flex_mask_graph_breaks.py::test_compiled_flex_mask_has_no_graph_breaks_and_matches_eager
E   torch._dynamo.exc.Unsupported: Data-dependent branching
E     File ".../unsloth_zoo/temporary_patches/misc.py", line 1318, in flex_attention_mask
E       return original(*bound.args, **bound.kwargs)
E     File ".../unsloth/import_fixes.py", line 2471, in flex_attention_mask
E       return original(*args, **kwargs)
E     File ".../transformers/masking_utils.py", line 685, in flex_attention_mask
E       if attention_mask is not None and not fast_all(attention_mask):

It started with unslothai/unsloth-zoo#2551 (the test passes with zoo at its parent and fails at it). That PR wraps the registered flex_attention mask builder to keep the padding mask_mod during training, and forwards every call as original(*bound.args, **bound.kwargs), i.e. by position. The wrapper it sits on is Unsloth's fix_transformers_flex_mask_graph_breaks patch, which only handled keyword calls: with any positional argument it called transformers directly, so while Dynamo traces the fast_all(attention_mask) branch came back and fullgraph tracing broke.

Both patches are right on their own; the Unsloth one was fragile about how it is called, so this hardens it rather than changing zoo.

Change

  • unsloth/import_fixes.py: the flex mask patch binds positional arguments to the original's signature and continues with keywords (new helper _keyword_arguments, which merges **kwargs parameters and returns None for anything it cannot express as keywords; then the call goes through unchanged, as before).
  • tests/test_flex_mask_graph_breaks.py: new test_a_wrapper_forwarding_by_position_keeps_the_compiled_path registers a wrapper that forwards by position above the patch (as zoo's does) and checks the fullgraph compile of a padded batch matches eager. It does not depend on which zoo is installed.

Testing

unsloth unsloth_zoo test_flex_mask_graph_breaks.py
main main 1 failed (the CI failure)
this PR main 4 passed, 1 skipped
this PR before #2551 4 passed, 1 skipped
main before #2551 1 failed: the new positional-wrapper test

CPU, torch 2.10, transformers 5.17 (the CI pins for this shard).

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 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-16T09:49:46.742166Z ae56eb1 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. Hooray!

Reviewed commit: ae56eb1c2b

ℹ️ 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 c0afb62 into main Nov 16, 2026
@danielhanchen
danielhanchen deleted the fix-flex-mask-positional-caller branch November 16, 2026 09:52
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