Skip to content

[vllm] fix: reset all caches after weight updates#6522

Open
s-isaev wants to merge 2 commits into
verl-project:mainfrom
s-isaev:fix/vllm-reset-mm-cache-after-weight-update
Open

[vllm] fix: reset all caches after weight updates#6522
s-isaev wants to merge 2 commits into
verl-project:mainfrom
s-isaev:fix/vllm-reset-mm-cache-after-weight-update

Conversation

@s-isaev
Copy link
Copy Markdown

@s-isaev s-isaev commented May 28, 2026

What does this PR do?

This PR resets all available vLLM rollout caches after updating model weights.

Previously, verl only reset the prefix/KV cache after update_weights. For multimodal rollouts, vLLM may also cache multimodal inputs and encoder outputs. Reusing those cached values after a weight update can lead to stale features being used during rollout.

This change adds a clear_all_caches helper on the vLLM HTTP server and calls it after weight updates.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: https://github.com/verl-project/verl/pulls?q=is%3Apr+is%3Aopen+vllm+cache
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

Copy link
Copy Markdown
Contributor

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

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 introduces a clear_all_caches method in vllm_async_server.py to clear KV, multi-modal, and encoder caches, and updates vllm_rollout.py to call this new method instead of only clearing the KV cache after updating weights. Feedback was provided to replace fragile hardcoded vLLM version checks with dynamic hasattr checks to verify the presence of the cache-clearing methods on the engine.

Comment on lines +646 to +650
if self.node_rank == 0:
if _VLLM_VERSION >= version.parse("0.9.0"):
await self.engine.reset_mm_cache()
if _VLLM_VERSION >= version.parse("0.16.0"):
await self.engine.reset_encoder_cache()
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.

high

Using hardcoded version checks like _VLLM_VERSION >= version.parse('0.16.0') is fragile and can lead to bugs. For instance, current vLLM releases are in the 0.7.x range, meaning the check for 0.16.0 will evaluate to False and prevent reset_encoder_cache() from being called even if the installed vLLM version supports it.

A much more robust and idiomatic approach is to dynamically check for the presence of these methods on the engine using hasattr(). This ensures compatibility across different vLLM versions, custom forks, or backported features without relying on hardcoded version strings.

Suggested change
if self.node_rank == 0:
if _VLLM_VERSION >= version.parse("0.9.0"):
await self.engine.reset_mm_cache()
if _VLLM_VERSION >= version.parse("0.16.0"):
await self.engine.reset_encoder_cache()
if self.node_rank == 0:
if hasattr(self.engine, 'reset_mm_cache'):
await self.engine.reset_mm_cache()
if hasattr(self.engine, 'reset_encoder_cache'):
await self.engine.reset_encoder_cache()

@s-isaev s-isaev changed the title [vLLM] Reset all caches after weight updates [vllm] fix: reset all caches after weight updates May 28, 2026
Comment thread verl/workers/rollout/vllm_rollout/vllm_async_server.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants