Skip to content

fix(sglang): preserve pause state across tagged memory resumes - #13823

Closed
zeroRains wants to merge 1 commit into
ai-dynamo:mainfrom
zeroRains:pause
Closed

zeroRains wants to merge 1 commit into
ai-dynamo:mainfrom
zeroRains:pause

Conversation

@zeroRains

@zeroRains zeroRains commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Overview:

In the RL rollout weight-update flow, weights and kv_cache are released together before the new weights are transferred. They must be resumed in two ordered calls: weights first, so the new weights can be loaded, and kv_cache second, so its size can be recomputed from the GPU memory remaining after the weight load. This ordering is required by the RL workflow and is not equivalent to one all-tags resume call.

Previously, the first weights resume cleared Dynamo's single boolean pause state. The later kv_cache resume was therefore treated as an idempotent no-op, leaving SGLang's KV cache pages unmapped. The worker could also be re-registered with discovery between the two calls and receive traffic before it was ready, causing the first post-update prefill to fail in a Triton kernel.

co-auther: @gongshaotian

Details:

  • Track released GPU memory regions by tag in SGLangEnginePauseController.
  • Keep the controller paused while any released tag remains unmapped, so a second tagged resume is not swallowed by the handler's idempotency check.
  • Resume generation only after all released tags have been restored.
  • Re-register the worker with discovery only after the final memory region is resumed, preventing routing during the partial-resume window.
  • Add a regression test covering separate weights and kv_cache resumes.

Validation

  • python -m compileall -q components/src/dynamo/sglang/pause.py components/src/dynamo/sglang/request_handlers/handler_base.py components/src/dynamo/sglang/tests/test_sglang_memory_occupation_handlers.py
  • git diff --check
  • Targeted SGLang unit tests were not executable in this environment because the sglang package is not installed; the repository test conftest skips these tests when that dependency is unavailable.
  • Ruff format validation was attempted, but uv could not resolve the uncached ai-dynamo-runtime==1.5.0 dependency with offline package access.

Where should the reviewer start?

@galletas1712

Related Issues

⚠️ This section is required. Choose one path below and delete the other.

🔗 This PR is linked to an issue:

No

🚫 This PR is NOT linked to an issue:

  • Confirmed — no related issue

Open in Devin Review

Summary by CodeRabbit

  • Bug Fixes

    • Improved pause and resume behavior for SGLang generation when GPU memory is released in multiple regions.
    • Generation now remains paused until all released memory regions are restored, preventing premature resumption.
    • Resuming selected memory regions no longer incorrectly reactivates the endpoint before recovery is complete.
  • Tests

    • Added coverage for partial memory restoration and final endpoint reactivation.

@zeroRains
zeroRains requested a review from a team as a code owner August 26, 2026 09:36
@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@zeroRains
zeroRains temporarily deployed to external_collaborator August 26, 2026 09:36 — with GitHub Actions Inactive
@zeroRains
zeroRains temporarily deployed to external_collaborator August 26, 2026 09:36 — with GitHub Actions Inactive
@github-actions github-actions Bot added the fix label Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi zeroRains! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added external-contribution Pull request is from an external contributor backend::sglang Relates to the sglang backend labels Aug 26, 2026
@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4dab26ea-3b24-4948-894a-e36031f2d351

📥 Commits

Reviewing files that changed from the base of the PR and between 27f09d5 and d1b88d6.

📒 Files selected for processing (3)
  • components/src/dynamo/sglang/pause.py
  • components/src/dynamo/sglang/request_handlers/handler_base.py
  • components/src/dynamo/sglang/tests/test_sglang_memory_occupation_handlers.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


Walkthrough

The SGLang pause controller now tracks released GPU memory tags. Partial resumes keep generation paused. The request handler re-registers the endpoint only after all released tags are restored. Tests cover partial and complete tagged resume behavior.

Changes

SGLang memory resume

Layer / File(s) Summary
Track released memory tags
components/src/dynamo/sglang/pause.py
SGLangEnginePauseController tracks released memory regions and remains paused until all released tags are restored.
Complete resume before endpoint registration
components/src/dynamo/sglang/request_handlers/handler_base.py, components/src/dynamo/sglang/tests/test_sglang_memory_occupation_handlers.py
resume_memory_occupation delays endpoint registration and resume-state updates until recovery completes. Tests validate partial tagged resumes and final continuation.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to d1b88

This localized SGLang pause/resume change preserves ordered memory restoration and delays worker re-registration until readiness; no actionable merge-blocking risk remains after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving pause state across separately tagged SGLang memory resumes.
Description check ✅ Passed The description explains the problem, implementation, reviewer focus, validation, and no-related-issue status. It is mostly complete, although the unused linked-issue path remains and the reviewer-sta…
Full details: Description check

Explanation

The description explains the problem, implementation, reviewer focus, validation, and no-related-issue status. It is mostly complete, although the unused linked-issue path remains and the reviewer-start section names a reviewer instead of specific files.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 potential issues.

Open in Devin Review

Comment on lines +74 to +78
self._released_tags -= set(tags) if tags else set(GPU_MEMORY_ALL_TYPES)
if self._released_tags:
# Generation must stay paused until every released region is back.
return True
self._is_paused = False

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.

🔴 Registration failure after resume leaves worker permanently unregistered

Restoring the last released region clears the paused flag before the worker re-registers with discovery. When register_endpoint_instance then fails, the controller is already marked resumed, so a retry short-circuits as "Memory already resumed" (resume_memory_occupation) and never rejoins the routing pool.

Prompt for agents
resume() in components/src/dynamo/sglang/pause.py sets self._is_paused = False as soon as the last released tag is resumed. The handler resume_memory_occupation (handler_base.py) reads pause_controller.is_paused AFTER calling resume() to decide whether to re-register with discovery and call mark_resumed(). Because resume() already cleared _is_paused, if register_endpoint_instance() raises, the controller no longer reports as paused (is_paused False, needs_resume_recovery False), so a retry of resume_memory_occupation returns early with 'Memory already resumed' and the worker is never re-registered — it stays out of the routing pool. This also fails the existing test test_resume_keeps_paused_state_when_register_fails, which requires is_paused to remain True when register fails after a full resume. The original design deliberately left _is_paused set until mark_resumed() (called only after a successful register). Rework so that (a) resume() signals 'all released regions restored' without prematurely clearing the paused state that the handler and retry logic depend on, and (b) the paused/recovery state is only cleared after registration succeeds (i.e. in mark_resumed). One approach: keep _is_paused True until mark_resumed, track completion via _released_tags being empty, and have the handler decide to register based on a dedicated 'fully resumed but not yet re-registered' condition rather than on is_paused becoming False. Ensure both test_partial_resume_waits_for_all_memory_tags and test_resume_keeps_paused_state_when_register_fails pass.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

raise

self._is_paused = True
self._released_tags = set(tags) if tags else set(GPU_MEMORY_ALL_TYPES)

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.

🔍 Empty tags list is treated as all memory types

set(tags) if tags else set(GPU_MEMORY_ALL_TYPES) in pause and resume treats an empty tags=[] identically to None, recording all regions as released. This round-trips only if SGLang also interprets an empty tags list as "all regions"; if SGLang treats [] as "nothing", the controller records regions as released that were not, and is_paused stays stuck True.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

raise

self._is_paused = True
self._released_tags = set(tags) if tags else set(GPU_MEMORY_ALL_TYPES)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Untagged releases record SGLang's full GPU_MEMORY_ALL_TYPES, which includes cuda_graph, so a Dynamo/GMS restore that resumes only weights and kv_cache leaves _released_tags non-empty and the worker never re-registers. Fix: track Dynamo-supported memory tags for GMS or require/resume cuda_graph consistently in the partial-resume flow.

🤖 AI Fix

In components/src/dynamo/sglang/pause.py, update SGLangEnginePauseController.pause and resume to normalize tags is None to Dynamo's supported GMS tag set {"weights", "kv_cache"} instead of GPU_MEMORY_ALL_TYPES, or update the partial resume contract and test_partial_resume_waits_for_all_memory_tags to include cuda_graph in both tracking and final resume.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the Stale label Nov 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed due to inactivity. If you believe this PR is still relevant, please feel free to reopen it with additional context or information.

@github-actions github-actions Bot closed this Nov 19, 2026

This branch was previously deployed

1 inactive deployment
external_collaborator — d1b88d66 Deployed Aug 26, 2026 by zeroRains via ok-to-test #12571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend::sglang Relates to the sglang backend external-contribution Pull request is from an external contributor fix size/M Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant