Skip to content

[BugFix] Fix cache issue in compilation_config#31376

Merged
yewentao256 merged 3 commits intovllm-project:mainfrom
BoyuanFeng:bf/fix-cache-compilation-config
Dec 27, 2025
Merged

[BugFix] Fix cache issue in compilation_config#31376
yewentao256 merged 3 commits intovllm-project:mainfrom
BoyuanFeng:bf/fix-cache-compilation-config

Conversation

@BoyuanFeng
Copy link
Copy Markdown
Collaborator

@BoyuanFeng BoyuanFeng commented Dec 26, 2025

#22204 added get_cached_compilation_config() with @lru_cache(maxsize=1) to cache compilation config access via

@lru_cache(maxsize=1)
def get_cached_compilation_config():
    """Cache config to avoid repeated calls to get_current_vllm_config()"""
    return get_current_vllm_config().compilation_config

Since get_cached_compilation_config() has no argument, it would never be refreshed, unless we explicitly call get_cached_compilation_config.cache_clear().

To refresh the config, #22204 implements get_cached_compilation_config.cache_clear() in set_current_vllm_config.

@contextmanager
def set_current_vllm_config(vllm_config: VllmConfig, check_compile=False, prefix: Optional[str] = None):
    try:
        _current_vllm_config = vllm_config
        _current_prefix = prefix
        yield
   finally:
        _current_vllm_config = old_vllm_config
        _current_prefix = old_prefix
        # Clear the compilation config cache when context changes
        get_cached_compilation_config.cache_clear() # <----- explicitly clear the cache

However, a bug would happen if an old_vllm_config has been accessed and cached before set_current_vllm_config(new_config) is called. In other words

config = old_config
with set_current_vllm_config(new_config):
    # old_config is accessed instead of new_config

This PR fixes the issue by clearing the cache when entering the context manager.

Signed-off-by: Boyuan Feng <boyuan@meta.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

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 addresses a caching bug in get_cached_compilation_config by ensuring the cache is cleared upon entering the set_current_vllm_config context manager. This prevents an old, cached configuration from being used when a new configuration is set. The fix is correct and directly solves the issue described. The added code comment clearly explains the necessity of this change. The implementation is sound, and I have no further recommendations.

Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the work!

Is there any specific issue this PR could solve? (If there is a case that without this PR would cause trouble?)

@yewentao256 yewentao256 added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 26, 2025
@BoyuanFeng
Copy link
Copy Markdown
Collaborator Author

BoyuanFeng commented Dec 26, 2025

@yewentao256 I added a unit test test_cached_compilation_config to show the issue.
tldr: prior to this pr, if I call old_config = get_cached_compilation_config first, and then call with set_current_vllm_config(vllm_config):, the old_config.compilation_config is used within the context manager instead of the new vllm_config.compilation_config.

Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the work!

Copy link
Copy Markdown
Member

@yewentao256 yewentao256 left a comment

Choose a reason for hiding this comment

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

Merge this PR as all CI tests pass

@yewentao256 yewentao256 merged commit 2f12cd3 into vllm-project:main Dec 27, 2025
46 checks passed
akh64bit pushed a commit to akh64bit/vllm that referenced this pull request Dec 28, 2025
yiliu30 pushed a commit to yiliu30/vllm-fork that referenced this pull request Dec 30, 2025
akh64bit pushed a commit to akh64bit/vllm that referenced this pull request Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants