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 に有効なステップのテレメトリが追記され続けていることを確認してください。
tmux new-session -d -s pretrain 'python3 train.py >> training.log 2>&1' を使用します。
# 1. Start the run detached. tee -a appends, so a restart never truncates earlier steps.
tmux new-session -d -s pretrain 'python3 train.py 2>&1 | tee -a training.log'
# 2. Confirm that the session and the training process both exist.
tmux ls # expect: pretrain: 1 windows (created ...)
ps aux | grep '[t]rain.py' # the [t] pattern stops grep from matching itself
# 3. Record two log tails a minute apart; the step number must grow.
tail -n 2 training.log; sleep 60; tail -n 2 training.log
# 4. Disconnect test: close the SSH client (do not type exit inside tmux), reconnect, then repeat
# step 2 and step 3. The process survives because the tmux server, not your SSH login shell,
# is its parent. nohup python3 train.py >> training.log 2>&1 & is the no-tmux fallback.
tmux attach -t pretrain # watch live; Ctrl-B then d detaches again without stopping training
# 5. Stop on purpose at the end. Ctrl-C sends SIGINT; train.py should save a checkpoint and exit.
tmux send-keys -t pretrain C-c
# Evidence to keep: the two tails (step grew), the ps line before and after the disconnect,
# and the wall-clock hours. Only the minutes you spent reading telemetry count as study time.
ネットワーク切断に耐える常駐バックグラウンド訓練セッションを運用できる。
公式ソースリソースと権利証跡
Experiment Tracking and Real-Time ML Telemetry Guide
該当セクション・タイムスタンプ: 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.
Enterprise lifecycle manager; W&B is preferred for quick LLM run telemetry.
nanoGPT: train.py pretraining loop
該当セクション・タイムスタンプ: 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)
Heavy abstraction layer wrapping distributed training; nanoGPT exposes raw PyTorch loops without framework overhead.
High-performance enterprise distributed framework; unsuitable for local educational first-principles comprehension.