mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-03-11 17:49:25 -05:00
- book/quarto/mlsys/__init__.py: add repo-root sys.path injection so
mlsysim is importable when scripts run from book/quarto/ context
- book/quarto/mlsys/{constants,formulas,formatting,hardware}.py: new
compatibility shims that re-export from mlsysim.core.* and mlsysim.fmt
- mlsysim/viz/__init__.py: remove try/except for dashboard import; use
explicit "import from mlsysim.viz.dashboard" pattern instead
- .codespell-ignore-words.txt: add "covert" (legitimate security term)
- book/tools/scripts/reference_check_log.txt: delete generated artifact
- Various QMD, bib, md files: auto-formatted by pre-commit hooks
(trailing whitespace, bibtex-tidy, pipe table alignment)
MLSys Developer Guide
The Physics-Based ML Systems Simulator Package
This package is the "Single Source of Truth" for the Machine Learning Systems textbook. It provides a hierarchical analytical engine for modeling, simulating, and optimizing ML systems from microcontrollers to global fleets.
🏗 Architecture (The 5-Layer Stack)
The package is organized hierarchically. Each layer depends only on the ones below it.
mlsysim.constants&mlsysim.formulas: The "Iron Laws" and physical truth (H100 specs, Grid carbon intensity).mlsysim.ledger: The "Universal Scorecard." Defines theSystemLedgerdata structure used for all results.mlsysim.engine: The "Solver." Computes static performance (Latency, MFU, Energy) for a single node.mlsysim.personas: The "Scale Layer." Defines personas (Cloud Titan, Tiny Pioneer) and their scale multipliers.mlsysim.simulations: The "Decision Engine." Implements domain logic (Sustainability, Reliability) that processes choices into ledgers.
🚀 For TAs & Researchers: How to Extend
1. Creating a Custom Simulation
To build a new interactive lab, subclass BaseSimulation and implement the evaluate method.
from mlsysim import BaseSimulation, SystemLedger
class MyCustomSimulation(BaseSimulation):
def evaluate(self, choice: dict) -> SystemLedger:
# 1. Get baseline node performance
system = self._get_system_archetype()
perf = Engine.solve(self.scenario.model, system)
# 2. Scale by persona
scale = self.persona.scale_factor
# 3. Add your custom physics logic here...
# 4. Return a SystemLedger
return SystemLedger(...)
2. Adding a New Hardware "Twin"
Add a new entry to mlsysim/hardware.py using the HardwareSpec dataclass.
🧪 Integration Testing
You can run the analytical engine directly in any Python environment:
from mlsysim import ResourceSimulation, Applications, Personas
sim = ResourceSimulation(Applications.Doorbell, Personas.TinyPioneer)
ledger = sim.evaluate({"region": "Quebec"})
print(f"Carbon Footprint: {ledger.sustainability.carbon_kg} kg")