Repository navigation
Attention: let the SDPA GQA probe trace under torch.compile(dynamic=True) - #14779
Merged
Merged
Conversation
…rue) The GQA and backend probes are assume_constant_result functions, and dynamo can only pass them Python constants. With dynamic=True the head dim and head counts are SymInts, so compilation failed before the forward with 'assume_constant_result argument conversion failed'. Specialise integer arguments with operator.index before the call: head sizes are fixed per model, batch and length stay dynamic, and plain ints pass through unchanged so every static-shape decision is the same.
Member
Author
|
@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. |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
Member
Author
|
pre-commit.ci run |
danielhanchen
added a commit
that referenced
this pull request
Oct 22, 2026
danielhanchen
added a commit
that referenced
this pull request
Oct 22, 2026
pre-commit.ci fails `ruff-format-with-kwargs` on every open PR (#14806, #14805, #14803, #14790, #14785, #14781, #14780, #14777, #14776, #14775, #14774, #14773, #14772, #14770, #14769, #14768, and others): "files were modified by this hook". pre-commit.ci runs the hooks on all files, and 20 files on main (26 by the time this lands) are not in the formatter's output, so every PR is reformatted outside its own diff. Where pre-commit.ci can push, its autofix commit drags those unrelated files into the PR (for example #14790's touches `tests/test_block_compile.py`, `tests/test_bnb_integration_compile.py` and `unsloth/models/_utils.py`). The drift came in with PRs merged today, among them #14702, #14751, #14759, #14784, #14786, #14787, #14788, #14791 and the FP8 block decode, GRPO routing replay, 4-bit decode, compiled blocks and MoE LoRA target changes. ### Change `python scripts/run_ruff_format.py` (the hook's own entry point, `ruff==0.6.9` as pinned in `.pre-commit-config.yaml`) applied to those 20 files, plus 6 more from #14739, #14779 and #14806, which merged while this was open. Formatting only. ### Verification - Every changed file parses to an identical AST before and after. - A second run of the hook over the same files changes nothing (fixed point), and over all tracked Python files on this branch it changes nothing. - `ruff check` passes on the changed files; `tests/test_formatter_fixed_point.py` passes (16). Open PRs pick this up on their next pre-commit.ci run after merging main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SDPA GQA routing added in #14158 asks torch which kernel a call would get. That probe,
_sdpa_gqa_state(and_sdpa_backend_statefor the varlen choice), runs throughtorch.compiler.assume_constant_result, and dynamo can only pass such a function Python constants. #14398 handled the boolean arguments. Undertorch.compile(fullgraph=True, dynamic=True)the head dim and head counts are still SymInts, so compilation fails before the forward:Repro:
run_attentionplus backward, noncausal GQA on CUDA, Q (2, 8, 32, 64), K/V (2, 2, 32, 64), no mask, SDPA backend. Before #14158 both static and dynamic fullgraph passed.Fix: a small
_constant_probewrapper replaces the two bareassume_constant_resultwraps. It passes integer arguments throughoperator.indexbefore the call. Under dynamo that specialises the head sizes, which are fixed per model. Batch and sequence length stay dynamic. Plain ints pass through unchanged, so eager and static-shape routing is identical.functools.wrapsis avoided on purpose:assume_constant_resultmarks the wrapped function in place, and copying its__dict__would mark the wrapper too.Tests (
tests/test_attention_dispatch_compiled_block.py):_sdpa_gqa_stateand_torch_varlen_beats_segmentstraced fullgraph, static anddynamic=True, match eager with 0 graph breaks and one graph across batch / length changes.run_attentionforward plus backward in bf16 GQA, compiled fullgraph static and dynamic with Inductor. Outputs and gradients match eager, with 0 graph breaks and one graph underdynamic=True.Results on B200, torch 2.13.0 and 2.14.1:
The remaining failure,
test_plain_causal_attention_traces_with_a_dynamic_length[xformers], is already on main and fails only on a GPU host: the xformers fp32 downcast gate looks at the host GPU, not at the tensor device. It is left for a separate change.