Skip to content

vllm.distributed.eplb.policy

Modules:

  • abstract –
  • default –

    Expert parallelism load balancer (EPLB) for vLLM.

Classes:

AbstractEplbPolicy

Bases: ABC

Methods:

rebalance_experts(stats, old_global_expert_indices=None) abstractmethod

Entry point for expert-parallelism load balancer.

Parameters:

  • stats

    (EplbStats) –

    Load/topology snapshot with a CPU load tensor. Built-in policies use [layers, num_logical_experts] loads. Policy-specific subclasses may provide additional inputs.

  • old_global_expert_indices

    (Tensor | None, default: None ) –

    [layers, num_replicas], the old global expert indices. Used to avoid unnecessary weight copying for experts moving within one rank.

Returns:

  • physical_to_logical_map ( Tensor ) –

    [layers, num_replicas], the expert index of each replica, on CPU.

DefaultEplbPolicy

Bases: AbstractEplbPolicy

Methods:

balanced_packing(weight, num_packs) classmethod

Pack n weighted objects to m packs, such that each bin contains exactly n/m objects and the weights of all packs are as balanced as possible.

Parameters:

  • weight

    (ndarray) –

    [X, n], the weight of each item

  • num_packs

    (int) –

    number of packs

Returns:

  • pack_index ( ndarray ) –

    [X, n], the pack index of each item

  • rank_in_pack ( ndarray ) –

    [X, n], the rank of the item in the pack

preserve_intragpu_slots(phy2log, num_ranks, old_phy2log) classmethod

Reorder the new mapping per GPU so that experts that remain on the same GPU keep their previous slot positions when possible. Incoming experts to that GPU fill any remaining available slots. This is applied only when the number of GPUs is unchanged and the slots per GPU remain the same between the old and new mappings.

rebalance_experts(stats, old_global_expert_indices=None)

Balance aggregate logical-expert loads and preserve local slots.

rebalance_experts_hierarchical(weight, num_physical_experts, num_groups, num_nodes, num_gpus) classmethod

Parameters weight: [num_moe_layers, num_logical_experts] num_physical_experts: number of physical experts after replication num_groups: number of expert groups num_nodes: number of server nodes, where the intra-node network (e.g, NVLink) is faster num_gpus: number of GPUs, must be a multiple of num_nodes

Returns:

  • phy2log ( ndarray ) –

    [layers, num_replicas], the expert index of each replica

replicate_experts(weight, num_phy) classmethod

Replicate num_log experts to num_phy replicas, such that the maximum load of all replicas is minimized.

Parameters:

  • weight

    (ndarray) –

    [X, num_log]

  • num_phy

    (int) –

    total number of experts after replication

Returns:

  • phy2log ( ndarray ) –

    [X, num_phy], logical expert id of each physical expert

  • logcnt ( ndarray ) –

    [X, num_log], number of replicas for each logical expert

EplbStats dataclass

Load and topology snapshot for one EPLB planning call.

Policies may accept subclasses with additional planning inputs.

Attributes:

global_expert_load_window instance-attribute

Expert load window, converted to CPU before policy invocation. Built-in policies use shape (num_moe_layers, num_logical_experts).

num_gpus instance-attribute

Number of GPUs.

num_groups instance-attribute

Number of expert groups.

num_nodes instance-attribute

Number of nodes.

num_replicas instance-attribute

Number of physical experts.