[BUG] HybridEngineRollout plain graph path fails to capture on Transformers 4.57.x with SDPA
Describe the bug
With use_graph_capture=True and no continuous_batch_size, _generate_graph fails on its first decode capture on Transformers 4.57.x with SDPA attention. @0z5a first reported this on #8197.
The captured forward receives a 2-D attention mask, so Transformers builds the causal mask during capture, and _ignore_causal_mask_sdpa evaluates padding_mask.all() on the host:
transformers/masking_utils.py:254, in _ignore_causal_mask_sdpa
padding_mask.all()
torch.AcceleratorError: CUDA error: operation not permitted when stream is capturing
The failed capture also poisons the CUDA context, so later calls in the same process fail too.
Continuous batching isn't affected: without graphs nothing is captured, and with graphs it passes a pre-built 4-D mask, so Transformers skips mask construction.
To Reproduce
HybridEngineRolloutConfig(use_graph_capture=True)
SamplingConfig(temperature=0, max_new_tokens=8)
Reproduced on Transformers 4.57.6, torch 2.14.1+cu130, NVIDIA A40, with a tiny random Llama using SDPA. @0z5a reproduced it on a GH200 with Qwen3-8B.
Impact
- Plain graph decoding is unusable on these versions, and the repo's dev requirements (
transformers>=4.51.3) still allow them. - CI runs Transformers from git
main, so it doesn't catch this. - #8939 also sends sampled requests to
_generate_graph, so once it lands they will fail here instead of usinggenerate().
Proposed fix
Pass a pre-built 4-D mask to the captured forward in _generate_graph, as continuous batching with graphs does, and update it in place between replays. @0z5a confirmed that this makes capture succeed on 4.57.6.
- Hybrid models need a mask per attention type. That stays with #8602, so this fix covers standard full-attention models.
#8602 also includes this change, but it's a large PR that will take a while to merge, and this fix is outside its kernel injection scope. So I plan to open a small standalone PR.
The PR needs a test on a real model with SDPA that runs on 4.57.x, since the current CI setup doesn't exercise this path on that version.