fix pp partition unbalanced#6666
Conversation
There was a problem hiding this comment.
Hello @zhjc1124, 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!
Summary of Changes
Hello everyone, Gemini here with a summary of this pull request. This PR addresses an issue where the pipeline partitioning logic in SGLang could result in an unbalanced distribution of layers across partitions, particularly leaving a large remainder on the last rank. The changes implement a new strategy, adapted from vLLM, to distribute the remaining layers more evenly across the partitions, aiming for better load balancing.
Highlights
- Fix Unbalanced Pipeline Partitioning: The primary goal is to improve the distribution of hidden layers across pipeline parallel partitions, preventing the last partition from receiving a disproportionately large number of layers when the total number of layers is not perfectly divisible by the number of partitions.
- Adopt vLLM Partitioning Logic: The PR replaces the existing layer partitioning logic with an approach adapted from vLLM, which distributes remaining layers more evenly, specifically avoiding the last partition and potentially distributing across middle partitions for better balance.
- Updated
get_pp_indicesFunction: The core changes are within theget_pp_indicesfunction inpython/sglang/srt/distributed/utils.py, including an updated docstring explaining the new distribution strategy and the revised calculation for layer start and end indices.
Changelog
- python/sglang/srt/distributed/utils.py
- Updated docstring for
get_pp_indicesto explain the new layer distribution strategy, noting its adaptation from vLLM. - Replaced the logic for calculating layer start and end indices when
SGLANG_PP_LAYER_PARTITIONis not set. - Implemented a new algorithm to distribute remaining layers more evenly across partitions, rather than assigning all to the last partition.
- Added a logger info message to indicate when uneven partitioning occurs and how it was handled.
- Moved the final calculation of
start_layerandend_layeroutside the conditional block, using the calculatedpartitionslist.
- Updated docstring for
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.
Layers split with care,
No more heavy load for one,
Balance in the code.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini 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 unbalanced pipeline parallelism (PP) partitions by adapting the get_pp_indices function, drawing inspiration from vLLM's approach. The core logic change effectively distributes remainder layers more evenly than the previous implementation, which assigned all remainders to the last rank. The updated code appears correct and handles edge cases like pp_size=1 and remaining_layers=0 properly.
The main improvement opportunity is to add specific unit tests for the get_pp_indices function to ensure its correctness across various configurations of num_hidden_layers and pp_size, and to prevent regressions.
Summary of Findings
- Missing Unit Tests: The core logic for
get_pp_indiceshas been significantly updated to improve partition balancing. However, new unit tests specifically for this function are missing, as indicated by the PR checklist. Adding these tests is crucial to verify correctness across various scenarios and prevent regressions.
Merge Readiness
The code changes for improving pipeline partition balance are well-implemented and address the described issue effectively. The primary recommendation before merging is to add comprehensive unit tests for the get_pp_indices function to ensure its robustness. Once the tests are in place, this PR should be in good shape for merging. As an AI reviewer, I am not authorized to approve pull requests; please ensure other human reviewers approve this change before merging.
#5724
Motivation
The current get_pp_indice function return an unbalanced partition of pipeline partition, because the last rank will contain all remainder layers.
I adapt the new get_pp_indice from vllm.
For example:
Modifications
Checklist