[AutoSP] Rebuild query-sharded attention masks before SDPA #8761
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 303 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8761"
general
weight: 0.35
jinyouzhi
Split out of #8457. This PR is stacked on #8760. It contains that PR's commit, so please review only the last commit.
Problem
AutoSP shards
input_ids,labelsandposition_idsalong the sequence dimension. A model can build its causal or attention mask from the shardedposition_ids, which gives the mask the shape[B, 1, S/sp, S]. After the Ulysses all-to-all, SDPA sees allSqueries, but the mask still covers onlyS/spof them. The run then fails with a shape mismatch:size of tensor a (s) must match ... (s//2).Fix
autosp::all_gather_sequence(input, dim)with a fake (meta) implementation.pass_insert_attention_all_to_all, check whether the mask's query dimension equals the local sequence length. If it does, all-gather the mask along dim -2 over the SP group. The mask can be passed as a kwarg or positionally. When several layers share one mask node, it is gathered only once.pass_propagate_shapesonce before the attention pass so that the mask shapes are current. This is why the PR depends on theget_node_shape_metafix.all_gather_sequencehas a backward pass, anautosp::reduce_scatter_sequenceop, so masks that require gradients (for example a learnable position bias) also work.Tests
Added
TestAutoSPAttentionMask(world_size=2):Without the fix, all 3 tests fail. With the fix but without the
fx.pychange, all 3 also fail.Hardware: 8× Intel Arc Pro B70 (XPU), torch 2.14.0.dev+xpu, transformers 5.17. 42 AutoSP tests pass.
TestAutoSPCompileis excluded because of a pre-existing environment failure that also happens on master.