67 / 90

第67日: 微調レシピの事前点検、ゼロショット基準値と支出上限

LoRA微調ハイパーパラメータの固定、事前ゼロショット基準値の測定、および厳格な支出上限の確立。

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

微調レシピの設定監査とハイパーパラメータ整合性検証

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

前提条件

第64-66日のLoRA数学と第49-51日の事前学習ループ。

学習目標

学習率スケジュール(ウォームアップ付きコサイン減衰、ピーク2e-4)、ランクr=16、alpha=32、バッチサイズ、対象線形層を標準レシピと照合する。

手順

参照資料: この活動に割り当てられた既存の読解・練習時間内で、Hugging Face LLM Course: Fine-tuning LLMs の Chapter 11.3: Training Configuration を参照し、ローカル課題とのつながりを一つ自分の言葉で説明する。既存の演習と合格基準は維持し、外部資料が開けない場合は本コース独自の説明を使う。1. 公開されているレシピ(Alpaca、LoRA 論文、PEFT)を確認し、それぞれの値を書き出す:
- 学習率:LoRA では 1e-4 から 3e-4。小さなアダプタだけを更新するので、通常のフルファインチューニングの学習率(1e-5 から 2e-5)の約 10 倍になる。
- ランクとスケール:r=16、alpha=32。アダプタの出力は alpha/r = 2.0 倍される。
- 対象モジュール:注意機構のすべての射影(q_proj、k_proj、v_proj、o_proj)、またはすべての線形層。
- スケジュール:ステップ数の 3% から 5% で線形ウォームアップし、その後ピークの 10% までコサイン減衰する。
2. これらの値に max_steps=1000、seq_len=1024、min_lr_ratio=0.1 を加えて config.json を書く。
3. lr_at(step) を実装し、3 点を手で確かめる:ウォームアップの終わり(30 ステップ中のステップ 29)は 2e-4、最後のステップは 2e-5、ウォームアップ中は学習率が上がる。
4. 系列の形式を確かめる:各ペアは固定長(512 または 1024 トークン)に詰められ、EOS トークンで終わる。
5. 1 つの例で損失マスクを確かめる:プロンプトのトークンはラベル -100 になり、損失に数えるのは回答のトークンと EOS だけである。

時間配分(120 分):読解 30 + 演習 60 + 確認 30。 読解:Alpaca の訓練レシピと Hu et al.(LoRA)7 節(どの重み行列を適応させ、どのランクを使うか)。演習:手順 2-5。確認:alpha/r とウォームアップのステップ数を計算し直し、LoRA の学習率が 10 倍高い理由を記憶から説明する。

演習と予測記録

Alpaca 形式のデータで 7B モデルの学習を行うための設定辞書 config.json を作成してください。rank=16、alpha=32、lr=2e-4、warmup_ratio=0.03、loss_masking=True であることをアサートしてください。

独立習得基準

微調ハイパーパラメータの妥当性を数理的に検証・設定できる。

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

linking Apache-2.0

Hugging Face LLM Course: Fine-tuning LLMs

著者・提供機関: Hugging Face course contributors | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Chapter 11.3: Training Configuration

検証バージョンと日付: Public edition checked 2026-11-01; moving pages may change

選定理由:

Sequenced templates, supervised fine-tuning and evaluation teaching with exercises/quizzes. LoRA method and memory claims are checked against the original paper, PEFT and the local parameter ledger, not accepted wholesale from Chapter 11.4.

ソース前提知識:

Python, PyTorch, language-model training and the preceding chat-format lessons.

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

Use the original localized explanations, exercises and checks already present in this activity; no external account or purchase is required for that fallback.

比較対象候補リソースと選定評価 (2)
LoRA original paper ↗ compared_alternative [arXiv.org perpetual non-exclusive license / Open Access]

Retained for initialization and the low-rank method, not a beginner teaching sequence.

Hugging Face PEFT ↗ compared_alternative [Apache-2.0]

Retained for actual API and implementation defaults; reference documentation is not a complete teaching course.

linking Copyright Stanford CRFM (blog post; no open license stated)

Stanford Alpaca: An Instruction-following LLaMA Model

著者・提供機関: Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, Tatsunori B. Hashimoto | オリジナル出所URL ↗

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

検証バージョンと日付: Stanford CRFM Release (Verified: 2026-10-30)

選定理由:

Original open recipe demonstrating lightweight instruction fine-tuning of open models, establishing prompt/response templates, batch scheduling, and learning rate ranges.

ソース前提知識:

Supervised fine-tuning, instruction formatting, and LoRA fundamentals.

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

