Skip to content

fix(sglang): reject recompute_kv_cache_after_weight_updates=false at setup - #5373

Open
lonexreb wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
lonexreb:fix/3747-sglang-recompute-kv
Open

lonexreb wants to merge 4 commits into
NVIDIA-NeMo:mainfrom
lonexreb:fix/3747-sglang-recompute-kv

Conversation

@lonexreb

@lonexreb lonexreb commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What and why

Every SGLang refit invalidates the KV cache before the weight transfer (_SGLangWeightSynchronizer._refit), whatever async_rl.recompute_kv_cache_after_weight_updates says. A SingleController run with the SGLang backend and the flag set to false therefore got recompute behaviour with no warning (#3747).

Following the issue's second option and the Megatron precedent (MegatronGeneration.validate_settings rejects a flag that disagrees with kv_cache_management_mode), this PR rejects the setting at setup instead of ignoring it:

  • SGLangGeneration.validate_settings raises ValueError when the flag is false. SC setup calls the backend's validate_settings before it builds anything.
  • The pause_generation_mode='in_place' rejection now gives the same reason (in_place keeps KV from the previous weights, and the SGLang refit always recomputes it) instead of calling it "unsafe".
  • docs/guides/single-controller.md: the flag's row says SGLang supports only true.
  • Test: a sglang_recompute_opt_out case in test_invalid_config_fails_before_setup_factories, next to megatron_recompute_mismatch. It fails without the fix.

The default is true (since #3929), and no shipped config or test script sets false with SGLang, so only runs that set false explicitly change: they now fail at setup. Async GRPO v1 already rejects the SGLang backend, so the v1 path is untouched.

Honouring false on SGLang instead (the issue's first option) would need someone who has run SGLang async to confirm that skipping the flush is safe; that can follow as its own change. The vLLM remote-sparse synchronizer has the same defect (#3746) and is left alone here because another contributor has claimed it.

Issues

Closes #3747

Convergence / perf / functionality proof

N/A: only a config combination that was already ignored now raises at setup; the default path and every shipped config behave as before. Locally at 2437f37 (main merged at fdef76c): tests/unit/single_controller/test_setup.py, tests/unit/weight_sync/, and tests/unit/models/generation/sglang/test_sglang_generation.py + test_config.py pass (900 tests); ruff and pyrefly 1.4.0 are clean on the changed files.

Needs upstream changes

None

PR commands and CI
  • CI label, exactly one:
    • CI:Lfast: the default for most PRs. Runs a fast test subset.
    • CI:L1: dependency or container changes (pyproject.toml, uv.lock, Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.
    • CI:docs: docs-only changes. Runs doc tests only.
  • /ok to test <full-commit-sha>: start CI for that commit. Post again after each push.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pa8JdzpuUd2BVbxJ8Anoba

…setup

Every SGLang refit invalidates the KV cache before the weight transfer,
so async_rl.recompute_kv_cache_after_weight_updates=false was silently
ignored on the SingleController path. SGLangGeneration.validate_settings
now rejects it before anything builds, like the Megatron backend does for
its kv_cache_management_mode mismatch. The in_place pause rejection now
gives the same reason.

Closes NVIDIA-NeMo#3747

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pa8JdzpuUd2BVbxJ8Anoba
Signed-off-by: Shubhankar Tripathy <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Nov 22, 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.

@github-actions github-actions Bot added Documentation Improvements or additions to documentation CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Nov 22, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 25, 2026
…pute-kv

Signed-off-by: Shubhankar Tripathy <[email protected]>

# Conflicts:
#	nemo_rl/models/generation/sglang/sglang_generation.py
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) labels Dec 2, 2026
@lonexreb

lonexreb commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@terrykong @youngeunkwon0405 this is the fix for #3747, which terrykong filed and youngeunkwon0405 is assigned. Every SGLang refit flushes the KV cache, so async_rl.recompute_kv_cache_after_weight_updates=false was silently ignored. The fix follows the issue's second option and the Megatron precedent: SGLangGeneration.validate_settings now rejects false at setup. The check sits at the end of main's existing method. The default is true, and no shipped config sets false with SGLang.

I merged main at 2437f37. Could you review and post /ok to test 2437f372d65c5e3c1211bd8d85295eaf4c6ea2e0?

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Dec 3, 2026

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

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) community-request complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:none Cannot change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: SGLang refit ignores recompute_kv_cache_after_weight_updates and rejects in_place pause

3 participants