Skip to content

Conversation

@simon-mo
Copy link
Collaborator

@simon-mo simon-mo commented May 1, 2025

V1 never supported this item in request output. so output.num_cached_tokens from LLM.generate is always None. This PR adds support for it.

@github-actions
Copy link

github-actions bot commented May 1, 2025

👋 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 v1 label May 1, 2025
Signed-off-by: simon-mo <[email protected]>
@simon-mo simon-mo enabled auto-merge (squash) May 1, 2025 06:09
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label May 1, 2025
@WoosukKwon
Copy link
Collaborator

One caveat is that num_cached_tokens will be refreshed if the request is preempted and resumed. I think this needs to be documented somewhere.

@simon-mo simon-mo enabled auto-merge (squash) May 8, 2025 17:08
Copy link
Collaborator

@WoosukKwon WoosukKwon left a comment

Choose a reason for hiding this comment

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

btw why do we want to have this feature?

self._all_token_ids: list[int] = self.prompt_token_ids.copy()
self.spec_token_ids: list[int] = []
self.num_computed_tokens = 0
self.num_cached_tokens = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@simon-mo Please add a comment. I think people will be confused between num_computed_tokens and num_cached_tokens otw.

@WoosukKwon WoosukKwon disabled auto-merge May 8, 2025 17:16
@WoosukKwon
Copy link
Collaborator

I think this exposes implementation details to the API, which is not recommended unless we have a clear use case.

Copy link
Collaborator Author

simon-mo commented May 8, 2025

This needs to be piped to the API as part of the protocol here

https://openai.com/index/api-prompt-caching/

Copy link
Collaborator

@WoosukKwon WoosukKwon left a comment

Choose a reason for hiding this comment

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

@simon-mo Oh I see, I didn't know that the prompt caching api had this.

self._all_token_ids: list[int] = self.prompt_token_ids.copy()
self.spec_token_ids: list[int] = []
self.num_computed_tokens = 0
self.num_cached_tokens = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

@simon-mo Please add a comment. I think people will be confused between num_computed_tokens and num_cached_tokens otw.

@mergify
Copy link

mergify bot commented May 12, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @simon-mo.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label May 12, 2025
@WoosukKwon
Copy link
Collaborator

@simon-mo Also, I think we can initialize num_cached_tokens to -1 and update it only once when the request is first scheduled.

@calvin0327
Copy link
Contributor

I didn't notice this fix. I also submitted a PR to address this issue. #18192 😅

@DarkLight1337
Copy link
Member

Closing as superseded by #18149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants