Skip to content

[Fix] cuda_graph: Disable full prefill CUDA graph for hybrid linear attention models (#48593) - #48680

Open
somuai wants to merge 1 commit into
sgl-project:mainfrom
somuai:fix-hybrid-linear-full-prefill-cudagraph-crash
Open

somuai wants to merge 1 commit into
sgl-project:mainfrom
somuai:fix-hybrid-linear-full-prefill-cudagraph-crash

Conversation

@somuai

@somuai somuai commented Nov 5, 2026 •

Copy link
Copy Markdown

Motivation

Fixes #48593

When attempting to capture full prefill CUDA graphs (--cuda-graph-config '{"prefill": {"backend": "full"}}') for hybrid linear attention models (e.g., Mamba2, GDN, KDA, NemotronH, GraniteMoe), the engine crashes during capture initialization with:

IndexError: list index out of range
  in HybridLinearAttnBackend._replay_metadata:
    indices = self.state_indices_list[bs - 1]

Root Cause

  1. In cuda_graph_setup.py, PrefillCudaGraphRunner runs capture() before DecodeCudaGraphRunner is constructed.
  2. self.state_indices_list is only allocated and populated inside init_cuda_graph_state(), which is called exclusively by DecodeCudaGraphRunner. PrefillCudaGraphRunner never calls init_cuda_graph_state().
  3. In python/sglang/srt/arg_groups/cuda_graph_hook.py, disable_full_prefill_cudagraph_if_incompatible() had an empty rule list (rules = []), so hybrid linear attention models were never filtered out during configuration compatibility resolution.
  4. If an operator explicitly passed --cuda-graph-config '{"prefill": {"backend": "full"}}', validate_cuda_graph_config() did not check architecture compatibility.

Modifications

  1. python/sglang/srt/arg_groups/cuda_graph_hook.py:
    • Populated disable_full_prefill_cudagraph_if_incompatible() to check mambaish_config(model_config_of(server_args)). When detected during compatibility resolution, it logs a warning and disables the prefill CUDA graph.
    • Added validation in validate_cuda_graph_config(): if an operator explicitly locks full prefill CUDA graph on a hybrid linear attention model, it raises a descriptive ValueError before engine capture begins.
  2. python/sglang/srt/layers/attention/hybrid_linear_attn_backend.py:
    • Added a defensive guard in _replay_metadata() to verify state_indices_list bounds, raising an explicit RuntimeError if an uninitialized replay is ever invoked.
  3. test/registered/unit/server_args/test_server_args.py:
    • Added TestHybridLinearPrefillCudaGraphPolicy covering:
      • Automatic disabling of full prefill CUDA graph for hybrid linear architectures.
      • Preservation of full prefill CUDA graph for standard non-hybrid architectures (e.g. Llama).
      • Validation rejection when full prefill CUDA graph is explicitly locked on hybrid models.

Accuracy Tests

N/A: Configuration validation and runtime defensive bounds checks; no alterations to model tensor outputs or numeric kernels.

Speed Tests and Profiling

N/A: Prevents initialization crash during full prefill CUDA graph capture.

Checklist

  • Format your code according to the Format code with pre-commit.
  • Add unit tests according to the Run and add unit tests.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ❌ Run #42066902800
Latest PR Test (Extra): ❌ Run #42066902358
Latest PR Test (AMD ROCm 10): ❌ Run #42066902499

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Full prefill CUDA graph capture fails for hybrid linear attention models (IndexError in HybridLinearAttnBackend._replay_metadata)

1 participant