Skip to content

Fix padded positions in breakable CUDA Graph attention - #33253

Merged
YAMY1234 merged 3 commits into
sgl-project:mainfrom
YAMY1234:agent/fix-bcg-padded-positions
Aug 5, 2026
Merged

YAMY1234 merged 3 commits into
sgl-project:mainfrom
YAMY1234:agent/fix-bcg-padded-positions

Conversation

@YAMY1234

@YAMY1234 YAMY1234 commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Breakable CUDA Graph pads token buffers to a captured bucket. The attention wrapper already narrows Q/K/V and cache locations to the real token count, but it still passes padded positions to the backend. Decode context parallelism (DCP) uses these positions to determine key-value (KV) ownership, so virtual padded tokens can compete with real tokens for the same physical KV slots and silently corrupt the cache.

Modifications

  • Narrow forward_batch.positions to the real query-token count together with out_cache_loc for the attention call.
  • Restore both tensors on the shared ForwardBatch after the call.
  • Extend the existing Breakable CUDA Graph test to verify the narrowed backend view and restored batch metadata.

Accuracy Tests

The targeted GPU regression was run before and after the change:

  • Before: the attention backend received five padded positions for three real cache locations, and the test failed.
  • After: the backend received only the three real positions. The targeted test passed, and the full TestBreakableCUDAGraphBasic suite passed (9 passed).

An end-to-end matched A/B used Qwen3.5-397B-A17B FP8 with TP16/DCP4, FP8 KV cache, Breakable CUDA Graph prefill, full decode CUDA Graph, GSM8K-128, 8-shot prompting, temperature 0, and max_tokens=16384. The validation stack included #32795 and #32858; the only runtime-code difference between before and after was this PR's four-line positions fix.

Version Runs GSM8K
Before 1 0.875 (112/128)
After 3 0.984375 (126/128) in every run

All four runs completed 128/128 requests with HTTP 200 and no non-200 responses.

Speed Tests and Profiling

Not benchmarked. This correctness fix does not change kernels or CUDA Graph configuration; it creates a tensor view and restores the original reference around the existing attention call.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #30979497752
Latest PR Test (Extra): ❌ Run #30979497576

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@YAMY1234
YAMY1234 marked this pull request as ready for review August 2, 2026 07:47
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@Oasis-Git Oasis-Git added run-ci CI: run the baseline test suite on this PR and removed run-ci CI: run the baseline test suite on this PR labels Aug 3, 2026

@Oasis-Git Oasis-Git left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wait CI for merge

efschu added a commit to efschu/htsglang that referenced this pull request Aug 3, 2026
…ne structurally immune (pinned), even-modulo lane silently dropped the write mask on CUDA (4/6 real rows into foreign slots measured) -> mask decision now raises, narrow/restore helpers cover positions with out_cache_loc, AST ratchet added. Diverges from upstream sgl-project#33253 by design.
@YAMY1234

YAMY1234 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

_unified_attention_with_output_impl now narrows forward_batch.positions
alongside out_cache_loc, but the shared _new_impl_context fake did not
define positions, so the three impl tests raised AttributeError.
@YAMY1234

YAMY1234 commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

TestBreakableCUDAGraphBasic and all NVIDIA CI tests pass.

@YAMY1234
YAMY1234 merged commit 990a446 into sgl-project:main Aug 5, 2026
161 of 176 checks passed
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 16, 2026
…3253)

TestBreakableCUDAGraphBasic and all NVIDIA CI tests pass.
@YAMY1234
YAMY1234 deleted the agent/fix-bcg-padded-positions branch August 25, 2026 16:15
Atituiset pushed a commit to Atituiset/sglang that referenced this pull request Sep 10, 2026
…3253)

TestBreakableCUDAGraphBasic and all NVIDIA CI tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants