Repository navigation
[Inductor][HOP] Handle unbacked FlexAttention predicates - #183838
sanketpurandare wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/183838
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 5 Unrelated Failures, 1 Unclassified FailureAs of commit 50304b4 with merge base 820ea17 ( NEW FAILURE - The following job has failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
3d1e6c3 to
deec133
Compare
9533492 to
123bb3f
Compare
Add the scheduling layer for graph_trainer's public ep_overlap pass. The graph and eager chunking producers create correctness-preserving chunked graphs; this commit consumes their shared chunk metadata after FSDP bucketing and reorders EP dispatch/combine phases so paired chunk all-to-all launches can run before their delayed wait suffixes. The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and MoE dispatcher regions annotated with custom EP metadata for dispatch and combine. The scheduler validates the chunk metadata, uses the last all-to-all in each EP phase as the overlap boundary, annotates delayed wait suffixes with EP_wait=True, and applies a priority topological sort. It does not duplicate nodes, delete nodes, split tensors, concatenate tensors, or otherwise change tensor values. For forward dispatch, the overlap boundary is deliberately the final token-exchange all-to-all, not the earlier split-size exchange. Forward regions schedule dispatch then combine. Backward autograd sees combine gradients before dispatch gradients, so the scheduler derives the observed EP phase chunk order instead of imposing a hardcoded chunk order. Wire the public ep_overlap pipeline as two stages: chunking runs before memory/offload/remat and bucketing, while scheduling runs after downstream FSDP bucketing/reordering. This lets distributed bucketing place shared full-value waits first, then lets the EP scheduler establish the final EP launch/wait order. Add focused scheduler tests and H100 full-Inductor integration coverage for graph chunking and eager chunking across SDPA and FlexAttention debug-model variants. The distributed bitwise numerics tests introduced with graph chunking cover this composed public ep_overlap path because scheduling is value-preserving. This pass stack relies on pending PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths: - FakeTensor folded matmul: pytorch/pytorch#183397 - ProxyTensor SDPA tracing: pytorch/pytorch#183398 - Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495 - Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544 - DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545 - HOP fake traces with discarded unbacked symbols: pytorch/pytorch#183837 - FlexAttention chunked unbacked input extents: pytorch/pytorch#183838 - FakeTensor trace metadata for hinted symbolic storage: pytorch/pytorch#183839 - Inductor symbolic stride ordering with unbacked hints: pytorch/pytorch#183840 Test Plan: - pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py - 84 passed, 1 skipped, 14 warnings, 5 subtests passed - pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - all 8 H100 integration tests passed stack-info: PR: #3328, branch: sanketpurandare/stack/14
Add the scheduling layer for graph_trainer's public ep_overlap pass. The graph and eager chunking producers create correctness-preserving chunked graphs; this commit consumes their shared chunk metadata after FSDP bucketing and reorders EP dispatch/combine phases so paired chunk all-to-all launches can run before their delayed wait suffixes. The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and MoE dispatcher regions annotated with custom EP metadata for dispatch and combine. The scheduler validates the chunk metadata, uses the last all-to-all in each EP phase as the overlap boundary, annotates delayed wait suffixes with EP_wait=True, and applies a priority topological sort. It does not duplicate nodes, delete nodes, split tensors, concatenate tensors, or otherwise change tensor values. For forward dispatch, the overlap boundary is deliberately the final token-exchange all-to-all, not the earlier split-size exchange. Forward regions schedule dispatch then combine. Backward autograd sees combine gradients before dispatch gradients, so the scheduler derives the observed EP phase chunk order instead of imposing a hardcoded chunk order. Wire the public ep_overlap pipeline as two stages: chunking runs before memory/offload/remat and bucketing, while scheduling runs after downstream FSDP bucketing/reordering. This lets distributed bucketing place shared full-value waits first, then lets the EP scheduler establish the final EP launch/wait order. Add focused scheduler tests and H100 full-Inductor integration coverage for graph chunking and eager chunking across SDPA and FlexAttention debug-model variants. The distributed bitwise numerics tests introduced with graph chunking cover this composed public ep_overlap path because scheduling is value-preserving. This pass stack relies on pending PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths: - FakeTensor folded matmul: pytorch/pytorch#183397 - ProxyTensor SDPA tracing: pytorch/pytorch#183398 - Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495 - Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544 - DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545 - HOP fake traces with discarded unbacked symbols: pytorch/pytorch#183837 - FlexAttention chunked unbacked input extents: pytorch/pytorch#183838 - FakeTensor trace metadata for hinted symbolic storage: pytorch/pytorch#183839 - Inductor symbolic stride ordering with unbacked hints: pytorch/pytorch#183840 Test Plan: - pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py - 84 passed, 1 skipped, 14 warnings, 5 subtests passed - pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - all 8 H100 integration tests passed stack-info: PR: #3328, branch: sanketpurandare/stack/14
Add the scheduling layer for graph_trainer's public ep_overlap pass. The graph and eager chunking producers create correctness-preserving chunked graphs; this commit consumes their shared chunk metadata after FSDP bucketing and reorders EP dispatch/combine phases so paired chunk all-to-all launches can run before their delayed wait suffixes. The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and MoE dispatcher regions annotated with custom EP metadata for dispatch and combine. The scheduler validates the chunk metadata, uses the last all-to-all in each EP phase as the overlap boundary, annotates delayed wait suffixes with EP_wait=True, and applies a priority topological sort. It does not duplicate nodes, delete nodes, split tensors, concatenate tensors, or otherwise change tensor values. For forward dispatch, the overlap boundary is deliberately the final token-exchange all-to-all, not the earlier split-size exchange. Forward regions schedule dispatch then combine. Backward autograd sees combine gradients before dispatch gradients, so the scheduler derives the observed EP phase chunk order instead of imposing a hardcoded chunk order. Wire the public ep_overlap pipeline as two stages: chunking runs before memory/offload/remat and bucketing, while scheduling runs after downstream FSDP bucketing/reordering. This lets distributed bucketing place shared full-value waits first, then lets the EP scheduler establish the final EP launch/wait order. Add focused scheduler tests and H100 full-Inductor integration coverage for graph chunking and eager chunking across SDPA and FlexAttention debug-model variants. The distributed bitwise numerics tests introduced with graph chunking cover this composed public ep_overlap path because scheduling is value-preserving. This pass stack relies on pending PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths: - FakeTensor folded matmul: pytorch/pytorch#183397 - ProxyTensor SDPA tracing: pytorch/pytorch#183398 - Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495 - Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544 - DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545 - HOP fake traces with discarded unbacked symbols: pytorch/pytorch#183837 - FlexAttention chunked unbacked input extents: pytorch/pytorch#183838 - FakeTensor trace metadata for hinted symbolic storage: pytorch/pytorch#183839 - Inductor symbolic stride ordering with unbacked hints: pytorch/pytorch#183840 Test Plan: - pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py - 84 passed, 1 skipped, 14 warnings, 5 subtests passed - pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - all 8 H100 integration tests passed stack-info: PR: #3328, branch: sanketpurandare/stack/14
Add the scheduling layer for graph_trainer's public ep_overlap pass. The graph and eager chunking producers create correctness-preserving chunked graphs; this commit consumes their shared chunk metadata after FSDP bucketing and reorders EP dispatch/combine phases so paired chunk all-to-all launches can run before their delayed wait suffixes. The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and MoE dispatcher regions annotated with custom EP metadata for dispatch and combine. The scheduler validates the chunk metadata, uses the last all-to-all in each EP phase as the overlap boundary, annotates delayed wait suffixes with EP_wait=True, and applies a priority topological sort. It does not duplicate nodes, delete nodes, split tensors, concatenate tensors, or otherwise change tensor values. For forward dispatch, the overlap boundary is deliberately the final token-exchange all-to-all, not the earlier split-size exchange. Forward regions schedule dispatch then combine. Backward autograd sees combine gradients before dispatch gradients, so the scheduler derives the observed EP phase chunk order instead of imposing a hardcoded chunk order. Wire the public ep_overlap pipeline as two stages: chunking runs before memory/offload/remat and bucketing, while scheduling runs after downstream FSDP bucketing/reordering. This lets distributed bucketing place shared full-value waits first, then lets the EP scheduler establish the final EP launch/wait order. Add focused scheduler tests and H100 full-Inductor integration coverage for graph chunking and eager chunking across SDPA and FlexAttention debug-model variants. The distributed bitwise numerics tests introduced with graph chunking cover this composed public ep_overlap path because scheduling is value-preserving. This pass stack relies on pending PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths: - FakeTensor folded matmul: pytorch/pytorch#183397 - ProxyTensor SDPA tracing: pytorch/pytorch#183398 - Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495 - Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544 - DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545 - HOP fake traces with discarded unbacked symbols: pytorch/pytorch#183837 - FlexAttention chunked unbacked input extents: pytorch/pytorch#183838 - FakeTensor trace metadata for hinted symbolic storage: pytorch/pytorch#183839 - Inductor symbolic stride ordering with unbacked hints: pytorch/pytorch#183840 Test Plan: - pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py - 84 passed, 1 skipped, 14 warnings, 5 subtests passed - pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_seq --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py /tmp/torchtitan_ep_overlap_integration_20260514_174529 --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8 - all 8 H100 integration tests passed stack-info: PR: #3328, branch: sanketpurandare/stack/14
deec133 to
3720258
Compare
| # These checks reject invalid block masks. With symbolic lengths, only | ||
| # raise when the invalid relation is provable at trace time. | ||
| block_mask_q_len = block_mask.shape[-2] | ||
| block_mask_kv_len = block_mask.shape[-1] | ||
| if query.size(-2) > block_mask_q_len or key.size(-2) > block_mask_kv_len: | ||
| if guard_or_false(query.size(-2) > block_mask_q_len) or guard_or_false( | ||
| key.size(-2) > block_mask_kv_len | ||
| ): | ||
| raise ValueError( | ||
| f"block_mask was created for block_mask.shape={block_mask.shape} but got q_len={query.size(-2)} and kv_len={key.size(-2)}. " | ||
| "As the block mask was created for a smaller length than you're using it for, you likely need to create a new block mask." | ||
| ) | ||
| elif ( | ||
| query.size(-2) < block_mask_q_len and key.size(-2) <= block_mask_kv_len | ||
| ) or (query.size(-2) <= block_mask_q_len and key.size(-2) < block_mask_kv_len): | ||
| guard_or_false(query.size(-2) < block_mask_q_len) | ||
| and guard_or_false(key.size(-2) <= block_mask_kv_len) | ||
| ) or ( | ||
| guard_or_false(query.size(-2) <= block_mask_q_len) | ||
| and guard_or_false(key.size(-2) < block_mask_kv_len) | ||
| ): | ||
| raise ValueError( | ||
| f"block_mask was created for block_mask.shape={block_mask.shape} but got q_len={query.size(-2)} and kv_len={key.size(-2)}. " | ||
| "As the block mask was created for a larger length than you're using it for, you can either 1. create a new block mask with the correct length, or 2. 'adjust' the existing block mask to the correct length by calling block_mask._adjust(q_len, kv_len). This essentially 'crops' the block mask to the upper left corner, which does not work for all mask_mods!" | ||
| ) | ||
| if query.size(-2) != block_mask_q_len: | ||
| if guard_or_false(query.size(-2) != block_mask_q_len): | ||
| raise AssertionError( | ||
| f"query.size(-2) ({query.size(-2)}) != block_mask_q_len ({block_mask_q_len})" | ||
| ) | ||
| if key.size(-2) != block_mask_kv_len: | ||
| if guard_or_false(key.size(-2) != block_mask_kv_len): | ||
| raise AssertionError( | ||
| f"key.size(-2) ({key.size(-2)}) != block_mask_kv_len ({block_mask_kv_len})" |
There was a problem hiding this comment.
AFAIk we dont use guard_or_false for runtime checks and things that if we choose wrongly will end up causing us to execute bad code. I think that this should be torch._check right?
drisspg
left a comment
There was a problem hiding this comment.
I approve of the guarding in flex
eellison
left a comment
There was a problem hiding this comment.
cc @laithsakka feels like there is an api gap here with unbacked shapes/ runtime conditions
| if guard_or_false(query.size(-2) > block_mask_q_len) or guard_or_false( | ||
| key.size(-2) > block_mask_kv_len | ||
| ): |
There was a problem hiding this comment.
This feels to me like an API issue. This should not translate to False if we can't guard here. It should just translate to a runtime assertion, ideally with the error message preserved.
cc @laithsakka
| guard_or_false(query.size(-2) < block_mask_q_len) | ||
| and guard_or_false(key.size(-2) <= block_mask_kv_len) | ||
| ) or ( | ||
| guard_or_false(query.size(-2) <= block_mask_q_len) | ||
| and guard_or_false(key.size(-2) < block_mask_kv_len) |
| # The fake kernel must choose one metadata shape during tracing. Reduce to | ||
| # key/value batch only when key/value is provably batch-broadcast; otherwise | ||
| # keep the non-broadcast metadata and record its equality precondition. | ||
| if guard_or_false(Bkv == 1) and guard_or_true(Bq != 1): |
There was a problem hiding this comment.
You should guard on the conjunction, so we don't add a guard on one without being able to prove the other
| # Keep concrete/hinted mismatches on the existing ValueError branches. | ||
| # Truly unbacked comparisons fall through to deferred equality checks. | ||
| if guard_or_false(query.size(-2) > block_mask_q_len) or guard_or_false( | ||
| key.size(-2) > block_mask_kv_len |
There was a problem hiding this comment.
cond = sym_or((q_len > block_mask_q_len, kv_len > block_mask_kv_len)
torch._check(cond!=False, ...)
cond3 = not cond1 and cond2
torch._check(cond3!=False, ...)
|
@pytorchbot merge -i |
|
@pytorchbot revert -m 'Sorry for reverting your change but one of the new tests is failing internally' -c ghfirst From D108817148 It's easier to revert and reland I think |
|
@pytorchbot successfully started a revert job. Check the current status here. |
|
@sanketpurandare your PR has been successfully reverted. |
EP-overlap graph chunking traces FlexAttention with unbacked symbolic batch and sequence dimensions. These are valid runtime sizes, but several FlexAttention predicate and lowering sites forced trace-time decisions that should either fall back to the general kernel or remain represented as symbolic assertions. Flex decoding remains an optional optimized implementation. Its predicates use guard_or_false because they are kernel eligibility checks, not user-visible invariants: when ShapeEnv can prove eligibility, decode can be selected; when an unbacked predicate is not provable, the general FlexAttention kernel is used. Failing to prove an optimization must not impose a runtime shape contract on user inputs. Backward fake propagation preserves the accepted KV-batch-broadcast metadata contract. It reduces grad_key and grad_value back to key/value batch when key/value batch is one and query batch is known to satisfy the eager broadcast precondition; otherwise it records the non-broadcast invariant with torch._check(Bq == Bkv). Public BlockMask length validation is expressed as symbolic torch._check predicates. Concrete mismatches still fail with the existing guidance, while unbacked symbolic lengths become deferred runtime assertions instead of forcing Python to branch on an unbacked expression. The FlexAttention lowering keeps scalar shape captures as subgraph inputs for dependency tracking and codegen, but autotuning only receives tensor-valued IR inputs because benchmarking materializes real tensors. Captured Python ints and SymInts are realized as scalar IR, including in backward lowering, so realize_inputs also avoids applying tensor stride constraints to non-tensor scalar IR. This preserves the existing algorithm-selector contract instead of teaching global autotune to key or benchmark scalar captures. This PR was authored with assistance from an AI assistant. Test Plan: ```bash python -m pytest test/inductor/test_flex_attention.py -q -s -k "unbacked_flex_decoding_eligibility_falls_back or backward_fake_symbolic_query_key_batch_metadata or direct_backward_inductor_batch_broadcast_matches_eager or direct_backward_inductor_supports_scalar_mask_mod_buffers or block_mask_vs_sequence_lengths" ``` ```bash python -m pytest test/inductor/test_flex_attention.py -q -s -k "direct_backward" ``` ```bash python -m pytest test/inductor/test_flex_attention.py -q -s -k "flex_decoding" ``` ```bash python -m pytest test/inductor/test_flex_attention.py -q -s -k "direct_backward_preserves_explicit_buffers or direct_backward_supports_symint_score_mod_buffers or captured_scalar_grad or symbol_closure_in_score_mod or mask_mod_handles_symint_addition or mask_mod_handles_derived_symint_closure" ``` ```bash python test/inductor/test_select_algorithm.py TestAlgorithmSelectorChoiceTypes ``` ```bash python test/inductor/test_dependencies.py TestDependencies.test_extern_kernel_nested_ir_args_are_dependencies ``` ```bash python test/inductor/test_mkldnn_pattern_matcher.py TestPatternMatcher.test_linear_add_bias TestPatternMatcher.test_linear_add_bias_float_constant ``` ```bash lintrunner -a ``` stack-info: PR: #183838, branch: sanketpurandare/stack/12
|
@pytorchbot merge -i |
EP-overlap graph chunking traces FlexAttention with unbacked symbolic batch and sequence dimensions. These are valid runtime sizes, but several FlexAttention predicate and lowering sites forced trace-time decisions that should either fall back to the general kernel or remain represented as symbolic assertions.
Flex decoding remains an optional optimized implementation. Its predicates use guard_or_false because they are kernel eligibility checks, not user-visible invariants: when ShapeEnv can prove eligibility, decode can be selected; when an unbacked predicate is not provable, the general FlexAttention kernel is used. Failing to prove an optimization must not impose a runtime shape contract on user inputs.
Backward fake propagation preserves the accepted KV-batch-broadcast metadata contract. It reduces grad_key and grad_value back to key/value batch when key/value batch is one and query batch is known to satisfy the eager broadcast precondition; otherwise it records the non-broadcast invariant with torch._check(Bq == Bkv).
Public BlockMask length validation is expressed as symbolic torch._check predicates. Concrete mismatches still fail with the existing guidance, while unbacked symbolic lengths become deferred runtime assertions instead of forcing Python to branch on an unbacked expression.
The FlexAttention lowering keeps scalar shape captures as subgraph inputs for dependency tracking and codegen, but autotuning only receives tensor-valued IR inputs because benchmarking materializes real tensors. Captured Python ints and SymInts are realized as scalar IR, including in backward lowering, so realize_inputs also avoids applying tensor stride constraints to non-tensor scalar IR. This preserves the existing algorithm-selector contract instead of teaching global autotune to key or benchmark scalar captures.
This PR was authored with assistance from an AI assistant.
Test Plan:
python -m pytest test/inductor/test_flex_attention.py -q -s -k "unbacked_flex_decoding_eligibility_falls_back or backward_fake_symbolic_query_key_batch_metadata or direct_backward_inductor_batch_broadcast_matches_eager or direct_backward_inductor_supports_scalar_mask_mod_buffers or block_mask_vs_sequence_lengths"python -m pytest test/inductor/test_flex_attention.py -q -s -k "direct_backward"python -m pytest test/inductor/test_flex_attention.py -q -s -k "flex_decoding"python -m pytest test/inductor/test_flex_attention.py -q -s -k "direct_backward_preserves_explicit_buffers or direct_backward_supports_symint_score_mod_buffers or captured_scalar_grad or symbol_closure_in_score_mod or mask_mod_handles_symint_addition or mask_mod_handles_derived_symint_closure"cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @azahed98