Skip to main content

Contributing to MLSys·im

Add hardware specs, write solvers, build tutorials, and grow the MLSys Zoo.

MLSys·im improves with every new hardware spec, solver, tutorial, and bug report. This guide explains how to contribute, whether the contributor is a student who spotted a wrong datasheet number, an instructor designing a teaching scenario, or a researcher who needs a new analytical solver.

NoteBefore starting

MLSys·im is maintained as part of the ML Systems textbook project. All contributions go through GitHub. For contributors new to Git and pull requests, GitHub’s guide is a good starting point.

Repository: harvard-edge/cs249r_book


Read the modeling and documentation conventions before changing equations, solver interfaces, or shared scenarios. They describe the code organization, generated API documentation, and textbook compatibility checks. The code walkthrough traces an existing serving scenario from its named inputs to its solver, equations, and result schema. Use it to find the file that owns a change.

At a Glance

Contribution Difficulty Impact Where it lives
Report a bug or wrong spec Beginner High (specs affect all users) GitHub Issues
Add hardware to the Silicon Zoo Intermediate High (expands coverage) mlsysim/hardware/
Add a model to the Model Zoo Intermediate Medium (new workloads) mlsysim/models/
Add a fleet or fabric Intermediate Medium (new topologies) mlsysim/systems/
Add a grid or rack profile Intermediate Medium (new infra) mlsysim/infrastructure/
Write a tutorial Intermediate High (improves learning) docs/tutorials/
Add or improve a solver Advanced High (new analysis capabilities) engine/solvers/

1. Reporting Issues

The fastest way to contribute: open an issue on GitHub.

Good bug reports include:

  • Which spec is wrong (e.g., “A100 peak TFLOP/s in Hardware.Cloud.A100”)
  • The correct value and its source (official datasheet URL preferred)
  • The installed version of MLSys·im (python -c "import mlsysim; print(mlsysim.__version__)")

Good feature requests include:

  • The hardware, model, or solver to add, and why
  • A link to the official specification or paper

2. Adding Hardware to the Silicon Zoo

Every chip in the Silicon Zoo lives in one of five hardware categories: Cloud, Workstation, Mobile, Edge (also aliased as Hardware.Embodied for cyber-physical boards), or Tiny, complemented by shared technology-class tiers in Hardware.Tech. Each entry follows a strict format with mandatory provenance metadata.

TipBackground reading

Read Vol I · Ch 11: Hardware Acceleration (Study sheet · Slides) and Vol II · Ch 2: Compute Infrastructure (Study sheet · Slides) for the accelerator landscape and datasheet specs that feed into MLSys·im’s hardware registry.

Step 1: Add a YAML spec under hardware/data/

Chip and board specs live in the Silicon Zoo; there is no shared constants file to park them in (units live in core/units.py, physical constants in physics/constants.py). Add one YAML file under the right tier, for example mlsysim/hardware/data/cloud/MyAccelerator.yaml. The loader validates the file against HardwareNode at import time and exposes it through the same Python API (Hardware.Cloud.MyAccelerator).

__key__: MyAccelerator
name: Example Accelerator
release_year: 2026
compute:
  peak_flops: 312 TFLOPs / s
  precision_flops:
    fp32: 19.5 TFLOPs / s
    int8: 624 TOPS
memory:
  capacity: 80 GiB
  bandwidth: 2039 GB / s
interconnect:
  name: PCIe Gen4 x16
  bandwidth: 32 GB / s
tdp: 400 W
metadata:
  provenance:
    kind: datasheet
    ref: Example accelerator datasheet
    url: https://...
    verified: "2026-05-30"

Reuse shared records from mlsysim/core/provenance_catalog.py when several entries share one external paper, benchmark, or report. For component-specific hardware or server nodes, define provenance colocated with the item (or inherit from the accelerator’s metadata.provenance). See mlsysim/PROVENANCE.md and run python -m mlsysim.tools.audit_provenance --scope all --strict before opening a PR.

The YAML data layer is intentionally strict: duplicate YAML keys, duplicate __key__ values, missing data directories, and unknown schema fields fail loading. If the value is a technology-class reference, use @tech: rather than copying a shared fact into many devices, for example latency: "@tech:Interconnect.NVLink.latency".

Step 2: Verify with the registry contract tests

The loader contract and duplicate-spec gates run automatically: tests/test_registry_loader_contract.py and tests/test_registry_no_duplicate_specs.py. The legacy core/constants.py catch-all module was deleted outright; tests/test_constants_allowlist.py enforces that neither it nor a compat shim for it ever comes back.

Step 3: Use the canonical path in downstream examples

Examples import Hardware.Cloud.A100, not A100_FLOPS_FP16_TENSOR. Downstream content should use the same canonical registry paths as package tutorials.

Provenance rules

Every registry entry requires metadata.provenance (Provenance model in core/provenance.py). Use kind honestly: datasheet, literature, estimate (needs notes), convention, or illustrative.

  1. Link to an official primary source (manufacturer datasheet, not a blog post)
  2. Set verified (YYYY-MM-DD) on datasheet and literature entries
  3. State which variant in ref or notes (e.g., SXM5 vs. PCIe)
  4. When a spec varies across SKUs, use the most conservative published value unless the variant is specified in the node name

Formatting for QMD and LEGO cells

Display helpers live in mlsysim.fmt, separate from the physics in mlsysim.physics.*:

Helper Use when
fmt(q, precision=1) Human-readable quantities in prose
fmt_int(n) Integer counts without spurious decimals
check(condition, message) Assert invariants in tutorials and LEGO cells
MarkdownStr Inline QMD values that must not be LaTeX-escaped

Registry operands come from zoos; derived values from mlsysim.physics.calc_* or solvers.


3. Adding Models to the Model Zoo

Models live in category YAML files under mlsysim/models/data/: language.yaml, vision.yaml, tiny.yaml, recommendation.yaml, statespace.yaml, generativevision.yaml, and embodied.yaml. Each entry includes a __type__ tag selecting the validated workload class (TransformerWorkload, SparseTransformerWorkload, CNNWorkload, SSMWorkload, DiffusionWorkload, EmbodiedWorkload, or plain Workload).

TipBackground reading

Read Vol I · Ch 6: Network Architectures (Study sheet · Slides) and Vol I · Ch 5: Neural Computation (Study sheet · Slides) for the architectural parameters (layers, heads, hidden dimensions) that define each workload.

Transformer workloads

Llama3_8B:
  __type__: TransformerWorkload
  name: Llama-3.1-8B
  architecture: Transformer
  metadata:
    provenance:
      kind: literature
      ref: 'Dubey et al. (2024), The Llama 3 Herd of Models'
      url: https://arxiv.org/abs/2407.21783
      verified: '2026-03-06'
      id: prov:dubey-llama3-2024
  parameters: 8030000000 param
  inference_flops: 16060000000 flop
  layers: 32
  hidden_dim: 4096
  heads: 32
  kv_heads: 8

For inference_flops, the standard approximation is \(2P\) FLOPs per token for transformer forward passes (multiply-accumulate counted as 2 operations). When a more precise count is available from the paper, use it and note the source in a comment.

CNN workloads

ResNet50:
  __type__: CNNWorkload
  name: ResNet-50
  architecture: CNN
  metadata:
    provenance:
      kind: literature
      ref: 'He et al. (2016), Deep Residual Learning for Image Recognition'
      url: https://arxiv.org/abs/1512.03385
      verified: '2026-03-06'
      id: prov:he-resnet-2015
  parameters: 25600000 param
  inference_flops: 8200000000 flop
  layers: 50

4. Adding Systems and Infrastructure

MLSys·im models the full deployment stack: individual accelerators compose into nodes, nodes compose into racks and fleets, and fleets connect via network fabrics. Infrastructure captures the grid, datacenter environment, pricing, and capacity facts that those systems run within.

TipBackground reading

Read Vol II · Ch 3: Network Fabrics (Study sheet · Slides) and Vol II · Ch 8: Fleet Orchestration (Study sheet · Slides) for the network topologies and cluster compositions that MLSys·im models analytically.

Adding a fleet or fabric (systems/registry.py)

# A new reference node (inheriting or defining colocated provenance)
DGX_B200 = Node(
    name="DGX B200",
    accelerator=Hardware.Cloud.B200,
    accelerators_per_node=8,
    intra_node_bw=1800 * ureg.GB / ureg.second,
    nics_per_node=8,
    psus_per_node=6,
    psu_redundancy=1,
    psu_rating=3.3 * kilowatt,
    max_power=14.3 * kilowatt,
    metadata=Metadata(
        provenance=pc.DGX_B200_USER_GUIDE_POWER,
        description="Official NVIDIA DGX B200 server: 8x B200 180GB SXM6, six 3.3 kW PSUs in 5+1 redundancy (14.3 kW max).",
    ),
)

# A new cluster built from that node
Training_2K = Fleet(
    name="Training Cluster (2048 GPUs)",
    node=DGX_B200,
    count=256,  # 256 nodes x 8 GPUs = 2048
    fabric=Fabrics.InfiniBand_NDR,
    metadata=Metadata(
        provenance=pc.CLUSTER_TIER_CONVENTIONS,
        description="2,048-GPU training cluster tier on InfiniBand NDR.",
    ),
)

Adding a grid profile (infrastructure/data/grids.yaml)

Grid profiles capture the carbon intensity, cooling efficiency (PUE), and water usage (WUE) of a datacenter region.

Iceland:
  name: Iceland (Geothermal)
  carbon_intensity_g_kwh: 28
  pue: 1.06
  wue: 0.0
  primary_source: geothermal
  metadata:
    provenance: "@prov:IEA_WEO_2023"
TipBackground reading

Read Vol II · Ch 15: Sustainable AI (Study sheet · Slides) for PUE, WUE, and carbon intensity, the exact quantities that GridProfile captures.


5. Writing a Tutorial

The best tutorials teach one insight through one concrete example. Before writing, answer three questions:

  1. What is the one thing the reader will understand after this tutorial?
  2. What would they have guessed incorrectly before reading it?
  3. What surprising number will they compute?

Tutorial structure

Follow the pattern established in Hello, Roofline, Geography is a Systems Variable, Two Phases of Inference, and Scaling to 1000 GPUs:

---
title: "Short, specific title"
subtitle: "Payoff sentence: core lesson in 10 words."
---

[2-3 sentence hook: what problem does this solve?]

This tutorial covers:
- [Concept 1]
- [Concept 2]
- [Concept 3]

::: {.callout-tip}
## Background concept
[1-paragraph intuition before any code]
:::

## 1. Setup
[clean import block: `import mlsysim` and explicit `mlsysim.solvers` imports]

## 2. First Example
[minimal working code + output]

## 3-N. Build Understanding
[progressive complexity, callouts explaining surprising results]

## Where This Clicks in the Textbook
[rendered automatically from `docs/config/curriculum_links.yml` via `render_tutorial_links("<slug>")`]

## Next Steps
[2-3 links to related content]

Code style in tutorials

  • Use clean imports: Start with import mlsysim. The package is pip install-ed in the docs build environment (see .github/workflows/mlsysim-preview-dev.yml), so no path manipulation is needed.
  • Use Zoo entries: Pull from mlsysim.Hardware.Cloud.A100, mlsysim.Models.Language.Llama3_70B, etc.; tutorial code contains no hardcoded constants
  • Print with units: Always use pint’s ~ format spec: f"{value.to('ms'):~.2f}"
  • Comment sparingly: Code should be readable without comments; add a callout if explanation is needed

Linking to textbook chapters, labs, and slide decks

Register new tutorials in docs/config/curriculum_links.yml and call render_tutorial_links("<slug>") so readers get validated links to web chapters, study sheets, and Beamer slides (with automatic .mls-unreleased gating for Volumes III and IV). Canonical companions for common tutorial topics:

Tutorial topic Textbook Chapter · Study Sheet · Slides
Roofline analysis Vol I · Ch 11: Hardware Acceleration (Study sheet · Slides)
Benchmarking & MFU Vol I · Ch 12: Benchmarking (Study sheet · Slides), Vol II · Ch 9: Fleet Efficiency (Study sheet · Slides)
LLM serving (TTFT/ITL) Vol I · Ch 13: Model Serving (Study sheet · Slides), Vol II · Ch 10: Serving at Scale (Study sheet · Slides)
Distributed training Vol I · Ch 8: Model Training (Study sheet · Slides), Vol II · Ch 6: Distributed Training (Study sheet · Slides)
Collective communication Vol II · Ch 5: Collective Communication (Study sheet · Slides)
Fault tolerance Vol II · Ch 7: Fault Tolerance (Study sheet · Slides)
Sustainability & carbon Vol II · Ch 15: Sustainable AI (Study sheet · Slides)
Model compression Vol I · Ch 10: Model Compression (Study sheet · Slides)
Network architectures Vol I · Ch 6: Network Architectures (Study sheet · Slides)

6. Adding or Improving a Solver

MLSys·im ships 276 concrete analytical resolvers (see mlsysim.solvers), each grounded in peer-reviewed literature or textbook derivations. All inherit from the 3-Tier base classes (ForwardModel, BaseSolver, BaseOptimizer) and implement solve(...). Six foundational models illustrate the core contract:

Solver What it computes Key references
SingleNodeModel Roofline bounds, MFU/HFU Williams et al. (2009)
DistributedModel 3D/4D parallelism, all-reduce, pipeline bubbles Shoeybi et al. (2019), Narayanan et al. (2019)
ReliabilityModel MTBF, failure probability, Young-Daly checkpointing Young (1974), Daly (2006)
SustainabilityModel Energy, carbon, water (PUE, WUE) Patterson et al. (2021)
EconomicsModel CapEx, OpEx, TCO Barroso et al. (2018)
ServingModel TTFT, ITL, KV-cache pressure Pope et al. (2023), Patel et al. (2024), Agrawal et al. (2024)
TipBackground reading

Read Vol II · Ch 9: Fleet Efficiency (Study sheet · Slides) and Vol II · Ch 6: Distributed Training (Study sheet · Slides) for the analytical models (Roofline, all-reduce cost, pipeline bubbles) that the solvers implement.

Solver contribution checklist

  1. Place canonical equations in mlsysim/physics/: every solver equation must be independently callable and unit-tested
  2. Inherit from ForwardModel (or BaseSolver / BaseOptimizer) and return a frozen Pydantic *Result model (ConfigDict(frozen=True, arbitrary_types_allowed=True)) from solve(...)
  3. Use pint units throughout: all physical inputs and outputs must carry Pint units
  4. Cite the source paper or chapter in the solver class docstring (References: section)
  5. Add tests (e.g. in tests/test_solver_invariants.py or a dedicated test file) covering dimensional invariants and at least one verified calculation
  6. Export in mlsysim.solvers and regenerate API reference pages via python3 docs/scripts/build_api.py (never hand-edit generated files under docs/api/)

Example: extending a solver

All formulas live in mlsysim/physics/ so they can be tested in isolation:

# In mlsysim/mlsysim/physics/
def ring_allreduce_time(message_bytes, num_nodes, bandwidth):
    """Ring all-reduce latency: 2(N-1)/N * M/B.

    Reference: Thakur et al. (2005), "Optimization of Collective
    Communication Operations in MPICH."
    """
    return 2 * (num_nodes - 1) / num_nodes * message_bytes / bandwidth

7. Running Tests

Before submitting a pull request, ensure the test suite passes:

# Install development dependencies
pip install -e ".[dev]"

# Run the full test suite (from the mlsysim package root)
pytest tests/ -v

# Run a specific test file
pytest tests/test_solver_invariants.py -v

Key areas of the test suite:

Test file What it validates
test_engine.py Single-node inference, OOM exceptions, precision switching
test_hardware.py Registry access, ridge point calculation, JSON serialization
test_solver_invariants.py / test_solver_module_exports.py Solver behavior and the public mlsysim.solvers surface
test_empirical.py Empirical validation against published numbers
test_registry_loader_contract.py / test_constants_allowlist.py YAML loader contract and the retired-constants gate

8. Submitting a Pull Request

  1. Fork the repository on GitHub
  2. Create a branch with a descriptive name: git checkout -b feat/add-b200-hardware
  3. Make the changes following the patterns in this guide
  4. Run tests to confirm nothing is broken
  5. Open a PR against the dev branch with:
    • A clear description of what changed and why
    • A link to the source document for any new spec values
    • Output showing the change working (python -c "..." snippet)

Branch naming conventions

Type Pattern Example
New feature feat/<scope> feat/add-mi300x-hardware
Bug fix fix/<scope> fix/a100-bandwidth-typo
Documentation docs/<scope> docs/tutorial-kv-cache
Tests test/<scope> test/reliability-solver

9. Architecture Overview

Knowing the module layout makes it easier to find the right file to edit.

mlsysim/
  core/
    loader.py              # YAML loading, duplicate-key checks, registry generation
    provenance.py          # Sourced values and provenance schema
    provenance_catalog.py  # Shared citation records across registries
    registry/              # Base Registry pattern
    types.py               # Shared schema types
    units.py               # Unit registry and exported Pint units
  engine/
    solvers/               # 3-Tier ForwardModel / BaseSolver / BaseOptimizer classes
    scenario_definitions/  # Runnable Scenarios.* domain definitions
    scenario_catalog/      # Scenario index and metadata helpers
    calibration.py         # Documented solver defaults (efficiency, dispatch)
    walls.py               # The 20 Walls of ML Systems metadata
  physics/                 # Canonical calc_* implementations (roofline, all-reduce, TCO, …)
  hardware/data/           # Hardware.* YAML zoo (Cloud, Edge/Embodied, Mobile, Tiny, Workstation, Tech)
  models/data/             # Models.* YAML zoo (7 workload families)
  datasets/data/           # Datasets.* YAML zoo
  systems/registry.py      # Systems.Nodes / Racks / Fabrics / Clusters / Storage / Pods
  infrastructure/          # Infrastructure.* grids, datacenters, cooling, capacity, pricing
  platforms/registry.py    # Platforms.* deployment envelopes
  agents/                  # Agents.* zoo (Vol III agentic profiles & harnesses)
  embodied/                # Embodied.* zoo (Vol IV cyber-physical platforms)
  sensors/                 # Sensors.* zoo (cameras, LiDARs, IMUs, safety scanners)
  actuators/               # Actuators.* zoo (drivetrains, servos, safety relays)
  ops/                     # Ops.* zoo (monitoring, runtime/memory/preemption overheads)
  literature/              # Literature.* cited appendix scalars
  reference_stats/         # ReferenceStats.* non-executable empirical anchors
  fmt/                     # Markdown/LaTeX quantity formatting & check() assertions
  viz/                     # Plotting helpers (Roofline, TCO, scaling curves)
  cli/                     # Typer CLI commands (`mlsysim eval`, `serve`, `fleet`, …)
  tests/                   # pytest suite (invariants, empirical bounds, loader & link gates)
  docs/                    # Quarto documentation site & generated API reference

Community Standards

MLSys·im is a pedagogical tool used in courses at Harvard and beyond. Contributions should:

  • Prioritize accuracy over completeness: a wrong spec is worse than a missing one
  • Cite sources: every number needs a URL to an official datasheet or peer-reviewed paper
  • Explain the analytical reasoning: a tutorial that teaches why is better than one that shows how
  • Use units everywhere: pint prevents dimensional errors; do not bypass it with raw floats

Every contribution makes MLSys·im more accurate and more useful for the next generation of ML systems engineers.

Back to top