-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcheck-programs
More file actions
executable file
·71 lines (60 loc) · 2.49 KB
/
Copy pathcheck-programs
File metadata and controls
executable file
·71 lines (60 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
#
# Check that the book's main programs are still runnable - that each one starts up, parses its
# arguments and prints its help - without running any actual workload.
#
# Why this exists: on 2026-08-04 `all_reduce_bench.py` was found to have been unrunnable since
# 2025-12-08. `parse_args(formatter_class=...)` raised a TypeError on every invocation, on every
# Python version. The file was syntactically valid, so a compile check would not have caught it,
# and nobody noticed for eight months because running that benchmark for real needs a GPU node.
# `--help` reaches the same argument-parsing code and exits in a second on a laptop.
#
# What this does not catch: anything that goes wrong after argument parsing, and anything in a
# program that has no --help. It also executes each program's module-level code, so imports do
# run - which is a feature (it catches import errors) but means this is not entirely inert.
#
# usage: build/check-programs
# PYTHON=python3.12 build/check-programs
set -uo pipefail
cd "$(dirname "$0")/.."
# The book's reader-facing programs - the ones a reader copies out of a chapter and runs. Build
# tooling is deliberately out of scope. Add new ones here.
PROGRAMS=(
network/benchmarks/all_reduce_bench.py
compute/accelerator/benchmarks/mamf-finder.py
training/checkpoints/torch-checkpoint-shrink.py
)
# Deliberately not listed - these refuse to start outside a site-specific environment, so they
# would fail here forever rather than telling us anything:
# training/fault-tolerance/slurm-status.py ("relies on JZ's specific environment")
# training/fault-tolerance/fs-watchdog.py (same)
PYTHON=${PYTHON:-python}
# `timeout` is GNU coreutils and is absent on macOS unless it was installed separately, so use it
# only if it is actually there rather than failing with "command not found".
TIMEOUT=()
for t in timeout gtimeout; do
if command -v "$t" >/dev/null 2>&1; then
TIMEOUT=("$t" 120)
break
fi
done
status=0
for prog in "${PROGRAMS[@]}"; do
printf '%-56s ' "$prog"
if [[ ! -f $prog ]]; then
printf 'MISSING\n'
status=1
continue
fi
if out=$("${TIMEOUT[@]}" "$PYTHON" "$prog" --help 2>&1); then
printf 'ok\n'
else
printf 'FAILED\n'
printf '%s\n' "$out" | tail -3 | sed 's/^/ /'
status=1
fi
done
if (( status != 0 )); then
printf '\nAt least one program failed to start. It is broken for every reader who copies it.\n'
fi
exit "$status"