vllm.models.deepseek_v41.amd.akr_eplb_plan
¶
Expert placement planner for kernel_config.amd_kernels.expert_perm
(DeepSeek-V4.1 MegaMoE experts on EP8). CPU only; not used at runtime.
Input: the routed-expert counts of a serving run, expert_counts_dp<r>.npz of
every DP rank (VLLM_AKR_EXPERT_COUNTS=<dir>, akr_expert_counts) or any
npz with the same counts_decode, counts_prefill, layer_ids (and
draft_*) arrays; several files are summed. Output: a plan file that
akr_eplb.Plan loads.
Per layer, with V[k, e] the normalised load of logical expert e under
objective k (2d: decode-only and prefill-carrying steps as two objectives,
all: their sum, decode: decode steps only):
- Replicas: every expert gets one slot; each of the
ep * S - Eextra slots goes to the expert with the largest per-replica loadmax_k V[k, e] / nrep[e], at most one replica per rank (ties: lower expert id). - Placement: replicas in descending per-replica load (longest processing time
first), each to the rank with a free slot and no replica of that expert
that minimises
max_k (load[rank, k] + V[k, e] / nrep[e])(ties: smaller sum, lower rank). - Slots within a rank are sorted by logical id; slot
plives on rankp // S.
The planner assumes that an expert's load splits evenly over its replicas,
which the runtime's per-route hash does on average. The shipped
configs/expert_plan_S49.npz is
--slots 49 --mode 2d --draft-mode all (draft slots 17) on the counts of
tests/models/deepseek_v41/amd/data/expert_counts_agentx_c1024.npz.
Usage
python -m vllm.models.deepseek_v41.amd.akr_eplb_plan \ --counts
Functions:
-
default_draft_slots–Draft slots that follow the backbone's: one more per 3 extra.
-
load_counts–Sum the count arrays of the given files (directories: their
-
make_plan–The plan arrays (format of
akr_eplb.Plan) for summed counts. -
objectives–One layer's normalised objectives
V [K, E]. -
place–phys2log [RANKS * slots]of the replicas (steps 2 and 3). -
plan_layers–phys2log [L, RANKS * slots]for the layers' counts[L, E]. -
rank_imbalance–Max over mean of the per-rank load when each expert's
loadsplits -
replicate–Replica count per expert for
n_slotsslots (step 1). -
report–Rank load max/mean of the identity placement and of
plan, on the -
step_imbalance–Mean per-step rank max/mean:
stepsbatches oftokenstokens per
default_draft_slots(slots)
¶
Draft slots that follow the backbone's: one more per 3 extra.
load_counts(paths)
¶
Sum the count arrays of the given files (directories: their
expert_counts_dp*.npz).
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
make_plan(counts, slots, mode='2d', draft_slots=None, draft_mode='all')
¶
The plan arrays (format of akr_eplb.Plan) for summed counts.
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
objectives(decode, prefill, mode)
¶
One layer's normalised objectives V [K, E].
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
place(V, nrep, slots)
¶
phys2log [RANKS * slots] of the replicas (steps 2 and 3).
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
plan_layers(decode, prefill, slots, mode)
¶
phys2log [L, RANKS * slots] for the layers' counts [L, E].
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
rank_imbalance(load, phys2log)
¶
Max over mean of the per-rank load when each expert's load splits
evenly over its replicas.
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
replicate(V, n_slots)
¶
Replica count per expert for n_slots slots (step 1).
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
report(counts, plan, steps, tokens, seed)
¶
Rank load max/mean of the identity placement and of plan, on the
aggregate counts and (steps > 0) on simulated decode steps.
Source code in vllm/models/deepseek_v41/amd/akr_eplb_plan.py
step_imbalance(load, phys2log, layer, tokens, topk, steps, rng)
¶
Mean per-step rank max/mean: steps batches of tokens tokens per
rank drawn from the popularity load, each route sent to the replica the
runtime's hash picks.