models.types.SparseTransformerWorkload
models.types.SparseTransformerWorkload()Workload representation of a Mixture-of-Experts (MoE) Transformer.
Attributes
| Name | Description |
|---|---|
| effective_compute_parameters | Return the active parameter count executed per token in an MoE model. |
Methods
| Name | Description |
|---|---|
| lower | Separate active-expert compute from total resident MoE weights. |
| sharded_parameter_count | Calculate per-rank MoE parameters separating shared and routed weights. |
lower
models.types.SparseTransformerWorkload.lower(precision=BYTES_FP16)Separate active-expert compute from total resident MoE weights.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| precision | Quantity or str | Bytes per stored element, or a registered format such as ‘fp16’. A byte quantity specifies the width directly; it must be positive. | BYTES_FP16 |
Returns
| Name | Type | Description |
|---|---|---|
| ComputationGraph | Work in FLOPs, resident weight bytes, parameter count, arithmetic intensity in FLOP/byte, and the available layer count. |
Notes
Equation: F = inference_flops if supplied, otherwise 2 * P_active; W = size_in_bytes(precision) uses P_total; I = F / W.
Assumptions: all expert weights remain resident even when only a subset executes for a token. A declared inference_flops value overrides the active-parameter approximation.
Excludes: expert routing, inter-device dispatch, load imbalance, sparse memory fetch efficiency, attention-context work, and KV state.
References
Derivation: multiply parameter count by storage width to obtain weight bytes, then divide the declared or approximated work by those bytes. This is a demand-accounting projection; it does not predict device time.
Examples
>>> from mlsysim.models.types import SparseTransformerWorkload
>>> from mlsysim.core.units import Q_
>>> model = SparseTransformerWorkload(name='MoE', architecture='moe', parameters=Q_(100, 'count'), active_parameters=Q_(25, 'count'), layers=1, experts=4)
>>> graph = model.lower('fp16')
>>> graph.total_ops == 2 * model.active_parameters.magnitude * Q_(1, 'flop')
True
>>> graph.weight_bytes == model.size_in_bytes('fp16')
Truesharded_parameter_count
models.types.SparseTransformerWorkload.sharded_parameter_count(
tp_size=1,
pp_size=1,
ep_size=1,
)Calculate per-rank MoE parameters separating shared and routed weights.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| tp_size | int | Positive tensor-parallel degree splitting shared and expert layers. | 1 |
| pp_size | int | Positive pipeline-parallel degree partitioning layers across stages. | 1 |
| ep_size | int | Positive expert-parallel degree partitioning routed experts only. | 1 |
Returns
| Name | Type | Description |
|---|---|---|
| Quantity | Resident parameter count per (tp_size, pp_size, ep_size) rank in count units. |
Notes
Equation: with E = experts and k = active_experts_per_token, P_shared = max(0, (E * P_active - k * P_total) / (E - k)) when E > k (else P_total), P_routed = P_total - P_shared, and P_rank = P_shared / (tp_size * pp_size) + P_routed / (tp_size * pp_size * ep_size).
Assumptions: P_total = P_shared + P_routed and P_active = P_shared + (k / E) * P_routed. Shared attention, norms, embeddings, and any always-active shared experts are replicated across ep_size and sharded only by tp_size * pp_size; routed experts are partitioned across tp_size * pp_size * ep_size. Synthetic workloads with P_active / P_total < k / E clamp P_shared at zero while conserving P_shared + P_routed = P_total.
Excludes: uneven expert counts when ep_size does not divide E and untied embedding stage imbalance.
References
Lepikhin et al. (2021), “GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding.” https://arxiv.org/abs/2006.16668 (bibliography key: lepikhin2021gshard).
Examples
>>> from mlsysim import Models
>>> moe = Models.Language.Mixtral_8x7B
>>> moe.sharded_parameter_count(ep_size=1) == moe.parameters
True
>>> moe.sharded_parameter_count(ep_size=8) > moe.parameters / 8
True