68 / 90

第 68 天:無人值守適配器微調、損失動力學與過擬合看門狗

託管後台無頭 LoRA 微調、流式解析驗證損失收斂軌跡,界定真實泛化與死記硬背。

模型與預訓練 480 分鐘有效研習(8 小時)
01 120 分鐘

基於 Tmux 的無頭 LoRA 微調託管與多路指標遙測

Agent 輔助工程檢查

前置要求

第 67 天微調行前檢查通過,Linux 進程後台脫機管理基礎。

學習目標

在獨立的持久化 tmux 會話中啟動無頭適配器微調,將訓練進度多路重定向至結構化遙測流,恪守等待掛機不計入研習時長的原則。

操作指引

1. 在儲存庫根目錄用 tmux new-session -d -s lora_train 啟動 projects/lora/train.py(CPU smoke 模式;真實模型執行時將 --smoke 換成 --model --device cuda)。
2. 指標多路複用:用 tee 將標準輸出寫入 lora_training.log;train.py 本身會在每個最佳化步驟向 /telemetry.jsonl 追加一行 JSON(step、train_loss、lr、elapsed_seconds、mode)。
3. 監測物理顯存:利用 nvidia-smi 觀察顯存開銷,見證其保持平穩無碎片波動的低顯存特性。
4. 堅守學習時長認知:將 GPU 跑計算的機械時間同主動分析指標的有效研習分鐘嚴加區分。

自主實作與記錄

啟動後台脫機訓練。通過 ps 和 tail -f 確認訓練在終端登出後平穩推進,並即時錄入步級損失數據。

獨立掌握標準

成功部署可抵禦終端異常斷開的持久化 LoRA 微調管道與即時遙測系統。

權威來源資源與權利證明

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 | 原始出處連結 ↗

對應章節 / 時間戳: 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 | 原始出處連結 ↗

對應章節 / 時間戳: 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.

02 120 分鐘

損失遙測動態分析:指令機械死記與真實泛化能力界定

獨立掌握檢查(無 AI 輔助)

前置要求

第 68 天活動 1 與交叉熵損失數值分析理論。

學習目標

數理剖析驗證 Loss 與訓練 Loss 的收斂軌跡差異,精準識別適配器微調從掌握通用任務結構跨入機械死記硬背(過擬合)的臨界拐點。

操作指引

學習來源:在本活動現有的閱讀與練習時段內,參考 Hugging Face LLM Course: Fine-tuning LLMs 的 Chapter 11.3: Monitoring Training Progress; Warning Signs to Watch For,用自己的話解釋一處與本地任務的聯繫。保留現有練習與驗收檢查;若外部資料無法存取,使用課程自寫的解釋。1. 繪製或表格化 step 步數與 train_loss、val_loss 的對應關係。
2. 階段一(格式快速對齊期):模型迅速熟悉指令格式與輸出邊界,訓練集與驗證集 Loss 均呈現陡峭下降。
3. 階段二(最佳泛化收斂點):驗證集 Loss 觸及全局極小值(通常出現在 400 - 600 步區間)。
4. 階段三(過擬合惡化期):訓練 Loss 持續單調探底逼近極限,而驗證 Loss 出現明顯抬頭回升。這代表模型開始機械背誦訓練集個例,喪失了在分布外樣本上的推理能力。

自主實作與記錄

給定一組驗證集損失序列:[2.8, 2.3, 1.9, 1.6, 1.45, 1.44, 1.48, 1.55, 1.63],從第 100 步起每 100 步評估一次(索引 i 對應第 100 * (i + 1) 步)。指出過擬合發生的拐點步數,並鎖定應保留的最佳早停模型快照。

獨立掌握標準

能準確研判真實驗證損失拐點,科學界定指令泛化與機械死記的本質界限。

權威來源資源與權利證明

linking Apache-2.0

Hugging Face LLM Course: Fine-tuning LLMs

作者 / 機構: Hugging Face course contributors | 原始出處連結 ↗

對應章節 / 時間戳: Chapter 11.3: Monitoring Training Progress; Warning Signs to Watch For

驗證版本與日期: 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 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. | 原始出處連結 ↗

對應章節 / 時間戳: Appendix C.1 Details of SFT training

驗證版本與日期: 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 | 原始出處連結 ↗

對應章節 / 時間戳: 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.

03 120 分鐘

週期性純適配器快照落盤與損壞異常物理隔離

Agent 輔助工程檢查

前置要求

第 68 天活動 1 與 2,第 66 天適配器獨立序列化標準。

學習目標

嚴格配置週期性快照僅持久化適配器張量(嚴禁重複複製基座巨型權重),核實單快照體積嚴格控制在 50MB 以內,並落實原子化防損機制。

操作指引

1. 配置訓練步數週期快照(如每 200 步觸發一次保存)。
2. 狀態字典過濾:僅篩選鍵名匹配 'lora_' 關鍵字的增量張量進行落盤。
3. 審查磁盤文件體積:嚴格斷言生成的快照大小處於 10MB - 40MB 區間,絕不允許出現十幾 GB 的冗餘基座全量堆積。
4. 貫徹原子化寫入規範:落盤至臨時文件後原子重命名,確保在意外斷電中斷時已有有效快照完好無損。

自主實作與記錄

檢查訓練快照輸出目錄。核實保存的 3 個滾動快照大小均在 50MB 以下,且能無縫載入乾淨基座模型完成權重復原。

獨立掌握標準

建立具備嚴格體積約束與原子防損能力的週期性輕量適配器輪轉落盤體系。

權威來源資源與權利證明

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 | 原始出處連結 ↗

對應章節 / 時間戳: 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 Apache-2.0

PEFT: State-of-the-art Parameter-Efficient Fine-Tuning Methods

作者 / 機構: Sourab Mangrulkar, Sylvain Gugger, Lysandre Debut, Younes Belkada, Sayak Paul, Benjamin Bossan | 原始出處連結 ↗

對應章節 / 時間戳: N/A

驗證版本與日期: PEFT 0.10.x / GitHub (Verified: 2026-10-30)

入選理由:

Widely adopted open-source library implementing LoRA configuration classes (LoraConfig), get_peft_model, and adapter serialization.

來源前置條件:

PyTorch nn.Module, Hugging Face transformers, and LoRA equations.

安全回退方案(離線彈性):

Standalone, zero-dependency PyTorch implementations of LoRALinear layers and save/reload logic are provided in curriculum scripts.

對比候選資源與選型分析 (2)

Original reference code by Hu et al.; PEFT expands this to broader multi-model ecosystem integration.

Lit-GPT LoRA implementation (Lightning AI) ↗ compared_alternative [Apache 2.0]

High-performance clean implementation; compared alongside PEFT for modular code architecture.

04 120 分鐘

考核評估:即時微調監視看門狗與最佳早停機制開發

獨立掌握檢查(無 AI 輔助)

前置要求

第 68 天活動 1 至 3 全部內容。

學習目標

獨立開發生產級 FinetuneWatchdog 即時看門狗類,流式解析遙測指標、動態追蹤驗證 Loss 優化斜率,在連續未改善達到忍受閾值時發出優雅早停信號。

操作指引

1. 編寫 FinetuneWatchdog(patience=3, delta_threshold=0.005) 類。
2. 訂閱並提取遙測流中的驗證評估事件。
3. 維護最優驗證損失 best_val_loss 與停滯計數器 counter:當新評估的損失未能比歷史最佳改善達 delta_threshold 時,計數器累加 1;若刷新則重置歸零。
4. 當 counter >= patience 時,拋出 EARLY_STOP_SIGNAL 並鎖定對應最優快照所在的步數編號。
5. 同步集成數值防禦:若檢測到 NaN,毫秒級拋出 CRITICAL_ABORT 阻斷進程。

自主實作與記錄

在包含先降後升特徵的模擬驗證日誌流上測試 FinetuneWatchdog。驗證其能在第 3 次無改善後精準發出停機信號並鎖定最佳檢查點步數。

獨立掌握標準

能夠獨立構建靈敏捕捉模型過擬合拐點並精準守護最佳收斂質量的工業級看門狗。

權威來源資源與權利證明

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 | 原始出處連結 ↗

對應章節 / 時間戳: 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 | 原始出處連結 ↗

對應章節 / 時間戳: 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.