-
Notifications
You must be signed in to change notification settings - Fork 442
feat: vllm Model diagnostic test checking long generation quality #516
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
857eb02
Create 2.long_generation_decode_vs_prefill.py test
vegaluisjose e40b1d3
Change threshold value
vegaluisjose bc99af4
Update adding-new-models.md
vegaluisjose 92a4e05
Update docs/adding-new-models.md
terrykong d830723
fixed formatting in test
vegaluisjose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tools/model_diagnostics/2.long_generation_decode_vs_prefill.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import torch | ||
| import argparse | ||
| from vllm import LLM, SamplingParams | ||
|
|
||
|
|
||
| def extract_logprobs(logprobs): | ||
| output = [] | ||
| for lp in logprobs: | ||
| if lp is not None: | ||
| output.append(list(lp.values())[0].logprob) | ||
| return output | ||
|
|
||
|
|
||
| def calculate_error(a, b): | ||
| return torch.exp(torch.abs(a - b)).mean().item() | ||
|
|
||
|
|
||
| def main(): | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--model", type=str, nargs="?", default="nvidia/Nemotron-H-8B-Base-8K" | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| seed = 0 | ||
|
|
||
| sampling_params = SamplingParams( | ||
| temperature=1.0, | ||
| top_p=1.0, | ||
| max_tokens=8192, | ||
| prompt_logprobs=0, | ||
| logprobs=0, | ||
| seed=seed, | ||
| ) | ||
|
|
||
| # Examples as of 0.9.1 | ||
| # model="meta-llama/Meta-Llama-3-8B", # pass | ||
| # model="nvidia/Nemotron-H-8B-Base-8K", # fail | ||
| # model="ibm-ai-platform/Bamba-9B-v1", # pass | ||
| llm = LLM( | ||
| model=args.model, | ||
| enforce_eager=True, | ||
| trust_remote_code=True, | ||
| enable_prefix_caching=False, | ||
| enable_chunked_prefill=False, | ||
| tensor_parallel_size=2, | ||
| gpu_memory_utilization=0.8, | ||
| seed=seed, | ||
| ) | ||
|
|
||
| num_batches = 2 | ||
|
|
||
| prompts = [ | ||
| "Hello, my name is", | ||
| "The president of the United States is", | ||
| "The capital of France is", | ||
| "The future of AI is", | ||
| ] | ||
|
|
||
| outputs = llm.generate(prompts * num_batches, sampling_params) | ||
|
|
||
| for i, output in enumerate(outputs): | ||
|
|
||
| sequence = output.prompt_token_ids + list(output.outputs[0].token_ids) | ||
| prompt_logprobs = extract_logprobs(output.prompt_logprobs) | ||
| logprobs = extract_logprobs(output.outputs[0].logprobs) | ||
| decode_lp = prompt_logprobs + logprobs | ||
| decode_lp = torch.tensor(decode_lp) | ||
|
|
||
| sampling_params = SamplingParams( | ||
| temperature=0.0, max_tokens=1, prompt_logprobs=0 | ||
| ) | ||
| score = llm.generate({"prompt_token_ids": sequence}, sampling_params) | ||
|
|
||
| prefill_lp = extract_logprobs(score[0].prompt_logprobs) | ||
| prefill_lp = torch.tensor(prefill_lp) | ||
|
|
||
| lp_error = calculate_error(decode_lp, prefill_lp) | ||
| max_abs_error = torch.abs(decode_lp - prefill_lp).max().item() | ||
| print( | ||
| f"Processed sequence length {len(sequence)} with lp error {lp_error} and max abs error {max_abs_error}" | ||
| ) | ||
| assert ( | ||
| lp_error < 1.05 | ||
| ), f"lp error is higher than expected (1.0636): {lp_error}" | ||
|
|
||
| print(f"[{args.model}] ALL GOOD!") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.