實戰範例 008:研究文獻記憶組織
背景
您是機器學習研究員,正在調研「語言模型推理加速」相關的論文。您已閱讀了多篇論文,做了筆記,但這些筆記散落在不同文件中,難以追溯與對比。透過 MemPalace,您能將論文著錄、核心洞見、實驗表格分層儲存,並建立關聯,讓文獻回顧更高效。
情境
您已閱讀了以下三部論文:
- KV Cache - 論文探討鍵值快取技術
- Speculative Decoding - 研究推測式解碼方法
- Quantization - 探討量化技術
您希望将这些論文的記憶儲存到 MemPalace,方便未來回顧與引用。
您想做什麼?
用戶:「能不能將這三部論文的記憶儲存到 MemPalace,並建立相互關聯?」
第 1 步:初始化 Palace(如果尚未初始化)
$ mempalace init --wing "d:/Repo/research-notes"
✓ Palace initialized at .mempalace
✓ First wing: d:/Repo/research-notes"
第 2 步:添加 Paper 出處 Drawers
每篇論文的水源頭 Metadata 作為 Verbatim Drawer:
論文 1:KV Cache
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "論文出處:KV Cache(2023)" \
--content "論文出處:KV Cache\n標題:Efficient Transformers with KV Cache\n作者:Juan Peng et al.\n刊登:NeurIPS 2023\n連結:https://arxiv.org/abs/2301.07062" \
--tags "paper,kv-cache,transformer,efficiency"
論文 2:Speculative Decoding
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "論文出處:Speculative Decoding(2024)" \
--content "論文出處:Speculative Decoding\n標題:Speculative Decoding: Accelerated Inference for Large Language Models via Draft-Then-Verify\n作者:Levi Chen et al.\n刊登:ICML 2024\n連結:https://arxiv.org/abs/2302.01818" \
--tags "paper,speculative-decoding,lm,inference"
論文 3:Quantization
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "論文出處:Quantization(2024)" \
--content "論文出處:Quantization\n標題:A4: Efficient 4-bit Quantization for LLMs\n作者:Michael Yao et al.\n刊登:ArXiv 2024\n連結:https://arxiv.org/abs/2305.14314" \
--tags "paper,quantization,llm,compression"
第 3 步:添加 Core Insight Drawers
洞見 1:KV Cache 核心洞見
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "核心洞見:KV Cache 技術原理與效益" \
--content "核心洞見:KV Cache 技術原理與效益\n技術原理:在生成階段,對於上下文部分的鍵值(K、V)張量,僅計算一次並將其快取起來(Cache)。之後每個 token 生成時,直接重用快取的 K、V,避免重複計算上下文部分。\n效益:理論減少計算量 O(n×L×d),其中 n 為序列長度,L 為序列長度,d 為隱藏層維度。\n限制:記憶體佔用 O(n×L×d),對長序列記憶體壓力大。\n部署建議:適合 batch size 大於 1 場合,GPU 記憶體充足時優先使用。" \
--tags "insight,kv-cache,cache-optimization"
洞見 2:Speculative Decoding 核心洞見
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "核心洞見:Speculative Decoding 算法流程與效益" \
--content "核心洞見:Speculative Decoding 算法流程與效益\n算法流程:1. 使用小模型(draft model)快速生成 k 個 token。2. 將 k 個 token 作為備選輸入,大模型(target model)用於驗證,即在一次前向推演中檢查 k 個 token 是否一致。3. 若一致(accept),則保留;不一致則用大模型的 token 替代,從落點繼續生成新备選。\n效益:實際計算次數減少,理論上報告加速比約 1.5-2x。\n限制:需訓練或找到合適的 draft model,增加 GPU 記憶體使用。\n部署建議:適合有現成小模型為 assistant 的場景,如輔助微調小模型指定。" \
--tags "insight,speculative-decoding,draft-verify"
洞見 3:Quantization 核心洞見
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "核心洞見:Quantization 技術與向量映射" \
--content "核心洞見:Quantization 技術與向量映射\n技術原理:將 FP16/FP32 向量映射到 4-bit 整數表示,藉由 Scale 因數與 Zero-point 耦合實施t量化與反量化計算。\n量化方法:A4 算法動態量化各層組件(線性層:權重、偏置;注意力層:Q、K、V;FFN:投影,嵌入層),推導部分整塊緩存(.activation cache)從 FP16 轉為 4-bit。\n效益:減少記憶體佔用約 3-4×,推理速度可達 1.2-1.5× 加速(對 batch-aware 框架)。\n限制:量化誤差可能導致性能下降,尤其在少樣本細節文本。\n部署建議:適合推理環境 GPU 記憶體受限,容忍小降性能。" \
--tags "insight,quantization,floating-point"
第 4 步:添加 Experiment Result Drawers
實驗 1:KV Cache 效能測試
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "實驗結果:KV Cache 效能測試" \
--content "實驗結果:KV Cache 效能測試\n實驗環境:NVIDIA A100 80GB GPU\n模型:LLaMA 2-70B\n測試場景:sequence length 1024, batch size 1, 上下文 512 tokens\n結果:\n- 無 KV Cache:推理時間 12.3 ms/t\n- 有 KV Cache:推理時間 2.1 ms/t\n- 加速比:5.86×\n- 記憶體:1.5 GB(上下文 cache)\n結論:對batch size=1 場合,KV Cache 效能增益顯著,長序列增益更大。" \
--tags "experiment,kv-cache,performance"
實驗 2:Speculative Decoding 效能測試
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "實驗結果:Speculative Decoding 效能測試" \
--content "實驗結果:Speculative Decoding 效能測試\n實驗環境:NVIDIA A100 80GB GPU\n模型:target=LLaMA 2-70B, draft=Phi-2(2.7B)\n測試場景:batch size 1, 平均序列長度 256 tokens\n結果:\n- 無 Speculative Decoding:推理時間 18.5 ms/t\n- Speculative Decoding(k=4):推理時間 9.7 ms/t\n- 加速比:1.91×\n- Accept Rate:82%\n結論:Speculative Decoding 在實場景中加速約 2×,需合適 draft model。" \
--tags "experiment,speculative-decoding,performance"
實驗 3:Quantization 效能測試
$ mempalace add \
--wing "d:/Repo/research-notes" \
--room "ml-lm-inference" \
--title "實驗結果:Quantization 效能測試" \
--content "實驗結果:Quantization 效能測試\n實驗環境:NVIDIA A100 80GB GPU\n模型:LLaMA 2-70B\n測試場景:batch size 4, 序列長度 1024 tokens, FP16 量化到 4-bit\n結果:\n- FP16:記憶體 67.2 GB, 推理時間 15.8 ms/t\n- 4-bit Quantization:記憶體 17.5 GB, 推理時間 11.2 ms/t\n- 記憶體減少:74%\n- 推理加速:1.41×\n- 性能下降:2-3% 在困惑度(Perplexity)上\n結論:Quantization 適合記憶體受限環境,小幅性能損失可接受。" \
--tags "experiment,quantization,performance"
第 5 步:建立分層關聯
Paper → Insight 關聯
$ mempalace link \
--wing "d:/Repo/research-notes" \
--from "論文出處:KV Cache(2023)" \
--to "核心洞見:KV Cache 技術原理與效益" \
--relation "describes" \
--description "論文出處關聯到對應核心洞見"
$ mempalace link \
--wing "d:/Repo/research-notes" \
--from "論文出處:Speculative Decoding(2024)" \
--to "核心洞見:Speculative Decoding 算法流程與效益" \
--relation "describes" \
--description "論文出處關聯到對應核心洞見"
$ mempalace link \
--wing "d:/Repo/research-notes" \
--from "論文出處:Quantization(2024)" \
--to "核心洞見:Quantization 技術與向量映射" \
--relation "describes" \
--description "論文出處關聯到對應核心洞見"
Insight → Experiment 關聯
$ mempalace link \
--wing "d:/Repo/research-notes" \
--from "核心洞見:KV Cache 技術原理與效益" \
--to "實驗結果:KV Cache 效能測試" \
--relation "validated-by" \
--description "核心洞見通過實驗驗證"
$ mempalace link \
--wing "d:/Repo/research-notes" \
--from "核心洞見:Speculative Decoding 算法流程與效益" \
--to "實驗結果:Speculative Decoding 效能測試" \
--relation "validated-by" \
--description "核心洞見通過實驗驗證"
$ mempalace link \
--wing "d:/Repo/research-notes" \
--from "核心洞見:Quantization 技術與向量映射" \
--to "實驗結果:Quantization 效能測試" \
--relation "validated-by" \
--description "核心洞見通過實驗驗證"
第 6 步:視覺化分層結構
$ mempalace graph --wing "d:/Repo/research-notes" --drawer "論文出處:KV Cache(2023)"
結果:
graph LR
drawer001[論文出處: KV Cache] -->|describes| drawer004[核心洞見: KV Cache 技術原理]
drawer004 -->|validated-by| drawer007[實驗結果: KV Cache 效能測試]
三個 Knowledge Graph 分別呈現三部論文的完整鏈路:出處 → 洞見 → 驗證實驗。
第 7 步:召喚跨論文洞見
$ mempalace recall --wing "d:/Repo/research-notes" --query "加速比 記憶體 限制"
搜尋結果顯示跨論文比較:
Top 1: drawer-004.md
Title: 核心洞見:KV Cache 技術原理與效益
Relevance: 0.87
Tags: insight,kv-cache,cache-optimization
Content:
[KV Cache 完整洞見...]
Top 2: drawer-005.md
Title: 核心洞見:Speculative Decoding 算法流程與效益
Relevance: 0.85
Tags: insight,speculative-decoding,draft-verify
Content:
[Speculative Decoding 完整洞見...]
Top 3: drawer-006.md
Title: 核心洞見:Quantization 技術與向量映射
Relevance: 0.83
Tags: insight,quantization,floating-point
Content:
[Quantization 完整洞見...]
Knowledge Graph 推理出的對比:
- KV Cache: 加速高(5.86×)、記憶體較高(1.5 GB)、適合長序列或 batch size 大於 1
- Speculative Decoding: 加速中(1.91×)、記憶體較高(draft model)、需合適 draft model
- Quantization: 加速中(1.41×)、記憶體極低(減少 74%)、容忍小降性能
關鍵成果
- ✅ 三部論文的出處、核心洞見、實驗結果均逐字儲存
- ✅ 建立分層關聯(describes、validated-by),形成完整鍊路
- ✅ 透過
recall跨論文搜尋「加速比 記憶體 限制」,Knowledge Graph 推理出三種技術的對比 - ✅ 使用
graph視覺化分層結構,幫助理解文獻脈絡
延伸練習
添加引用關係 drawers(例如 Paper A 引用 Paper B),建立完整的引用鏈。在研究報告中,您可以快速召喚「研究背景 → 目前任務 → 方法 → 實驗 → 結論」五層關聯,並從 MemPalace 匯出 Microsoft Word 或 LaTeX 格式。
Platform: Claude Code
Skill: oml-add、oml-link、oml-recall、oml-graph