Skip to content

fix pp partition unbalanced#6666

Closed
zhjc1124 wants to merge 6 commits intosgl-project:mainfrom
zhjc1124:unbalanced_pp_fix
Closed

fix pp partition unbalanced#6666
zhjc1124 wants to merge 6 commits intosgl-project:mainfrom
zhjc1124:unbalanced_pp_fix

Conversation

@zhjc1124
Copy link
Copy Markdown
Contributor

@zhjc1124 zhjc1124 commented May 27, 2025

#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:

DeepSeek-R1 num_hidden_layers=61, pp_size=8
Before:
partitions = [7, 7, 7, 7, 7, 7, 7, 12]
After:
partitions = [7, 7, 8, 8, 8, 8, 8, 7]

Modifications

Checklist

@zhjc1124 zhjc1124 requested a review from yizhang2077 as a code owner May 27, 2025 11:02
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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_indices Function: The core changes are within the get_pp_indices function in python/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_indices to 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_PARTITION is 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_layer and end_layer outside the conditional block, using the calculated partitions list.
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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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_indices has 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.

Comment thread python/sglang/srt/distributed/utils.py
@merrymercy merrymercy requested a review from ch-wan as a code owner November 29, 2025 07:06
@zhjc1124 zhjc1124 closed this by deleting the head repository Mar 25, 2026
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.

1 participant