Skip to main content

Choosing a Solver

A decision guide for choosing the right MLSys·im analytical tool

MLSys·im provides specialized analytical resolvers for different classes of ML systems questions. This page maps each question to the right release-facing workflow and shows how to compose solvers for real-world analyses.

For the distinction between Engine, specialized solvers, and scenarios, start with Choosing a Python API.


Start With the Question

“How fast will my model run on this GPU?”
Use the SingleNodeModel. It applies the roofline model to determine whether the workload is compute-bound or memory-bound and returns latency, throughput, and bottleneck classification.
Curriculum: Vol I · Ch 11: Hardware Acceleration (Study sheet · Slides) · Vol I · Ch 12: Benchmarking (Study sheet · Slides)
“How much memory and latency does group quantization or pruning save?”
Use the CompressionModel. It computes compressed weight bytes (including group-quantization scale metadata), effective speedup via Roofline analysis, and explicit accuracy trade-offs.
Curriculum: Vol I · Ch 10: Model Compression (Study sheet · Slides)
“How fast will my LLM generate tokens?”
Use the ServingModel. It models the two distinct phases of single-device autoregressive inference: a compute-based prefill estimate (TTFT) and a decode estimate (ITL) that compares compute and memory bounds, plus KV-cache memory pressure, phase splitting, prompt caching, speculative decode, and an optional chunked-prefill stall proxy.
Curriculum: Vol I · Ch 13: Model Serving (Study sheet · Slides) · Vol II · Ch 10: Serving at Scale (Study sheet · Slides)
“How much memory do I need for training?”
Use the TrainingMemoryModel. It separates weights, gradients, optimizer state, activations, and communication buffers so training memory is not confused with inference memory.
Curriculum: Vol I · Ch 8: Model Training (Study sheet · Slides) · Vol II · Ch 6: Distributed Training (Study sheet · Slides)
“How many serving replicas do I need for this SLA?”
Use the ServingCapacityModel. It composes serving latency, continuous-batching capacity, and queueing pressure into a replica-count estimate.
Curriculum: Vol I · Ch 13: Model Serving (Study sheet · Slides) · Vol II · Ch 10: Serving at Scale (Study sheet · Slides)
“How does performance scale across multiple GPUs?”
Use the DistributedModel. It decomposes workloads using 3D/4D parallelism (DP, TP, PP, EP) and calculates communication overhead, pipeline bubbles, and scaling efficiency.
Curriculum: Vol II · Ch 6: Distributed Training (Study sheet · Slides) · Vol II · Ch 5: Collective Communication (Study sheet · Slides) · Vol II · Ch 3: Network Fabrics (Study sheet · Slides)
“How much does MoE routing imbalance hurt?”
Use the MoERoutingModel. It keeps MoE modeling first-order: total parameters set memory, active parameters set compute, and a routing-imbalance factor inflates expert-parallel all-to-all traffic.
Curriculum: Vol II · Ch 6: Distributed Training (Study sheet · Slides) · Vol II · Ch 10: Serving at Scale (Study sheet · Slides)
“How much will this cost to run?”
Use the EconomicsModel. It calculates Total Cost of Ownership: CapEx (hardware purchase), OpEx (energy + maintenance), and total TCO over a specified duration.
Curriculum: Vol II · Ch 2: Compute Infrastructure (Study sheet · Slides)
“What is the carbon and water footprint?”
Use the SustainabilityModel. It computes facility energy consumption (factoring in PUE), carbon emissions (using regional grid intensity), and on-site cooling water usage (\(E_{\text{IT}} \times \text{WUE}\)) across datacenter locations.
Curriculum: Vol II · Ch 15: Sustainable AI (Study sheet · Slides)
“How often will my cluster fail during training?”
Use the ReliabilityModel. It estimates fleet-wide MTBF, failure probability for a given job duration, and the Young-Daly optimal checkpoint interval and waste fraction.
Curriculum: Vol II · Ch 7: Fault Tolerance (Study sheet · Slides)
“What noise and step overhead does differential privacy add?”
Use the ResponsibleEngineeringModel. It computes the Gaussian mechanism noise multiplier (\(\sigma\)) and explicit per-sample gradient-clipping slowdown factor (\(1 + c_{\text{clip}}\)).
Curriculum: Vol I · Ch 15: Responsible Engineering (Study sheet · Slides)

Quick Reference

Solver Key Inputs Key Outputs Best For
SingleNodeModel model, hardware, batch_size, precision latency, throughput, bottleneck, MFU “Is my model memory-bound?”
CompressionModel model, hardware, method, target_bitwidth, group_size compressed bytes, compression ratio, speedup “How much memory does INT4 group quantization save?”
EfficiencyModel model, hardware, workload_type, seq_len Roofline & FlashAttention SRAM IO-bound MFU “What theoretical MFU ceiling can attention reach?”
ServingModel model, hardware, seq_len, batch_size TTFT, ITL, KV-cache size, decode stall proxy, feasibility “Can I serve this LLM on one GPU?”
TrainingMemoryModel model, hardware, batch_size, seq_len memory breakdown, feasibility “Why does training not fit?”
ServingCapacityModel model, hardware, qps, target_p99_latency_ms replicas, QPS capacity, queue wait “How many replicas do I need?”
DistributedModel model, fleet, tp_size, pp_size, ep_size scaling efficiency, communication overhead “How many GPUs do I actually need?”
MoERoutingModel sparse model, batch_size, seq_len, ep_size active experts, routed bytes, all-to-all latency “What is the MoE routing tax?”
EconomicsModel fleet, duration_days, kwh_price CapEx, OpEx, total TCO “What will this cost over 3 years?”
SustainabilityModel fleet, duration_days, datacenter energy (kWh), carbon (kg CO₂e), water (L) “Where should I train to minimize carbon?”
ReliabilityModel fleet, job_duration_hours, checkpoint_time_s MTBF, failure probability, checkpoint interval “Will my training job complete?”
ResponsibleEngineeringModel base_training_time, epsilon, delta, sample_rate, steps noise multiplier, clipping slowdown factor “What overhead does DP-SGD add?”
DSE pipeline, search_space, objective, constraints ranked feasible configurations “Which multi-knob configuration satisfies my SLA?”

Code Examples

The examples below import solver classes from the canonical mlsysim.solvers namespace (from mlsysim.solvers import SingleNodeModel, or mlsysim.solvers.SingleNodeModel after import mlsysim).

Single-node roofline analysis

import mlsysim
from mlsysim.solvers import SingleNodeModel

solver = SingleNodeModel()
profile = solver.solve(
    model=mlsysim.Models.Vision.ResNet50,
    hardware=mlsysim.Hardware.Cloud.A100,
    batch_size=1
)
print(f"Bottleneck: {profile.bottleneck}")
print(f"Latency:    {profile.latency.to('ms'):~.2f}")
print(f"MFU:        {profile.mfu:.1%}")
Bottleneck: Compute
Latency:    0.07 ms
MFU:        38.9%

LLM serving analysis

import mlsysim
from mlsysim.solvers import ServingModel

serving = ServingModel()
result = serving.solve(
    model=mlsysim.Models.Language.Llama3_8B,
    hardware=mlsysim.Hardware.Cloud.H100,
    seq_len=2048,
    batch_size=1
)
print(f"TTFT: {result.ttft.to('ms'):~.1f}")
print(f"ITL:  {result.itl.to('ms'):~.2f}")
print(f"KV:   {result.kv_cache_size:~.2f}")
print(f"Fits: {result.feasible}")
TTFT: 68.7 ms
ITL:  4.87 ms
KV:   0.27 GB
Fits: True

Training memory breakdown

import mlsysim
from mlsysim.solvers import TrainingMemoryModel

memory = TrainingMemoryModel().solve(
    model=mlsysim.Models.Language.Llama3_8B,
    hardware=mlsysim.Hardware.Cloud.H100,
    batch_size=8,
    seq_len=2048,
    zero_stage=2,
    dp_size=8
)
print(f"Total:       {memory.total_memory:~.2f}")
print(f"Weights:     {memory.weights:~.2f}")
print(f"Optimizer:   {memory.optimizer_state:~.2f}")
print(f"Activations: {memory.activations:~.2f}")
print(f"Fits:        {memory.feasible}")
Total:       39.34 GB
Weights:     16.06 GB
Optimizer:   12.04 GB
Activations: 9.13 GB
Fits:        True

Serving capacity planning

import mlsysim
from mlsysim.solvers import ServingCapacityModel

capacity = ServingCapacityModel().solve(
    model=mlsysim.Models.Language.Llama3_8B,
    hardware=mlsysim.Hardware.Cloud.H100,
    qps=20,
    target_p99_latency_ms=2000,
    max_seq_len=1024,
    output_tokens=64
)
print(f"Replicas: {capacity.required_replicas}")
print(f"P99:      {capacity.estimated_p99_latency:~.1f}")
print(f"Util:     {capacity.utilization:.1%}")
Replicas: 1
P99:      1522.1 ms
Util:     24.3%

MoE routing imbalance

from mlsysim import Systems, ureg
from mlsysim.solvers import MoERoutingModel
from mlsysim.models.types import SparseTransformerWorkload

moe = SparseTransformerWorkload(
    name="Toy-MoE-64B",
    architecture="Sparse Transformer",
    parameters=64e9 * ureg.count,
    active_parameters=8e9 * ureg.count,
    experts=8,
    active_experts_per_token=2,
    layers=32,
    hidden_dim=4096,
    heads=32,
)

routing = MoERoutingModel().solve(
    model=moe,
    batch_size=4,
    seq_len=2048,
    ep_size=8,
    routing_imbalance_factor=1.25,
    fleet=Systems.Clusters.Research_256,
)
print(f"Active experts: {routing.effective_active_experts:.2f}")
print(f"Routed bytes:   {routing.token_dispatch_bytes:~.2f}")
print(f"All-to-all:     {routing.all_to_all_latency:~.2f}")
Active experts: 2.50
Routed bytes:   146.80 MB
All-to-all:     12.09 ms

Distributed training at scale

import mlsysim
from mlsysim import Systems
from mlsysim.solvers import DistributedModel

dist = DistributedModel()
result = dist.solve(
    model=mlsysim.Models.Language.Llama3_70B,
    fleet=Systems.Clusters.Frontier_8K,
    batch_size=2048,
    tp_size=8,
    pp_size=4,
    microbatch_count=16
)
print(f"Scaling efficiency: {result.scaling_efficiency:.1%}")
print(f"Bubble fraction:    {result.bubble_fraction:.1%}")
print(f"DP comm latency:    {result.dp_communication_latency.to('ms'):~.2f}")
Scaling efficiency: 56.0%
Bubble fraction:    15.8%
DP comm latency:    178.36 ms

Parameter sweeps

For multi-dimensional grid searches under explicit constraints, use DSE (see Design Space Exploration) or CompressionModel.sweep(). For quick one-parameter hardware comparisons, a plain Python loop keeps the analysis completely transparent:

import mlsysim
from mlsysim.solvers import SingleNodeModel

solver = SingleNodeModel()
targets = [
    mlsysim.Hardware.Cloud.T4,
    mlsysim.Hardware.Cloud.A100,
    mlsysim.Hardware.Cloud.H100,
    mlsysim.Hardware.Cloud.B200,
]

for hw in targets:
    p = solver.solve(model=mlsysim.Models.Vision.ResNet50, hardware=hw, batch_size=32)
    print(f"{hw.name:20s}  {p.latency.to('ms'):>8.2f~}  {p.bottleneck}")
NVIDIA T4                 8.10 ms  Compute
NVIDIA A100               1.70 ms  Compute
NVIDIA H100               0.54 ms  Compute
NVIDIA B200               0.24 ms  Compute

Composing Solvers

Real-world questions often require chaining multiple solvers. The output of one solver feeds naturally into the next because all solvers share typed inputs and pint.Quantity-valued outputs.

How to Validate a Result

Use MLSys·im results in three passes:

  1. Check feasibility first. Memory, KV cache, and checkpoint sizes are direct byte counts. If these say the configuration cannot fit, a benchmark will not make it fit.
  2. Check the binding constraint. If the result is memory-bound, compare bandwidth-oriented alternatives; if it is compute-bound, compare FLOP/s and efficiency.
  3. Calibrate before production commitments. For latency and throughput, measure one representative configuration, back-calculate efficiency, then reuse that calibrated value for sweeps. The default efficiency=0.5 is an informed starting point, not a universal constant.

Serving Llama-70B on H100s within budget

  1. ServingModel / ServingCapacityModel: check single-GPU memory feasibility (e.g., INT4 on 1×H100) and size replica count for target QPS and P99 latency.
  2. EconomicsModel: calculate the annual TCO of the resulting node fleet.

The most sustainable way to train GPT-3

  1. DistributedModel: find the optimal parallelism configuration.
  2. SustainabilityModel: compare carbon footprint across regions.

A100s or H100s for inference

  1. SingleNodeModel on A100: get latency and bottleneck.
  2. SingleNodeModel on H100: get latency and bottleneck.
  3. EconomicsModel for each: compare cost per query.

Textbook Chapter Mapping

Each solver connects to canonical chapters, study sheets, and lecture decks in the Machine Learning Systems textbook (see the Cross-Volume Textbook Map for all chapters across Volumes I–IV).

