Skip to content

Conversation

DarkLight1337
Copy link
Member

@DarkLight1337 DarkLight1337 commented Dec 19, 2024

LRUDictCache and LRUCache are fundamentally the same, so I merged them together. I also improved the existing type annotations to be more precise.

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
@DarkLight1337 DarkLight1337 added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 19, 2024
Copy link

👋 Hi! Thank you for contributing to the vLLM project.
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 do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

Copy link
Collaborator

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Meanwhile I'd like to make sure the logic is the same when pinned items are not used. cc @alexm-neuralmagic

raise RuntimeError("All items are pinned, "
"cannot remove oldest from the cache.")
else:
lru_key = next(iter(self.cache))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since mm hash cache doesn't need the pin logic, could we optimize this function when there's no pinned items? For example

if remove_pinned and self.pinned_items:
    ...
else:
    lru_key = ...

Also I'm wondering whether to use .popitem(last=False) would be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this optimization is somewhat unnecessary, as the first key will be returned if pinned_items is empty. So either way, we will check for the emptiness of pinned_items once.

Copy link
Collaborator

Choose a reason for hiding this comment

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

IIUC in the branch with remove_pinned is False, we iterative an entire cache anyways whatever pinned_items are empty or not?

Copy link
Member Author

Choose a reason for hiding this comment

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

The next() statement only consumes the first item in the generator comprehension, it doesn't consume the generator fully.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah you're right. Miss the point that it's a generator. Should be good then

@DarkLight1337 DarkLight1337 merged commit cdf22af into vllm-project:main Dec 19, 2024
52 checks passed
@DarkLight1337 DarkLight1337 deleted the lru-cache branch December 19, 2024 16:59
mzusman pushed a commit to mzusman/vllm that referenced this pull request Mar 12, 2025
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
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.

2 participants