Skip to main content

Auto-graded exercises in low-level ML systems: real C++, real CUDA-C on a software GPU, deterministic metrics

Project description

mlsys-lab

Auto-graded exercises in low-level ML systems. You write real C++, real CUDA-C and Python; a local grader runs it and checks a measured number against declarative gates.

No cloud, no account, no GPU required. Every metric is deterministic, so the same submission scores identically on any machine.

$ mlsys grade gpu-1-padding-to-remove-transpose-bank-conflicts

  max_abs_err        0.0        <= 1e-12   PASS
  smem_wave_ratio    16.5       <= 1.05    FAIL
                     ^ your tile is 32 wide, so every column read hits one bank

Why the numbers are trustworthy

Wall-clock timing is never a gate. Instead the engine models the hardware and counts what actually happened:

you write it runs on it measures
solve.cu a software GPU: 32-lane warps, 128-byte transactions, 32 shared-memory banks, barriers, warp shuffles coalescing transactions, bank-conflict waves, warp divergence, cycles
solve.cpp the local clang++ -O2 -std=c++20, plus a modelled set-associative cache cache misses, lines touched, and the program's own output
solve.py the interpreter, with an instrumented probe allocations, copies, numerical error against a computed oracle

The reference answer is always computed by the grader, never hard-coded — so a task cannot be passed by guessing the expected output.

Install

pip install mlsys-lab           # the engine and all 2052 tasks

mlsys list                      # browse the bank
mlsys grade <task-id> --file my_solution.py

The bank ships inside the package, so there is nothing to clone and nothing to download on first run. Your solutions live wherever you put them — --file takes a path, and the bank is never written to.

C++ tasks need a C++20 compiler (clang++ or g++); everything else is Python plus NumPy. CUDA tasks need no NVIDIA hardware — the .cu is executed by the simulator in src/mlsys/sim/.

VS Code

Install mlsys-lab from the Marketplace, then run mlsys-lab: Open Workspace. If the package is not installed yet, the extension offers to do it. Solutions go to ~/mlsys-lab/<task-id>/ (configurable via mlsys.workDir).

Contributing to the bank

git clone https://github.com/mikamika06/mlsys-lab
cd mlsys-lab && pip install -e .

A checkout takes precedence over the installed copy, so the tasks you are editing are the ones that get graded. $MLSYS_TASKS overrides both.

What is in the bank

Three native tracks plus the systems material:

  • Deep Python — the data model, descriptors, the GIL, memory layout
  • Deep C++ — ownership, moves, ABI, undefined behaviour you can observe
  • CPU performance — cache blocking, layout (AoS/SoA), branches, SIMD
  • GPU / CUDA — coalescing, bank conflicts, divergence, barriers, shuffles
  • Numerics & tensors — stability, shapes and strides, low-precision formats
  • LLM internals — attention, RoPE, GQA, the KV cache, sampling
  • LLM systems — paged KV, continuous batching, parallelism, speculative decoding
  • Applied — quantization, attention/KV, export & compilation, serving, memory & offload, sparsity & distillation

Concepts, explained with a number

docs/concepts/ — one page per concept, each with a measurement produced by the simulator in this repo and the command that regenerates it, then the graded exercise. Start with memory coalescing (128-byte transactions against read stride, 2 → 33) or false sharing (coherence invalidations against padding, 7,999 → 0).

What else exists

docs/LANDSCAPE.md surveys the other resources aimed at each of these areas — 141 of them, every link checked — and marks whether each one actually grades your work or only shows you code. It says where this bank is not your best option, which is most of the point of having the page.

The short version: GPU/CUDA, algorithms-from-scratch and LLM internals are well served already (GPU-Puzzles, LeetGPU, Tensara, deep-ml, CS336, LeetCUDA). Six of the fourteen areas have no auto-graded resource anywhere, and four — applied quantization, compilation & export, memory & offload, and sparsity/pruning/distillation — have nothing to practise against at all: papers, production libraries and documentation, but no exercise that tells you that you got it wrong.

Writing a task

A task is a directory under tasks/. See docs/TASK_FORMAT.md.

tasks/<id>/
  meta.json     id, title, difficulty, gates       ("native": "cpp" | "cuda")
  task.md       ## Context / ## Task / ## Example / ## What the gate checks
  check.py      grade(sol, fx) -> {metric: value}  — computes its own reference
  starter.py    the empty contract the learner starts from
  solution_ref.py
tools/verify_task.sh   <id>    # python task:  reference passes, starter fails
tools/verify_native.sh <id>    # C++ / CUDA task

Both print TASK_OK only if the reference passes the gates and the shipped starter fails them — a task that anything can pass is not a task.

Layout

src/mlsys/        the engine
  sim/            software GPU, CUDA-C front end, cache model, ABI model
  runners/        cpp.py (clang++), cuda.py (software GPU)
  scorers.py      the metrics tasks gate on
tasks/            the bank
editor/           VS Code extension
tools/            verify, queue helpers, browser preview
docs/             curriculum and research

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlsys_lab-0.1.0.tar.gz (9.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlsys_lab-0.1.0-py3-none-any.whl (12.2 MB view details)

Uploaded Python 3

File details

Details for the file mlsys_lab-0.1.0.tar.gz.

File metadata

  • Download URL: mlsys_lab-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mlsys_lab-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbe057504a6d6ee40691b191b92ad0a1a4c96923ae6bc12e70927cb7ba347d84
MD5 9f4755c9465dcbc3a2bee2cb8b4840b3
BLAKE2b-256 48ed5b96b182f11cc108ee5c411b3da534c2c3a648c5fb3e86ff0ce9e4d52500

See more details on using hashes here.

File details

Details for the file mlsys_lab-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mlsys_lab-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for mlsys_lab-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee6f34b00dd80e343795fda0f72ae7970015f22871b5b5b000717085f0eed1c2
MD5 c34d03e6f27a58e5a5fcfb6c8160efc1
BLAKE2b-256 8ab386ef3ff6202d67f02279f7e44b34d99ab9e3dca24ab4b39192405caf2ff1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page