59 / 90

Day 59: Unattended Cloud Execution, Metric Telemetry & Active Analysis

Launch decoupled headless training via Tmux, stream loss and gradient norms, and analyze tokens/sec without waiting idle.

Models and Pretraining 480 active minutes (8 hours)
01 120 min

Detached Unattended Execution via Tmux and Stream Telemetry

Agent-Assisted Engineering Check

Prerequisites

Day 58 Preflight validation, Linux tmux/nohup process management.

Learning Objective

Launch pretraining inside a detached tmux session, streaming real-time metrics to structured telemetry logs while decoupling passive waiting time from active study minutes.

Instructions

1. Start the run detached: tmux new-session -d -s pretrain '...' creates the session without attaching. Pipe through tee -a so training.log is appended, never truncated, on a restart.
2. Confirm that both the session (tmux ls) and the process (ps aux | grep '[t]rain.py') exist.
3. Take two log tails a minute apart and check that the step number grew.
4. Disconnect test: close the SSH client without typing exit inside tmux, reconnect, and repeat steps 2 and 3. Explain why the process survived: its parent is the tmux server, not your login shell.
5. Attach with tmux attach -t pretrain to watch, and detach again with Ctrl-B then d.
6. Keep the evidence (both tails, the ps line before and after, wall-clock hours) and log only the minutes you spent reading telemetry as study time; waiting for the GPU is not study.

Time plan (120 min): reading 20 + exercise 70 + check 30. Reading: the nanoGPT train.py logging loop and the W&B experiment-tracking overview. Exercise: steps 1-5 on a mock or real run. Check: reproduce the disconnect test from memory and compare your evidence with the reference.

Practice & Prediction Log

Start a mock training run in a detached session. Verify with ps aux | grep python that it continues executing after disconnecting SSH, appending valid step telemetry to training.log.

Independent Mastery Criterion

Successfully run a persistent detached training job that streams structured log telemetry.

Authoritative Source Resources & Provenance

linking Open Access / Terms of Service

Experiment Tracking and Real-Time ML Telemetry Guide

Author: Lukas Biewald et al. / Weights & Biases | Original Source Link ↗

Relevant Section / Range: Experiments overview: How it works (wandb.init, run.log)

Verified Version & Date: W&B Documentation (Verified: 2026-10-30)

Selection Rationale:

Widely adopted concepts for decoupling active human study time from passive unattended GPU training runs.

Source Prerequisites:

Loss functions, learning rate schedules, and step loops.

Safe Fallback (Offline Resilience):

Offline local CSV/JSONL telemetry logging is fully provided in lesson code.

Compared Candidate Sources & Selection Analysis (2)

Local self-hosted visualizer; compared alongside cloud telemetry dashboards.

MLflow Tracking Documentation ↗ compared_alternative [Apache 2.0]

Enterprise lifecycle manager; W&B is preferred for quick LLM run telemetry.

linking MIT

nanoGPT: train.py pretraining loop

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: train.py: logging (wandb_log, wandb.init) and the per-iteration print of loss, time and mfu

Verified Version & Date: Git master commit 71c3905 (Verified: 2026-10-30)

Selection Rationale:

Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.

Source Prerequisites:

Python, PyTorch, and Day 46-48 Transformer model architecture.

Safe Fallback (Offline Resilience):

Runnable pretraining scripts and step-by-step tensor mechanics are fully self-contained in the curriculum lessons.

Compared Candidate Sources & Selection Analysis (2)
Hugging Face Accelerate / Trainer ↗ compared_alternative [Apache-2.0]

Heavy abstraction layer wrapping distributed training; nanoGPT exposes raw PyTorch loops without framework overhead.

Megatron-LM (NVIDIA) ↗ compared_alternative [BSD-3-Clause]

High-performance enterprise distributed framework; unsuitable for local educational first-principles comprehension.

02 120 min

Active Telemetry Dynamics: Loss Trajectories, Gradient Norms & MFU

Independent Mastery Check (no AI assistance).

Prerequisites

Day 59 Activity 1 and Day 56 compute formulas.

Learning Objective

Conduct active analytical telemetry review: evaluate tokens/sec throughput, track gradient norms to detect instability, and calculate Model FLOPs Utilization (MFU) in real-time.

Instructions

1. Parse each log line into step, train_loss, val_loss, grad_norm, dt (seconds per step) and tokens_per_sec.
2. Compute throughput: tokens_per_sec = tokens_per_step / dt.
3. Compute MFU = 6 * N * tokens_per_sec / peak_FLOPs, where 6N is the forward-plus-backward cost per token from the weight matrix products. Keep N, the peak and its dtype explicit.
4. Say what 6N leaves out: the attention score products, about 12 * n_layer * T * d_model extra FLOPs per token for training. Compute them for the run and state whether your MFU includes them.
5. Watch grad_norm against the clip threshold (for example 1.0). Clipping on most steps suggests the learning rate is too high or the batch too small.
6. Classify loss anomalies: ordinary noise, divergence (loss rising quickly or NaN), or collapse (loss stuck near ln(V), which means uniform guessing over the vocabulary).

Time plan (120 min): reading 30 + exercise 55 + check 35. Reading: the EleutherAI Transformer Math 101 sections on compute and MFU, and the W&B metrics overview. Exercise: the prompt calculation plus items (a) and (b). Check: compute MFU for one real log line unaided.

Practice & Prediction Log

Given N=124M, batch_tokens=32768, dt=0.25s on an A100 (312 TFLOPs). Calculate the instantaneous tokens/sec and achieved MFU percentage. (a) The 6N estimate omits attention score FLOPs. Compute 12 * n_layer * T * d_model for n_layer=12, T=1024, d_model=768 and the MFU that includes them. (b) For GPT-2's vocabulary V=50257, what loss value signals collapse to uniform guessing?

Independent Mastery Criterion

Compute MFU and tokens/sec from real log lines with mathematical exactness.

Authoritative Source Resources & Provenance

linking Open Access / Terms of Service

Experiment Tracking and Real-Time ML Telemetry Guide

Author: Lukas Biewald et al. / Weights & Biases | Original Source Link ↗

Relevant Section / Range: Experiments overview: How it works (wandb.init, run.log)

Verified Version & Date: W&B Documentation (Verified: 2026-10-30)

Selection Rationale:

Widely adopted concepts for decoupling active human study time from passive unattended GPU training runs.

Source Prerequisites:

Loss functions, learning rate schedules, and step loops.

Safe Fallback (Offline Resilience):

Offline local CSV/JSONL telemetry logging is fully provided in lesson code.

Compared Candidate Sources & Selection Analysis (2)

Local self-hosted visualizer; compared alongside cloud telemetry dashboards.

MLflow Tracking Documentation ↗ compared_alternative [Apache 2.0]

Enterprise lifecycle manager; W&B is preferred for quick LLM run telemetry.

linking CC-BY 4.0

Transformer Math 101

Author: Quentin Anthony, Stella Biderman, Hailey Schoelkopf | Original Source Link ↗

Relevant Section / Range: Compute Requirements (C = 6PD)

Verified Version & Date: EleutherAI Research Blog (Verified: 2026-10-30)

Selection Rationale:

Widely cited, practical industry guide deriving 6ND compute FLOPs, activation memory, KV cache size, and VRAM estimation.

Source Prerequisites:

Transformer matrix dimensions and matrix multiplication FLOP counting.

Safe Fallback (Offline Resilience):

The 6ND derivation (2ND forward, 4ND backward) and peak VRAM estimation models are fully worked out in the curriculum.

Compared Candidate Sources & Selection Analysis (2)

Rigorous academic formulation; Transformer Math 101 provides accessible step-by-step arithmetic equations.

Kaplan et al. Section 2.1 Compute Budgeting ↗ compared_alternative [Open Access]

Original 6ND approximation; EleutherAI expands on activation memory and KV cache.

03 120 min

Remote Periodic Checkpointing and Simulated Preemption Recovery

Agent-Assisted Engineering Check

Prerequisites

Day 59 Activities 1-2 and Day 55 atomic checkpoint patterns.

Learning Objective

Audit remote periodic checkpoint creation, verify disk quota consumption, and validate that simulated process termination reloads without loss discontinuities.

Instructions

1. Check that every checkpoint is written atomically: save to a .tmp file in the same directory, then os.replace it over the final name (Day 55).
2. Save the full training state: model, optimizer (AdamW moments), step and loss. Make the batch depend only on the step so a resumed run sees the same data.
3. Keep a rolling retention of the last 3 checkpoints, and delete the oldest only after the newest os.replace has succeeded. Check free disk space before a long run.
4. Simulate preemption: stop the run after the step-100 save, as a SIGTERM handler that finishes the step, saves and exits would.
5. Resume in a fresh process state from the saved step + 1 and compare the losses of steps 101-110 with an uninterrupted baseline run.
6. Provoke one failure on purpose: resume without loading the optimizer state and observe where the losses start to drift.

Time plan (120 min): reading 20 + exercise 70 + check 30. Reading: the checkpoint and resume code in nanoGPT train.py and the PyTorch notes on saving optimizer state. Exercise: steps 1-6 with the reference script. Check: explain without notes why the no-optimizer resume drifts.

Practice & Prediction Log

Run a resume verification test. Confirm that step 100 loss recorded before interruption matches step 100 loss evaluated immediately upon resume.

Independent Mastery Criterion

Demonstrate seamless training resumption with zero loss discrepancy after remote process interruption.

Authoritative Source Resources & Provenance

linking MIT

nanoGPT: train.py pretraining loop

Author: Andrej Karpathy | Original Source Link ↗

Relevant Section / Range: train.py: checkpoint dict {'model', 'optimizer', 'model_args', 'iter_num', 'best_val_loss', 'config'} written with torch.save to out_dir/ckpt.pt; the init_from == 'resume' branch reloads it

Verified Version & Date: Git master commit 71c3905 (Verified: 2026-10-30)

Selection Rationale:

Compact historical code reference for the named implementation functions; CS336 spring2025 provides the lead component exercises. Do not infer top-p, atomic persistence or cloud budget enforcement from nanoGPT.

Source Prerequisites:

Python, PyTorch, and Day 46-48 Transformer model architecture.

Safe Fallback (Offline Resilience):

Runnable pretraining scripts and step-by-step tensor mechanics are fully self-contained in the curriculum lessons.

Compared Candidate Sources & Selection Analysis (2)
Hugging Face Accelerate / Trainer ↗ compared_alternative [Apache-2.0]

Heavy abstraction layer wrapping distributed training; nanoGPT exposes raw PyTorch loops without framework overhead.

Megatron-LM (NVIDIA) ↗ compared_alternative [BSD-3-Clause]

High-performance enterprise distributed framework; unsuitable for local educational first-principles comprehension.

linking BSD-3-Clause

PyTorch Documentation: Automatic Mixed Precision (torch.amp)

Author: PyTorch Team | Original Source Link ↗

Relevant Section / Range: Gradient Scaling

Verified Version & Date: PyTorch 2.x Documentation (Verified: 2026-10-30)

Selection Rationale:

Official reference on autocast and GradScaler for numerical stability in FP16/BF16 training.

Source Prerequisites:

PyTorch tensors, autograd, and GPU compute basics.

Safe Fallback (Offline Resilience):

All scaling and precision casting mechanics are demonstrated in self-contained Python examples.

Compared Candidate Sources & Selection Analysis (2)
NVIDIA Apex Documentation ↗ compared_alternative [BSD-3-Clause]

Legacy external AMP implementation; native torch.cuda.amp is the modern standard.

Framework wrapper around PyTorch AMP; we study the underlying PyTorch primitive.

04 120 min

Assessment: Lightweight Training Telemetry Monitor and Alert Watchdog

Independent Mastery Check (no AI assistance).

Prerequisites

Day 59 Activities 1-3.

Learning Objective

Build a comprehensive TelemetryMonitor script that streams training log lines, calculates instantaneous/average MFU, detects loss plateaus and NaN spikes, and triggers automatic alerts.

Instructions

1. Create TelemetryMonitor(model_params, tokens_per_step, peak_flops), plus a rolling window size and a divergence threshold (max_loss = 20.0).
2. Parse lines of the form 'step: %d, loss: %f, dt: %f' with a regular expression and ignore every line that does not match.
3. In process_step, check the loss first: a non-finite loss or a loss above max_loss returns a CRITICAL alert that recommends immediate termination.
4. For a healthy step, compute the step MFU, the run-average MFU, the rolling tokens/sec over the window, and the loss moving average.
5. Implement a non-blocking tail generator: seek to the end of training.log, yield each new parsed report, and yield None when nothing is new so the caller can check time limits.
6. Test it on a simulated stream of 20 healthy steps plus an injected NaN: the average MFU must equal the Activity 2 value, and the NaN must be flagged on its own line.

Time plan (120 min): reading 15 + exercise 75 + check 30. Reading: your Activity 2 MFU calculation and the W&B alerts overview. Exercise: build and test the monitor. Check: the mastery test run, with all assertions passing, then add one test of your own.

Practice & Prediction Log

Feed a simulated training log stream to TelemetryMonitor. Verify that it correctly tracks MFU across 20 steps and flags an injected NaN event immediately.

Independent Mastery Criterion

Construct a telemetry watchdog that flags divergences and computes real-time MFU with 100% test pass rate.

Authoritative Source Resources & Provenance

linking Open Access / Terms of Service

Experiment Tracking and Real-Time ML Telemetry Guide

Author: Lukas Biewald et al. / Weights & Biases | Original Source Link ↗

Relevant Section / Range: Experiments overview: How it works (wandb.init, run.log)

Verified Version & Date: W&B Documentation (Verified: 2026-10-30)

Selection Rationale:

Widely adopted concepts for decoupling active human study time from passive unattended GPU training runs.

Source Prerequisites:

Loss functions, learning rate schedules, and step loops.

Safe Fallback (Offline Resilience):

Offline local CSV/JSONL telemetry logging is fully provided in lesson code.

Compared Candidate Sources & Selection Analysis (2)

Local self-hosted visualizer; compared alongside cloud telemetry dashboards.

MLflow Tracking Documentation ↗ compared_alternative [Apache 2.0]

Enterprise lifecycle manager; W&B is preferred for quick LLM run telemetry.

linking CC-BY 4.0

Transformer Math 101

Author: Quentin Anthony, Stella Biderman, Hailey Schoelkopf | Original Source Link ↗

Relevant Section / Range: N/A

Verified Version & Date: EleutherAI Research Blog (Verified: 2026-10-30)

Selection Rationale:

Widely cited, practical industry guide deriving 6ND compute FLOPs, activation memory, KV cache size, and VRAM estimation.

Source Prerequisites:

Transformer matrix dimensions and matrix multiplication FLOP counting.

Safe Fallback (Offline Resilience):

The 6ND derivation (2ND forward, 4ND backward) and peak VRAM estimation models are fully worked out in the curriculum.

Compared Candidate Sources & Selection Analysis (2)

Rigorous academic formulation; Transformer Math 101 provides accessible step-by-step arithmetic equations.

Kaplan et al. Section 2.1 Compute Budgeting ↗ compared_alternative [Open Access]

Original 6ND approximation; EleutherAI expands on activation memory and KV cache.