models.types.Workload
models.types.Workload()Layer A (Workload Demand): Base representation of an ML model or task.
A Workload defines the computational requirements of a task without any knowledge of the hardware it will run on. It must implement lower() to project its architectural definition down into a ComputationGraph.
inference_flops semantics — the unit of work DIFFERS BY MODEL FAMILY (documented 2026-06-06; the field is dimensioned only as flop, so the family convention is the contract):
- Autoregressive LMs (
TransformerWorkloaddecoder-only,SparseTransformerWorkload): FLOPs per generated token, following the 2 x params convention — 2 x TOTAL params for dense models, 2 x ACTIVE params for MoE. - Encoder models (BERT-family): FLOPs per sequence at the reference sequence length recorded in the entry’s provenance (BERT-Base: 22 GFLOP at seq=128).
- Vision / CNN / recommendation models: FLOPs per input (one image / one query forward pass).
NEVER compare inference_flops across families without normalizing — the magnitudes differ by orders of magnitude purely from the work unit.
Attributes
| Name | Description |
|---|---|
| effective_compute_parameters | Return the parameter count active in one forward evaluation. |
Methods
| Name | Description |
|---|---|
| activation_traffic_bytes | Calculate per-sample off-chip activation read/write traffic. |
| lower | Project stored workload facts into a computation graph. |
| sharded_parameter_count | Calculate resident parameters per rank under model parallelism. |
| size_in_bytes | Calculate stored model weights at the requested precision. |
activation_traffic_bytes
models.types.Workload.activation_traffic_bytes(
precision=BYTES_FP16,
tokens_per_sample=1,
ops_multiplier=1,
)Calculate per-sample off-chip activation read/write traffic.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| precision | Quantity or str | Bytes per activation element, or a registered format such as ‘fp16’. | BYTES_FP16 |
| tokens_per_sample | int | Positive token count per sample for sequence architectures. | 1 |
| ops_multiplier | int | Positive pass multiplier (1 for inference, 3 for training, 4 with full activation recomputation). | 1 |
Returns
| Name | Type | Description |
|---|---|---|
| Quantity | Activation bytes transferred per sample in byte units. |
Notes
Equation: A_sample = 0 byte on the generic base workload when no feature-map or hidden-state geometry is declared.
Assumptions: architectural subclasses override this method using their declared tensor dimensions; generic workloads with only parameter counts report zero rather than inventing a fraction of weight bytes.
Excludes: weight traffic, KV-cache reads/writes, and temporary workspace spills; callers with measured activation I/O can pass an explicit override to Engine.solve.
References
Derivation: without layer activation dimensions, off-chip feature-map traffic is undetermined and defaults to zero until a subclass or caller supplies tensor geometry.
Examples
>>> from mlsysim.models.types import Workload
>>> from mlsysim.core.units import Q_
>>> w = Workload(name='Generic', architecture='mlp', parameters=Q_(1000, 'count'))
>>> w.activation_traffic_bytes('fp16') == Q_(0, 'byte')
Truelower
models.types.Workload.lower(precision=BYTES_FP16)Project stored workload facts into a computation graph.
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: W = P * b and I = F / W. F uses inference_flops when supplied; otherwise F = 2 * P. If P is absent but model_size exists, W = model_size, P = 0, and missing FLOPs become zero.
Assumptions: one graph represents the work unit described by the workload family. With parameter count present, this base implementation computes W from P and b rather than preferring model_size. A zero-byte size-only workload has zero arithmetic intensity by convention.
Excludes: activation or cache storage, backward work, hardware efficiency, and precision-dependent operation counts. The 2P fallback is an approximation, not a graph trace.
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 Workload
>>> from mlsysim.core.units import Q_
>>> model = Workload(name='Example', architecture='dense', parameters=Q_(100, 'count'))
>>> graph = model.lower('fp16')
>>> graph.weight_bytes == model.parameters.magnitude * Q_(2, 'byte')
Truesharded_parameter_count
models.types.Workload.sharded_parameter_count(tp_size=1, pp_size=1, ep_size=1)Calculate resident parameters per rank under model parallelism.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| tp_size | int | Positive tensor-parallel degree splitting layers within a stage. | 1 |
| pp_size | int | Positive pipeline-parallel degree partitioning layers across stages. | 1 |
| ep_size | int | Positive expert-parallel degree; must be 1 for dense workloads. | 1 |
Returns
| Name | Type | Description |
|---|---|---|
| Quantity | Parameters stored on one (tp_size, pp_size, ep_size) rank in count units. |
Notes
Equation: P_rank = P / (tp_size * pp_size) when ep_size == 1.
Assumptions: tensor and pipeline parallelism partition dense parameters uniformly across tp_size * pp_size shards. Passing ep_size > 1 on a non-MoE workload raises ValueError.
Excludes: untied embedding imbalance across pipeline stages, padding to tensor-core alignment multiples, and ZeRO data-parallel sharding.
References
Shoeybi et al. (2019), “Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism.” https://arxiv.org/abs/1909.08053 (bibliography key: shoeybi2019megatron).
Examples
>>> from mlsysim import Models
>>> model = Models.Language.Llama3_8B
>>> model.sharded_parameter_count(tp_size=4, pp_size=2) == model.parameters / 8
Truesize_in_bytes
models.types.Workload.size_in_bytes(precision=BYTES_FP16)Calculate stored model weights at the requested precision.
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 |
|---|---|---|
| Quantity | Resident weight size with data units, normally bytes. A supplied model_size retains its original compatible units when returned. |
Notes
Equation: W = P * b when parameter count P is available. A supplied model_size takes precedence at FP16/BF16; if P is missing it is used at every precision because there is no count from which to rescale.
Assumptions: all parameters use one element width. An explicit model_size is an authoritative footprint at the default storage format. Without parameters or model_size, the method raises NotImplementedError.
Excludes: gradients, optimizer states, activations, KV caches, quantization scales, packing alignment, and allocator reserve.
References
Derivation: multiply the number of stored elements by bytes per element. The model_size precedence is an implementation convention for workloads whose stored footprint is known but whose parameter inventory is absent.
Examples
>>> from mlsysim.models.types import Workload
>>> from mlsysim.core.units import Q_
>>> model = Workload(name='Example', architecture='dense', parameters=Q_(100, 'count'))
>>> model.size_in_bytes('fp16') == 2 * model.size_in_bytes('int8')
True