Skip to content

[Config] Make prefix cache metrics interval configurable #19634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jeremyeder
Copy link

Purpose

Resolves TODO left by @comaniac in vllm/v1/metrics/loggers.py:58 - makes the prefix cache metrics interval configurable instead of hardcoded to 1000 requests.

The prefix cache metrics currently use a hardcoded limit of 1000 recent requests to calculate hit rates. This adds a configurable parameter to let users adjust this based on their memory vs stability preferences.

Changes

  • Add prefix_cache_metrics_max_requests to ObservabilityConfig (default: 1000)
  • Add --prefix-cache-metrics-max-requests CLI argument
  • Validate range 1-100000 to prevent excessive memory usage
  • Update LoggingStatLogger to respect the configured value
  • Add comprehensive tests for validation and integration

Higher values give more stable hit rate metrics but use more memory.
Lower values are more memory-efficient but metrics may be noisier.

Test Plan

# Test default behavior (should use 1000)
python -c "from vllm.config import ObservabilityConfig; print(ObservabilityConfig().prefix_cache_metrics_max_requests)"

# Test custom value via config
python -c "from vllm.config import ObservabilityConfig; print(ObservabilityConfig(prefix_cache_metrics_max_requests=2000).prefix_cache_metrics_max_requests)"

# Test validation - should fail
python -c "from vllm.config import ObservabilityConfig; ObservabilityConfig(prefix_cache_metrics_max_requests=0)"

# Test CLI argument (when serving)
vllm serve model_name --prefix-cache-metrics-max-requests=2000

# Run the new tests
pytest tests/test_prefix_cache_metrics_config.py -v

Test Results

Default value (1000): Works correctly, maintains backward compatibility
Custom values: Accepted and properly used by PrefixCachingMetrics
Validation: Invalid values (0, negative, >100000) properly rejected with clear error messages
Integration: LoggingStatLogger correctly uses configured value or falls back to 1000
All tests pass: 3 test functions covering validation, metrics behavior, and end-to-end integration

Example usage: --prefix-cache-metrics-max-requests=2000

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

Copy link
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.

Summary of Changes

Hello @jeremyeder, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a long-standing TODO by making the window size for prefix cache hit rate metrics configurable. This allows users to tune the trade-off between the stability of the reported metrics and the memory overhead required to track recent requests. The change introduces a new configuration parameter and CLI argument, adds validation, and updates the relevant logging component to respect the user's setting.

Highlights

  • Configuration: I've added a new parameter prefix_cache_metrics_max_requests to the ObservabilityConfig dataclass. This parameter controls the number of recent requests used for calculating prefix cache hit rates, defaulting to 1000.
  • CLI Argument: A corresponding command-line argument --prefix-cache-metrics-max-requests has been added to EngineArgs to allow users to configure this setting via the CLI.
  • Validation: I've implemented validation in ObservabilityConfig.__post_init__ to ensure the prefix_cache_metrics_max_requests value is within a reasonable range (1 to 100000) to prevent excessive memory usage.
  • Integration: The LoggingStatLogger has been updated to read the configured prefix_cache_metrics_max_requests from the VllmConfig and pass it to the PrefixCachingMetrics instance, falling back to the default 1000 if no config is provided.
  • Testing: I've added a new test file tests/test_prefix_cache_metrics_config.py with comprehensive tests covering the validation logic, the correct instantiation of PrefixCachingMetrics with the configured value, and the end-to-end integration within LoggingStatLogger.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mergify mergify bot added the v1 label Jun 14, 2025
Copy link
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 effectively introduces configurability for the prefix cache metrics interval, enhancing flexibility for users. The changes are well-implemented across the configuration, argument parsing, and logging components, and are accompanied by comprehensive tests. The code is clear and addresses the TODO appropriately.

I have one minor suggestion to improve the robustness of the default value handling in LoggingStatLogger by referencing the default directly from ObservabilityConfig.

@jeremyeder jeremyeder force-pushed the feat/configurable-prefix-cache-metrics-interval branch from d31f8ca to fb761dc Compare June 14, 2025 02:10
The prefix cache metrics currently use a hardcoded limit of 1000 recent
requests to calculate hit rates. This adds a configurable parameter to
let users adjust this based on their memory vs stability preferences.

- Add prefix_cache_metrics_max_requests to ObservabilityConfig (default: 1000)
- Add --prefix-cache-metrics-max-requests CLI argument
- Validate range 1-100000 to prevent excessive memory usage
- Update LoggingStatLogger to respect the configured value
- Resolves TODO left by @comaniac in vllm/v1/metrics/loggers.py:58

Higher values give more stable hit rate metrics but use more memory.
Lower values are more memory-efficient but metrics may be noisier.

Example: --prefix-cache-metrics-max-requests=2000
Signed-off-by: Jeremy Eder <jeder@redhat.com>
@jeremyeder jeremyeder force-pushed the feat/configurable-prefix-cache-metrics-interval branch from 9826a7b to 2e0a000 Compare June 14, 2025 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant