-
Notifications
You must be signed in to change notification settings - Fork 903
[EPLB] Display the expert hotness comparison before and after eplb. #6877
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 all commits
Commits
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
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||||
| from multiprocessing import Process, Queue | ||||||||
| from typing import Any | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| import torch | ||||||||
| import torch.distributed as dist | ||||||||
| from vllm.logger import logger | ||||||||
|
|
@@ -60,6 +61,16 @@ def do_update(self): | |||||||
| old_placement = self.global2local(self.old_expert_maps, self.num_local_experts) | ||||||||
| _, _, new_placement = self.calculate_rebalance_experts(load_info, old_placement) | ||||||||
|
|
||||||||
| if self.rank_id == 0: | ||||||||
| hotness = self._calculate_hotness(old_placement, load_info) | ||||||||
| current_mean, current_max = self._compute_imbalance(old_placement, hotness) | ||||||||
| update_mean, update_max = self._compute_imbalance(new_placement, hotness) | ||||||||
| logger.info( | ||||||||
| "[Expert Hotness] Current: mean={:.3f}, max={:.3f}, Updated: mean={:.3f}, max={:.3f}".format( | ||||||||
| current_mean, current_max, update_mean, update_max | ||||||||
| ) | ||||||||
| ) | ||||||||
|
|
||||||||
| if not torch.is_tensor(new_placement): | ||||||||
| new_placement = torch.tensor(new_placement) | ||||||||
| self.check_expert_placement(old_placement, new_placement) | ||||||||
|
|
@@ -251,6 +262,36 @@ def pack_update_info(self, update_info_generator): | |||||||
|
|
||||||||
| return list(zip(send_all, recv_all, maps, log2phy_all, layer_ids)) | ||||||||
|
|
||||||||
| @staticmethod | ||||||||
| def _compute_imbalance(deployment_all_layer, hotness_all_layer: np.ndarray): | ||||||||
| imbalance_list = [] | ||||||||
| deployment_all_layer = np.array(deployment_all_layer) | ||||||||
| for deployment, hotness in zip(deployment_all_layer, hotness_all_layer): | ||||||||
| counts = np.bincount(deployment.reshape(-1), minlength=hotness.shape[0]) | ||||||||
|
|
||||||||
| unit_hotness = np.divide(hotness, counts, out=np.zeros_like(hotness, dtype=float), where=counts != 0) | ||||||||
|
|
||||||||
| stage_load = unit_hotness[deployment].sum(-1) | ||||||||
| stage_par = stage_load.max() / stage_load.mean() | ||||||||
| imbalance_list.append(stage_par) | ||||||||
|
|
||||||||
| max_val = max(imbalance_list) | ||||||||
| mean_val = sum(imbalance_list) / len(imbalance_list) | ||||||||
| return mean_val, max_val | ||||||||
|
|
||||||||
| @staticmethod | ||||||||
| def _calculate_hotness(deployment_all_layer, moe_load_all_layer): | ||||||||
| hotnesses = [] | ||||||||
| num_of_expert = deployment_all_layer.shape[1] * deployment_all_layer.shape[2] | ||||||||
| for deployment, rank_load in zip(deployment_all_layer, moe_load_all_layer.numpy()): | ||||||||
| hotness = np.zeros(num_of_expert, dtype=rank_load.dtype) | ||||||||
| deployment_flat = deployment.ravel() | ||||||||
| rank_load_flat = rank_load.ravel() | ||||||||
| np.add.at(hotness, deployment_flat, rank_load_flat) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||
| hotnesses.append(hotness) | ||||||||
|
|
||||||||
| return np.array(hotnesses) | ||||||||
|
|
||||||||
|
|
||||||||
| class EplbProcess: | ||||||||
| def __init__(self, shared_dict, policy_type: int = 0, enable_d2d: bool = True): | ||||||||
|
|
||||||||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method has several critical issues that can lead to crashes or incorrect calculations:
np.bincountwill raise aValueErrorifdeploymentcontains negative values, which it can for unassigned experts.unit_hotness[deployment]will incorrectly index from the end of the array ifdeploymentcontains-1.stage_load.mean()can be zero, leading to aZeroDivisionErrorwhen calculatingstage_par.deployment_all_layeris empty,imbalance_listwill be empty, causingmax()to raise aValueError.Please refactor this method to handle these edge cases gracefully.