Browse all lecture decks at mlsysbook.ai/slides and chapter study sheets in each volume (Volume I, Volume II).
Solver Vol I Chapters · Labs · Slides Vol II Chapters · Labs · Slides
SingleNodeModel Ch 8: Training · Ch 11: HW Accel (Study sheet · Slides) · Ch 12: Benchmarking Ch 9: Fleet Efficiency (Study sheet · Slides)
CompressionModel Ch 10: Model Compression (Study sheet · Slides) Ch 11: Edge Intelligence (Study sheet · Slides)
ServingModel / ServingCapacityModel Ch 13: Model Serving (Study sheet · Slides) Ch 10: Serving at Scale (Study sheet · Slides)
DistributedModel — Ch 6: Distributed Training (Study sheet · Slides) · Ch 5: Collectives · Ch 3: Fabrics
EconomicsModel Ch 3: ML Lifecycle Ch 2: Compute Infrastructure (Study sheet · Slides)
SustainabilityModel Ch 15: Responsible Engr Ch 15: Sustainable AI (Study sheet · Slides)
ReliabilityModel — Ch 7: Fault Tolerance (Study sheet · Slides)

TipEngine.solve() vs. SingleNodeModel

Engine.solve() is a convenience shortcut that produces identical results to SingleNodeModel().solve(). Use Engine.solve() for quick single-node analysis. Use the individual solver classes (ServingModel, DistributedModel, etc.) for specialized analyses beyond the roofline.


Why Analytical Solvers

MLSys·im is not an empirical profiler (like PyTorch Profiler) or a cycle-accurate simulator (like gem5). It is an analytical modeling platform that computes performance bounds from specifications and first-order equations. This is a deliberate design choice:

  • Speed. Closed-form equations evaluate in microseconds. A sweep over thousands of hardware x model x parallelism configurations takes seconds, which is impossible with empirical profiling.
  • Intuition. By working from equations rather than opaque traces, students see exactly which physical quantity (bandwidth, compute, memory capacity) creates the bottleneck.
  • Accessibility. No hardware required. A laptop running pip install mlsysim produces the same analysis as a $50,000 GPU cluster.
  • Composability. Solvers can be chained because they share typed inputs/outputs. The output of one solver feeds naturally into the next.

Solver Architecture

Every solver follows the same three-step pattern:

  1. Takes typed registry objects (HardwareNode, TransformerWorkload, Fleet, GridProfile) as input. These carry physical units (pint.Quantity), so dimensional errors are caught at runtime.
  2. Applies first-order equations from the Math Foundations page.
  3. Returns typed results: frozen Pydantic result models (PerformanceProfile for SingleNodeModel, and domain *Result subclasses of AnalyticalResult for specialized solvers).

The key principle: every .solve() method is a pure function of its inputs. No hidden state, no side effects, no network calls.


Writing a Custom Solver

A custom solver subclasses ForwardModel and returns a frozen Pydantic result model so it composes cleanly with Pipeline, DSE, and differential explainers:

import pint
from pydantic import BaseModel, ConfigDict
import mlsysim
from mlsysim.hardware.types import HardwareNode
from mlsysim.solvers import ForwardModel

class PowerEfficiencyResult(BaseModel):
    model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)
    device: str
    peak_flops: pint.Quantity
    tdp: pint.Quantity
    flops_per_watt: pint.Quantity

class PowerEfficiencyModel(ForwardModel):
    """Compare hardware on performance-per-watt."""

    def solve(self, hardware: HardwareNode) -> PowerEfficiencyResult:
        if hardware.tdp is None:
            raise ValueError(f"{hardware.name}: no TDP specified")

        flops_per_watt = (hardware.compute.peak_flops / hardware.tdp).to("TFLOPs/s/kW")

        return PowerEfficiencyResult(
            device=hardware.name,
            peak_flops=hardware.compute.peak_flops,
            tdp=hardware.tdp,
            flops_per_watt=flops_per_watt,
        )

# Use it
solver = PowerEfficiencyModel()

for hw in [mlsysim.Hardware.Cloud.H100, mlsysim.Hardware.Cloud.A100,
           mlsysim.Hardware.Cloud.T4, mlsysim.Hardware.Edge.JetsonOrinNX]:
    r = solver.solve(hw)
    print(f"{r.device:25s}  {r.flops_per_watt:>10.1f~}")
NVIDIA H100                    1412.9 TFLOPs / kW / s
NVIDIA A100                     780.0 TFLOPs / kW / s
NVIDIA T4                       928.6 TFLOPs / kW / s
NVIDIA Jetson Orin NX          1000.0 TFLOPs / kW / s

Use pint.Quantity for all physical calculations so that unit errors are caught at runtime. For more complex solvers, inspect mlsysim/engine/solvers/ in the repository.


For the equations behind each solver, see Math Foundations. For full API details, see the API Reference.

Back to top