Skip to content

[Feature] Add graceful scheduler shutdown; free hisparse host buffer on exit - #28779

Merged
hnyls2002 merged 6 commits into
mainfrom
lsyin/hisparse-graceful-teardown
Jun 21, 2026
Merged

hnyls2002 merged 6 commits into
mainfrom
lsyin/hisparse-graceful-teardown

Conversation

@hnyls2002

@hnyls2002 hnyls2002 commented Jun 20, 2026 •

Copy link
Copy Markdown
Collaborator

The scheduler previously had no graceful-shutdown path — it was always SIGKILL'd, so its resources were reclaimed by the kernel. This adds a ShutdownReq control message that breaks the event loop (broadcast across TP ranks, so they stop in lockstep) and releases resources in userspace via a release_host_resources hook before exit.

The first consumer unregisters HiSparse's large pinned host KV buffer (cudaHostRegister'd, many GB per rank), whose kernel-side unpin on SIGKILL was stalling process teardown for tens of seconds (uninterruptible sleep).


CI States

Latest PR Test (Base): 🚫 Run #27918296308
Latest PR Test (Extra): ❌ Run #27918296249

@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 implements a graceful shutdown mechanism to release pinned host KV buffers (such as those used by HiSparse) in userspace, preventing process teardown from stalling in uninterruptible sleep during kernel reclaim. Key changes include adding explicit unregistration methods, handling SIGTERM in the scheduler process, and updating process termination utilities to support graceful timeouts. However, two critical issues were identified in the review: first, an undefined helper function _still_holding_resources in kill_process_tree will cause a NameError at runtime, which can be resolved by using psutil.wait_procs; second, due to PEP 475, the SIGTERM handler needs to raise SystemExit(0) to successfully interrupt blocking socket/pipe reads and trigger the cleanup block.

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/utils/common.py Resolved
Comment thread python/sglang/srt/managers/scheduler.py Resolved
@hnyls2002

hnyls2002 commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_dsa_glm5_hisparse.py
(2 tries)

@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_dsa_glm5_hisparse.py:

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_dsa_glm5_hisparse.py

@hnyls2002 hnyls2002 changed the title [Fix] Release hisparse pinned host KV buffer on graceful shutdown [Feature] Add graceful scheduler shutdown; free hisparse host buffer on exit Jun 21, 2026
@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_dsa_glm5_hisparse.py:

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_dsa_glm5_hisparse.py

…ul-teardown

# Conflicts:
#	python/sglang/srt/mem_cache/memory_pool_host.py
@hnyls2002

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_dsa_glm5_hisparse.py:

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_dsa_glm5_hisparse.py

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 21, 2026
@hnyls2002
hnyls2002 merged commit e6722c7 into main Jun 21, 2026
103 of 151 checks passed
@hnyls2002
hnyls2002 deleted the lsyin/hisparse-graceful-teardown branch June 21, 2026 22:08
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant