Skip to main content

engine.solvers.performance

engine.solvers.performance

Single-node, network-roofline, efficiency, and inverse-design solvers.

Domain implementations behind mlsysim.solvers (the public import path, derived from engine.solvers.__init__); kept per-domain so the logic stays reviewable.

Classes

Name Description
AmdahlModel Amdahl’s law for a sequential request path: one stage made speedup
DecodeBoundModel Weight-streaming bound on one autoregressive decode step.
EfficiencyModel Models the gap between peak and achieved FLOPS (Wall 3: Software Efficiency).
IronLawModel The iron law of ML systems on one machine, in its two forms.
NetworkRooflineModel Analyzes the Distributed Performance Bounds (The Network Wall).
SensitivitySolver Identifies the binding constraint via numerical sensitivity analysis (Wall 21).
SingleNodeModel Resolves single-node hardware Roofline bounds and feasibility.
SynthesisSolver Given an SLA, synthesizes the required hardware specs (Wall 22: Inverse Solve).

AmdahlModel

engine.solvers.performance.AmdahlModel()

Amdahl’s law for a sequential request path: one stage made speedup times faster, the others untouched. The untouched time caps the overall speedup at total / untouched, however fast the stage becomes.

Methods

Name Description
solve Evaluate the end-to-end effect of accelerating one sequential stage.
solve
engine.solvers.performance.AmdahlModel.solve(stages, stage, speedup)

Evaluate the end-to-end effect of accelerating one sequential stage.

Parameters
Name Type Description Default
stages dict Stage names mapped to nonnegative time quantities in compatible units. Total and untouched time must both be positive for the reported bound. required
stage str Existing key identifying the stage to accelerate. required
speedup float Positive stage speedup; positive infinity represents its zero-time limit. required
Returns
Name Type Description
AmdahlResult Original and upgraded times in the selected stage’s units, fractional reductions, overall speedup, and the untouched-time speedup ceiling.
See Also

mlsysim.physics.performance.calc_amdahls_speedup : Fractional form.

Notes

Equation: T_new = T_other + T_stage/s; speedup_total = T_total/T_new. With p = T_stage/T_total, this is 1/(1-p+p/s).

Assumptions: sequential stages and only the named stage changes. Excludes: stage overlap, workload growth, and acceleration overhead.

References

Derivation: partition total duration into the accelerated stage and untouched stages, divide only the former by its speedup, and sum.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import AmdahlModel
>>> r = AmdahlModel().solve({"compute": Q_("3 ms"), "io": Q_("1 ms")}, "compute", 2)
>>> bool(r.upgraded_total_time < r.total_time and r.overall_speedup < r.speedup_bound)
True

DecodeBoundModel

engine.solvers.performance.DecodeBoundModel()

Weight-streaming bound on one autoregressive decode step.

At small batch every new token multiplies every weight once and must read every weight from memory, so a decode step needs 2P FLOPs per request and P x bytes_per_param of weight traffic. Comparing the two times on one device (one accelerator-equivalent path, capacity assumed) shows which resource binds; the weight-only arithmetic intensity places the step on the roofline. KV-cache reads and launch overhead are excluded (see ServingModel for those).

Literature Source: 1. Williams, Waterman, and Patterson (2009), “Roofline.” 2. Kaplan et al. (2020), the 2P forward-FLOP rule.

Methods

Name Description
solve Compute a weight-only decode Roofline bound per tensor-parallel shard.
solve
engine.solvers.performance.DecodeBoundModel.solve(
    model,
    hardware,
    precision='fp16',
    batch_size=1,
    peak_flops=None,
    tp_size=1,
)

Compute a weight-only decode Roofline bound per tensor-parallel shard.

Parameters
Name Type Description Default
model Workload Model supplying parameter count and weight storage. required
hardware HardwareNode Device supplying peak FLOP/s and memory bandwidth in bytes/s. required
precision str Storage precision; default FP16. Does not select compute peak here. 'fp16'
batch_size int Positive requests decoded together; default one. 1
peak_flops Quantity Positive FLOP/s override; otherwise uses the device’s generic peak. None
tp_size int Positive count of ideal equal weight/work shards; default one. 1
Returns
Name Type Description
DecodeBoundResult Compute and memory times, weight bytes, work in FLOPs, intensity in FLOP/byte, attainable FLOP/s, and the binding resource. No residency or deployment-feasibility check is performed.
See Also

mlsysim.physics.performance.calc_bottleneck : Compare resource times. mlsysim.physics.transformer.calc_transformer_decode_flops : Linear work.

Notes

Equation: F = 2 * P_active * B / TP, W = P_total * b / TP; T_compute = F/peak and T_memory = W/BW. Attainable rate is min(peak, BW * F / W).

Assumptions: equal sharding, one weight read shared across the batch, full use of supplied peak rates, and active-parameter forward work. Excludes: KV-cache reads, attention over context, communication, activations, runtime overhead, and memory-capacity checks.

References

Williams, Waterman, and Patterson (2009), “Roofline.” https://doi.org/10.1145/1498765.1498785 (bibliography key: williams2009). Kaplan et al. (2020), “Scaling Laws for Neural Language Models.” https://arxiv.org/abs/2001.08361 (bibliography key: kaplan2020scaling).

Examples
>>> from mlsysim import Hardware, Models
>>> from mlsysim.solvers import DecodeBoundModel
>>> r = DecodeBoundModel().solve(Models.Language.Llama3_8B, Hardware.Cloud.H100)
>>> bool(r.memory_time.m_as("ms") > 0 and r.compute_time.m_as("ms") > 0)
True

EfficiencyModel

engine.solvers.performance.EfficiencyModel()

Models the gap between peak and achieved FLOPS (Wall 3: Software Efficiency).

This model quantifies the software efficiency of a workload — the fraction of peak hardware FLOPS that the software stack actually converts into useful computation. It decomposes Model FLOPs Utilization (MFU) by workload type, accounting for kernel fusion efficiency, SM occupancy, and memory access patterns.

Literature Source: 1. Chowdhery et al. (2022), “PaLM: Scaling Language Modeling with Pathways.” (First systematic MFU reporting for large Transformers.) 2. Dao et al. (2022), “FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness.” (FlashAttention MFU improvement.) 3. NVIDIA (2023), “Hopper Architecture Tuning Guide.” (SM Occupancy model.)

Methods

Name Description
solve Estimate achievable MFU and FLOPS from kernel IO-complexity and Roofline bounds.
solve
engine.solvers.performance.EfficiencyModel.solve(
    model,
    hardware,
    workload_type='ffn',
    use_flash_attention=False,
    precision='fp16',
    efficiency=0.5,
    seq_len=2048,
    batch_size=1,
)

Estimate achievable MFU and FLOPS from kernel IO-complexity and Roofline bounds.

Parameters
Name Type Description Default
model Workload Workload supplying hidden geometry or lowered graph work/bytes. required
hardware HardwareNode Target accelerator supplying precision peak FLOP/s and HBM bandwidth. required
workload_type str Dominant kernel family: 'attention', 'ffn', or 'conv'. 'ffn'
use_flash_attention bool Tile attention in SRAM so HBM traffic avoids O(S^2) score/softmax materialization (applies when workload_type == 'attention'). False
precision str Registered numerical format controlling element byte width and peak FLOP/s. 'fp16'
efficiency float Compute-pipe / SM occupancy ceiling eta_comp (clamped to [0, 1]). 0.5
seq_len int Positive sequence length S for attention and FFN kernel intensity. 2048
batch_size int Positive batch size B scaling token count or image batch reuse. 1
Returns
Name Type Description
EfficiencyResult Roofline-bounded MFU, achievable FLOP/s, peak FLOP/s, and an exact partition of unity mfu + occupancy_loss + memory_stall == 1.
Notes

Equation: with eta_comp = clamp(efficiency, 0, 1) and peak ridge point I_peak = F_peak / BW_HBM, mfu = min(eta_comp, I_kernel / I_peak), occupancy_loss = 1 - eta_comp, and memory_stall = eta_comp - mfu. Kernel arithmetic intensity I_kernel at byte width b is: unfused causal attention 2 * S^2 * d_h / ((4 * S * d_h + 4 * S^2) * b); FlashAttention 2 * S^2 * d_h / (4 * S * d_h * b) = S / (2 * b); two-projection H x 4H FFN over T = B * S tokens 16 * T * H^2 / ((8 * H^2 + 4 * T * H) * b); convolution/generic (B * F_sample) / (W + B * A_sample).

Assumptions: HBM bandwidth is evaluated at peak device rate; eta_comp caps compute throughput; missing Transformer geometry defaults to H = 4096 and d_h = 128 when evaluating attention or FFN kernels on non-Transformer workloads.

Excludes: SRAM tile-size capacity spills for huge head dimensions, kernel launch latency, and multi-device communication.

References

Williams, Waterman, and Patterson (2009), “Roofline: An Insightful Visual Performance Model for Multicore Architectures.” https://doi.org/10.1145/1498765.1498785 (bibliography key: williams2009). Dao et al. (2022), “FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awareness.” https://arxiv.org/abs/2205.14135 (bibliography key: dao2022).

Examples
>>> from mlsysim import Hardware, Models
>>> from mlsysim.solvers import EfficiencyModel
>>> r = EfficiencyModel().solve(Models.Language.Llama3_8B, Hardware.Cloud.H100)
>>> bool(0 <= r.mfu <= 1 and r.achievable_flops <= r.peak_flops)
True

IronLawModel

engine.solvers.performance.IronLawModel()

The iron law of ML systems on one machine, in its two forms.

Sequential: T = memory + compute + overhead, the safe estimate when the stages run one after another. Overlapped: T >= max(memory, compute) + overhead, the best case when loading and computing overlap perfectly. An upgrade divides the memory term by memory_speedup (more bandwidth or fewer bytes) and the compute term by compute_speedup; the overhead stays, which is why the sum falls by less than the upgrade.

Methods

Name Description
solve Compare sequential and ideally overlapped memory and compute times.
solve
engine.solvers.performance.IronLawModel.solve(
    memory_time,
    compute_time,
    overhead,
    memory_speedup=1.0,
    compute_speedup=1.0,
)

Compare sequential and ideally overlapped memory and compute times.

Parameters
Name Type Description Default
memory_time Quantity Nonnegative memory-transfer duration, convertible to overhead’s unit. required
compute_time Quantity Nonnegative compute duration, convertible to overhead’s unit. required
overhead Quantity Nonnegative fixed time unaffected by either upgrade; total must be positive. required
memory_speedup float Positive divisor of memory time; default one leaves it unchanged. 1.0
compute_speedup float Positive divisor of compute time; default one leaves it unchanged. 1.0
Returns
Name Type Description
IronLawResult Original and upgraded times in overhead’s units and the dimensionless sequential-time reduction. These are bounds, with no capacity check.
Notes

Equation: T_serial = M+C+O; T_overlap = max(M,C)+O. Upgrade terms are M/s_memory and C/s_compute while O remains fixed.

Assumptions: distinct memory, compute, and overhead components; either serial execution or complete overlap between memory and compute. Excludes: partial overlap schedules, resource contention, and workload changes.

References

Derivation: add disjoint durations for serial execution and take the longer duration for simultaneous memory/compute execution.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import IronLawModel
>>> r = IronLawModel().solve(Q_("2 ms"), Q_("3 ms"), Q_("1 ms"), memory_speedup=2)
>>> bool(r.upgraded_sequential_time < r.sequential_time)
True

NetworkRooflineModel

engine.solvers.performance.NetworkRooflineModel()

Analyzes the Distributed Performance Bounds (The Network Wall).

This model elevates the single-node Roofline analysis to the fleet scale. It calculates the Communication Intensity (CI) of a workload and identifies if the fleet is Compute-Bound (Wall 1) or Network-Bound (Wall 2).

Literature Source: 1. Williams et al. (2009), “Roofline Model.” (Theoretical basis) 2. Ghose et al. (2019), “A Survey of Communication-Efficient Distributed Training.”

Methods

Name Description
solve Solve for the fleet-scale performance bound (network roofline).
solve
engine.solvers.performance.NetworkRooflineModel.solve(
    model,
    fleet,
    precision='fp16',
    efficiency=0.5,
)

Solve for the fleet-scale performance bound (network roofline).

Models one data-parallel training step as two independent ceilings — compute and gradient synchronization — and takes the slower as the binding latency (ideal overlap is assumed, so this is a lower-bound model). The conventions used:

  • communication intensity CI = training_ops / sync_bytes [FLOP/byte], with training_ops = 6 * P FLOPs per sample (Kaplan/Chinchilla forward+backward convention) and sync_bytes = 2 * P * bytes_per_param (ring all-reduce moves roughly 2x the gradient volume);
  • network ridge = fleet_peak_FLOPS / bisection_BW [FLOP/byte], the CI above which the fleet is compute-bound.
Parameters
Name Type Description Default
model Workload Workload with a parameter count (required). required
fleet Fleet The cluster; supplies total accelerators, per-accelerator FLOPS, and fabric bandwidth / oversubscription ratio. required
precision str Numerical precision; sets bytes per parameter and the FLOPS entry. 'fp16'
efficiency float Software efficiency factor in (0, 1] applied to fleet peak FLOPS. 0.5
Returns
Name Type Description
PerformanceProfile latency_compute holds the compute ceiling, latency_memory the network ceiling (both in ms); bottleneck is ‘Network’ or ‘Compute’; arithmetic_intensity carries CI.
Notes

Equation: T = max(6P / (eta * fleet_peak), 2P*b / bisection_BW), where P is parameter count and b is bytes per gradient element. CI = 6P / (2P*b); the reported ridge uses fleet peak without eta.

Assumptions: one normalized training sample, uniform data-parallel replicas, and ideal overlap between the two independent ceilings. Excludes: batch/sequence scaling, ring startup latency, optimizer state, capacity checks, and pipeline bubbles. feasible=True does not check whether training state fits; the stored footprint is sync traffic.

References

Williams, Waterman, and Patterson (2009), “Roofline.” https://doi.org/10.1145/1498765.1498785 (bibliography key: williams2009). Derivation: replace memory traffic and its rate by gradient traffic and fabric bisection rate; the 2P*b traffic is an approximate ring volume.

Examples
>>> from mlsysim import Models, Systems
>>> from mlsysim.solvers import NetworkRooflineModel
>>> r = NetworkRooflineModel().solve(Models.Language.Llama3_8B, Systems.Clusters.Research_256)
>>> bool(r.latency >= r.latency_compute and r.latency >= r.latency_memory)
True

SensitivitySolver

engine.solvers.performance.SensitivitySolver()

Identifies the binding constraint via numerical sensitivity analysis (Wall 21).

This solver computes numerical partial derivatives of performance with respect to hardware parameters to identify the ‘binding constraint.’

Literature Source: 1. Williams et al. (2009), “Roofline Model.” 2. Ofenbeck et al. (2014), “Applying the Roofline Model.”

Methods

Name Description
solve Solve for parameter sensitivities and identify the binding constraint.
solve
engine.solvers.performance.SensitivitySolver.solve(
    model,
    hardware,
    precision='fp16',
    perturbation_pct=10.0,
    efficiency=0.5,
)

Solve for parameter sensitivities and identify the binding constraint.

Numerically perturbs each hardware parameter (peak FLOPS, memory bandwidth, memory capacity) by perturbation_pct and re-solves the single-node Roofline. Each sensitivity is the normalized latency response (T_perturbed - T_base) / T_base (dimensionless; negative means the upgrade helps). The binding constraint is the parameter with the largest absolute sensitivity — the resource whose improvement moves latency the most.

Parameters
Name Type Description Default
model Workload The workload to analyze. required
hardware HardwareNode The baseline hardware configuration. required
precision str Numerical precision used for both baseline and perturbed solves. 'fp16'
perturbation_pct float Perturbation size in percent (default 10.0, i.e. a 1.1x upgrade). 10.0
efficiency float Software efficiency factor in (0, 1]. 0.5
Returns
Name Type Description
SensitivityResult Per-parameter sensitivities, the binding constraint name, the baseline latency, and feasible. If the baseline does not fit in memory, feasible is False, binding_constraint is "memory_capacity", and constraint_trace carries the Memory Wall failure: the offload path pins latency, so the sensitivities (typically all zero) do not rank hardware levers.
See Also

mlsysim.engine.engine.Engine.solve : Baseline and perturbed evaluator.

Notes

Equation: response_j = (T(x_j*(1+p/100)) - T(x)) / T(x), where p is perturbation_pct. The reported response is a finite fractional change, not a derivative divided by the perturbation size.

Assumptions: each hardware field changes alone; all other inputs and the generic engine’s assumptions remain fixed. Use positive p for an upgrade experiment. Capacity-infeasible baselines are labeled separately. Excludes: coupled hardware costs, changes in kernel efficiency, and uncertainty intervals. Near a regime boundary the finite step matters.

References

Derivation: compute a finite difference in latency and normalize by the baseline; rank the absolute responses of compute, bandwidth, and capacity.

Examples
>>> from mlsysim import Hardware, Models
>>> from mlsysim.solvers import SensitivitySolver
>>> r = SensitivitySolver().solve(Models.Language.Llama3_8B, Hardware.Cloud.H100)
>>> sorted(r.sensitivities)
['memory_bandwidth', 'memory_capacity', 'peak_flops']

SingleNodeModel

engine.solvers.performance.SingleNodeModel()

Resolves single-node hardware Roofline bounds and feasibility.

This model handles the ‘Iron Law’ of machine learning systems, calculating whether a model fits in memory and predicting its throughput based on arithmetic intensity.

Literature Source: Williams et al. (2009), “Roofline: An Insightful Visual Performance Model for Floating-Point Programs and Multicore Architectures.”

Methods

Name Description
solve Calculate the Roofline performance profile for a single hardware node.
solve
engine.solvers.performance.SingleNodeModel.solve(
    model,
    hardware,
    batch_size=1,
    precision='fp16',
    efficiency=0.5,
    raise_errors=False,
    **kwargs,
)

Calculate the Roofline performance profile for a single hardware node.

