engine.solvers.collective
engine.solvers.collective
Collective-communication solvers: AllReduce schedules, hierarchy, AllToAll dispatch, gradient compression, and overlap with the backward pass.
Domain implementations behind mlsysim.solvers (the public import path, derived from engine.solvers.__init__); kept per-domain so the logic stays reviewable. Every model is an alpha-beta bound: a startup alpha per round or message plus bytes over a stated bandwidth beta, with contention, protocol overhead, and the reduction arithmetic left out.
Classes
| Name | Description |
|---|---|
| AllReduceAlgorithmModel | Ring, simple-tree, and parameter-server (star) AllReduce of one buffer at several group sizes. |
| AllToAllDispatchModel | One mixture-of-experts dispatch AllToAll under uniform routing, and one hot receiver. |
| CompressionRunModel | Time to a quality target with and without gradient compression, per network. |
| ErrorFeedbackModel | A compressor that sends each value rounded to a whole unit, with error feedback. |
| HierarchicalAllReduceModel | Three-phase hierarchical AllReduce against one flat ring across every GPU. |
| OverlapBudgetModel | Layer-by-layer gradient AllReduce, run after the backward pass or overlapped with it. |
| RingTraceModel | Every step of a ring AllReduce on one small vector per GPU, the vectors split into N chunks. |
AllReduceAlgorithmModel
engine.solvers.collective.AllReduceAlgorithmModel()Ring, simple-tree, and parameter-server (star) AllReduce of one buffer at several group sizes.
A ring takes 2(N-1) rounds, each paying one startup alpha and moving one chunk of M/N bytes, so each rank sends 2(N-1)/N times the buffer. The simple tree reduces up and broadcasts down in 2 log2 N rounds, forwarding the whole buffer each round. A single parameter server receives and sends N buffers through one port. The crossover is the buffer at which ring and tree cost the same: the log-aware estimate N alpha beta / log2 N and the exact intersection of the two models.
Literature Source: 1. Patarasuk and Yuan (2009), bandwidth-optimal ring AllReduce. 2. Thakur, Rabenseifner, and Gropp (2005), tree and ring collectives.
Methods
| Name | Description |
|---|---|
| solve | Compare ring, tree, and star transfer bounds. |
solve
engine.solvers.collective.AllReduceAlgorithmModel.solve(
message,
group_sizes,
alpha,
bandwidth,
)Compare ring, tree, and star transfer bounds.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| message | Quantity | Nonnegative buffer size as a byte-compatible quantity. | required |
| group_sizes | Sequence[int] | Integer rank counts, each at least two. | required |
| alpha | Quantity | Nonnegative startup latency per round as a time quantity. | required |
| bandwidth | Quantity | Positive per-port transfer rate in bytes per second. | required |
Returns
| Name | Type | Description |
|---|---|---|
| AllReduceAlgorithmResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: T_ring = 2(N-1) alpha + 2(N-1)M/(N bandwidth); tree uses twice the ceiling of log2(N) rounds.
Assumptions: Equal chunks and serialized startup-plus-transfer costs.
Excludes: Contention, reduction arithmetic, and protocol overhead.
References
Derivation: T_ring = 2(N-1) alpha + 2(N-1)M/(N bandwidth); tree uses twice the ceiling of log2(N) rounds. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> r = AllReduceAlgorithmModel().solve(Q_('1 MB'), [2, 4], Q_('1 us'), Q_('1 GB/s'))
>>> r.ring_time[4] > r.ring_startup_time[4]
TrueAllToAllDispatchModel
engine.solvers.collective.AllToAllDispatchModel()One mixture-of-experts dispatch AllToAll under uniform routing, and one hot receiver.
Each device holds tokens / N tokens and sends an equal share to every device, keeping its own; a token is hidden_dim values. The concurrent peer streams share one injection port, so dispatch takes at least alpha + sent / beta. On the receive side the bound is the receiving port: a device whose experts draw skew times the uniform remote load takes skew times longer, and every device waiting on its outputs waits with it.
Methods
| Name | Description |
|---|---|
| solve | Bound uniform and skewed expert dispatch. |
solve
engine.solvers.collective.AllToAllDispatchModel.solve(
total_tokens,
n_devices,
n_experts,
hidden_dim,
bytes_per_element,
alpha,
bandwidth,
receive_skew=1.0,
)Bound uniform and skewed expert dispatch.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| total_tokens | int | Nonnegative total token count; integer division discards routing remainders. | required |
| n_devices | int | Positive integer device count. | required |
| n_experts | int | Positive integer expert count. | required |
| hidden_dim | int | Positive hidden-vector width in elements. | required |
| bytes_per_element | Quantity | Storage per element as a byte quantity. | required |
| alpha | Quantity | Nonnegative startup latency per round as a time quantity. | required |
| bandwidth | Quantity | Positive per-port transfer rate in bytes per second. | required |
| receive_skew | float | Nonnegative multiplier on uniform remote receiver load; default one. | 1.0 |
Returns
| Name | Type | Description |
|---|---|---|
| AllToAllDispatchResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: sent = (N-1) floor(floor(tokens/N)/N) hidden_dim bytes_per_element; injection time = alpha + sent/bandwidth.
Assumptions: Uniform integer token partitions; skew changes receiver load only.
Excludes: Routing remainders, expert compute, combine phase, and contention.
References
Derivation: sent = (N-1) floor(floor(tokens/N)/N) hidden_dim bytes_per_element; injection time = alpha + sent/bandwidth. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> r = AllToAllDispatchModel().solve(16, 2, 4, 8, Q_('2 byte'), Q_('1 us'), Q_('1 GB/s'))
>>> r.hot_remote_tokens == r.uniform_remote_tokens
TrueCompressionRunModel
engine.solvers.collective.CompressionRunModel()Time to a quality target with and without gradient compression, per network.
Each step is compute plus exposed communication, with nothing overlapped. Compression divides only the communication term by ratio and needs 1 + step_penalty times the steps to reach the same quality, so it pays only where communication is a large share of the step.
Methods
| Name | Description |
|---|---|
| solve | Compare time to a supplied quality target. |
solve
engine.solvers.collective.CompressionRunModel.solve(
steps,
compute_time,
communication_times,
ratio,
step_penalty,
)Compare time to a supplied quality target.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| steps | int | Positive baseline optimizer-step count. | required |
| compute_time | Quantity | Nonnegative compute duration per step. | required |
| communication_times | Dict[str, Quantity] | Mapping from network name to nonnegative communication duration. | required |
| ratio | float | Positive communication compression ratio; one leaves traffic unchanged. | required |
| step_penalty | float | Fractional increase in steps needed for the quality target; must exceed minus one. | required |
Returns
| Name | Type | Description |
|---|---|---|
| CompressionRunResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: T = steps (compute + communication); compressed T = round(steps(1+penalty)) (compute + communication/ratio).
Assumptions: Step penalty is a supplied assumption; communication does not overlap compute.
Excludes: Compression kernels and prediction of achieved quality.
References
Derivation: T = steps (compute + communication); compressed T = round(steps(1+penalty)) (compute + communication/ratio). The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> r = CompressionRunModel().solve(10, Q_('1 ms'), {'link': Q_('1 ms')}, 1, 0)
>>> r.totals == r.compressed_totals
TrueErrorFeedbackModel
engine.solvers.collective.ErrorFeedbackModel()A compressor that sends each value rounded to a whole unit, with error feedback.
Without a residual, every value below half a unit is lost. With error feedback the worker adds the carried residual e_t to the gradient, sends the rounded v_t, and keeps e_{t+1} = g_t + e_t - v_t; what is sent plus the last residual equals the true sum at every step.
Literature Source: Karimireddy et al. (2019), “Error Feedback Fixes SignSGD”.
Methods
| Name | Description |
|---|---|
| solve | Track rounding residuals across gradient transmissions. |
solve
engine.solvers.collective.ErrorFeedbackModel.solve(gradients)Track rounding residuals across gradient transmissions.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| gradients | Sequence[float] | Scalar gradient sequence in consistent arbitrary units. | required |
Returns
| Name | Type | Description |
|---|---|---|
| ErrorFeedbackResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: v_t = round(g_t + e_t); e_(t+1) = g_t + e_t - v_t.
Assumptions: Scalar whole-unit compressor with ties rounded away from zero.
Excludes: Optimizer convergence and vector compression costs.
References
Derivation: v_t = round(g_t + e_t); e_(t+1) = g_t + e_t - v_t. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> r = ErrorFeedbackModel().solve([0.25, 0.25])
>>> r.total_sent + r.final_error == r.true_total
TrueHierarchicalAllReduceModel
engine.solvers.collective.HierarchicalAllReduceModel()Three-phase hierarchical AllReduce against one flat ring across every GPU.
Inside each node of G GPUs a ReduceScatter over the fast link leaves each GPU 1/G of the node’s partial sum, sending (G-1)/G of the buffer. GPUs in the same position on every node then ring-AllReduce their M/G shard across nodes, one ring per GPU position, each on its own port; an AllGather inside the node rebuilds the sum. The in-node phases carry no startup term here. The flat ring runs at the slowest edge, the inter-node port; flat_bound_time is its large-N byte bound 2M/beta.
Literature Source: Sergeev and Del Balso (2018); NCCL hierarchical rings.
Methods
| Name | Description |
|---|---|
| solve | Compare hierarchical and flat AllReduce bounds. |
solve
engine.solvers.collective.HierarchicalAllReduceModel.solve(
message,
n_nodes,
gpus_per_node,
intra_bandwidth,
inter_bandwidth,
inter_alpha,
)Compare hierarchical and flat AllReduce bounds.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| message | Quantity | Nonnegative buffer size as a byte-compatible quantity. | required |
| n_nodes | int | Positive integer node count. | required |
| gpus_per_node | int | Positive integer accelerator count per node. | required |
| intra_bandwidth | Quantity | Positive within-node bandwidth in bytes per second. | required |
| inter_bandwidth | Quantity | Positive between-node bandwidth in bytes per second; required for multiple nodes. | required |
| inter_alpha | Quantity | Nonnegative between-node startup latency as a time quantity. | required |
Returns
| Name | Type | Description |
|---|---|---|
| HierarchicalAllReduceResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: T = 2 M(G-1)/(G intra_bandwidth) + T_ring(M/G, nodes, inter_bandwidth, inter_alpha).
Assumptions: Independent inter-node ports per GPU position and no intra-node startup.
Excludes: Shared-port contention and reduction arithmetic.
References
Derivation: T = 2 M(G-1)/(G intra_bandwidth) + T_ring(M/G, nodes, inter_bandwidth, inter_alpha). The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> r = HierarchicalAllReduceModel().solve(Q_('1 MB'), 2, 2, Q_('10 GB/s'), Q_('1 GB/s'), Q_('1 us'))
>>> r.total_time > r.inter_time
TrueOverlapBudgetModel
engine.solvers.collective.OverlapBudgetModel()Layer-by-layer gradient AllReduce, run after the backward pass or overlapped with it.
Each of L equal layers yields its gradient, reduced in fixed-size buckets that each take time_per_bucket. Sequentially, the step pays the whole backward pass and then every reduction. Overlapped, a layer’s reduction starts when its backward finishes; when a reduction outlasts the next layer’s backward, the excess accumulates, and the last reduction has no compute left to hide under.
Methods
| Name | Description |
|---|---|
| solve | Account for layerwise reduction overlap. |
solve
engine.solvers.collective.OverlapBudgetModel.solve(
workload,
bytes_per_value,
backward_per_layer,
bucket_size,
time_per_bucket,
)Account for layerwise reduction overlap.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| workload | Workload | Layered workload with positive layer count and weight-size conversion. | required |
| bytes_per_value | Quantity | Gradient storage per element as a byte quantity. | required |
| backward_per_layer | Quantity | Nonnegative backward duration of each equal layer. | required |
| bucket_size | Quantity | Positive gradient bucket size as a byte quantity. | required |
| time_per_bucket | Quantity | Nonnegative reduction duration per bucket. | required |
Returns
| Name | Type | Description |
|---|---|---|
| OverlapBudgetResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: T_overlap = L b + c + (L-1) max(0,c-b), where c is rounded-up bucket count times bucket duration.
Assumptions: Equal layers and serialized communication with backward/reduction overlap.
Excludes: Variable layer sizes and transport contention.
References
Derivation: T_overlap = L b + c + (L-1) max(0,c-b), where c is rounded-up bucket count times bucket duration. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> from mlsysim import Models
>>> r = OverlapBudgetModel().solve(Models.Language.Llama3_8B, Q_('2 byte'), Q_('1 ms'), Q_('1 GB'), Q_('1 ms'))
>>> r.overlapped_time <= r.sequential_time
TrueRingTraceModel
engine.solvers.collective.RingTraceModel()Every step of a ring AllReduce on one small vector per GPU, the vectors split into N chunks.
In ReduceScatter step s, GPU i sends chunk (i - s) mod N to GPU i + 1, which adds it into its own copy; after N - 1 steps GPU i owns the fully reduced chunk (i + 1) mod N. In AllGather step s (from 1), GPU i forwards chunk (i - s + 2) mod N, the one it completed or received most recently, so after N - 1 more steps every GPU holds every chunk.
Methods
| Name | Description |
|---|---|
| solve | Trace integer reduction and gathering around a ring. |
solve
engine.solvers.collective.RingTraceModel.solve(vectors)Trace integer reduction and gathering around a ring.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| vectors | Sequence[Sequence[int]] | Square sequence of integer vectors, one vector and one chunk per rank. | required |
Returns
| Name | Type | Description |
|---|---|---|
| RingTraceResult | Modeled accounting components with unit-bearing sizes and times; ratios are dimensionless. These components do not certify deployment feasibility. |
Notes
Equation: Each of N-1 scatter steps adds the received chunk; N-1 gather steps disseminate completed sums.
Assumptions: Square input vectors with one scalar chunk per rank.
Excludes: Transfer time, floating-point reduction order, and failures.
References
Derivation: Each of N-1 scatter steps adds the received chunk; N-1 gather steps disseminate completed sums. The class documentation describes the accounting sequence and its modeling context.
Examples
>>> from mlsysim.core.units import Q_
>>> r = RingTraceModel().solve([[1, 2], [3, 4]])
>>> r.totals == [sum(x) for x in zip([1, 2], [3, 4])]
True