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

Commit
27 days ago
[Hybrid Engine] Require an explicit accelerator opt-in for graph capture (#8980) 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. --------- Signed-off-by: Zizhao Tang <1601677496@qq.com>
Author
Parents
Loading