solvers.MoERoutingModel
solvers.MoERoutingModel()Models first-order MoE routing imbalance and expert-parallel all-to-all cost.
Sparse models decouple memory from compute, but routing is rarely perfectly balanced. This model keeps the abstraction small: a single imbalance factor inflates the effective active experts and the routed-token communication volume. It does not simulate a router or token dispatcher.
Methods
| Name | Description |
|---|---|
| solve | Estimate effective active parameters and optional EP all-to-all latency. |
solve
solvers.MoERoutingModel.solve(
model,
batch_size,
seq_len,
precision='fp16',
ep_size=1,
routing_imbalance_factor=1.0,
fleet=None,
)Estimate effective active parameters and optional EP all-to-all latency.
Single-factor imbalance model: a router that overloads hot experts behaves as if each token activated top_k * routing_imbalance_factor experts (capped at the model’s expert count), inflating active parameters and routed traffic by the same multiplier. The routed payload per step is batch * seq_len * hidden_dim * bytes_per_param * top_k * multiplier bytes, of which the fraction (ep_size - 1) / ep_size crosses ranks (a token’s target expert is local with probability 1/ep_size under uniform placement).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model | SparseTransformerWorkload | MoE workload (experts, active_experts_per_token, hidden_dim, active_parameters). | required |
| batch_size | int | Sequences per step (>= 1). | required |
| seq_len | int | Tokens per sequence (>= 1). | required |
| precision | str | Numerical precision; sets bytes per routed activation element. | 'fp16' |
| ep_size | int | Expert-parallel group size (1 = no expert parallelism, no all-to-all cost). | 1 |
| routing_imbalance_factor | float | >= 1.0; 1.0 is perfectly balanced routing, larger values approximate hot experts. | 1.0 |
| fleet | Fleet | If given (and ep_size > 1), prices the all-to-all exchange over the fleet fabric (bandwidth deflated by oversubscription). | None |
Returns
| Name | Type | Description |
|---|---|---|
| MoERoutingResult | Effective active experts/parameters, the dispatch volume (MB), and the all-to-all latency (ms) when a fleet is provided. |
Notes
Equation: effective experts are min(experts, top_k * imbalance); routed bytes are B * S * H * bytes * effective_experts * (EP-1)/EP. Assumptions: uniform expert placement and one scalar imbalance multiplier applied to both active work and dispatch traffic. Excludes: per-expert queues, token dropping, capacity-factor admission, and measured routing distributions. No fleet means latency is unset, not a zero-cost exchange.
References
Derivation: count hidden-state elements dispatched per token and multiply by the fraction of destinations outside the local expert-parallel rank.
Examples
>>> from mlsysim.models.types import SparseTransformerWorkload
>>> model = SparseTransformerWorkload(name="example", architecture="transformer", parameters=Q_(1000, "count"),
... active_parameters=Q_(250, "count"), experts=4,
... active_experts_per_token=1, layers=1, hidden_dim=16, heads=1)
>>> result = MoERoutingModel().solve(model, batch_size=1, seq_len=8)
>>> result.token_dispatch_bytes.m_as("byte") == 0
True