mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 23:24:55 -05:00
Move the simulator out of core/ into a new engine/ package: solver, engine,
evaluation, results, pipeline, dse, walls, resolver_factory, explainers,
config, calibration, and the evaluatable scenarios bundle. core/ now holds
only primitives (units, types, provenance, registry, validation, exceptions).
No core primitive imports an engine module; the dependency runs one way.
Also relocate the appendix_lineage audit gate (a used lineage auditor, NOT
vestigial — kept, not deleted) from core/ to tools/, beside its consumer
audit_provenance.py.
Consumers repointed mlsysim.core.<mod> -> mlsysim.engine.<mod> (and the
from-core-import-calibration form): package internals (cli, sim, solvers,
viz), tests, runnable examples, paper scripts, and 9 book chapters. Pure
reorg, zero functional change.
482 passed; import clean (no cycles); vol1 (engine.calibration) and vol2
(engine.solver) chapters render with 0 {python} leaks, 0 tracebacks.
Deferred to P10: mlsysim/docs prose, generated docs/api/* stubs, tutorial
slides, paper.tex, README — propagate to website/slides/paper.
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
"""
|
|
Example: Custom System Design
|
|
=============================
|
|
This script demonstrates how to build a hypothetical system from scratch
|
|
without using the vetted registries. This is how researchers can use
|
|
mlsysim to model unreleased or generic hardware.
|
|
"""
|
|
|
|
import mlsysim
|
|
from mlsysim.hardware.types import HardwareNode, ComputeCore, MemoryHierarchy
|
|
from mlsysim.models.types import CNNWorkload
|
|
from mlsysim.engine.scenarios import Scenario
|
|
|
|
def main():
|
|
print("--- Designing a Hypothetical 'Generic Drone' ---")
|
|
|
|
# 1. Manually define hardware (Supply)
|
|
drone_chip = HardwareNode(
|
|
name="Hypothetical Drone NPU",
|
|
release_year=2026,
|
|
compute=ComputeCore(peak_flops="10 TFLOPs/s"),
|
|
memory=MemoryHierarchy(capacity="2 GB", bandwidth="50 GB/s"),
|
|
tdp="10 W",
|
|
dispatch_tax="0.5 ms"
|
|
)
|
|
|
|
# 2. Manually define workload (Demand)
|
|
my_model = CNNWorkload(
|
|
name="Custom Vision Model",
|
|
architecture="CNN",
|
|
parameters="50 Mparam",
|
|
inference_flops="10 Gflop"
|
|
)
|
|
|
|
# 3. Bundle into a Scenario
|
|
my_scenario = Scenario(
|
|
name="Generic Drone Vision",
|
|
description="A custom vision task on unreleased drone hardware.",
|
|
workload=my_model,
|
|
system=drone_chip,
|
|
sla_latency="30 ms"
|
|
)
|
|
|
|
# 4. Evaluate the custom design
|
|
print(f"Evaluating {my_scenario.name}...")
|
|
report = my_scenario.evaluate()
|
|
print(report.scorecard())
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# Expected output (mlsysim v0.1.1):
|
|
# --- Designing a Hypothetical 'Generic Drone' ---
|
|
# Evaluating Generic Drone Vision...
|
|
# +============================================================+
|
|
# | MLSys-im SYSTEM EVALUATION
|
|
# | Scenario: Generic Drone Vision
|
|
# +============================================================+
|
|
# | Level 1: Feasibility [PASS]
|
|
# | Model fits in memory (100.0 MB / 2000.0 MB)
|
|
# +------------------------------------------------------------+
|
|
# | Level 2: Performance [PASS]
|
|
# | Latency: 2.71 millisecond (Target: 30 ms)
|
|
# +------------------------------------------------------------+
|
|
# | Level 3: Macro/Economics [PASS]
|
|
# | Annual Carbon: 42.1 kg | TCO: $11,512
|
|
# +============================================================+
|