← Back to Pull requests

fix(rollout): pass a pre-built 4-D mask to the static graph decode forward #9004

Closed
unknown closed this pull request without merging on Nov 06, 2026 07:11 UTC
View on GitHub
unknown unknown commented on Nov 04, 2026 04:23 UTC
Author

Closes #9000.

Problem

With use_graph_capture=True and no continuous_batch_size, _generate_graph gives the captured decode forward a 2-D attention mask, so Transformers builds the causal mask during capture. That fails on the supported versions:

  • 4.57.x with SDPA: padding_mask.all() runs on the host and breaks capture with "operation not permitted when stream is capturing" (reported by @0z5a on #8197).

  • 5.x: Transformers calls get_query_offset, which DeepSpeedStaticCache doesn't have.
  • Fix

    The captured forward now gets a pre-built 4-D additive mask. The mask is refreshed before each replay, and prefill is unchanged. The fix is cherry-picked from @0z5a's commit.

    _generate_graph also raises a ValueError for flash_attention_2, as the continuous graph path does, because it can't use a 4-D mask.

    #8602 includes the same mask change, but it's a much larger PR that will take a while to merge. #8852 is still needed for continuous batching without graphs on 5.x.

    Test results

    Run on 1 NVIDIA A40 with torch 2.14.1+cu130, using real Hugging Face models without a DeepSpeed engine.

    python -m pytest tests/unit/v1/test_hybrid_engine_rollout_v1.py tests/unit/runtime/rollout/ tests/unit/utils/test_static_cache.py
    

    | Transformers | New tests with this PR | Rollout and cache suites with this PR |
    | --- | --- | --- | --- |
    | 4.57.6 | 4 passed | 89 passed, 2 skipped |
    | 5.19.0 | 4 passed | 89 passed, 2 skipped |
    | 5.22.1 | 4 passed | 89 passed, 2 skipped |

    Compatibility

  • Validated: CUDA on an A40; fp32, fp16 and bf16; eager and SDPA attention; Transformers 4.57.6, 5.19.0 and 5.22.1.

  • Not validated:

  • - accelerators other than CUDA
    - hybrid models
    - the flash_attention_2 rejection on a real FlashAttention model

    Diff: 224 lines (+168 / -56) across 2 files Reviewer: delock Review duration: 3048m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 224 lines diff across 2 files
    0.37
    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%
    56%
    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.324
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9004"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 36.9% (MEDIUM) · Higher = larger blast radius
    36.9%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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.9% · Safe to merge
    15.9%