| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | from abc import ABC, abstractmethod |
| 5 | |
| 6 | import torch |
| 7 | |
| 8 | |
| 9 | class AbstractEplbPolicy(ABC): |
| 10 | @classmethod |
| 11 | @abstractmethod |
| 12 | def rebalance_experts( |
| 13 | cls, |
| 14 | weight: torch.Tensor, |
| 15 | num_replicas: int, |
| 16 | num_groups: int, |
| 17 | num_nodes: int, |
| 18 | num_ranks: int, |
| 19 | old_global_expert_indices: torch.Tensor | None = None, |
| 20 | ) -> torch.Tensor: |
| 21 | """Entry point for expert-parallelism load balancer. |
| 22 | |
| 23 | Args: |
| 24 | weight: [layers, num_logical_experts], the load statistics |
| 25 | for all logical experts |
| 26 | num_replicas: number of physical experts, must be a multiple of |
| 27 | `num_ranks` |
| 28 | num_groups: number of expert groups |
| 29 | num_nodes: number of server nodes |
| 30 | num_ranks: number of ranks, must be a multiple of `num_nodes` |
| 31 | old_global_expert_indices: [layers, num_logical_experts], the old global |
| 32 | expert indices. Used to avoid unnecessary weight copying |
| 33 | for experts moving within one rank. |
| 34 | |
| 35 | Returns: |
| 36 | physical_to_logical_map: [layers, num_replicas], the expert |
| 37 | index of each replica |
| 38 | |
| 39 | """ |
| 40 | raise NotImplementedError |