Skip to content

[Misc] Consolidate LRUCache implementations #15481

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 8 commits into from
Mar 27, 2025

Conversation

Avabowler
Copy link
Contributor

@Avabowler Avabowler commented Mar 25, 2025

Fix #14927

To unify the functionality of different LRUCache implementations, I designed vllm.utils.LRUCache based on cachetools.LRUCache, incorporating the following features:

  • Implemented function to compute the size for each item using the interfaces provided by cachetools.LRUCache.
  • Reimplemented the feature to pin specific entries in the cache.
  • Reimplemented the custom callback functions when an item is removed.

Notably, cachetools.Cache inherits from collections.abc.MutableMapping, allowing LRUCache to seamlessly integrate into scenarios utilizing cachetools.cached, ensuring thread safety.
I have run tests involving LRUCache in tests/models/multimodal/processing/test_common.py and tests/lora/test_utils.py, all of which passed. However, due to hardware limitations, I only tested the Qwen2-VL-2B-Instruct model in test_common.py and have not verified compatibility with other models.

Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: Bella kira <2374035698@qq.com>
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.

🚀

@mergify mergify bot added the multi-modality Related to multi-modality (#4194) label Mar 25, 2025
Signed-off-by: Bella kira <2374035698@qq.com>
@DarkLight1337
Copy link
Member

Btw you can run pre-commit run --all-files to check mypy locally.

Signed-off-by: Bella kira <2374035698@qq.com>
@Avabowler
Copy link
Contributor Author

Btw you can run pre-commit run --all-files to check mypy locally.

Thanks for your suggestion. However, I found that in my local environment, pre-commit run --all-files reports MyPy errors only on the first run. When I run the command a second time without modifying any code, the errors are no longer reported. Could you provide some help in resolving this problem?

@DarkLight1337
Copy link
Member

I haven't encountered this. Did you stage any changes after you ran the first pre-commit?

@Avabowler
Copy link
Contributor Author

I haven't encountered this. Did you stage any changes after you ran the first pre-commit?

No, so maybe I should stage changes before I run the pre-commit?

@DarkLight1337
Copy link
Member

Normally pre-commit only runs on staged changes while --all-files is supposed to run it on everything (not just staged files), so I'm not really sure...

@DarkLight1337
Copy link
Member

@hmellor any idea?

@hmellor
Copy link
Member

hmellor commented Mar 25, 2025

Sounds like you've got it right @DarkLight1337.


With pre-commit installed with pre-commit install, the hooks will only be run on the staged files. The process goes roughly as follows:

  1. Temporarily stash unstaged files
  2. Run pre-commit on staged files
  3. Pop temporary stash

When running with --all-files it includes unstaged files. Therefore the original behaviour observed by @Avabowler makes sense:

  1. First run fixes the issues
    a. but fails because files were changed
    b. these changed files are unstaged
  2. The second run passes because the first run fixed the issues

@Avabowler
Copy link
Contributor Author

Normally pre-commit only runs on staged changes while --all-files is supposed to run it on everything (not just staged files), so I'm not really sure...

Sounds like you've got it right @DarkLight1337.

With pre-commit installed with pre-commit install, the hooks will only be run on the staged files. The process goes roughly as follows:

  1. Temporarily stash unstaged files
  2. Run pre-commit on staged files
  3. Pop temporary stash

When running with --all-files it includes unstaged files. Therefore the original behaviour observed by @Avabowler makes sense:

  1. First run fixes the issues
    a. but fails because files were changed
    b. these changed files are unstaged
  2. The second run passes because the first run fixed the issues

Thank you for your response, which helped me understand how pre-commit works. I really appreciate it.

@Avabowler
Copy link
Contributor Author

Hi @DarkLight1337 , I have fixed the pre-commit errors and recommitted the code. Could you please help review it?

Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: Bella kira <2374035698@qq.com>
Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks for your effort and patience!

@DarkLight1337 DarkLight1337 enabled auto-merge (squash) March 27, 2025 03:35
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Mar 27, 2025
@DarkLight1337 DarkLight1337 merged commit f4c98b4 into vllm-project:main Mar 27, 2025
33 of 35 checks passed
lengrongfu pushed a commit to lengrongfu/vllm that referenced this pull request Apr 2, 2025
Signed-off-by: Bella kira <2374035698@qq.com>
kylesayrs pushed a commit to neuralmagic/vllm that referenced this pull request Apr 2, 2025
Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
Alex4210987 pushed a commit to LeiWang1999/vllm-bitblas that referenced this pull request Apr 5, 2025
Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: xinyuxiao <xinyuxiao2024@gmail.com>
lulmer pushed a commit to lulmer/vllm that referenced this pull request Apr 7, 2025
Signed-off-by: Bella kira <2374035698@qq.com>
Signed-off-by: Louis Ulmer <ulmerlouis@gmail.com>
nishith-fujitsu pushed a commit to nishith-fujitsu/vllm that referenced this pull request Apr 9, 2025
Signed-off-by: Bella kira <2374035698@qq.com>
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
multi-modality Related to multi-modality (#4194) 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.

[Feature]: Consolidate LRUCache implementations
3 participants