mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-04-30 01:29:07 -05:00
Moves the mlsysim package from book/quarto/mlsysim/ to the repo root so it is importable as a proper top-level package across the codebase. Key changes: - mlsysim/fmt.py: new top-level module for all formatting helpers (fmt, sci, check, md_math, fmt_full, fmt_split, etc.), moved out of viz/ - mlsysim/viz/__init__.py: now exports only plot utilities; dashboard.py (marimo-only) is no longer wildcard-exported and must be imported explicitly by marimo labs - mlsysim/__init__.py: added `from . import fmt` and `from .core import constants`; removed broken `from .viz import plots as viz` alias - execute-env.yml: fixed PYTHONPATH from "../../.." to "../.." so chapters resolve to repo root, not parent of repo - 51 QMD files: updated `from mlsysim.viz import <fmt-fns>` to `from mlsysim.fmt import <fmt-fns>` - book/quarto/mlsys/: legacy shadow package contents cleaned up; stub __init__.py remains for backward compat - All Vol1 and Vol2 chapters verified to build with `binder build pdf`
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
# test_registry.py
|
|
# Unit tests for the mlsysim Hardware and Models registries.
|
|
|
|
import unittest
|
|
from mlsysim import Hardware, Models
|
|
from mlsysim.constants import ureg
|
|
|
|
class TestMLSysRegistry(unittest.TestCase):
|
|
def test_hardware_ridge_points(self):
|
|
"""Test that ridge points are calculated correctly and are positive."""
|
|
h100 = Hardware.H100
|
|
ridge = h100.ridge_point()
|
|
self.assertGreater(ridge.magnitude, 0)
|
|
self.assertEqual(ridge.units, ureg.parse_units('flop/byte'))
|
|
|
|
# H100: ~2 PFLOPS / 3.35 TB/s = ~590 FLOP/byte
|
|
self.assertGreater(ridge.magnitude, 100)
|
|
self.assertLess(ridge.magnitude, 1000)
|
|
|
|
def test_model_size(self):
|
|
"""Test model weight storage calculations."""
|
|
gpt3 = Models.GPT3
|
|
from mlsysim.constants import BYTES_FP16, BYTES_INT4
|
|
|
|
# GPT-3 175B @ FP16 (2 bytes) = 350 GB
|
|
size_fp16 = gpt3.size_in_bytes(BYTES_FP16)
|
|
self.assertAlmostEqual(size_fp16.to('GB').magnitude, 350, delta=1)
|
|
|
|
# GPT-3 175B @ INT4 (0.5 bytes) = 87.5 GB
|
|
size_int4 = gpt3.size_in_bytes(BYTES_INT4)
|
|
self.assertAlmostEqual(size_int4.to('GB').magnitude, 87.5, delta=1)
|
|
|
|
def test_assertions(self):
|
|
"""Test that unrealistic hardware/models trigger assertions."""
|
|
from mlsysim.hardware import HardwareSpec
|
|
from mlsysim.models import ModelSpec
|
|
|
|
# Non-positive bandwidth
|
|
with self.assertRaises(AssertionError):
|
|
HardwareSpec("Broken", 2024, 0 * ureg.GB/ureg.s, 1 * ureg.TFLOPs/ureg.s, 1 * ureg.GB)
|
|
|
|
# Non-positive params
|
|
with self.assertRaises(AssertionError):
|
|
ModelSpec("Ghost", 0 * ureg.count, "Transformer")
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|