Complete instruction templates, JSONL formatting scripts, and learning rate schedules are self-contained in curriculum materials.

比較対象候補リソースと選定評価 (2)

Multi-turn ShareGPT tuning recipe; Alpaca provides simpler, single-turn clarity ideal for foundational instruction tuning study.

Databricks Dolly 15k Dataset & Training Recipe ↗ compared_alternative [CC-BY-SA 3.0]

Commercially permissive crowdsourced dataset; Alpaca established the academic instruction tuning standard.

linking arXiv non-exclusive license / Open Access

LoRA: Low-Rank Adaptation of Large Language Models

著者・提供機関: Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Appendix D Hyperparameters Used in Experiments

検証バージョンと日付: ICLR 2022 / arXiv:2106.09685v2 (Verified: 2026-10-30)

選定理由:

Primary literature introducing Low-Rank Adaptation, establishing parameter decomposition W = W0 + (alpha/r)*BA, initialization strategies, and zero inference latency merging.

ソース前提知識:

Matrix factorization, rank, linear layers, and transformer attention.

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

Complete matrix derivations, tensor dimensions, and pure PyTorch LoRALinear modules are implemented directly in lesson code.

比較対象候補リソースと選定評価 (2)

Introduces bottleneck adapter layers in series, which introduces unavoidable inference latency overhead; LoRA's parallel formulation merges with zero latency.

Prepends virtual prompt tokens; reduces available context length, unlike LoRA which preserves full sequence capacity.

02 120 分

対象評価プロンプトに対するゼロショット基準値(ベースライン)の測定

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

前提条件

第67日アクティビティ1およびモデル評価指標の理解。

学習目標

微調前の元モデルに対して固定評価プロンプト集合を実行し、基準正解率、フォーマット準拠率、代表的失敗例を記録する。

手順

1. ドメインのプロンプトからなる評価用の固定セットを決める(たとえば構造化抽出のプロンプト 50 個)。各項目には id、プロンプト、正しい回答が含むべき JSON のキーを持たせる。
2. アダプタなしでベースモデルを読み込む。temperature=0.1、max_new_tokens=256、固定のシードでデコードし、これらのパラメータを正確に記録する。Day 69 で同じものを使う。
3. すべての出力を自動で採点する:json.loads で解析でき、JSON オブジェクトであり、期待するキーをすべて含むこと。失敗ごとにその理由を記録する。
4. 失敗した出力をそのまま保存する。ベースモデルの典型的な失敗:JSON の前の雑談的な前置き、途中で止まったオブジェクト、キーの欠落。
5. 正解率、プロンプト数、デコードのパラメータ、プロンプトセットの SHA-256 ハッシュを baseline_results.json に書く。これで Day 69 が同じセットを使ったことを証明できる。
6. 測定の分解能を記録する:プロンプトが 10 個なら、1 個ごとに正解率が 10 ポイント動く。

時間配分(120 分):読解 15 + 演習 75 + 確認 30。 読解:InstructGPT(Ouyang et al.)1 節(ベースモデルが指示に従わない理由)と Alpaca の評価に関する説明。演習:10 個のプロンプトで手順 1-6。確認:保存した失敗例を 1 つ手で採点し直し、ハッシュがセットと一致することを確かめる。

演習と予測記録

元モデルを使い、10 件のテストプロンプトに対して zero_shot_eval.py を実行してください。正解率(例: 10% から 20%)を算出し、要求された JSON ではなく会話調の余計な文章を出力してしまった失敗出力を、そのまま記録してください。

独立習得基準

微調着手前に客観的で改ざん不可能なベースライン測定証跡を確立できる。

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

linking Open Access

Training language models to follow instructions with human feedback

著者・提供機関: Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, et al. | オリジナル出所URL ↗

該当セクション・タイムスタンプ: Section 3.6 Evaluation and Section 4.1 Results on the API distribution

検証バージョンと日付: arXiv:2203.02155v1 (Verified: 2026-10-30)

選定理由:

Foundational InstructGPT paper defining the SFT objective: maximizing log-likelihood of demonstrator completions conditioned on prompts.

ソース前提知識:

Supervised fine-tuning, conditional autoregressive generation.

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

The conditional likelihood objective and prompt-conditioning derivations are completely formulated in the review.

比較対象候補リソースと選定評価 (2)

Earlier RLHF formulation on summarization; InstructGPT standardizes the prompt-response SFT training phase.

Focuses on massive multi-task scaling; InstructGPT details the exact prompt-conditioned loss setup.

linking Copyright Stanford CRFM (blog post; no open license stated)

Stanford Alpaca: An Instruction-following LLaMA Model

