mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-11-14 18:24:37 -06:00
Every module page carries a "Launch Binder" button, and binder/postBuild built those notebooks with `jupytext --to notebook src/NN_x/NN_x.py`. That is the reference source. convert_py_to_notebook's own docstring draws the line: student=False "keeps the full reference", student=True "clears every student-core solution region to nbgrader's stub". Raw jupytext is the student=False path, so a Binder student opened 01_tensor and found all 17 solution regions already solved. #1684 closed exactly this leak for `tito module start`; the Binder path was never updated. Measured before: 17 BEGIN SOLUTION regions, bodies intact (`if isinstance(data, Tensor): data = data.data`). Measured after: 0 regions, 7 NotImplementedError stubs, bodies gone. postBuild now generates through convert_py_to_notebook(student=True), so Binder and local students get byte-identical notebooks from one code path, and then asserts no notebook contains an unstubbed solution region, failing the image build if one does. Also removes tinytorch/binder/{requirements.txt,postBuild}. repo2docker reads config from the repo root, binder/, or .binder/, so in a monorepo tinytorch/binder/ is never consulted. Both files claimed to be kept synchronized with the live pair and were not: numpy >=1.24 vs >=2.2.6, rich >=13 vs >=15, ipykernel >=6.31 vs >=7.2. Because nothing read them, the drift was invisible. The README stays, rewritten to point at the live pair and to record why the duplicates are gone.
88 lines
2.8 KiB
Bash
Executable File
88 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Binder (mybinder.org) postBuild script.
|
|
# repo2docker reads its configuration from binder/, which is also the book
|
|
# toolchain; postBuild and requirements.txt are the only files here it uses.
|
|
|
|
set -euo pipefail
|
|
|
|
echo "🔧 Setting up TinyTorch from monorepo..."
|
|
cd tinytorch
|
|
|
|
echo "🔧 Installing TinyTorch package..."
|
|
pip install -e .
|
|
|
|
echo ""
|
|
echo "📓 Generating student notebooks from source..."
|
|
# These notebooks MUST be generated the same way `tito module start` generates
|
|
# them, i.e. through convert_py_to_notebook(student=True), which clears every
|
|
# student-core solution region to nbgrader's stub.
|
|
#
|
|
# This script used to call `jupytext --to notebook src/NN_x/NN_x.py` directly.
|
|
# That is the `student=False` path: it shipped the full reference solution in
|
|
# every notebook a Binder student opened (17 solved regions in 01_tensor
|
|
# alone), which is exactly the leak #1684 closed for the local workflow.
|
|
python3 - <<'PY'
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path.cwd()))
|
|
from tito.commands.export_utils import convert_py_to_notebook
|
|
|
|
|
|
class _Console:
|
|
def print(self, *args, **kwargs):
|
|
if args:
|
|
print(args[0])
|
|
|
|
|
|
root = Path.cwd()
|
|
venv = Path(sys.prefix)
|
|
failed = []
|
|
|
|
for src in sorted((root / "src").iterdir()):
|
|
if not src.is_dir() or not (src / f"{src.name}.py").exists():
|
|
continue
|
|
print(f" 📝 Converting {src.name}...")
|
|
if not convert_py_to_notebook(src, venv, _Console(),
|
|
student=True, project_root=root):
|
|
failed.append(src.name)
|
|
|
|
if failed:
|
|
sys.exit(f"❌ Failed to generate student notebooks: {', '.join(failed)}")
|
|
PY
|
|
|
|
echo ""
|
|
echo "🔎 Verifying no reference solutions leaked into the student notebooks..."
|
|
python3 - <<'PY'
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
leaked = []
|
|
for nb_path in sorted(Path("modules").rglob("*.ipynb")):
|
|
nb = json.loads(nb_path.read_text(encoding="utf-8"))
|
|
code = "\n".join(
|
|
"".join(c["source"]) for c in nb["cells"] if c["cell_type"] == "code"
|
|
)
|
|
# A student notebook keeps scaffold regions solved, so the marker itself is
|
|
# expected; an unstubbed student-core region is not.
|
|
if "### BEGIN SOLUTION" in code and "raise NotImplementedError" not in code:
|
|
leaked.append(nb_path.as_posix())
|
|
|
|
if leaked:
|
|
sys.exit("❌ Reference solutions present in: " + ", ".join(leaked))
|
|
print(" ✅ Student notebooks carry stubs, not solutions.")
|
|
PY
|
|
|
|
echo ""
|
|
echo "✅ TinyTorch setup complete!"
|
|
echo ""
|
|
echo "📚 Available resources:"
|
|
echo " - TinyTorch modules: tinytorch/modules/ (Jupyter notebooks)"
|
|
echo " - Source files: tinytorch/src/ (Python files)"
|
|
echo " - Milestone examples: tinytorch/milestones/"
|
|
echo ""
|
|
echo "🚀 Start exploring with:"
|
|
echo " - Open any notebook from tinytorch/modules/ in the file browser"
|
|
echo " - Or import tinytorch in a new notebook"
|