Moving from RAG Apps to RAG Systems Engineering
從基礎 RAG 原型邁向 production RAG 系統,需要在檢索(retrieval)與生成(generation)階段皆具備工程紀律。系統可能會在證據輸入層(evidence input layer)因為文件修訂、過期 chunks 或混合 embedding spaces 而失效,也可能在輸出層因為產生無根據的主張而失敗。解決這些失效需要維運機制(如安全索引遷移和 data lineage),並結合應用機器學習技術(如 query-time verification 和校準後的 abstention thresholds)。由於驗證只能檢驗回答是否符合檢索出的段落,而無法確認段落本身是否為最新資訊,因此檢索新鮮度與回答的佐證支援都需要獨立且協調的控制措施。本節將解釋 GPU 如何調度與組織工作負載,從啟動 kernel 轉變為硬體層級的執行。程式會將 thread 分組為組成 grid 的 block,這些 block 會被分配至 Streaming Multiprocessors (SMs),並以稱為 warp 的 32-thread 單位執行。Warp scheduling 讓 SM 能夠在其他 thread 等待記憶體時,切換執行已就緒的 thread,從而避免閒置停頓(idle stalls)。本文還將 GPU 硬體機制(如 shared memory、registers 與 High Bandwidth Memory, HBM)與 LLM serving 的實際情況連結起來,說明為何小 batch size 的解碼通常是 memory-bound 的。
從 RAG apps 邁向 RAG systems engineering
從基礎 RAG 原型邁向 production RAG 系統,需要在檢索(retrieval)與生成(generation)階段皆具備工程紀律。系統可能會在證據輸入層(evidence input layer)因為文件修訂、過期 chunks 或混合 embedding spaces 而失效,也可能在輸出層因為產生無根據的主張而失敗。解決這些失效需要維運機制(如安全索引遷移和 data lineage),並結合應用機器學習技術(如 query-time verification 和校準後的 abstention thresholds)。由於驗證只能檢驗回答是否符合檢索出的段落,而無法確認段落本身是否為最新資訊,因此檢索新鮮度與回答的佐證支援都需要獨立且協調的控制措施。
- RAG 系統可能在兩個不同的層級失效:進入系統的佐證資料(retrieval rot)以及系統輸出的主張(unsupported generation)。
- 佐證資料層級的失效源自於文件更新、混合 embedding spaces、過期 chunks 以及 query distribution shifts 等問題。
- 輸出驗證應被定義為分類與 selective prediction 問題,而非 generation 任務。
- 驗證器(verifier)可以確認回答是否與檢索到的 context 一致,但無法判斷檢索到的 context 是否已經過期。
- Production RAG 工程需要實作維運控制機制(如 migration gates 和 rollback paths),同時搭配 ML 控制機制(如 risk bounds 和校準後的 abstention thresholds)。
GPU 如何組織工作負載,清楚解析:
本節將解釋 GPU 如何調度與組織工作負載,從啟動 kernel 轉變為硬體層級的執行。程式會將 thread 分組為組成 grid 的 block,這些 block 會被分配至 Streaming Multiprocessors (SMs),並以稱為 warp 的 32-thread 單位執行。Warp scheduling 讓 SM 能夠在其他 thread 等待記憶體時,切換執行已就緒的 thread,從而避免閒置停頓(idle stalls)。本文還將 GPU 硬體機制(如 shared memory、registers 與 High Bandwidth Memory, HBM)與 LLM serving 的實際情況連結起來,說明為何小 batch size 的解碼通常是 memory-bound 的。
- GPU kernel 的 launch 會將 thread 組織成構成 grid 的 block,隨後指派給 Streaming Multiprocessors (SMs)。
- 單一 block 中的所有 thread 都會在同一個 SM 上執行,並可透過 shared memory 共享資料。
- SMs 會以稱為 warps 的 32-thread 群組來執行 threads,並對所有 active threads 套用單一指令。
- warp 內部的 branch divergence 會迫使 inactive threads 在 active threads 執行時等待,進而降低執行效率。
- 當其他 warps 因等待資料而 stall 時,SMs 會透過 context-switching 切換至 ready warps 來隱藏 memory latency。
- 在小 batch sizes 下進行 LLM decoding 通常屬於 memory-bound,因為從 HBM 搬移 weights 所花的時間比執行運算還要長。