58 / 90

第58日: クラウド事前学習の事前点検、支出上限とドライラン

GPU環境の監査、厳格な予算上限の設定、依存関係の検証、ゼロコストの事前ドライランの実施。

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

クラウドGPU環境の監査とハードウェア接続検証

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

前提条件

第56日リソース計画の計算およびSSH公開鍵暗号の基礎。

学習目標

Gitに秘密情報をコミットすることなく、リモートホストのGPU性能、CUDAランタイム、PyTorchのGPU認識を厳格に検証する。

手順

1. SSH鍵を用いた安全な接続手法(ssh -i ~/.ssh/id_rsa user@ip)を確認し、APIキーや秘密鍵をコードに埋め込まない原則を徹底します。
2. nvidia-smi コマンドを用いて契約通りのGPUモデルと物理VRAM容量が提供されているか照合します。
3. Python仮想環境内で torch.cuda.is_available()、デバイス名、デバイス数を確認します。
4. bfloat16のハードウェア対応状況(torch.cuda.is_bf16_supported())をチェックします。

演習と予測記録

リモート環境を検証する verify_env.py を作成し、GPU認識、VRAM容量(15GB以上)、BF16対応を検証して合格時に終了コード0を返すスクリプトを作成してください。

独立習得基準

認証情報を露出させることなく、リモートGPU環境の要件適合性を検証できる。

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

linking MIT

CS336 Assignment 1: Basics (Spring 2025 tagged release)

著者・提供機関: Stanford University CS336 Staff | オリジナル出所URL ↗

該当セクション・タイムスタンプ: README setup; tests/adapters.py; tests/test_optimizer.py; tests/test_nn_utils.py; tests/test_serialization.py

検証バージョンと日付: spring2025 tag; README, tests and MIT LICENSE checked 2026-11-01

選定理由:

Lead assignment-driven source for pretraining component practice and tests. nanoGPT remains a compact historical code-reading companion, not the current recommended training curriculum.

ソース前提知識:

Fluent Python, PyTorch, and linear algebra

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

Local self-contained pretraining scripts run on standard local CPUs or budget GPUs without Stanford cluster dependency.

比較対象候補リソースと選定評価 (2)
Karpathy nanoGPT ↗ compared_alternative [MIT]

Simpler code layout, useful complementary reference for minimal PyTorch Transformer.

Hugging Face Transformers Course ↗ compared_alternative [Apache-2.0]

High-level API focus rather than building from raw tensor fundamentals.

linking MIT

nanoGPT: train.py pretraining loop

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

該当セクション・タイムスタンプ: train.py: system settings (device, dtype bfloat16/float16 selection, compile) and DDP settings

検証バージョンと日付: 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 分

厳格な支出上限、自動シャットダウンと課金トラップの防御

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

前提条件

第58日アクティビティ1および第56日クラウド費用算定法。

学習目標

厳格な予算上限(10〜20ドル)を設け、アイドル監視による自動停止とクラウド特有の課金トラップ(ディスク未解放等)を完全に排除する。

手順

1. 許容最大訓練時間の算出: 上限予算 / 時間単価。例えば1.5ドル/時で上限15ドルの場合、最長稼働時間は10時間です。
2. クラウドの落とし穴: インスタンスを停止(STOP)しても、ストレージディスクは破棄(DESTROY)するまで毎時課金が継続します。
3. GPU利用率が一定時間(例: 15分)連続で5%未満となった場合に自動停止する監視スクリプトを設計します。
4. 目標ステップ到達、損失の収束、または制限時間到達時の明確な停止条件をコード化します。

演習と予測記録

経過時間と時間単価から累積コストを監視し、予算上限に達した際に安全にSIGTERMを送信して訓練を停止させる budget_watchdog.py を実装してください。

独立習得基準

予算上限の超過を物理的に阻止する自動監視看門狗(ウォッチドッグ)を実装できる。

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

linking CC-BY 4.0

Transformer Math 101

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

該当セクション・タイムスタンプ: Engineering Takeaways for Compute Costs

検証バージョンと日付: 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.

linking MIT

CS336 Assignment 1: Basics (Spring 2025 tagged release)

著者・提供機関: Stanford University CS336 Staff | オリジナル出所URL ↗

該当セクション・タイムスタンプ: README setup; tests/adapters.py; tests/test_optimizer.py; tests/test_nn_utils.py; tests/test_serialization.py

検証バージョンと日付: spring2025 tag; README, tests and MIT LICENSE checked 2026-11-01

選定理由:

Lead assignment-driven source for pretraining component practice and tests. nanoGPT remains a compact historical code-reading companion, not the current recommended training curriculum.

ソース前提知識:

Fluent Python, PyTorch, and linear algebra

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

Local self-contained pretraining scripts run on standard local CPUs or budget GPUs without Stanford cluster dependency.

比較対象候補リソースと選定評価 (2)
Karpathy nanoGPT ↗ compared_alternative [MIT]

Simpler code layout, useful complementary reference for minimal PyTorch Transformer.

Hugging Face Transformers Course ↗ compared_alternative [Apache-2.0]

High-level API focus rather than building from raw tensor fundamentals.

03 120 分

訓練レシピの妥当性確認と単一バッチによる事前ドライラン

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

前提条件

第58日アクティビティ1〜2、PyTorch AMP autocastの基本。

学習目標

クラウド課金開始前に、ダミーバッチ(batch_size=1)によるゼロコストのドライランを行い、テンソル形状、損失値、AMP GradScalerの安定性を検証する。

手順

1. 形状 (1, 64) の入力 x とターゲット y を作成します。
2. torch.cuda.amp.autocast(dtype=torch.bfloat16 if supported else torch.float16) のもとで単一の順伝播を実行します。
3. クロスエントロピー損失を計算し、scaler.scale(loss).backward() を実行します。
4. optimizer.step() が重みを更新し、scaler.update() がスケール係数を調整する際に NaN が発生しないことを確認します。

演習と予測記録

1ステップの dry_run.py を実行し、損失が正常値であること、全勾配テンソルが存在することを確認してください。

独立習得基準

クラウド投入前に1ステップのドライランで全パイプラインの正常性を証明できる。

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

linking MIT

nanoGPT: train.py pretraining loop

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

該当セクション・タイムスタンプ: train.py: eval_only flag and default config values (batch_size, block_size, max_iters)

検証バージョンと日付: 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 ↗

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

検証バージョンと日付: 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 支援なし)

前提条件

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

学習目標

ハードウェア、依存関係、予算上限(20ドル以内)、ドライランの全項目を自動診断し、GO/NO-GO判定を出力する PreflightValidator を完成させる。

手順

1. PreflightValidator(config, budget_ceiling_usd) クラスを構築します。
2. 各種点検メソッド(ハードウェア、ライブラリ、予算額、1ステップ実行)を実装します。
3. 厳格な失敗処理: いずれかのチェックが失敗した場合、または budget_ceiling_usd が (0, 20.0] の範囲外の場合は status='NO-GO' とし、続行を拒否します。
4. 判定結果をJSON形式で記録するレポート出力を確認します。

演習と予測記録

PreflightValidator のテストスイートを実行し、正常時に 'GO'、異常値に対して 'NO-GO' を返すことを確認してください。

独立習得基準

予算制限と実行安全性を保証する事前検証スクリプトを構築できる。

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

linking MIT

CS336 Assignment 1: Basics (Spring 2025 tagged release)

著者・提供機関: Stanford University CS336 Staff | オリジナル出所URL ↗

該当セクション・タイムスタンプ: README setup; tests/adapters.py; tests/test_optimizer.py; tests/test_nn_utils.py; tests/test_serialization.py

検証バージョンと日付: spring2025 tag; README, tests and MIT LICENSE checked 2026-11-01

選定理由:

Lead assignment-driven source for pretraining component practice and tests. nanoGPT remains a compact historical code-reading companion, not the current recommended training curriculum.

ソース前提知識:

Fluent Python, PyTorch, and linear algebra

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

Local self-contained pretraining scripts run on standard local CPUs or budget GPUs without Stanford cluster dependency.

比較対象候補リソースと選定評価 (2)
Karpathy nanoGPT ↗ compared_alternative [MIT]

Simpler code layout, useful complementary reference for minimal PyTorch Transformer.

Hugging Face Transformers Course ↗ compared_alternative [Apache-2.0]

High-level API focus rather than building from raw tensor fundamentals.

linking CC-BY 4.0

Transformer Math 101

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

該当セクション・タイムスタンプ: Engineering Takeaways for Compute Costs

検証バージョンと日付: 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.