Thin wrapper that delegates to Engine.solve (the core Roofline implementation in engine/engine.py), exposing it through the resolver interface so it can participate in pipelines.

Parameters
Name Type Description Default
model Workload The workload to profile. required
hardware HardwareNode The accelerator node (compute, memory, interconnect specs). required
batch_size int Samples per forward pass (>= 1). 1
precision str Numerical precision (‘fp32’, ‘fp16’, ‘int8’, …); sets bytes per parameter and selects the hardware’s precision FLOPS entry. 'fp16'
efficiency float Software efficiency factor in (0, 1] applied to peak FLOPS. 0.5
raise_errors bool If True, raise OOMError on memory infeasibility instead of returning a profile with feasible=False. False
**kwargs dict Additional Engine.solve options such as training mode or sequence length. {}
Returns
Name Type Description
PerformanceProfile Latency breakdown, throughput, bottleneck, MFU, and memory footprint.
See Also

mlsysim.engine.engine.Engine.solve : Generic node calculation.

Notes

Equation: T = max(F / (eta * peak), traffic / bandwidth) + overhead. This wrapper delegates the workload lowering, memory accounting, and constraint traces to Engine.solve.

Assumptions: architecture-derived activation traffic from Workload.activation_traffic_bytes and one forward step unless additional engine options select training. Efficiency scales compute capacity, not peak memory bandwidth. Excludes: explicit KV-aware serving and distributed collectives.

References

Williams, Waterman, and Patterson (2009), “Roofline.” https://doi.org/10.1145/1498765.1498785 (bibliography key: williams2009). Activation traffic and runtime taxes are separate modeling conventions.

Examples
>>> from mlsysim import Hardware, Models
>>> from mlsysim.solvers import SingleNodeModel
>>> r = SingleNodeModel().solve(Models.Language.Llama3_8B, Hardware.Cloud.H100)
>>> bool(r.feasible and r.latency.m_as("ms") > 0)
True

SynthesisSolver

engine.solvers.performance.SynthesisSolver()

Given an SLA, synthesizes the required hardware specs (Wall 22: Inverse Solve).

This solver inverts the Roofline model to derive minimum hardware specifications required to meet a target latency SLA.

Literature Source: 1. Williams et al. (2009), “Roofline Model.” 2. Jouppi et al. (2017), “In-Datacenter Performance Analysis of a TPU.”

Methods

Name Description
solve Synthesize minimum hardware requirements from a latency SLA.
solve
engine.solvers.performance.SynthesisSolver.solve(
    model,
    target_latency,
    precision='fp16',
    efficiency=0.5,
)

Synthesize minimum hardware requirements from a latency SLA.

Inverts the Roofline model: instead of asking “how fast does this hardware run the model?”, asks “what hardware would run the model in target_latency?”. Assumes a single full pass that streams every weight once (batch size 1, no weight reuse), so:

  • required_bw = weight_bytes / T_target [GB/s] — the bandwidth needed if the workload is memory-bound;
  • required_flops = total_ops / (T_target * efficiency) [TFLOP/s] — the compute rate needed if it is compute-bound;
  • compute_memory_ratio = required_flops / required_bw [FLOP/byte] — the hardware balance point a matching part should sit near.
Parameters
Name Type Description Default
model Workload The workload to serve; sets weight bytes and operation count. required
target_latency Quantity The SLA latency target (any time unit; converted to seconds). required
precision str Numerical precision; sets bytes per parameter. 'fp16'
efficiency float Expected software efficiency in (0, 1]; lower values inflate the required FLOPS to compensate. 0.5
Returns
Name Type Description
SynthesisResult Required bandwidth, FLOPS, memory capacity, and the compute:memory balance ratio.
Notes

Equation: BW_required = weight_bytes / T; peak_required = F / (T*eta). Required capacity is weight storage alone and the reported balance is peak_required / BW_required.

Assumptions: positive target time and efficiency in (0, 1], batch one, one full weight read, and the workload’s lowered forward operation count. Excludes: activations, KV cache, dispatch overhead, and communication. These are screening requirements, not a sufficient deployment specification.

References

Williams, Waterman, and Patterson (2009), “Roofline.” https://doi.org/10.1145/1498765.1498785 (bibliography key: williams2009). Derivation: solve each resource-time inequality for its required rate.

Examples
>>> from mlsysim import Models, Q_
>>> from mlsysim.solvers import SynthesisSolver
>>> r = SynthesisSolver().solve(Models.Language.Llama3_8B, Q_("50 ms"))
>>> bool(r.required_bw.m_as("GB/s") > 0 and r.required_memory.m_as("GB") > 0)
True
Back to top