59 / 90

第59日: バックグラウンド実行、メトリクステレメトリと動的解析

Tmuxによる無人訓練実行、損失と勾配ノルムのストリーミング監視、待機時間と学習時間の明確な分離。

モデルと事前学習 480 分(8時間)
01 120 分

Tmuxによるバックグラウンド実行とテレメトリ監視の確立

Agent支援エンジニアリングチェック

前提条件

第58日事前検証、Linux tmux/nohupプロセス管理知識。

学習目標

tmuxセッションで訓練を常駐させ、メトリクスを構造化ログに出力しつつ、単なるGPU待ち時間を学習時間と誤認しない規律を確立する。

手順

1. デタッチ状態で実行を開始する:tmux new-session -d -s pretrain '...' はアタッチせずにセッションを作る。tee -a を通して、再起動時に training.log が切り詰められず追記されるようにする。
2. セッション(tmux ls)とプロセス(ps aux | grep '[t]rain.py')の両方が存在することを確認する。
3. 1 分間隔でログの末尾を 2 回取り、ステップ番号が増えたことを確認する。
4. 切断テスト:tmux 内で exit を打たずに SSH クライアントを閉じ、再接続して手順 2 と 3 を繰り返す。プロセスが生き残った理由を説明する:親はログインシェルではなく tmux サーバーである。
5. tmux attach -t pretrain でアタッチして様子を見て、Ctrl-B の後に d で再びデタッチする。
6. 証拠(2 回の末尾、切断前後の ps の行、経過時間)を残し、学習時間として記録するのはテレメトリを読んだ分だけにする。GPU を待つ時間は学習ではない。

時間配分(120 分):読解 20 + 演習 70 + 確認 30。 読解:nanoGPT train.py のログ出力ループと W&B の実験管理の概要。演習:モックまたは実際の実行で手順 1-5。確認:切断テストを記憶だけで再現し、証拠を参考解答と比べる。

演習と予測記録

デタッチドセッションでモックの訓練実行を開始してください。ps aux | grep python で、SSH切断後もプロセスが実行を継続し、training.log に有効なステップのテレメトリが追記され続けていることを確認してください。

独立習得基準

ネットワーク切断に耐える常駐バックグラウンド訓練セッションを運用できる。

公式ソースリソースと権利証跡

linking Open Access / Terms of Service

Experiment Tracking and Real-Time ML Telemetry Guide

著者・提供機関: Lukas Biewald et al. / Weights & Biases | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Experiments overview: How it works (wandb.init, run.log)

検証バージョンと日付: W&B Documentation (Verified: 2026-10-30)

選定理由:

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

ソース前提知識:

Loss functions, learning rate schedules, and step loops.

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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

著者・提供機関: Andrej Karpathy | オリジナル出所URL ↗

該当セクション・タイムスタンプ: train.py: logging (wandb_log, wandb.init) and the per-iteration print of loss, time and mfu

検証バージョンと日付: Git master commit 71c3905 (Verified: 2026-10-30)

選定理由:

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.

ソース前提知識:

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

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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 分

動的テレメトリ分析: 損失曲線、勾配ノルム、およびMFUの追跡

独立習得チェック(AI 支援なし)

前提条件

第59日アクティビティ1および第56日計算量公式。

学習目標

受信ログの数学的分析: トークン/秒のスループット測定、勾配ノルム追跡による異常検知、実効MFUのリアルタイム算定を行う。

手順

1. 各ログ行を step、train_loss、val_loss、grad_norm、dt(1 ステップの秒数)、tokens_per_sec に分解する。
2. スループットを計算する:tokens_per_sec = tokens_per_step / dt。
3. MFU = 6 * N * tokens_per_sec / ピーク FLOPs を計算する。6N は重み行列の積による、トークンあたりの順伝播と逆伝播のコストである。N、ピーク値、その dtype を明示する。
4. 6N が含まないものを述べる:注意スコアの積で、訓練時にトークンあたり約 12 * n_layer * T * d_model FLOPs が加わる。この実行について計算し、自分の MFU がそれを含むかどうかを述べる。
5. grad_norm をクリップ閾値(例えば 1.0)と比べて監視する。ほとんどのステップでクリップされるなら、学習率が高すぎるかバッチが小さすぎる可能性がある。
6. 損失の異常を分類する:通常のノイズ、発散(損失の急上昇または NaN)、崩壊(損失が ln(V) 付近で止まる。語彙全体に対する一様な推測を意味する)。

時間配分(120 分):読解 30 + 演習 55 + 確認 35。 読解:EleutherAI Transformer Math 101 の計算量と MFU の節、W&B のメトリクス概要。演習:問題の計算と項目 (a)(b)。確認:実際のログ 1 行について MFU を補助なしで計算する。

演習と予測記録

N=124M, 1ステップ32,768トークン, 所要時間0.25秒, A100(312 TFLOPs) における秒間トークン数とMFU(%)を求めてください。(a) 6N の見積もりは注意スコアの FLOPs を含みません。n_layer=12、T=1024、d_model=768 について 12 * n_layer * T * d_model を計算し、それを含めた MFU を求めてください。(b) GPT-2 の語彙 V=50257 では、どの損失値が一様な推測への崩壊を示しますか。

独立習得基準

ログデータから実効スループットとMFUを正確に導出できる。

公式ソースリソースと権利証跡

linking Open Access / Terms of Service

Experiment Tracking and Real-Time ML Telemetry Guide

著者・提供機関: Lukas Biewald et al. / Weights & Biases | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Experiments overview: How it works (wandb.init, run.log)

検証バージョンと日付: W&B Documentation (Verified: 2026-10-30)

選定理由:

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

ソース前提知識:

Loss functions, learning rate schedules, and step loops.

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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

著者・提供機関: Quentin Anthony, Stella Biderman, Hailey Schoelkopf | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Compute Requirements (C = 6PD)

検証バージョンと日付: EleutherAI Research Blog (Verified: 2026-10-30)

選定理由:

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

ソース前提知識:

Transformer matrix dimensions and matrix multiplication FLOP counting.

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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 分

リモート定期チェックポイント保存とプリエンプション復旧試験

Agent支援エンジニアリングチェック

前提条件

第59日アクティビティ1〜2および第55日アトミック保存手法。

学習目標

リモート環境における定期スナップショットの生成、ディスク消費量監視、および強制中断後の損失連続性を実証する。

手順

1. すべてのチェックポイントがアトミックに書かれることを確認する:同じディレクトリの .tmp ファイルに保存し、os.replace で最終名に置き換える(Day 55)。
2. 訓練状態をすべて保存する:モデル、オプティマイザ(AdamW のモーメント)、ステップ、損失。バッチをステップだけに依存させ、再開した実行が同じデータを見るようにする。
3. 直近 3 つのチェックポイントを保持するローテーションにし、最古のものは最新の os.replace が成功した後にだけ削除する。長い実行の前に空きディスク容量を確認する。
4. プリエンプションを模擬する:ステップ 100 の保存の後で実行を止める。ステップを終えて保存し終了する SIGTERM ハンドラと同じ動きである。
5. 新しいプロセス状態で保存ステップ + 1 から再開し、ステップ 101-110 の損失を中断なしのベースライン実行と比べる。
6. わざと 1 つ失敗を起こす:オプティマイザ状態を読み込まずに再開し、損失がどこからずれ始めるかを観察する。

時間配分(120 分):読解 20 + 演習 70 + 確認 30。 読解:nanoGPT train.py のチェックポイントと再開のコード、オプティマイザ状態の保存に関する PyTorch の説明。演習:参考スクリプトで手順 1-6。確認:オプティマイザなしの再開がずれる理由をノートなしで説明する。

演習と予測記録

再開検証テストを実行し、中断直前のステップ損失と再開直後のステップ損失が一致することを検証してください。

独立習得基準

リモートプロセス中断後も損失の乖離なく正確に再開できることを実証できる。

公式ソースリソースと権利証跡

linking MIT

nanoGPT: train.py pretraining loop

著者・提供機関: Andrej Karpathy | オリジナル出所URL ↗

該当セクション・タイムスタンプ: 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

検証バージョンと日付: Git master commit 71c3905 (Verified: 2026-10-30)

選定理由:

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.

ソース前提知識:

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

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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)

著者・提供機関: PyTorch Team | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Gradient Scaling

検証バージョンと日付: PyTorch 2.x Documentation (Verified: 2026-10-30)

選定理由:

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

ソース前提知識:

PyTorch tensors, autograd, and GPU compute basics.

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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 分

評価課題: 軽量テレメトリ監視ツールと発散検知アラートの実装

独立習得チェック(AI 支援なし)

前提条件

第59日アクティビティ1〜3の全知識。

学習目標

ログファイルを継続監視し、瞬間/平均MFUを算出し、損失発散やNaNを即座に検知して警告を発する TelemetryMonitor を構築する。

手順

1. TelemetryMonitor(model_params, tokens_per_step, peak_flops) を作り、移動窓の大きさと発散の閾値(max_loss = 20.0)も持たせる。
2. 'step: %d, loss: %f, dt: %f' 形式の行を正規表現で解析し、一致しない行はすべて無視する。
3. process_step では最初に損失を調べる:有限でない損失、または max_loss を超える損失は、即時終了を勧める CRITICAL アラートを返す。
4. 正常なステップでは、そのステップの MFU、実行全体の平均 MFU、窓内の移動平均トークン/秒、損失の移動平均を計算する。
5. ノンブロッキングの tail ジェネレータを実装する:training.log の末尾にシークし、新しい行ごとに解析結果を返し、新しい行がないときは None を返して呼び出し側が時間制限を確認できるようにする。
6. 正常な 20 ステップと注入した NaN からなる模擬ストリームでテストする:平均 MFU は活動 2 の値と一致し、NaN はその行自体で検出されなければならない。

時間配分(120 分):読解 15 + 演習 75 + 確認 30。 読解:活動 2 の MFU 計算と W&B のアラート概要。演習:監視ツールを作ってテストする。確認:習熟テストを実行してすべての assert を通し、自分のテストを 1 つ加える。

演習と予測記録

疑似ログストリームを TelemetryMonitor に投入し、MFUの追跡と意図的に注入したNaNの検知を確認してください。

独立習得基準

異常値を即座に検知し、ハードウェア利用効率を正確に算出する監視スクリプトを完成できる。

公式ソースリソースと権利証跡

linking Open Access / Terms of Service

Experiment Tracking and Real-Time ML Telemetry Guide

著者・提供機関: Lukas Biewald et al. / Weights & Biases | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Experiments overview: How it works (wandb.init, run.log)

検証バージョンと日付: W&B Documentation (Verified: 2026-10-30)

選定理由:

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

ソース前提知識:

Loss functions, learning rate schedules, and step loops.

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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

著者・提供機関: Quentin Anthony, Stella Biderman, Hailey Schoelkopf | オリジナル出所URL ↗

該当セクション・タイムスタンプ: N/A

検証バージョンと日付: EleutherAI Research Blog (Verified: 2026-10-30)

選定理由:

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

ソース前提知識:

Transformer matrix dimensions and matrix multiplication FLOP counting.

安全フォールバック(オフライン回復性):

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

比較対象候補リソースと選定評価 (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.