Skip to content

Dp balancer #991

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Dp balancer #991

wants to merge 7 commits into from

Conversation

shihaobai
Copy link
Collaborator

No description provided.

Copy link

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

Summary of Changes

Hello @shihaobai, 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 significantly enhances the Data Parallelism (DP) request handling by introducing a more intelligent load balancing mechanism. The core change is the implementation of a new DP balancer designed to optimize GPU utilization by distributing requests more evenly across DP ranks, thereby preventing idle resources. This refactoring centralizes the request assignment logic, making the system more robust and efficient in managing concurrent requests in DP mode.

Highlights

  • Enhanced Data Parallelism (DP) Load Balancing: Introduced a new DpBalancerForPd class to intelligently distribute incoming requests across Data Parallel (DP) ranks, aiming to balance batch sizes and prevent GPU resource waste by minimizing idle ranks.
  • Configurable DP Balancer: Added a --dp_balancer command-line argument, allowing users to specify the DP balancing strategy. The default round_robin option now utilizes the new DpBalancerForPd implementation.
  • Centralized Request Assignment Logic: Refactored the DpQueue to delegate the assignment of requests to specific DP ranks to the new dp_balancer. Requests are now temporarily queued and then assigned by the balancer based on the current load across DP ranks during batch generation.
  • Increased Default Concurrency: The default value for the --running_max_req_size argument was increased from 1000 to 2048, potentially accommodating higher throughput and larger concurrent request loads with the improved balancing.
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 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 or fill out our survey 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

  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

@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 introduces a data parallelism (DP) balancer to manage request distribution across DP ranks. The existing round-robin logic is refactored into a RoundRobinDpBalancer class, and a new DpBalancerForPd is added for prefill/decode modes. The main issue is the incorrect balancer selection in the factory function. Additionally, there are some minor issues related to code style and exception handling.

Comment on lines 8 to 11
if args.dp_balancer == "round_robin":
return DpBalancerForPd(dp_size_in_node, inner_queues)
if args.run_mode in ["prefill", "decode"]:
return DpBalancerForPd(dp_size_in_node, inner_queues)

Choose a reason for hiding this comment

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

high

The get_dp_balancer function returns DpBalancerForPd when args.dp_balancer is "round_robin". This seems incorrect as it should return RoundRobinDpBalancer in this case. This could lead to unexpected behavior. Consider swapping the return values for the round_robin case to ensure the correct balancer is used.

Suggested change
if args.dp_balancer == "round_robin":
return DpBalancerForPd(dp_size_in_node, inner_queues)
if args.run_mode in ["prefill", "decode"]:
return DpBalancerForPd(dp_size_in_node, inner_queues)
def get_dp_balancer(args, dp_size_in_node: int, inner_queues: List[BaseQueue]):
if args.dp_balancer == "round_robin":
return RoundRobinDpBalancer(dp_size_in_node, inner_queues)
if args.run_mode in ["prefill", "decode"]:
return DpBalancerForPd(dp_size_in_node, inner_queues)

suggested_dp_index = select_dp_indexes[0]
else:
# if multiple dp ranks have the same minimum load, randomly select one
import random

Choose a reason for hiding this comment

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

medium

The import random statement is located inside the assign_reqs_to_dp method. It's better to move this import statement to the top of the file for better code organization and readability.

Comment on lines +43 to +44
logger.error(f"generate new batch failed: {e}")
raise e

Choose a reason for hiding this comment

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

medium

When an exception occurs during batch generation, using raise e can obscure the original stack trace. Using a bare raise will preserve the original traceback, making debugging easier.

Suggested change
logger.error(f"generate new batch failed: {e}")
raise e
except Exception as e:
logger.error(f"generate new batch failed: {e}")
raise

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