Repository navigation
Description
Summary
grpo.async_grpo.recompute_kv_cache_after_weight_updates selects between two documented strategies, per the comment in nemo_rl/algorithms/async_utils/trajectory_collector.py:
Invalidate&recompute vLLM caches after the weight updates (in-flight or not) if
recompute_kv_cache_after_weight_updatesis True (AREAL-style implementation). Otherwise, keep using the stale KV caches (Magistral-style implementation).
The default is False — Magistral-style, keep the caches.
VllmRemoteSparseWeightSynchronizer.sync_weights invalidates the KV cache unconditionally, without consulting that setting:
# nemo_rl/weight_sync/vllm_remote_sparse_weight_synchronizer.py:133
if not self._generation.invalidate_kv_cache():
raise RuntimeError(
f"vLLM KV cache invalidation failed before {self._transport} "
"weight update."
)So a run using the remote-sparse transport gets AREAL-style behaviour regardless of what the user configured, with no warning.
Where the setting is and is not honored
grep -rn "invalidate_kv_cache" nemo_rl/ --include=*.py gives four call sites:
| call site | gated on the setting? |
|---|---|
nemo_rl/algorithms/single_controller.py:1015 |
✅ yes, :1014 |
nemo_rl/algorithms/async_utils/trajectory_collector.py:603 |
✅ yes, :598 |
nemo_rl/weight_sync/vllm_remote_sparse_weight_synchronizer.py:133 |
❌ no |
nemo_rl/weight_sync/sglang_weight_synchronizer.py:161 |
❌ no — see the companion issue |
The pattern is clean: both orchestrator-level call sites honor the setting; both synchronizer-level call sites ignore it.
For contrast, the Megatron generation backend does honor it — nemo_rl/algorithms/grpo.py:1080 translates it into mcore_generation_config.kv_cache_management_mode = "recompute", and TRT-LLM reads it directly at nemo_rl/models/generation/trtllm/trtllm_generation.py:471.
Question rather than assertion
It is possible this is deliberate and the sparse transport genuinely requires invalidation — a partial or delta weight update could leave KV entries inconsistent in a way a full refit does not. If so, that is worth stating.
But it should then reject the non-default value rather than silently overriding it, so a user who sets recompute_kv_cache_after_weight_updates: false learns their setting does not apply on this transport. Right now the config says one thing and the code does another.
Suggested resolution, either way
- If the setting should apply: gate the call, matching
trajectory_collector.py:598. - If invalidation is required by the transport: keep it, add a comment saying why, and raise at setup when
recompute_kv_cache_after_weight_updatesisFalsetogether with this transport.
Related
- Companion issue for the same defect on the SGLang refit path (filed alongside this one)
- The setting is defined at
nemo_rl/algorithms/grpo.py:196and mirrored atnemo_rl/algorithms/single_controller_utils/config.py:188
Activity
terrykong commentedon Aug 21, 2026
Companion issue for the same defect on the SGLang refit path: #3747
ajing commentedon Aug 24, 2026
Hi, I'd like to work on this. I traced both async call paths on current
main:AsyncTrajectoryCollector.resume_after_refit()already invalidates after the update only whenrecompute_kv_cache_after_weight_updatesis true._sync_weights()applies the same config-gated, post-update invalidation.The remote-sparse synchronizer currently invalidates before every transfer regardless of that setting. That makes the
false/Magistral-style path impossible, and thetruepath invalidates twice.I have a small local patch that removes cache-policy ownership from
VllmRemoteSparseWeightSynchronizerand leaves invalidation to those orchestrators, keeping the synchronizer as a pure weight mover. The focused unit suite passes (17 tests), along with Ruff and format checks.Before opening the PR, could a maintainer confirm that the S3/ZeroMQ sparse transports have no hidden requirement to pre-invalidate the cache? If they do, I can instead pass the config into the synchronizer and gate it explicitly, but the orchestrator-owned version avoids duplicate invalidation and matches the other weight-synchronizer boundaries.