8
9
import vllm.envs as envs
10
from vllm.config import ParallelConfig
11
-from vllm.distributed import get_dp_group, get_tensor_model_parallel_rank
11
+from vllm.distributed import (
12
+ get_dp_group,
13
+ get_pcp_group,
14
+ get_tensor_model_parallel_rank,
15
+)
16
from vllm.logger import init_logger
17
from vllm.model_executor.layers.quantization.utils.ocp_mx_utils import (
18
OCP_MX_DTYPES,
688
@dataclass
689
class FusedMoEParallelConfig:
690
tp_size: int
691
+ pcp_size: int
692
dp_size: int
693
ep_size: int
694
tp_rank: int
695
+ pcp_rank: int
696
dp_rank: int
697
ep_rank: int
698
719
return self.use_all2all_kernels and self.all2all_backend == "deepep_low_latency"
720
721
@staticmethod
716
- def flatten_tp_across_dp(
717
- tp_size: int, dp_size: int, dp_rank: int
722
+ def flatten_tp_across_dp_and_pcp(
723
+ tp_size: int, dp_size: int, dp_rank: int, pcp_size: int, pcp_rank: int
724
) -> tuple[int, int]:
725
tp_rank = 0 if tp_size == 1 else get_tensor_model_parallel_rank()
720
- # There are actually dp_size * tp_size devices. Update tp_size
721
- # and tp_rank so we shard across all devices.
722
- flatten_tp_size = dp_size * tp_size
723
- flatten_tp_rank = dp_rank * tp_size + tp_rank
726
+ # There are actually dp_size * pcp_size * tp_size devices.
727
+ # Update tp_size and tp_rank so we shard across all devices.
728
+ flatten_tp_size = dp_size * pcp_size * tp_size
729
+ flatten_tp_rank = dp_rank * pcp_size * tp_size + pcp_rank * tp_size + tp_rank
730
return flatten_tp_size, flatten_tp_rank
731
732
@staticmethod
733
def make(
728
- tp_size_: int, dp_size_: int, vllm_parallel_config: ParallelConfig
734
+ tp_size_: int,
735
+ pcp_size_: int,
736
+ dp_size_: int,
737
+ vllm_parallel_config: ParallelConfig,
738
) -> "FusedMoEParallelConfig":
739
"""
740
Determine MoE parallel configuration. Based on the input `tp_size_`,
743
744
Args:
745
tp_size_ (int): `tp_size` passed into the FusedMoE constructor.
746
+ pcp_size_ (int): `pcp_size` passed into the FusedMoE constructor.
747
dp_size_ (int): `dp_size` passed into the FusedMoE constructor.
748
vllm_parallel_config (ParallelConfig): vLLM's parallel config
749
object which contains the `enable_expert_parallel` flag.
750
751
Examples:
752
When there is no parallelism requested,
743
- i.e. `tp_size_` = `dp_size_` = 1, we simply return the sizes
753
+ i.e. `tp_size_` = `pcp_size_` = `dp_size_` = 1, we simply return the sizes
754
unaltered and the ranks set to 0.
755
746
- Expert Parallelism is considered only when either `dp_size_` or
756
+ Expert Parallelism is considered only when either `dp_size_`, `pcp_size_` or
757
`tp_size_` is non trivial.
758
749
- When TP = 2, DP = 1 and EP = False, the configuration on different
759
+ Note that PCP serves the same function as DP here.
760
+
761
+ When TP = 2, DP(PCP) = 1 and EP = False, the configuration on different
762
devices:
763
764
- device 0 : TP = {2, 0} DP = {1, 0} EP = {1, 0} //
766
- device 1 : TP = {2, 1} DP = {1, 0} EP = {1, 0}
767
- Comment : Tensors are sharded across 2 devices.
768
757
- When TP = 1, DP = 2 and EP = False, the configuration on different
769
+ When TP = 1, DP(PCP) = 2 and EP = False, the configuration on different
770
devices:
771
772
- device 0 : TP = {2, 0} DP = {2, 0} EP = {1, 0}
774
- Comment: There are 2 engine instances and the tensors are sharded
775
across 2 decvices.
776
765
- When TP = 2, DP = 2 and EP = False, the configuration on different
777
+ When TP = 2, DP(PCP) = 2 and EP = False, the configuration on different
778
devices:
779
780
- device 0: TP = {4, 0} DP = {2, 0} EP = {1, 0}
784
- Comment: There are 2 engine instances and the tensors are sharded
785
across 4 devices.
786
775
- When, TP = 2, DP = 1 and EP = True, the configuration on different
787
+ When, TP = 2, DP(PCP) = 1 and EP = True, the configuration on different
788
devices:
789
790
- device 0: TP = {1, 0} DP = {1, 0} EP = {2, 0}
791
- device 1: TP = {1, 0} DP = {1, 0} EP = {2, 1}
792
- Comment: The experts are split between the 2 devices.
793
782
- When, TP = 1, DP = 2 and EP = True, the configuration on different
794
+ When, TP = 1, DP(PCP) = 2 and EP = True, the configuration on different
795
devices:
796
797
- device 0: TP = {1, 0} DP = {2, 0} EP = {2, 0}
799
- Comment: There are 2 engine instances and the experts are split
800
between the 2 devices.
801
790
- When TP = 2, DP = 2 and EP = True, the configuration on different
802
+ When TP = 2, DP(PCP) = 2 and EP = True, the configuration on different
803
devices:
804
805
- device 0: TP = {1, 0} DP = {2, 0} EP = {4, 0}
810
between the 4 devices.
811
"""
812
801
- use_ep = dp_size_ * tp_size_ > 1 and vllm_parallel_config.enable_expert_parallel
813
+ use_ep = (
814
+ dp_size_ * pcp_size_ * tp_size_ > 1
815
+ and vllm_parallel_config.enable_expert_parallel
816
+ )
817
818
dp_size = dp_size_
819
dp_rank = get_dp_group().rank_in_group if dp_size > 1 else 0
805
- tp_size, tp_rank = FusedMoEParallelConfig.flatten_tp_across_dp(
806
- tp_size_, dp_size_, dp_rank
820
+ pcp_size = pcp_size_
821
+ pcp_rank = get_pcp_group().rank_in_group if pcp_size > 1 else 0
822
+ tp_size, tp_rank = FusedMoEParallelConfig.flatten_tp_across_dp_and_pcp(
823
+ tp_size_, dp_size_, dp_rank, pcp_size_, pcp_rank
824
)
825
826
if not use_ep:
827
return FusedMoEParallelConfig(
828
tp_size=tp_size,
829
tp_rank=tp_rank,
830
+ pcp_size=pcp_size,
831
+ pcp_rank=pcp_rank,
832
dp_size=dp_size,
833
dp_rank=dp_rank,
834
ep_size=1,
845
return FusedMoEParallelConfig(
846
tp_size=1,
847
tp_rank=0,
848
+ pcp_size=pcp_size,
849
+ pcp_rank=pcp_rank,
850
dp_size=dp_size,
851
dp_rank=dp_rank,
852
ep_size=ep_size,