Skip to content
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

Fix vllm:prompt_tokens_total metric calculation #2869

Merged
merged 5 commits into from
Feb 19, 2024

Conversation

ronensc
Copy link
Contributor

@ronensc ronensc commented Feb 14, 2024

I have identified an issue with the vllm:prompt_tokens_total counter metric when there are multiple prompts in a batch with different token lengths.

The root cause of the problem lies in the metric counting the token length of the longest prompt in the batch multiplied by the number of prompts in the batch (as if the shorter prompts were padded to match the logest).
Code ref:

vllm/vllm/core/scheduler.py

Lines 262 to 263 in 7e45107

num_batched_tokens=len(seq_lens) *
max(seq_lens) if seq_lens else 0,

This PR resolves this issue by accurately counting the tokens of all the prompts in the batch. A simple unit test has been added to validate the correctness of the counter.
Additionally, I have fixed _read_prompts() to read all prompts from a file, rather than the first prompt.

Copy link
Contributor

@NikolaBorisov NikolaBorisov left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -14,11 +14,9 @@


def _read_prompts(filename: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this function has wrong signature. output seems to be List[str]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! fixed.

@NikolaBorisov
Copy link
Contributor

@simon-mo This is small fix for stats. Safe to merge

Copy link
Collaborator

@zhuohan123 zhuohan123 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for your contribution!

@zhuohan123 zhuohan123 merged commit e433c11 into vllm-project:main Feb 19, 2024
17 of 21 checks passed
@ronensc ronensc deleted the fix-counter_prompt_tokens branch February 19, 2024 10:59
@ronensc
Copy link
Contributor Author

ronensc commented Feb 19, 2024

I noticed that the 2nd prompt of prompts/example.txt causes some tests to fail.
https://buildkite.com/vllm/ci/builds/1399#018dc04b-091b-46e8-8ac4-6973f0536b82/51-1384

Possibly related to: #975

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants