Skip to content

[DSV4] Fix SWA state pool over-allocation by using storage page size instead of model window - #30371

Open
mitu626 wants to merge 10 commits into
sgl-project:mainfrom
mitu626:dsv4_state_pool_size
Open

mitu626 wants to merge 10 commits into
sgl-project:mainfrom
mitu626:dsv4_state_pool_size

Conversation

@mitu626

@mitu626 mitu626 commented Jul 7, 2026

Copy link
Copy Markdown

Motivation

For DeepSeek-V4 models, DSV4PoolConfigurator sizes the c4 compressed-state pool using the model's SWA window (cfg.window_size = 128), while the runtime addresses that same pool
using the pool's SWA storage page size (server_args.page_size = 256). These two values differ by 2x, causing capacity waste.

Modifications

Align the state-pool paging to the SWA storage page size (server_args.page_size), consistent with how DeepSeekV4TokenToKVPool and CompressStatePool address the pool at runtime:

self.swa_storage_page_size = mr.server_args.page_size # 256
c4_state_ratio = self.c4_ring_size / self.swa_storage_page_size
c4_state_pool_size = swa_tokens // self.swa_storage_page_size * self.c4_ring_size

A comment is added to disambiguate this storage page size from the model's SWA window (cfg.window_size / SWA_WINDOW = 128). This is not a correctness bug — the runtime already
divides by 256, so the smaller pool stays within bounds; it purely recovers wasted capacity.

Accuracy Tests

Speed Tests and Profiling

Validated on GB200 with DeepSeek-V4-Flash (TP4 / DP4, default config, mem-fraction-static unconstrained). Expected improvements from the memory-pool sizing logs:

Metric Before After Change
bytes_per_full_token 7705.45 7033.45 −8.7%
full_token 14,211,072 15,568,896 +9.6%
swa 1,421,056 1,556,736 +9.6%
c4 3,552,768 3,892,224 +9.6%
c128 111,024 121,632 +9.6%
c4_state 88,816 48,648 −45%

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 #32143584914
Latest PR Test (Extra): ✅ Run #32143584743

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the PoolConfigurator to size the c4 state pool using the SWA storage page size (server_args.page_size) instead of the model's SWA window size (cfg.window_size), preventing over-allocation. Feedback suggests accessing mr.page_size directly instead of mr.server_args.page_size for consistency, and using the passed page_size parameter inside _compute_dsv4_sizes instead of self.swa_storage_page_size.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/model_executor/pool_configurator.py Outdated
c4_max_total_num_tokens=full_token // (4 * self.c4_shrink_factor),
c128_max_total_num_tokens=full_token // 128,
c4_state_pool_size=swa_tokens // self.swa_page_size * self.c4_ring_size,
c4_state_pool_size=swa_tokens // self.swa_storage_page_size * self.c4_ring_size,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In _compute_dsv4_sizes, the page_size is already passed as an argument to the function. To maintain consistency and ensure correctness if a different page size is used (e.g., during profiling or testing), you should use the passed page_size parameter instead of self.swa_storage_page_size for calculating c4_state_pool_size.

Suggested change
c4_state_pool_size=swa_tokens // self.swa_storage_page_size * self.c4_ring_size,
c4_state_pool_size=swa_tokens // page_size * self.c4_ring_size,

mitu626 and others added 5 commits July 7, 2026 16:43
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
# Conflicts:
#	python/sglang/srt/model_executor/pool_configurator.py
@b8zhong b8zhong mentioned this pull request Aug 5, 2026
41 tasks
Leoyzen added a commit to Leoyzen/sglang that referenced this pull request Aug 8, 2026
…project#32035 sgl-project#33656 sgl-project#32183 sgl-project#33145)

Applied PRs (latest from GitHub):
  sgl-project#33288  Indexer logits OOM fix
  sgl-project#30393  HiCache packed/sidecar draft caches
  sgl-project#31170  DPA prefix_affinity load balancing
  sgl-project#33795  DSpark compact ragged-verify CUDA graph JIT race
  sgl-project#32467  C128 plan-kernel warp barrier
  sgl-project#33865  DSpark x prefill CP unblock
  sgl-project#30371  SWA state pool sizing (storage page)
  sgl-project#33358  FlashMLA norm-rope K-tokens-per-block ILP
  sgl-project#33872  num_draft_tokens clamp + extend_len==0 skip (supersede sgl-project#32183)
  sgl-project#34002  Sidecar backup vacuously-successful fix (replaces sgl-project#33656, with tests)
  sgl-project#33862  Reclaim redundant host mirrors after storage backup
  sgl-project#31315  Avoid repeated Mooncake gets after stale hits
  sgl-project#32327  Q8KV8 sparse MLA prefill backend (flashmla_sparse_q8)
  sgl-project#31668  Fix sidecar pool life-time (use-after-free on prefetch abort)
  sgl-project#31195  TP0 verify-token-budget broadcast (adapted to get_schedule() API)

Dropped (per user request or superseded):
  sgl-project#32771  IndexCache C4 top-k reuse — has bug
  sgl-project#32035  DSpark C128 online compressor — has bug
  sgl-project#33656  Superseded by sgl-project#34002 (same fix + unit tests)
  sgl-project#32183  Superseded by sgl-project#33872 (included in supersede PR)
  sgl-project#33145  Base f01f706 already has superior reasoning-effort profile system

Conflicts resolved:
  sgl-project#31195: adapted to base get_schedule().disable_overlap_schedule API
  sgl-project#32327: path remapped jit_kernel/ -> kernels/jit/ and kernels/ops/attention/
  sgl-project#31668: applied cleanly on top of sgl-project#30393+sgl-project#34002+sgl-project#33862 modifications
@ispobock

Copy link
Copy Markdown
Collaborator

@mitu626 please fix the lint issue

ispobock

This comment was marked as duplicate.

@ispobock ispobock 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.

can merge after lint fixed and ci passed

@ispobock

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@ispobock ispobock 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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants