← Back to Pull requests

[Hybrid Engine] Require an explicit accelerator opt-in for graph capture #8980

Closed
unknown closed this pull request without merging on Nov 05, 2026 04:00 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 03:21 UTC
Author

Follow-up to #8933 (review feedback from @0z5a).

Background

#8933 made the HybridEngine graph capture gate device-agnostic: instead of matching the device name, it admits every accelerator whose create_graph() returns a graph. That is CUDA and NPU, but also HPU (HPUGraph), MLU (MLUGraph) and SUPA (SUPAGraph).

Only CUDA and NPU implement is_current_stream_capturing(). DeepSpeedStaticCache.update relies on it to skip the per-row write-position bounds check ((cache_position < 0).any()) while capturing. On the other backends the check would run during capture and synchronize the host, which is illegal while a stream is being captured, and none of those backends is in the test matrix. Before #8933, the device-name check kept them on the eager fallback.

Change

  • Add is_graph_capture_supported() to the accelerator interface. The default is False, so backends opt in explicitly, and only after they implement is_current_stream_capturing().

  • Override it to True for CUDA and NPU.

  • Use it in both graph capture gates: validate_graph_capture_support() in hybrid_engine_graph.py and the continuous rollout path in hybrid_engine_rollout.py.

  • Update the affected unit tests and add a case that a backend exposing create_graph() without the opt-in stays on eager decode.
  • HPU, MLU and SUPA keep the eager fallback with the existing warning. They can be enabled later by implementing the stream-capture query and validating the path.

    Testing

    Branch fix-hybrid-engine-graph-capture-opt-in, HEAD 9427e0d55 (parent 2d80cedd2), working tree clean. Both on-device runs use this commit.

    CUDA (8×A100-SXM4-80GB, single card used; torch 2.14.1+cu126, CUDA 12.6, Python 3.10.22; transformers 4.57.6)

  • Gate: CUDA_Accelerator.is_graph_capture_supported() returns True and CPU returns False.

  • validate_graph_capture_support(): allows ZeRO-2 and rejects ZeRO-3.

  • DecodeGraphCache: all 4 decode positions captured, the host forward runs exactly once per position; the same length reuses graphs, a length change recaptures, and exceeding max_positions raises.

  • End-to-end generate (local tiny GPT-J): 2 inference containers, capture active, 7/7 positions captured, graph output identical to eager.

  • Deprecated alias enable_cuda_graph: true: warning emitted, capture active, output identical.

  • Official OPT E2E passes with transformers 4.44.2 (legacy tuple cache).

  • No regression observed.
  • Suite results (transformers 4.57.6, default marker selection):

    | Suite | Result |
    | --- | --- |
    | test_he_graph.py | 21 passed |
    | test_hybrid_engine_rollout.py | 50 passed |
    | test_accelerator_graph.py | 1 passed, 1 skipped (CUDA has graph support; the eager-fallback case is skipped by design) |
    | test_accelerator.py | 35 passed |
    | Total | 107 passed, 1 skipped |

    NPU (Ascend 910B4; torch 2.10 + torch_npu 2.10.0.post7)

  • Unit tests on the changed gate with transformers 5.19.0: pytest tests/unit/hybrid_engine/test_he_graph.py tests/unit/runtime/rollout/test_hybrid_engine_rollout.py -q -m "not seq_inference" — 70 passed, 1 skipped (native CUDA kernel test).

  • Official OPT E2E passes with transformers 4.44.2 (venv-tf442).

  • Full-model end-to-end on the gated paths (validated in #8933): transformers 4.57.6 — GPT-2 continuous graph capture, token-identical 32/32 over 3 runs, 5.97×; transformers 4.44.2 — inference-container graph capture and replay.

  • Full-model continuous-path validation uses transformers 4.57.6; 5.x support is tracked separately in #8852.
  • Other backends

  • HPU, MLU and SUPA are not available here; their fallback is covered by the default-False unit test, not an on-device run. CPU was verified to return False.
  • Conclusion

    The implementation behaves correctly with no CUDA regression: the opt-in gate applies per backend, CUDA keeps graph capture, non-opt-in backends fall back to eager decode, and the old config alias remains compatible.

    Diff: 494 lines (+370 / -124) across 6 files Reviewer: delock Review duration: 4358m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.47) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 494 lines diff across 6 files
    0.47
    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.371
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8980"
    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: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    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: 20.5% · Safe to merge
    20.5%