著者・提供機関: Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, Tatsunori B. Hashimoto | オリジナル出所URL ↗

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

検証バージョンと日付: Stanford CRFM Release (Verified: 2026-10-30)

選定理由:

Original open recipe demonstrating lightweight instruction fine-tuning of open models, establishing prompt/response templates, batch scheduling, and learning rate ranges.

ソース前提知識:

Supervised fine-tuning, instruction formatting, and LoRA fundamentals.

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

Complete instruction templates, JSONL formatting scripts, and learning rate schedules are self-contained in curriculum materials.

比較対象候補リソースと選定評価 (2)

Multi-turn ShareGPT tuning recipe; Alpaca provides simpler, single-turn clarity ideal for foundational instruction tuning study.

Databricks Dolly 15k Dataset & Training Recipe ↗ compared_alternative [CC-BY-SA 3.0]

Commercially permissive crowdsourced dataset; Alpaca established the academic instruction tuning standard.

03 120 分

クラウド支出上限、稼働時間制限と事前停止トリガーの設定

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

前提条件

第67日アクティビティ1および第58日予算上限原則。

学習目標

LoRA微調における厳格な資金・時間境界(予算上限10ドル以下、実行時間2時間未満)を確立し、自動強制停止条件を組み込む。

手順

1. 実行を見積もる:LoRA が訓練するのはパラメータの約 0.5% で、バッチは GPU 1 台に収まり、指示チューニングの実行には通常 1 から 2 GPU 時間かかる。
2. 上限を決める:支出上限は $10.00。計画は 2.0 時間:A10G の $0.60/時間なら $1.20、A100 の $1.50/時間なら $3.00。
3. 停止トリガーを決める:
- ステップ上限:ステップ 1000 または 3 エポックで停止する。
- 停滞:検証損失が 3 回連続で改善しなければ早期停止する。
- タイムアウトガード:実時間が 2.5 時間を超えたらプロセスを終了する。A100 での最悪の場合:2.5 * $1.50 = $3.75 で、まだ上限を下回る。
4. check_budget_limits(max_cost, max_hours) を書く。費用が $10.00 を超えるか、3 時間(2.5 時間のガードより上の、検証用の絶対上限)を超える設定を拒否する。
5. 不正な入力も拒否する:NaN、無限大、負の値、真偽値。NaN > 10.0 は False なので、単純な比較では NaN が通ってしまう。
6. これらの上限なしでバックグラウンドのジョブを起動しない。

時間配分(120 分):読解 20 + 演習 70 + 確認 30。 読解:訓練するパラメータがいかに少ないかについての Hu et al.(LoRA)、Alpaca の費用に関する説明、Day 58 の予算ルール。演習:手順 2-5 と、不正な入力ごとのテスト。確認:3 つの費用($1.20、$3.00、$3.75)をノートなしで計算し直す。

演習と予測記録

予算と稼働時間の上限を検証する check_budget_limits 関数を実装し、10ドル超過の設定を確実に拒絶することを確認してください。

独立習得基準

予期せぬクラウド課金を完全に防ぐ厳格な事前ガードレールを実装できる。

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

linking arXiv non-exclusive license / Open Access

LoRA: Low-Rank Adaptation of Large Language Models

著者・提供機関: Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen | オリジナル出所URL ↗

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

検証バージョンと日付: ICLR 2022 / arXiv:2106.09685v2 (Verified: 2026-10-30)

選定理由:

Primary literature introducing Low-Rank Adaptation, establishing parameter decomposition W = W0 + (alpha/r)*BA, initialization strategies, and zero inference latency merging.

ソース前提知識:

Matrix factorization, rank, linear layers, and transformer attention.

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

Complete matrix derivations, tensor dimensions, and pure PyTorch LoRALinear modules are implemented directly in lesson code.

比較対象候補リソースと選定評価 (2)

Introduces bottleneck adapter layers in series, which introduces unavoidable inference latency overhead; LoRA's parallel formulation merges with zero latency.

Prepends virtual prompt tokens; reduces available context length, unlike LoRA which preserves full sequence capacity.

linking Copyright Stanford CRFM (blog post; no open license stated)

Stanford Alpaca: An Instruction-following LLaMA Model

著者・提供機関: Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, Tatsunori B. Hashimoto | オリジナル出所URL ↗

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

検証バージョンと日付: Stanford CRFM Release (Verified: 2026-10-30)

選定理由:

Original open recipe demonstrating lightweight instruction fine-tuning of open models, establishing prompt/response templates, batch scheduling, and learning rate ranges.

ソース前提知識:

Supervised fine-tuning, instruction formatting, and LoRA fundamentals.

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

Complete instruction templates, JSONL formatting scripts, and learning rate schedules are self-contained in curriculum materials.

比較対象候補リソースと選定評価 (2)

Multi-turn ShareGPT tuning recipe; Alpaca provides simpler, single-turn clarity ideal for foundational instruction tuning study.

Databricks Dolly 15k Dataset & Training Recipe ↗ compared_alternative [CC-BY-SA 3.0]

Commercially permissive crowdsourced dataset; Alpaca established the academic instruction tuning standard.

04 120 分

評価課題: 微調前バリデータ実装とベースライン台帳監査

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

前提条件

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

学習目標

データセット形式、損失マスク、予算上限(10ドル以内)、ベースライン記録を自動照合し、GO/NO-GO判定を出力するバリデータを完成させる。

手順

1. FinetunePreflightValidator(dataset_path, baseline_path, budget_limit) を作る。
2. verify_data():トークン化した JSONL を読む。各行の input_ids と labels は同じ長さで、最初のラベルは -100(プロンプトがマスクされている)、少なくとも 1 つのラベルは -100 ではない(何かが訓練される)こと。行数と最初の不正な行を報告する。
3. verify_baseline():活動 2 の baseline_results.json が存在し、正解率が 0 から 1 の数値で、n が正で、デコードのパラメータが記録されていること。
4. verify_budget():上限は 10.0 以下の有限の正の数であること。
5. validate():3 つの確認をすべて実行し、すべて通ったときだけ verdict='GO' を返し、それ以外は 'NO-GO' を返す。レポートには各確認の詳細、baseline_score、data_samples_count を含める。
6. 両方の結果をテストする:正しいフィクスチャ 1 つで GO、確認ごとに壊れた入力 1 つ(10 を超える予算、存在しないベースライン、NaN の予算)で NO-GO。NO-GO を出せない検証器は何も保証しない。

時間配分(120 分):読解 10 + 演習 80 + 確認 30。 読解:活動 1-3 のノートと Alpaca のデータ形式。演習:クラスとそのフィクスチャ。確認:AI の助けなしに、GO と NO-GO の assert がすべて通る習熟実行。

演習と予測記録

正しいフィクスチャで FinetunePreflightValidator を実行し、レポートに baseline_score と data_samples_count を含む 'GO' が返ることを確かめる。次に各確認を順に壊し($10.00 を超える予算、存在しないベースラインファイル、NaN の予算)、どの場合も 'NO-GO' が返ることを確かめる。

独立習得基準

微調前の環境・データ・予算の完全性を自動認証するバリデータを完成できる。

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

linking Copyright Stanford CRFM (blog post; no open license stated)

Stanford Alpaca: An Instruction-following LLaMA Model

著者・提供機関: Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, Tatsunori B. Hashimoto | オリジナル出所URL ↗

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

検証バージョンと日付: Stanford CRFM Release (Verified: 2026-10-30)

選定理由:

Original open recipe demonstrating lightweight instruction fine-tuning of open models, establishing prompt/response templates, batch scheduling, and learning rate ranges.

ソース前提知識:

Supervised fine-tuning, instruction formatting, and LoRA fundamentals.

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

Complete instruction templates, JSONL formatting scripts, and learning rate schedules are self-contained in curriculum materials.

比較対象候補リソースと選定評価 (2)

Multi-turn ShareGPT tuning recipe; Alpaca provides simpler, single-turn clarity ideal for foundational instruction tuning study.

Databricks Dolly 15k Dataset & Training Recipe ↗ compared_alternative [CC-BY-SA 3.0]

Commercially permissive crowdsourced dataset; Alpaca established the academic instruction tuning standard.

linking arXiv non-exclusive license / Open Access

LoRA: Low-Rank Adaptation of Large Language Models

著者・提供機関: Edward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen | オリジナル出所URL ↗

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

検証バージョンと日付: ICLR 2022 / arXiv:2106.09685v2 (Verified: 2026-10-30)

選定理由:

Primary literature introducing Low-Rank Adaptation, establishing parameter decomposition W = W0 + (alpha/r)*BA, initialization strategies, and zero inference latency merging.

ソース前提知識:

Matrix factorization, rank, linear layers, and transformer attention.

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

Complete matrix derivations, tensor dimensions, and pure PyTorch LoRALinear modules are implemented directly in lesson code.

比較対象候補リソースと選定評価 (2)

Introduces bottleneck adapter layers in series, which introduces unavoidable inference latency overhead; LoRA's parallel formulation merges with zero latency.

Prepends virtual prompt tokens; reduces available context length, unlike LoRA which preserves full sequence capacity.