engine.solvers.parallelism
engine.solvers.parallelism
Distributed-training solvers: parallel layouts, ZeRO sharding, data-parallel scale-out, tensor-parallel layer exchanges, and alignment-training state.
Domain implementations behind mlsysim.solvers (the public import path, derived from engine.solvers.__init__). Added 2026-10-20.
Classes
| Name | Description |
|---|---|
| AlignmentMemoryModel | Model state of PPO-style RLHF against DPO, and its split over a model-parallel group. |
| DataParallelScaleOutModel | A data-parallel job inside one node and across nodes, from its one-device profile. |
| ParallelLayoutModel | One training step of a TP x PP x DP layout, read through the Fleet Law. |
| TensorParallelLayerModel | One Transformer layer’s forward compute against its tensor-parallel exchange. |
| ZeroShardingModel | Per-device training state at each ZeRO stage, and what full sharding sends. |
AlignmentMemoryModel
engine.solvers.parallelism.AlignmentMemoryModel()Model state of PPO-style RLHF against DPO, and its split over a model-parallel group.
PPO trains a policy and a value model (16 B per parameter of mixed-precision Adam each) and runs a frozen reference copy of the policy and a reward model forward only (16-bit weights). DPO keeps only the policy and the reference. During rollout the policy also holds a KV cache for every generated sequence.
Methods
| Name | Description |
|---|---|
| solve | Compare PPO and DPO model-state storage. |
solve
engine.solvers.parallelism.AlignmentMemoryModel.solve(
policy,
critic,
tp_size,
pp_size,
rollout_sequences,
rollout_tokens,
device_memory=None,
)Compare PPO and DPO model-state storage.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| policy | TransformerWorkload | Transformer policy supplying parameters and KV-cache geometry. | required |
| critic | Workload | Value/reward workload supplying parameter count. | required |
| tp_size | int | Positive tensor-parallel group size. | required |
| pp_size | int | Positive pipeline stage count. | required |
| rollout_sequences | int | Nonnegative concurrent rollout sequence count. | required |
| rollout_tokens | int | Nonnegative cached tokens per rollout sequence. | required |
| device_memory | Optional[Quantity] | Optional positive memory capacity in bytes for a state-only device-count bound. | None |
Returns
| Name | Type | Description |
|---|---|---|
| AlignmentMemoryResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: PPO = policy_train + reference + reward + value_train; DPO = policy_train + reference; KV is divided by TP PP.
Assumptions: Mixed-precision Adam trainable state and FP16 frozen state; equal model partitions.
Excludes: Training activations, rollout compute, workspace, and deployment feasibility.
References
Derivation: PPO = policy_train + reference + reward + value_train; DPO = policy_train + reference; KV is divided by TP PP. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim import Models
>>> r = AlignmentMemoryModel().solve(Models.Language.Llama3_8B, Models.Language.Llama3_8B, 1, 1, 1, 128)
>>> r.ppo_total > r.dpo_total
TrueDataParallelScaleOutModel
engine.solvers.parallelism.DataParallelScaleOutModel()A data-parallel job inside one node and across nodes, from its one-device profile.
Every update reduces the full gradient with a hierarchical ring AllReduce: an intra-node ReduceScatter and AllGather on the fast intra-node link (combined byte factor 2(G-1)/G for G = devices_per_node), and, with more than one node, an inter-node ring AllReduce across the nodes nodes over one shared inter-node link per node (byte factor 2(M-1)/M for M = nodes). Gradient accumulation runs accumulation_steps local steps per update, so the same exchange serves more compute and the global batch grows. Speedup is the device count times the compute share of each update; training time and cost follow from the one-device run.
Methods
| Name | Description |
|---|---|
| solve | Estimate data-parallel speedup from a device profile. |
solve
engine.solvers.parallelism.DataParallelScaleOutModel.solve(
model,
precision,
step_time,
training_time,
per_device_batch,
devices_per_node,
nodes,
intra_bandwidth,
inter_bandwidth=None,
accumulation_steps=1,
node_hour_rate=None,
)Estimate data-parallel speedup from a device profile.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model | Workload | Workload with parameter count and weight-size conversion. | required |
| precision | str or Quantity | Gradient precision name or bytes-per-element quantity. | required |
| step_time | Quantity | Positive one-device compute duration per local step. | required |
| training_time | Quantity | Positive baseline one-device training duration. | required |
| per_device_batch | int | Positive samples per local step per device. | required |
| devices_per_node | int | Positive devices per node. | required |
| nodes | int | Positive node count. | required |
| intra_bandwidth | Quantity | Positive within-node bandwidth in bytes per second. | required |
| inter_bandwidth | Optional[Quantity] | Positive between-node bandwidth in bytes per second; required for multiple nodes. | None |
| accumulation_steps | int | Positive local steps per synchronized update; defaults to one. | 1 |
| node_hour_rate | Optional[Quantity] | Optional nonnegative node rental rate in USD/hour. | None |
Returns
| Name | Type | Description |
|---|---|---|
| DataParallelScaleOutResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: speedup = N compute/(compute + intra_ring + inter_ring); compute = accumulation_steps step_time.
Assumptions: Serial intra/inter exchanges and unchanged one-device work per sample.
Excludes: Overlap, startup, convergence changes from larger batches, and capacity.
References
Derivation: speedup = N compute/(compute + intra_ring + inter_ring); compute = accumulation_steps step_time. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim import Models
>>> r = DataParallelScaleOutModel().solve(Models.Language.Llama3_8B, 'fp16', Q_('1 s'), Q_('1 hour'), 1, 2, 1, Q_('100 GB/s'))
>>> 0 < r.efficiency <= 1
TrueParallelLayoutModel
engine.solvers.parallelism.ParallelLayoutModel()One training step of a TP x PP x DP layout, read through the Fleet Law.
Compute: the step’s 6 P D FLOPs (flops_per_param_token per parameter per token, D tokens per update) spread over every device at a local share of peak. Communication: each data-parallel rank reduces its gradient shard (the full gradient over TP x PP) with a ring AllReduce of about twice the shard; up to overlap_fraction of that transfer hides under the compute window, never more than the window itself. Pipeline stages idle (p-1)/(m+p-1) of the step, which stretches the compute window by 1/(1 - bubble). State: 16 B per parameter of mixed-precision Adam split over TP x PP; ZeRO-1 also shards the 12 B of optimizer state across the data-parallel group.
Literature Source: 1. Narayanan et al. (2021), Megatron-LM 3D parallelism. 2. Rajbhandari et al. (2020), ZeRO (16 B/param, optimizer sharding). 3. Huang et al. (2019), GPipe (bubble fraction).
Methods
| Name | Description |
|---|---|
| solve | Estimate a specified parallel training layout. |
solve
engine.solvers.parallelism.ParallelLayoutModel.solve(
model,
tp_size,
pp_size,
dp_size,
microbatches,
batch_tokens,
flops_per_param_token,
peak_flops,
local_efficiency,
link_bandwidth,
overlap_fraction,
gradient_precision='fp16',
window_resolution=None,
device_memory=None,
)Estimate a specified parallel training layout.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model | Workload | Workload with parameter count and weight-size conversion. | required |
| tp_size | int | Positive tensor-parallel group size. | required |
| pp_size | int | Positive pipeline stage count. | required |
| dp_size | int | Positive data-parallel group size. | required |
| microbatches | int | Positive microbatch count per pipeline iteration. | required |
| batch_tokens | float | Positive total tokens per optimizer update. | required |
| flops_per_param_token | float | Positive FLOP count per parameter per token, supplied by the caller. | required |
| peak_flops | Quantity | Positive per-device peak compute rate in FLOP/s. | required |
| local_efficiency | float | Fraction of peak compute achieved, greater than zero and at most one. | required |
| link_bandwidth | Quantity | Positive link rate in bytes per second; None skips optional transfer timing. | required |
| overlap_fraction | float | Fraction of communication eligible for hiding, between zero and one. | required |
| gradient_precision | str or Quantity | Gradient precision name or bytes-per-element quantity; defaults to fp16. | 'fp16' |
| window_resolution | Optional[Quantity] | Optional positive time resolution for decimal rounding of compute duration. | None |
| device_memory | Optional[Quantity] | Optional positive memory capacity in bytes for a state-only device-count bound. | None |
Returns
| Name | Type | Description |
|---|---|---|
| ParallelLayoutResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: T = compute/(1-bubble) + communication - min(overlap_fraction communication, compute); bubble=(PP-1)/(microbatches+PP-1).
Assumptions: Large-group ring communication approximation, equal partitions, mixed-precision Adam.
Excludes: Activation memory, runtime workspaces, and detailed pipeline schedules.
References
Derivation: T = compute/(1-bubble) + communication - min(overlap_fraction communication, compute); bubble=(PP-1)/(microbatches+PP-1). The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim import Models
>>> r = ParallelLayoutModel().solve(Models.Language.Llama3_8B, 1, 1, 2, 2, 128, 6, Q_('100 TFLOP/s'), 0.5, Q_('100 GB/s'), 0.5)
>>> r.step_time >= r.compute_time
TrueTensorParallelLayerModel
engine.solvers.parallelism.TensorParallelLayerModel()One Transformer layer’s forward compute against its tensor-parallel exchange.
The layer’s forward pass is 2 (P/L) FLOPs per token, split over the TP group and run at a sustained share of peak. Megatron-style tensor parallelism sums an activation of tokens x d_model once after attention and once after the MLP, each a ring AllReduce of 2(t-1)/t times the payload per device. The exchange must fit inside the compute on the link that carries it.
Literature Source: 1. Shoeybi et al. (2019), “Megatron-LM” (two AllReduces per layer per pass).
Methods
| Name | Description |
|---|---|
| solve | Compare layer compute with tensor-parallel communication. |
solve
engine.solvers.parallelism.TensorParallelLayerModel.solve(
model,
tp_size,
tokens,
peak_flops,
local_efficiency,
links,
collectives_per_layer=2,
)Compare layer compute with tensor-parallel communication.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model | TransformerWorkload | Workload with parameter count and weight-size conversion. | required |
| tp_size | int | Positive tensor-parallel group size. | required |
| tokens | int | Positive tokens processed by the layer. | required |
| peak_flops | Quantity | Positive per-device peak compute rate in FLOP/s. | required |
| local_efficiency | float | Fraction of peak compute achieved, greater than zero and at most one. | required |
| links | Dict[str, Quantity] | Mapping of link names to positive bandwidth quantities in bytes per second. | required |
| collectives_per_layer | int | Positive number of activation AllReduces; defaults to two. | 2 |
Returns
| Name | Type | Description |
|---|---|---|
| TensorParallelLayerResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: Compute = 2(P/L) tokens/(TP peak efficiency); bytes = collectives tokens hidden_dim FP16_bytes 2(TP-1)/TP.
Assumptions: Equal parameter share per layer and FP16 activation collectives.
Excludes: Attention quadratic work, startup, overlap scheduling, and capacity.
References
Derivation: Compute = 2(P/L) tokens/(TP peak efficiency); bytes = collectives tokens hidden_dim FP16_bytes 2(TP-1)/TP. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim import Models
>>> r = TensorParallelLayerModel().solve(Models.Language.Llama3_8B, 2, 128, Q_('100 TFLOP/s'), 0.5, {'link': Q_('100 GB/s')})
>>> r.transfer_times['link'].m_as('ms') > 0
TrueZeroShardingModel
engine.solvers.parallelism.ZeroShardingModel()Per-device training state at each ZeRO stage, and what full sharding sends.
DDP replicates weights (W), gradients (G), and optimizer state (O) on every device. ZeRO-1 shards O over N devices, ZeRO-2 also G, and ZeRO-3 (FSDP) also W. Stages 1 and 2 move DDP’s bytes (a ring AllReduce, about 2W per device); ZeRO-3 gathers every layer’s weights in forward and again in backward and reduce-scatters the gradients, about 3W, 1.5x as much.
Literature Source: 1. Rajbhandari et al. (2020), “ZeRO” (stages and communication volume).
Methods
| Name | Description |
|---|---|
| solve | Account for persistent state at each ZeRO stage. |
solve
engine.solvers.parallelism.ZeroShardingModel.solve(
model,
n_devices,
activations=None,
link_bandwidth=None,
)Account for persistent state at each ZeRO stage.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model | Workload | Workload with parameter count and weight-size conversion. | required |
| n_devices | int | Positive integer device count. | required |
| activations | Optional[Quantity] | Optional nonnegative unsharded activation memory; None contributes zero bytes. | None |
| link_bandwidth | Optional[Quantity] | Positive link rate in bytes per second; None skips optional transfer timing. | None |
Returns
| Name | Type | Description |
|---|---|---|
| ZeroShardingResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: State is W+G+O, W+G+O/N, W+(G+O)/N, or (W+G+O)/N for DDP through ZeRO-3.
Assumptions: FP16 weights/gradients and registry mixed-precision Adam state; supplied activations remain unsharded.
Excludes: Allocator reserve, temporary gather buffers, and communication startup.
References
Derivation: State is W+G+O, W+G+O/N, W+(G+O)/N, or (W+G+O)/N for DDP through ZeRO-3. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim import Models
>>> r = ZeroShardingModel().solve(Models.Language.Llama3_8B, 2)
>>> r.stage_state['ZeRO-3'] < r.stage_state['DDP']
True