[PD] Respect sampling_params.max_new_tokens when PD disaggregation is activated#7147
[PD] Respect sampling_params.max_new_tokens when PD disaggregation is activated#7147ShangmingCai wants to merge 1 commit intosgl-project:mainfrom
Conversation
…tivated Signed-off-by: Shangming Cai <caishangming@linux.alibaba.com>
There was a problem hiding this comment.
Summary of Changes
Hello @ShangmingCai, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request fixes a specific issue in the system's handling of max_new_tokens when Prefill/Decode disaggregation is enabled, particularly for requests with a maximum token limit of 1 or less. The core change ensures the system correctly respects the requested output length and reports the accurate finish reason under these conditions.
Highlights
- Bug Fix for
max_new_tokens: I've addressed a bug where the reportedcompletion_tokensandfinish_reasonwere incorrect when Prefill/Decode (PD) disaggregation was active andsampling_params.max_new_tokenswas set to 1 or less. The system was incorrectly generating and reporting two tokens instead of respecting the requested limit. - Respecting Length Constraint: The changes ensure that when in decode disaggregation mode and
max_new_tokens <= 1, the system now correctly stops after the specified number of tokens (usually 1) and sets thefinish_reasonto 'length'. This prevents streaming of extra tokens and ensures accurate output length. - Tokenizer Manager Handling: I've added logic in the tokenizer manager to handle requests that are finished early due to this length constraint in decode disaggregation mode. This prevents unnecessary error logging related to missing request states when the request is intentionally completed.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request aims to fix a bug where sampling_params.max_new_tokens was not correctly respected when PD disaggregation is active, especially for small values of max_new_tokens. The changes involve adjusting the logic in scheduler_output_processor_mixin.py to control token output and correctly set the finish reason, and modifying tokenizer_manager.py to prevent erroneous error logging in early finish scenarios.
My review focuses on ensuring the conditional logic precisely matches the intended scope described in the comments and PR description, clarifying potential discrepancies, suggesting a minor code simplification, and enhancing robustness against a potential runtime error. The changes appear to correctly address the core issue demonstrated in the examples.
ByronHsu
left a comment
There was a problem hiding this comment.
looks a bit hacky. i wonder if we can just skip the first decode step?
Sure. Let's fix this at the source. |
Motivation
This fixes a bug when PD disaggregation is activated and sampling_params.max_new_tokens <= 1
Before:
The
completion_tokensdon't match the length required in the sampling params or in the finish reason.After:
Modifications
The reason behind this is that we get the first token ids from the prefill node and return the first two tokens when the decode instance finishes the first forward pass. We didn't want to cause a weird waiting time and introduce a concept of Time to Second Token, but we still need to respect the
sampling_params.max_new_tokens. This fix is simple by skipping the second token in the streaming output. We should not usereq.check_finished()since it will cause a memory leak when disaggregation PD is on.CC: @ByronHsu @acelyc111 @fzyzcjy @whybeyoung
Checklist