← Back to Pull requests

[AutoSP] Rebuild query-sharded attention masks before SDPA #8761

Closed
unknown closed this pull request without merging on Oct 12, 2026 00:55 UTC
View on GitHub
unknown unknown commented on Oct 06, 2026 18:40 UTC
Author

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, labels and position_ids along the sequence dimension. A model can build its causal or attention mask from the sharded position_ids, which gives the mask the shape [B, 1, S/sp, S]. After the Ulysses all-to-all, SDPA sees all S queries, but the mask still covers only S/sp of them. The run then fails with a shape mismatch: size of tensor a (s) must match ... (s//2).

Fix


  • Add a custom op autosp::all_gather_sequence(input, dim) with a fake (meta) implementation.

  • In 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.

  • If the mask's key dimension is also sharded, it cannot be rebuilt correctly from the local pieces, so raise a clear error.

  • Run pass_propagate_shapes once before the attention pass so that the mask shapes are current. This is why the PR depends on the get_node_shape_meta fix.

  • all_gather_sequence has a backward pass, an autosp::reduce_scatter_sequence op, so masks that require gradients (for example a learnable position bias) also work.

  • A mask with a full head dimension is redistributed like the query: if its query rows are sharded, it goes through all-to-all; otherwise each rank keeps only its own block of heads. A broadcast key dimension of 1 is never treated as sharded.

  • Document the behavior under AutoSP Limitations.
  • Tests


    Added TestAutoSPAttentionMask (world_size=2):
  • With a learnable mask bias (shared, per-head with sharded queries, or per-head with full queries), the loss and all parameter gradients match a single-device reference.

  • With a query-sharded mask, passed as a kwarg and positionally, the forward loss matches a single-device full-sequence reference.

  • A mask whose key dimension is sharded is rejected with a clear error.
  • Without the fix, all 3 tests fail. With the fix but without the fx.py change, all 3 also fail.

    Hardware: 8× Intel Arc Pro B70 (XPU), torch 2.14.0.dev+xpu, transformers 5.17. 42 AutoSP tests pass. TestAutoSPCompile is excluded because of a pre-existing environment failure that also happens on master.

    Diff: 303 lines (+227 / -76) across 3 files Reviewer: jinyouzhi Review duration: 7575m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%