import mlsysim
from mlsysim.engine.dse import DSE
from mlsysim.solvers import DistributedModel, EconomicsModel
from mlsysim.engine.pipeline import PipelineDesign Space Exploration (DSE)
Declaratively navigate trade-offs without writing nested for-loops.
The Question
Optimizing an ML system often involves navigating complex trade-offs: choosing between Tensor Parallelism (TP) and Pipeline Parallelism (PP), or deciding whether a larger batch size improves throughput without violating a strict 50ms latency SLA.
Building a real system requires searching a vast grid of possibilities, evaluating the analytical constraints of each point, and ranking the configurations by a target objective. How do we explore this design space cleanly, without writing messy nested loops?
- Define a declarative
SearchSpaceof system parameters. - Formulate optimization objectives (e.g.,
minimize: EconomicsModel.tco_usd). - Execute an exhaustive search using the
DSEengine. - Filter configurations based on HBM feasibility and step-latency SLA constraints.
1. Setup
Import the necessary classes. The DSE (Design Space Explorer) is the Tier 3 engine that wraps around any Tier 1 analytical model.
2. Defining the Evaluation Function
The search first needs a function that evaluates a given configuration point. It uses the Pipeline from Composable Pipelines & Callbacks to chain distributed performance and economics, rejecting configurations whose per-GPU shard exceeds HBM capacity (node_profile.feasible == False).
# Fixed baseline constants: 1,024 H100 GPUs across 128 DGX H100 nodes on InfiniBand NDR
model = mlsysim.Models.Language.Llama3_70B
fleet = mlsysim.Systems.Clusters.Training_1K
# The evaluation function accepts a dictionary of parameters and returns a structured object
def evaluate_config(params):
pipe = Pipeline([DistributedModel(), EconomicsModel()])
res = pipe.run(
model=model,
fleet=fleet,
batch_size=params["batch_size"],
tp_size=params["tp"],
pp_size=params["pp"],
microbatch_count=16,
precision="fp16",
efficiency=0.45,
duration_days=30
)
if not res["DistributedModel"].node_profile.feasible:
raise ValueError("Model shard exceeds per-GPU HBM")
return resThis baseline pairs Llama-3.1-70B (70.6B parameters) with Training Cluster (1024 GPUs) (1,024 accelerators across 128 nodes).
3. The Declarative Search
Rather than writing three nested for loops to test batch_size, tp, and pp, define the DSE engine declaratively to find the HBM-feasible configuration that maximizes effective training throughput.
# 1. Define the dimensions of the search grid (global batch >= DP ranks)
space = {
"batch_size": [1024, 2048, 4096],
"tp": [1, 2, 4, 8],
"pp": [1, 2, 4]
}
_n_combinations = len(space["batch_size"]) * len(space["tp"]) * len(space["pp"])
# 2. Initialize the Design Space Explorer
dse = DSE(
space=space,
objective="maximize: DistributedModel.effective_throughput"
)
# 3. Search across all combinations analytically
print(f"Starting search across {_n_combinations} configurations...")
result = dse.search(evaluate_config)
# 4. Analyze the best configuration
best_params = result["best_params"]
best_throughput = result["best_objective"]
print(f"\nBest Configuration: TP={best_params['tp']}, PP={best_params['pp']}, Batch={best_params['batch_size']}")
print(f"Max Throughput: {best_throughput:,.1f} samples/sec")Starting search across 36 configurations...
Best Configuration: TP=8, PP=4, Batch=4096
Max Throughput: 374.5 samples/sec
Across all 36 combinations (3 × 4 × 3), DSE skips unsharded OOM candidates and identifies TP=8, PP=4, Batch=4096 with a peak throughput of 374.5 samples/sec (10,938 ms per step) and a 30-day TCO of $875,939.
4. Applying SLA Constraints
Maximizing raw throughput selects Batch=4096, pushing per-step latency past 10 seconds. Passing declarative constraints to DSE enforces hard step-latency (<= 6000 ms) and scaling-efficiency (>= 0.65) bounds without changing the evaluator:
dse_sla = DSE(
space=space,
objective="maximize: DistributedModel.effective_throughput",
constraints=[
"DistributedModel.step_latency_total <= 6000.0",
"DistributedModel.scaling_efficiency >= 0.65",
],
)
sla_result = dse_sla.search(evaluate_config)
print("Top SLA-Compliant Configurations (Step <= 6,000 ms, Efficiency >= 65%):")
print(f"{'TP':>4} | {'PP':>4} | {'Batch':>6} | {'Throughput':>12} | {'Step Time':>10} | {'Efficiency':>10}")
print("-" * 62)
for candidate in sla_result["top_candidates"][:3]:
p = candidate["params"]
dist_res = candidate["result"]["DistributedModel"]
throughput = dist_res.effective_throughput.to("1/s").magnitude
latency = dist_res.step_latency_total.to("ms").magnitude
print(f"{p['tp']:>4} | {p['pp']:>4} | {p['batch_size']:>6} | {throughput:>12,.1f} | {latency:>8,.1f}ms | {dist_res.scaling_efficiency:>9.1%}")Top SLA-Compliant Configurations (Step <= 6,000 ms, Efficiency >= 65%):
TP | PP | Batch | Throughput | Step Time | Efficiency
--------------------------------------------------------------
8 | 2 | 2048 | 371.9 | 5,507.3ms | 70.8%
8 | 4 | 2048 | 363.1 | 5,640.7ms | 69.1%
8 | 4 | 1024 | 342.3 | 2,991.8ms | 65.2%
Enforcing the 6-second step budget shifts the optimal choice to TP=8, PP=2, Batch=2048, retaining 371.9 samples/sec while cutting step latency nearly in half.
Where This Clicks in the Textbook
Frames ML systems engineering as constrained multi-objective optimization across latency, cost, and quality.
Maps declarative SLA constraints and Pareto trade-offs onto heterogeneous cluster hardware.
Extends design-space search to partitioning perception and planning across robot compute and cloud links.
Next Steps
- Full-Stack Audit: LLaMA-70B Training: Compose solvers across all six taxonomy domains in one end-to-end analysis
- Composable Pipelines & Callbacks: Build custom multi-solver pipelines and attach logging callbacks
- Where to Invest: Sensitivity Analysis: Identify binding constraints using partial derivatives and inverse Roofline synthesis