<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AI 和機器學習 - 東東 GCP 教學 - GCP 實戰講師</title>
	<atom:link href="https://dongdonggcp.com/category/ai/feed/" rel="self" type="application/rss+xml" />
	<link>https://dongdonggcp.com</link>
	<description>助你考取證照，轉職成功</description>
	<lastBuildDate>Sun, 25 Oct 2026 12:48:29 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://dongdonggcp.com/wp-content/uploads/2025/04/cropped-340838097_121391010914395_5443948698124160121_n-32x32.jpg</url>
	<title>AI 和機器學習 - 東東 GCP 教學 - GCP 實戰講師</title>
	<link>https://dongdonggcp.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>GCP ML 證照怎麼考？PMLE 考試範圍、準備地圖與 23 篇重點整理</title>
		<link>https://dongdonggcp.com/2026/10/25/gcp-professional-machine-learning-engineer-certification-guide/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gcp-professional-machine-learning-engineer-certification-guide</link>
					<comments>https://dongdonggcp.com/2026/10/25/gcp-professional-machine-learning-engineer-certification-guide/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:46:30 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<category><![CDATA[生成式 AI]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12894</guid>

					<description><![CDATA[<p>GCP ML 證照怎麼考？PMLE 考 2 小時 50～60 題、200 美元、英日文，六大區比重換算題數、23 篇系列文對應哪一區、零基礎 8 週 72 小時怎麼排、舊題庫名稱對照現況，一篇總整理。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/gcp-professional-machine-learning-engineer-certification-guide/">GCP ML 證照怎麼考？PMLE 考試範圍、準備地圖與 23 篇重點整理</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>GCP ML 證照怎麼考？PMLE 考 2 小時、50～60 題、200 美元、英日文；範圍分六大區，這篇給你準備地圖和 23 篇重點。</strong></p>



<p class="wp-block-paragraph">這是「GCP ML 工程師 SEO／GEO 系列文」的最後一篇，也是<strong>總整理</strong>。前面 23 篇把 Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照會考的觀念，一篇一個主題、全部用白話講過一遍。這篇把它們接起來：考試長什麼樣、六大區各考什麼、哪一篇對應哪一區、零基礎怎麼排 8 週、舊題庫的名稱要換成什麼。</p>



<p class="wp-block-paragraph">先說兩件事。第一，這不是考試心得：東東還沒考 PMLE，這篇是整理<strong>官方考試指南</strong>和<strong>官方考試頁</strong>的範圍與準備重點。第二，名稱：<strong>Vertex AI 在 2026 年 4 月起改名為 Gemini Enterprise Agent Platform（簡稱 Agent Platform）</strong>，2026 年 6 月 1 日起的考試指南全面用新名稱，但大家搜尋還是打 Vertex AI，所以系列文標題都保留舊名，文中附新舊對照。</p>



<figure class="wp-block-image aligncenter size-full"><img fetchpriority="high" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-01-exam-facts.png" alt="GCP ML 證照 PMLE 考試基本資料：2 小時、50 到 60 題單選與複選、200 美元加稅、英文與日文、線上監考或考試中心、無先決條件、建議 3 年以上業界經驗含 1 年以上 Google Cloud、不直接考程式但要看懂 Python 與 SQL、2026 年 6 月 1 日起用 Gemini Enterprise Agent Platform 新名稱" class="wp-image-12889" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-01-exam-facts.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-01-exam-facts-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-01-exam-facts-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-01-exam-facts-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>不知道範圍，讀的都不會考</strong>：PMLE 不考「演算法怎麼推導」，考的是「這個情境該選哪個 Google Cloud 服務、為什麼」。讀錯方向，花一樣的時間分數差很多</li>

<li><strong>舊題庫會害你</strong>：網路上的題庫多半是 2023 年前整理的，裡面的 AutoML Tables、Cloud Source Repositories、Vertex Explainable AI 要嘛改名、要嘛停用。現在的考題用新名稱</li>

<li><strong>轉職要的是證照加作品</strong>：這張證照是 Google Cloud 專業級裡最偏「做出來」的一張，考試指南第一段就寫 ML 工程師要「建置、評估、產品化、最佳化 AI 方案」。準備過程本身就是作品</li>

<li><strong>一張地圖省三個月</strong>：系列 23 篇照考試邏輯排，這篇告訴你哪篇對應哪區、先讀哪篇</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 先搞懂：PMLE 是什麼</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph">Google Cloud 發的<strong>機器學習工程師證照</strong>。考你會不會用 Google Cloud 的服務，把機器學習模型從「有資料」做到「上線、監控、自動重訓」，包括傳統模型和生成式 AI。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph"><strong>汽車駕照的筆試</strong>。不考你引擎怎麼設計，考你「這個路口該怎麼做」：題目給一個公司情境（資料在哪、要多快、預算多少、法規要求什麼），四個選項全是 Google Cloud 服務的組合，你選最合理的。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">這張證照 2020 年推出。2024 年改版加入生成式 AI。2026 年 6 月 1 日再改版，<a href="https://cloud.google.com/learn/certification/machine-learning-engineer">官方考試頁</a>寫得很清楚：反映 <strong>Vertex AI 改名為 Gemini Enterprise Agent Platform</strong>、Google Cloud <strong>資料與分析堆疊的更新</strong>，並且<strong>優先考 Google Cloud 原生方案</strong>。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph"><a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">考試指南</a>定義的 ML 工程師：處理大型複雜資料集、寫可重複使用的程式、懂模型架構、資料與 ML 管線、MLOps、指標解讀，還要熟提示工程、應用開發、基礎架構、資料工程與治理的基礎概念。這份清單就是 ML 工程師的職缺描述。站上的<a href="https://dongdonggcp.com/2026/07/29/cloud-jobs-comparison/">雲端職缺大解析</a>講過這些角色差在哪。</p>



<h3 class="wp-block-heading">考試基本資料</h3>



<p class="wp-block-paragraph"><a href="https://cloud.google.com/learn/certification/machine-learning-engineer">官方考試頁</a>列的（2026 年 10 月查）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>項目</th><th>內容</th></tr></thead><tbody><tr><td>時間</td><td><strong>2 小時</strong></td></tr><tr><td>題數與題型</td><td><strong>50～60 題</strong>，單選與<strong>複選</strong></td></tr><tr><td>費用</td><td><strong>200 美元</strong>（依地區加稅）</td></tr><tr><td>語言</td><td><strong>英文、日文</strong>（沒有中文）</td></tr><tr><td>方式</td><td>線上監考（遠端），或到考試中心</td></tr><tr><td>先決條件</td><td><strong>無</strong>，不用先考 Associate Cloud Engineer</td></tr><tr><td>建議經驗</td><td>3 年以上業界經驗，含 1 年以上用 Google Cloud 設計與管理方案</td></tr><tr><td>程式能力</td><td><strong>不直接考寫程式</strong>，但要看得懂題目裡的 Python 和 SQL 片段</td></tr><tr><td>及格分數</td><td>官方不公布</td></tr><tr><td>續證</td><td>在續證期間內可更新，效期與流程以<a href="https://support.google.com/cloud-certification/answer/9907853">官方續證 FAQ</a>為準（專業級證照目前是 2 年）</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">算一次給你看：一題幾分鐘</h3>



<pre class="wp-block-code"><code>120 分鐘 ÷ 60 題 = 每題 2 分鐘
留 15 分鐘回頭檢查標記的題目：
(120 − 15) ÷ 60 = 每題 1 分 45 秒</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：PMLE 的題目是一段情境加四個選項，讀題就要 40 秒。所以「看到關鍵字就想到答案」不是偷懶，是<strong>時間上的必要</strong>：前面每一篇文章最後的「看到這些字，就想到這個」表，就是為這 1 分 45 秒準備的。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. 六大考試區塊：各考什麼、占多少、對應哪幾篇</h2>



<p class="wp-block-paragraph"><a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">考試指南</a>分六區。比重是官方給的「約」數，題數是用 60 題換算（教學估算，四捨五入後加總會超過 60）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>區</th><th>名稱</th><th>比重</th><th>約幾題</th><th>考什麼（白話）</th><th>對應本系列</th></tr></thead><tbody><tr><td>1</td><td><strong>低程式碼 AI 方案</strong></td><td>13%</td><td>8</td><td>不寫程式或少寫程式：BigQuery ML、AutoML、現成 API、Model Garden、Gemini 調校</td><td>第 14、15、23 篇</td></tr><tr><td>2</td><td><strong>跨團隊協作管理資料與模型</strong></td><td>16%</td><td>10</td><td>前處理工具選擇、Feature Store、隱私、筆記本環境、實驗追蹤、評估、血緣</td><td>第 10、11、12、22、23 篇；評估指標在第 5、6 篇</td></tr><tr><td>3</td><td><strong>把原型放大成 ML 模型</strong></td><td><strong>21%</strong></td><td>13</td><td>選模型類型與產品、可解釋性、訓練資料組織、SDK、除錯、超參數、調校基礎模型、GPU／TPU、分散式訓練</td><td>第 1～4、7～9、13、14、16、21 篇</td></tr><tr><td>4</td><td><strong>服務與擴展模型</strong></td><td><strong>20%</strong></td><td>12</td><td>批次與線上推論、容器、Model Registry、A/B 與金絲雀、Feature Store 線上服務、端點、硬體、擴展</td><td>第 17、22、23 篇</td></tr><tr><td>5</td><td><strong>自動化與協調 ML 管線</strong></td><td>18%</td><td>11</td><td>管線、資料與模型驗證、訓練與服務一致的前處理、重訓政策、CI/CD/CT</td><td>第 10、18、19 篇</td></tr><tr><td>6</td><td><strong>監控 AI 方案</strong></td><td>13%</td><td>8</td><td>安全風險（Model Armor、資料外洩、惡意提示）、偏見、可解釋性、Model Monitoring、漂移與偏差、生成式 AI 評估</td><td>第 12、20、21 篇</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：第 3 區加第 4 區就占 <strong>41%</strong>，也就是「訓練」和「上線」。很多零基礎讀者最怕的理論（混淆矩陣、過度擬合、資料洩漏）其實散在 2.3「評估」和 3.2「訓練」裡，不是獨立一區，但不懂它們，情境題的「為什麼」就選不出來。</p>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-02-six-sections.png" alt="PMLE 六大考試區塊比重換算題數：第 1 區低程式碼 13% 約 8 題、第 2 區協作管理資料與模型 16% 約 10 題、第 3 區把原型放大成模型 21% 約 13 題、第 4 區服務與擴展 20% 約 12 題、第 5 區自動化管線 18% 約 11 題、第 6 區監控 13% 約 8 題；第 3 加第 4 區占 41%，每區標出對應的系列文章篇號" class="wp-image-12890" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-02-six-sections.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-02-six-sections-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-02-six-sections-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-02-six-sections-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">每一區的子項目，白話版</h3>



<p class="wp-block-paragraph"><strong>第 1 區（1.1、1.2）</strong>：BigQuery ML 或 Agent Platform AutoML 建分類、迴歸、預測、分群；用 BigQuery ML 做特徵工程和預測；用 BigQuery 調校 Gemini；從 Model Garden 選模型；用 Document AI、Vision、Translate 建方案；Gemini、Imagen、Veo 的應用；成本、延遲、可用性最佳化。</p>



<p class="wp-block-paragraph"><strong>第 2 區（2.1～2.3）</strong>：表格、文字、影像怎麼組織；依規模與複雜度選 BigQuery SQL、Dataflow、Spark、Python；Feature Store；PII 處理；Workbench 與 Colab Enterprise 的協作與安全；用 PyTorch、sklearn、JAX 做原型；選實驗環境（Experiments、Pipelines、Kubeflow）；評估預測式與生成式方案（含 LLM 當評審）；追蹤成品、版本、血緣。</p>



<p class="wp-block-paragraph"><strong>第 3 區（3.1～3.3）</strong>：選模型類型（ARIMA、DNN、LLM）與產品（AutoML、BigQuery ML、Pipelines）；部署策略；可解釋性需求；訓練資料放 Cloud Storage 或 BigQuery；用不同 SDK 訓練（自訂訓練、Kubeflow on GKE、AutoML、Tabular Workflows）；排除訓練失敗；超參數調校；調校基礎模型與何時該調；CPU／GPU／TPU；資料平行與模型平行。</p>



<p class="wp-block-paragraph"><strong>第 4 區（4.1、4.2）</strong>：批次與線上推論部署到 Agent Platform、Model Garden、Cloud Run、GKE；PyTorch、XGBoost 用預建或自訂容器；Model Registry 版本；A/B 測試與金絲雀；推論前後處理；Feature Store 服務特徵；公開與私有端點；CPU／GPU／TPU／邊緣；依吞吐量擴展；訓練與服務的調校。</p>



<p class="wp-block-paragraph"><strong>第 5 區（5.1、5.2）</strong>：驗證資料與模型；用 Pipelines、Managed Service for Apache Airflow、Ray 協調，從範本或自訂；訓練與服務一致的前處理；重訓政策；用 Cloud Build 做 CI/CD/CT。</p>



<p class="wp-block-paragraph"><strong>第 6 區（6.1、6.2）</strong>：防資料與模型外洩、惡意提示（正規表達式、安全過濾器、Model Armor）；監控偏見；Agent Platform 上的可解釋性；Model Monitoring 持續評估；訓練與服務偏差、資料漂移、概念漂移、特徵歸因漂移；監控與評估生成式 AI。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. 23 篇重點整理：每篇一句話＋一個考點</h2>



<p class="wp-block-paragraph">照系列順序，也是建議的閱讀順序。第 1～10 篇已發布可以直接點，其他篇發布後會補上連結。</p>



<h3 class="wp-block-heading">第一段：基礎觀念（第 1～4 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">1. 機器學習有哪幾種？監督式、非監督式、強化學習</a></td><td>有答案的叫監督式、沒答案找規律的叫非監督式、試錯拿獎勵的叫強化學習</td><td>「有標籤」→ 監督式；「分群」「推薦」→ 非監督式</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">2. 分類和迴歸差在哪？附 MAE、RMSE 計算</a></td><td>預測類別是分類、預測數字是迴歸；迴歸用 MAE、RMSE 評分，RMSE 對大錯更敏感</td><td>「流失／不流失」→ 分類；「金額」→ 迴歸</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">3. 特徵、標籤、超參數是什麼？</a></td><td>特徵是輸入、標籤是答案、參數是模型學的、超參數是人設的</td><td>「學習率」「樹深度」→ 超參數調校</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">4. 訓練集、驗證集、測試集怎麼切？</a></td><td>訓練用來學、驗證用來調、測試只看一次；時間序列要照時間切</td><td>「時間序列」「隨機切」→ 錯，會洩漏</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">第二段：模型評估（第 5～6 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">5. 混淆矩陣是什麼？準確率、精確率、召回率、F1</a></td><td>四格是抓對、冤枉、漏掉、放對；不平衡時準確率會騙人</td><td>「不能漏掉病人」→ 召回率；「不能冤枉」→ 精確率</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">6. ROC 曲線和 AUC 怎麼看？AUC-PR 差在哪</a></td><td>門檻一調，精確率和召回率就對換；AUC 是不看門檻的總分</td><td>「資料不平衡」→ 看 AUC-PR 不看 AUC-ROC</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">第三段：訓練時會遇到的問題（第 7～9 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">7. 過度擬合是什麼？正則化、Dropout、提前停止</a></td><td>訓練分數高、驗證分數低就是背答案；三招讓它別背</td><td>「訓練 loss 降、驗證 loss 升」→ 過度擬合</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">8. 資料洩漏是什麼？3 種常見情況</a></td><td>答案偷偷混進特徵，訓練超準、上線全錯</td><td>「準到不合理」「某特徵貢獻超大」→ 洩漏</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">9. 類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></td><td>少數類太少，模型全猜多數；補少數、減多數或加權</td><td>「欠取樣」一定配「Upweighting」</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">第四段：資料處理（第 10～13 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">10. 資料前處理怎麼做？標準化、遺失值、高基數類別</a></td><td>數字要放同一個尺度、空值要有策略、類別太多用雜湊桶</td><td>「訓練和服務用同一套轉換」→ 5.1</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">11. 特徵工程是什麼？特徵交叉、詞嵌入、資料增強</a></td><td>把原始資料變成模型看得懂的特徵；交叉抓交互作用、嵌入把文字變向量、增強讓影像變多</td><td>「經緯度 × 類別」→ 特徵交叉</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">12. 機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></td><td>去識別化、資料不離開裝置、服務邊界防外洩</td><td>「PII」→ DLP；「資料不能出專案」→ VPC SC</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">13. 訓練資料讀太慢？TFRecords、tf.data 與 prefetch</a></td><td>GPU 在等硬碟就是輸入瓶頸；打包、平行讀、預取</td><td>「TPU 閒置」→ prefetch、interleave</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">第五段：在 GCP 上做 ML（第 14～17 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">14. Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></td><td>資料在 BigQuery 用 SQL、影像用 AutoML、自己的框架走自訂訓練、文字影片改 Gemini</td><td>「最少程式」→ AutoML／BigQuery ML</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">15. BigQuery ML 入門：只會 SQL 也能訓練模型</a></td><td>CREATE MODEL、ML.EVALUATE、ML.PREDICT 三句 SQL 走完</td><td>「資料已在 BigQuery」「分析師」→ BigQuery ML</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">16. Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></td><td>把程式包成容器丟給 Agent Platform 跑；資料平行、模型平行；Reduction Server</td><td>「多 GPU 同步」→ 分散式策略</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">17. 模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></td><td>低延遲用線上端點、大量非即時用批次；新版先給 10% 流量</td><td>「低延遲」→ 線上；「每晚跑一次」→ 批次</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">第六段：MLOps（第 18～21 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">18. MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX</a></td><td>把訓練流程拆成元件接成管線，可重跑、可快取、可追蹤</td><td>「重複步驟不要重算」→ 管線快取</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">19. 機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></td><td>程式改動用 Cloud Build 觸發、新資料用 Cloud Run functions 觸發、定時用 Scheduler</td><td>「Cloud Source Repositories」已不開放新客戶 → GitHub</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">20. 模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a></td><td>世界變了叫漂移、訓練和上線不一樣叫偏差；Model Monitoring 抓</td><td>「上線後準確率下降」→ 漂移監控</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">21. 可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a></td><td>算每個特徵對預測貢獻多少；樹用 Sampled Shapley、神經網路用 IG、影像用 XRAI</td><td>Vertex Explainable AI 2027 年 3 月停用 → SHAP、LIME</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">第七段：追蹤與基礎服務（第 22～23 篇）</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>篇</th><th>一句話</th><th>考點</th></tr></thead><tbody><tr><td><a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">22. 實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</a></td><td>Experiments 記設定與分數、ML Metadata 記血緣、TensorBoard 畫曲線；Model Registry 管版本</td><td>「哪份資料訓練了哪個模型」→ ML Metadata</td></tr><tr><td><a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">23. ML 用哪個資料服務？BigQuery、Cloud Storage、Feature Store、Bigtable</a></td><td>分析訓練用 BigQuery、檔案放 Cloud Storage、線上查特徵用 Bigtable；Dataflow 串流、Spark 搬遷；API 先用</td><td>「線上預測查特徵」→ 不查 BigQuery</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-03-series-map.png" alt="GCP ML 證照系列 23 篇地圖分七段：基礎觀念第 1 到 4 篇、模型評估第 5 到 6 篇、訓練問題第 7 到 9 篇、資料處理第 10 到 13 篇、在 GCP 上做 ML 第 14 到 17 篇、MLOps 第 18 到 21 篇、追蹤與基礎服務第 22 到 23 篇，每段標出對應的考試區塊" class="wp-image-12891" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-03-series-map.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-03-series-map-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-03-series-map-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-03-series-map-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 零基礎的 8 週準備地圖</h2>



<p class="wp-block-paragraph">以下是<strong>建議的排程</strong>（教學假設，依每週 8～10 小時估），不是保證：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>週</th><th>讀什麼</th><th>動手做什麼</th><th>對應考試區</th></tr></thead><tbody><tr><td>1～2</td><td>第 1～6 篇：類型、分類迴歸、名詞、切資料、混淆矩陣、ROC</td><td>用第 5、6 篇的互動頁自己調門檻；開 Google Cloud 免費額度</td><td>2.3、3.1</td></tr><tr><td>3～4</td><td>第 7～13 篇：過度擬合、洩漏、不平衡、前處理、特徵工程、隱私、資料讀取</td><td>BigQuery 公開資料集練 SQL 做特徵</td><td>2.1、3.2</td></tr><tr><td>5～6</td><td>第 14～17 篇：AutoML、BigQuery ML、自訂訓練、部署</td><td>用 BigQuery ML 訓練一個模型、部署一個端點、跑一次批次預測</td><td>1.1、3.2、4.1、4.2</td></tr><tr><td>7</td><td>第 18～23 篇：管線、CI/CD、監控、可解釋、實驗、資料服務</td><td>跑一條 Pipelines 範本、開 Model Monitoring、記一次 Experiments</td><td>5.1、5.2、6.1、6.2、2.2</td></tr><tr><td>8</td><td>這篇的六區對照表＋每篇的「看到這些字」總複習</td><td>官方<a href="https://cloud.google.com/learn/certification/machine-learning-engineer">考試頁</a>的範例題、<a href="https://www.skills.google/paths/17">官方學習路徑</a>的實作實驗室</td><td>全部</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">算一次給你看：時間夠不夠</h3>



<pre class="wp-block-code"><code>8 週 × 9 小時 = 72 小時
23 篇文章 × 1.5 小時（讀＋做筆記）= 34.5 小時
動手實驗 6 次 × 3 小時 = 18 小時
官方學習路徑與範例題 = 12 小時
總複習 = 7.5 小時
合計 72 小時 ✓</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：動手那 18 小時不能省。考題是情境題，自己部署過一次端點，「線上 vs 批次」「流量分割」就不用背。有 Google Cloud 經驗的人可以把前 4 週壓成 2 週，從第 14 篇開始。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-04-eight-weeks.png" alt="零基礎 8 週準備地圖：第 1 到 2 週讀基礎與評估並開免費額度、第 3 到 4 週讀資料處理並用 BigQuery 公開資料集練 SQL、第 5 到 6 週讀 GCP 服務並用 BigQuery ML 訓練部署端點、第 7 週讀 MLOps 並跑管線與監控、第 8 週總複習官方範例題與學習路徑；72 小時配置：讀 34.5、動手 18、官方資源 12、複習 7.5" class="wp-image-12892" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-04-eight-weeks.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-04-eight-weeks-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-04-eight-weeks-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-04-eight-weeks-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 舊題庫看到這些，現在叫什麼</h2>



<p class="wp-block-paragraph">這是整個系列查官方文件查出來的名稱變動，集中在這一張表。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/vertex-ai-name-changes">官方改名對照表</a>和<a href="https://docs.cloud.google.com/vertex-ai/docs/deprecations">淘汰清單</a>是來源。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊題庫、舊筆記寫的</th><th>現在（2026 年 10 月）</th><th>哪篇講</th></tr></thead><tbody><tr><td>Vertex AI</td><td><strong>Gemini Enterprise Agent Platform</strong>（Agent Platform）</td><td>全系列</td></tr><tr><td>AutoML Tables、AutoML Vision、AutoML Natural Language</td><td><strong>AutoML on Agent Platform</strong>；AutoML Text 2025 年 6 月、AutoML Video 2025 年 7 月停用，改 <strong>Gemini 調校</strong></td><td>第 14 篇</td></tr><tr><td>AI Platform Training／Prediction</td><td>2025 年 4 月關閉；現在是 <strong>Managed Training</strong>、<strong>Agent Platform Inference</strong></td><td>第 16、17 篇</td></tr><tr><td>Vertex AI Workbench managed／user-managed notebooks</td><td>2025 年 4 月停止支援；現在只有 <strong>Workbench instances</strong>，另有 <strong>Colab Enterprise</strong></td><td>第 22 篇</td></tr><tr><td>Vertex AI Feature Store（featurestore、entity type）</td><td>Legacy 與 Optimized online serving <strong>2027 年 2 月停用</strong>；現在是 <strong>Feature Store V2</strong>（BigQuery 離線、Bigtable 線上）</td><td>第 23 篇</td></tr><tr><td>Vertex Explainable AI（Sampled Shapley、IG、XRAI）</td><td><strong>2027 年 3 月停用</strong>；方法概念還考，工具改 <strong>SHAP、LIME</strong>、BigQuery ML 內建</td><td>第 21 篇</td></tr><tr><td>Vertex AI Model Monitoring</td><td><strong>Model Monitoring on Agent Platform</strong>，分 v1（GA）與 v2（預覽）</td><td>第 20 篇</td></tr><tr><td>Cloud Source Repositories</td><td><strong>不開放新客戶</strong>；CI/CD 改 <strong>GitHub＋Cloud Build</strong></td><td>第 19 篇</td></tr><tr><td>Cloud Functions</td><td><strong>Cloud Run functions</strong></td><td>第 19、23 篇</td></tr><tr><td>Cloud Composer</td><td><strong>Managed Service for Apache Airflow</strong></td><td>第 18、23 篇</td></tr><tr><td>Dataproc、Dataproc Serverless</td><td><strong>Managed Service for Apache Spark</strong>（叢集版與 Serverless 版）</td><td>第 23 篇</td></tr><tr><td>Container Registry</td><td><strong>Artifact Registry</strong></td><td>第 16 篇</td></tr><tr><td>Dataprep</td><td>主控台叫 <strong>Alteryx Designer Cloud</strong>（第三方）；Google 主推 BigQuery 資料準備</td><td>第 23 篇</td></tr><tr><td>Recommendations AI、Vertex AI Search for Commerce</td><td><strong>AI Commerce Search</strong></td><td>第 23 篇</td></tr><tr><td>Data Catalog、Dataplex Catalog</td><td><strong>Knowledge Catalog</strong></td><td>第 22 篇</td></tr><tr><td>Vertex AI TensorBoard 每人每月 300 美元</td><td><strong>每 GiB 每月 10 美元</strong>（2023 年 8 月起）</td><td>第 22 篇</td></tr><tr><td>Gen AI evaluation service</td><td><strong>Gemini Enterprise Agent Platform Evals</strong></td><td>第 22 篇</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>考試會用哪個名字</strong>：2026 年 6 月 1 日起的指南全面用新名稱。但有些功能的淘汰公告在指南之後（Explainable AI 是 2026 年 3 月），題目裡還可能看到舊功能名。做法：<strong>名稱記兩個、概念記一個</strong>。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-05-old-vs-new-names.png" alt="舊題庫名稱對照現況：Vertex AI 改名 Gemini Enterprise Agent Platform、AutoML Text 與 Video 停用改 Gemini 調校、Workbench 舊筆記本停用剩 Workbench instances、Feature Store Legacy 2027 年 2 月停用改 V2、Vertex Explainable AI 2027 年 3 月停用改 SHAP 與 LIME、Cloud Source Repositories 不開放新客戶改 GitHub 加 Cloud Build、Cloud Functions 改 Cloud Run functions、Cloud Composer 改 Managed Service for Apache Airflow、Dataproc 改 Managed Service for Apache Spark、Container Registry 改 Artifact Registry" class="wp-image-12893" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-05-old-vs-new-names.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-05-old-vs-new-names-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-05-old-vs-new-names-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml24-05-old-vs-new-names-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考：全系列關鍵字總表</h2>



<p class="wp-block-paragraph">每篇文末都有一張「看到這些字，就想到這個」。這裡挑出<strong>跨篇最常出現的 20 組</strong>，考前最後一晚看這張就好：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th><th>篇</th></tr></thead><tbody><tr><td>「有標籤」「預測類別」「預測數值」</td><td>監督式；分類；迴歸</td><td>1、2</td></tr><tr><td>「不能漏掉」「不能冤枉」</td><td>召回率；精確率</td><td>5</td></tr><tr><td>「資料不平衡」「全猜多數也 99%」</td><td>AUC-PR、F1；過取樣／欠取樣＋Upweighting</td><td>6、9</td></tr><tr><td>「訓練好驗證差」</td><td>過度擬合：正則化、Dropout、提前停止</td><td>7</td></tr><tr><td>「準到不合理」「時間序列隨機切」</td><td>資料洩漏</td><td>4、8</td></tr><tr><td>「PII」「去識別化」「資料不能出專案」</td><td>DLP（Sensitive Data Protection）；VPC Service Controls</td><td>12</td></tr><tr><td>「GPU 閒置」「輸入瓶頸」</td><td>tf.data、prefetch、TFRecords</td><td>13</td></tr><tr><td>「資料在 BigQuery」「分析師」「只會 SQL」</td><td>BigQuery ML</td><td>14、15</td></tr><tr><td>「最少程式」「影像分類」</td><td>AutoML on Agent Platform</td><td>14</td></tr><tr><td>「自己的框架」「PyTorch」「多 GPU」</td><td>自訂訓練、預建或自訂容器、分散式策略</td><td>16</td></tr><tr><td>「低延遲」「即時」</td><td>線上推論端點</td><td>17</td></tr><tr><td>「大量」「每晚」「不急」</td><td>批次推論</td><td>17</td></tr><tr><td>「新版先給一部分流量」</td><td>流量分割、A/B、金絲雀</td><td>17</td></tr><tr><td>「可重跑」「不要重算」「元件」</td><td>Pipelines、快取</td><td>18</td></tr><tr><td>「程式改了就重訓」「新資料到就重訓」</td><td>Cloud Build；Cloud Run functions 觸發</td><td>19</td></tr><tr><td>「上線後變差」「訓練和上線分布不同」</td><td>漂移；訓練與服務偏差；Model Monitoring</td><td>20</td></tr><tr><td>「為什麼這樣預測」「法規要能解釋」</td><td>特徵歸因；可解釋模型</td><td>21</td></tr><tr><td>「哪份資料訓練了哪個模型」「比較實驗」</td><td>ML Metadata；Experiments</td><td>22</td></tr><tr><td>「線上查特徵」「毫秒」</td><td>Bigtable、Feature Store 線上服務，不是 BigQuery</td><td>23</td></tr><tr><td>「串流」「Pub/Sub」vs「已有 Spark 程式」</td><td>Dataflow vs Managed Service for Apache Spark</td><td>23</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">答題的三個習慣</h3>


<ol class="wp-block-list">
<li><strong>先找限制條件</strong>：題目一定藏一個限制，「低延遲」「最少工程量」「最低成本」「法規要求」「不能出專案」。限制決定答案，其他描述是背景</li>

<li><strong>刪掉舊名字和過度工程</strong>：選項出現已停用的服務、或「自己訓練」而題目有現成 API，先刪</li>

<li><strong>複選題數清楚</strong>：題目說「選兩個」就是兩個，多選少選都不給分</li>
</ol>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">GCP ML 證照（PMLE）是什麼？</h3>



<p class="wp-block-paragraph">Google Cloud 的 Professional Machine Learning Engineer 專業級證照，考你會不會用 Google Cloud 的服務把機器學習方案從資料做到上線、監控、重訓，涵蓋傳統模型和生成式 AI。考試 2 小時、50 到 60 題單選與複選、200 美元、英文或日文、線上監考或考試中心，沒有先決條件。</p>



<h3 class="wp-block-heading">PMLE 考試範圍有哪些？比重多少？</h3>



<p class="wp-block-paragraph">2026 年 6 月 1 日起的指南分六區：低程式碼 AI 方案約 13%、跨團隊協作管理資料與模型約 16%、把原型放大成 ML 模型約 21%、服務與擴展模型約 20%、自動化與協調 ML 管線約 18%、監控 AI 方案約 13%。第 3 加第 4 區占 41%，是訓練和上線。</p>



<h3 class="wp-block-heading">PMLE 有中文版嗎？要會寫程式嗎？</h3>



<p class="wp-block-paragraph">只有英文和日文。官方說不直接考寫程式，但題目會有 Python 和 SQL 片段，要看得懂。系列文裡第 15、16、22 篇的程式片段就是為了這個。</p>



<h3 class="wp-block-heading">零基礎考 PMLE 要準備多久？</h3>



<p class="wp-block-paragraph">這篇給的是 8 週、每週 8 到 10 小時的建議排程（教學假設）：前 4 週讀基礎、評估、資料處理，後 4 週讀 GCP 服務、MLOps 並動手做，最後一週用官方範例題和學習路徑總複習。官方建議的經驗是 3 年以上業界加 1 年以上 Google Cloud，有經驗可以壓到一半。</p>



<h3 class="wp-block-heading">PMLE 和 Data Engineer 證照差在哪？</h3>



<p class="wp-block-paragraph">Data Engineer 考的是資料怎麼進來、存、處理、分析（BigQuery、Dataflow、Spark、Pub/Sub 是主角）；PMLE 考的是資料之後怎麼訓練模型、部署、監控、自動重訓。兩張有重疊（第 23 篇的資料服務），先考哪張看你的工作：偏資料管線先 Data Engineer，偏模型先 PMLE。站上有 Data Engineer 怎麼考的文章。</p>



<h3 class="wp-block-heading">舊題庫還能用嗎？</h3>



<p class="wp-block-paragraph">能用來練情境判斷，但名稱要自己換：Vertex AI 改 Gemini Enterprise Agent Platform、AutoML Tables 改 AutoML on Agent Platform、Cloud Functions 改 Cloud Run functions、Dataproc 改 Managed Service for Apache Spark；Vertex Explainable AI 和 Feature Store Legacy 已公告停用。第 5 節有整張對照表。考試自 2026 年 6 月 1 日起用新名稱。</p>



<h3 class="wp-block-heading">考試會用 Vertex AI 還是 Gemini Enterprise Agent Platform？</h3>



<p class="wp-block-paragraph">2026 年 6 月 1 日起的考試指南全面用 Gemini Enterprise Agent Platform（簡稱 Agent Platform），底下的功能也跟著改（Agent Platform AutoML、Agent Platform Inference、Experiments on Agent Platform）。官方考試頁明寫這次改版是為了反映這個改名。準備時兩個名字都要認得。</p>



<h3 class="wp-block-heading">PMLE 證照效期多久？</h3>



<p class="wp-block-paragraph">專業級證照目前是 2 年，可在續證期間內更新，流程與期間以官方續證 FAQ 為準。</p>



<h3 class="wp-block-heading">要先考 Associate Cloud Engineer 嗎？</h3>



<p class="wp-block-paragraph">不用，PMLE 沒有先決條件。但完全沒碰過 Google Cloud 的人，建議先把第 23 篇的資料服務和站上的 GCP 學習路徑看一遍，因為考題預設你知道 BigQuery、Cloud Storage、Pub/Sub 是什麼。</p>



<h3 class="wp-block-heading">考試最重的是哪一區？要先讀哪裡？</h3>



<p class="wp-block-paragraph">第 3 區「把原型放大成 ML 模型」21% 最重，加第 4 區「服務與擴展」20%，合計 41%。但這兩區的情境題要靠第 1 到 9 篇的基礎觀念才選得出「為什麼」，所以閱讀順序還是從第 1 篇開始，有基礎的人從第 14 篇開始。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>PMLE</strong>：2 小時、50～60 題單複選、200 美元、英日文、無先決條件；不直接考程式但要看懂 Python 與 SQL；每題約 1 分 45 秒</li>

<li><strong>六區比重</strong>：13／16／<strong>21</strong>／<strong>20</strong>／18／13，第 3＋4 區（訓練、上線）占 41%</li>

<li><strong>23 篇對應</strong>：基礎（1～4）、評估（5～6）、訓練問題（7～9）、資料（10～13）、GCP 做 ML（14～17）、MLOps（18～21）、追蹤與服務（22～23）</li>

<li><strong>8 週 72 小時</strong>：讀 34.5、動手 18、官方資源 12、複習 7.5；動手不能省</li>

<li><strong>名稱記兩個、概念記一個</strong>：Vertex AI → Gemini Enterprise Agent Platform；Explainable AI、Feature Store Legacy 停用；Cloud Functions、Composer、Dataproc 都改名</li>

<li><strong>答題三習慣</strong>：先找限制條件、刪舊名字和過度工程、複選題數清楚</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列全部 23 篇</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>

<li>第 19 篇：<a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></li>

<li>第 20 篇：<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a></li>

<li>第 21 篇：<a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a></li>

<li>第 22 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</a></li>

<li>上一篇：第 23 篇：<a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">ML 用哪個資料服務？BigQuery、Cloud Storage、Feature Store、Bigtable 怎麼選</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2024/10/01/how-to-pass-gcp-data-engineer-certification-test/">GCP 證照 Data Engineer 怎麼考？費用、題數、考試範圍</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Learning Roadmap 和八大關卡</a></li>

<li><a href="https://dongdonggcp.com/2026/07/29/cloud-jobs-comparison/">雲端職缺大解析：雲端工程師、架構師、SRE、DevOps、資料工程師差在哪</a></li>

<li><a href="https://dongdonggcp.com/2026/03/10/cloud-architect-salary-taiwan-guide/">雲端架構師薪水完整指南</a></li>

<li><a href="https://dongdonggcp.com/2026/07/21/t-career-change-beginners-guide-cloud-technology/">轉職 IT 新手必學知識完整指南</a></li>

<li><a href="https://dongdonggcp.com/2025/08/04/cloud-architect-without-coding/">不會寫程式，可以轉職雲端架構師嗎？</a></li>

<li><a href="https://dongdonggcp.com/2025/04/14/vertex-ai-functions-agent-builder-model-builder-model-garden-introduction/">Vertex AI 核心功能 Agent Builder、Model Builder 和 Model Garden 介紹</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">23 篇讀完、8 週做完，你手上會有一張證照的準備和一個真的跑過的 ML 專案。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "GCP ML 證照（PMLE）是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Google Cloud 的 Professional Machine Learning Engineer 專業級證照，考你會不會用 Google Cloud 的服務把機器學習方案從資料做到上線、監控、重訓，涵蓋傳統模型和生成式 AI。考試 2 小時、50 到 60 題單選與複選、200 美元、英文或日文、線上監考或考試中心，沒有先決條件。"
      }
    },
    {
      "@type": "Question",
      "name": "PMLE 考試範圍有哪些？比重多少？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "2026 年 6 月 1 日起的指南分六區：低程式碼 AI 方案約 13%、跨團隊協作管理資料與模型約 16%、把原型放大成 ML 模型約 21%、服務與擴展模型約 20%、自動化與協調 ML 管線約 18%、監控 AI 方案約 13%。第 3 加第 4 區占 41%，是訓練和上線。"
      }
    },
    {
      "@type": "Question",
      "name": "PMLE 有中文版嗎？要會寫程式嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "只有英文和日文。官方說不直接考寫程式，但題目會有 Python 和 SQL 片段，要看得懂。系列文裡第 15、16、22 篇的程式片段就是為了這個。"
      }
    },
    {
      "@type": "Question",
      "name": "零基礎考 PMLE 要準備多久？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "這篇給的是 8 週、每週 8 到 10 小時的建議排程（教學假設）：前 4 週讀基礎、評估、資料處理，後 4 週讀 GCP 服務、MLOps 並動手做，最後一週用官方範例題和學習路徑總複習。官方建議的經驗是 3 年以上業界加 1 年以上 Google Cloud，有經驗可以壓到一半。"
      }
    },
    {
      "@type": "Question",
      "name": "PMLE 和 Data Engineer 證照差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Data Engineer 考的是資料怎麼進來、存、處理、分析（BigQuery、Dataflow、Spark、Pub/Sub 是主角）；PMLE 考的是資料之後怎麼訓練模型、部署、監控、自動重訓。兩張有重疊（第 23 篇的資料服務），先考哪張看你的工作：偏資料管線先 Data Engineer，偏模型先 PMLE。站上有 Data Engineer 怎麼考的文章。"
      }
    },
    {
      "@type": "Question",
      "name": "舊題庫還能用嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "能用來練情境判斷，但名稱要自己換：Vertex AI 改 Gemini Enterprise Agent Platform、AutoML Tables 改 AutoML on Agent Platform、Cloud Functions 改 Cloud Run functions、Dataproc 改 Managed Service for Apache Spark；Vertex Explainable AI 和 Feature Store Legacy 已公告停用。第 5 節有整張對照表。考試自 2026 年 6 月 1 日起用新名稱。"
      }
    },
    {
      "@type": "Question",
      "name": "考試會用 Vertex AI 還是 Gemini Enterprise Agent Platform？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "2026 年 6 月 1 日起的考試指南全面用 Gemini Enterprise Agent Platform（簡稱 Agent Platform），底下的功能也跟著改（Agent Platform AutoML、Agent Platform Inference、Experiments on Agent Platform）。官方考試頁明寫這次改版是為了反映這個改名。準備時兩個名字都要認得。"
      }
    },
    {
      "@type": "Question",
      "name": "PMLE 證照效期多久？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "專業級證照目前是 2 年，可在續證期間內更新，流程與期間以官方續證 FAQ 為準。"
      }
    },
    {
      "@type": "Question",
      "name": "要先考 Associate Cloud Engineer 嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "不用，PMLE 沒有先決條件。但完全沒碰過 Google Cloud 的人，建議先把第 23 篇的資料服務和站上的 GCP 學習路徑看一遍，因為考題預設你知道 BigQuery、Cloud Storage、Pub/Sub 是什麼。"
      }
    },
    {
      "@type": "Question",
      "name": "考試最重的是哪一區？要先讀哪裡？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "第 3 區「把原型放大成 ML 模型」21% 最重，加第 4 區「服務與擴展」20%，合計 41%。但這兩區的情境題要靠第 1 到 9 篇的基礎觀念才選得出「為什麼」，所以閱讀順序還是從第 1 篇開始，有基礎的人從第 14 篇開始。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/gcp-professional-machine-learning-engineer-certification-guide/">GCP ML 證照怎麼考？PMLE 考試範圍、準備地圖與 23 篇重點整理</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/gcp-professional-machine-learning-engineer-certification-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>ML 用哪個資料服務？BigQuery、Cloud Storage、Feature Store、Bigtable 怎麼選</title>
		<link>https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable</link>
					<comments>https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:46:00 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[BigQuery]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12888</guid>

					<description><![CDATA[<p>ML 用哪個資料服務？算延遲預算：線上預測剩 50 毫秒查特徵，BigQuery 以秒計不行，要用 Bigtable；Feature Store V2、Dataflow vs Spark、預訓練 AI API 怎麼選，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">ML 用哪個資料服務？BigQuery、Cloud Storage、Feature Store、Bigtable 怎麼選</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>ML 用哪個資料服務？訓練用 BigQuery、檔案放 Cloud Storage、線上查特徵用 Feature Store 配 Bigtable。</strong></p>



<p class="wp-block-paragraph">機器學習的資料不是「存起來」就好。訓練時要一次掃幾億筆，線上預測時要在幾十毫秒內查出一個會員的特徵，照片和模型檔又是另一種東西。一個服務做不到全部，所以 Google Cloud 有一整排：BigQuery、Cloud Storage、Bigtable、Memorystore、Feature Store，再加上處理資料的 Dataflow、Spark，和直接拿來用的 AI API。</p>



<p class="wp-block-paragraph">這篇把 PMLE 筆記最後一塊「基礎服務與工具」一次整理：<strong>存在哪、怎麼算、怎麼端上桌</strong>，每個服務用一句白話加一個飲料店的情境，最後給你一張「看到什麼需求就選什麼」的表。</p>



<p class="wp-block-paragraph">照系列慣例先說名稱：Vertex AI 在 2026 年 4 月起改名為 <strong>Gemini Enterprise Agent Platform</strong>（簡稱 Agent Platform），Feature Store 現在叫 Feature Store on Gemini Enterprise Agent Platform；Dataproc 改叫 Managed Service for Apache Spark；Cloud Composer 改叫 Managed Service for Apache Airflow；Cloud Functions 改叫 Cloud Run functions。文末有完整對照表。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店、50 萬名會員的連鎖飲料店當例子（教學假設）：POS 每天進 300 萬筆交易、App 有會員照片、要做流失模型和推薦。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-01-four-stores.png" alt="ML 用哪個資料服務：用飲料店比喻四個儲存服務，BigQuery 是總部帳本用 SQL 問大問題、Cloud Storage 是倉庫什麼檔案都能放、Bigtable 是櫃台的會員卡機按卡號毫秒內查出、Memorystore 是櫃台抽屜最快但小又貴，Feature Store 是特徵的統一供應站" class="wp-image-12883" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-01-four-stores.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-01-four-stores-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-01-four-stores-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-01-four-stores-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>存錯地方，模型上線就慢</strong>：線上預測要在 100 毫秒內回答，去 BigQuery 查一筆要一秒以上，整個端點就卡住。這是最常見的架構錯誤</li>

<li><strong>算錯地方，帳單爆炸</strong>：每天 300 萬筆交易用 Python 在筆記本裡跑，記憶體爆掉；全部丟 Spark 叢集又貴。考試指南 2.1 直接寫「<strong>依規模和複雜度選前處理工具</strong>」</li>

<li><strong>重複造輪子</strong>：Vision API 一行呼叫就能 OCR，很多人還是自己訓練模型。考試 1.2 考的就是「什麼時候用現成的 API」</li>

<li><strong>證照必考</strong>：2.1 選前處理工具與 Feature Store、3.2 訓練資料放 Cloud Storage 還是 BigQuery、4.2 用 Feature Store 服務特徵、1.2 產業 API，這篇全包</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 先搞懂：資料有三種用法，服務跟著分三類</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph">機器學習對資料有三種動作，每種對速度的要求不一樣：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>動作</th><th>白話</th><th>要多快</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>分析與訓練</strong></td><td>一次掃<strong>幾億筆</strong>，算統計、做特徵、訓練模型</td><td>幾秒到幾分鐘都可以</td><td>算每個會員 90 天來店次數</td></tr><tr><td><strong>線上查詢</strong></td><td>預測當下，查<strong>一個人</strong>的資料</td><td><strong>幾十毫秒內</strong></td><td>會員掃碼，馬上推薦一杯</td></tr><tr><td><strong>放檔案</strong></td><td>照片、影片、模型檔、CSV，<strong>整個檔案</strong>存取</td><td>看情況</td><td>50 萬會員的照片、訓練好的模型檔</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>毫秒</strong>是千分之一秒。眨一次眼大約 100～150 毫秒，線上預測的預算常常就是「一次眨眼」。</p>



<h3 class="wp-block-heading">比喻：飲料店的四個地方</h3>


<ul class="wp-block-list">
<li><strong>BigQuery</strong> 是<strong>總部的帳本</strong>：所有交易都記在這，老闆問「哪個分店的珍奶賣最好」，一句 SQL 幾秒就有答案。但要查「這一位會員剛剛買什麼」，翻帳本太慢</li>

<li><strong>Cloud Storage</strong> 是<strong>倉庫</strong>：什麼都能放，照片、影片、模型檔、備份，按件計價，一件一件拿</li>

<li><strong>Bigtable</strong> 是<strong>櫃台的會員卡機</strong>：刷卡號，毫秒內跳出這個人的資料，而且全台 2,000 家同時刷也不卡。但它只認卡號，不能問「誰買最多」</li>

<li><strong>Memorystore</strong> 是<strong>櫃台抽屜</strong>：手伸過去就拿到，最快，但空間小、放的是最常用的幾樣</li>
</ul>



<p class="wp-block-paragraph"><strong>Feature Store</strong> 不是第五個倉庫，它是<strong>特徵的供應站</strong>：帳本（BigQuery）算好的特徵，自動搬一份到會員卡機（Bigtable），訓練和線上預測拿到的是同一份。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">這些名字對應四種資料庫家族：<strong>資料倉儲</strong>（data warehouse，給分析用）、<strong>物件儲存</strong>（object storage，放檔案）、<strong>NoSQL</strong>（不用表格、按鍵查值、能橫向擴張）、<strong>快取</strong>（cache，放記憶體的暫存）。BigQuery 是 Google 把內部的 Dremel 做成服務，Bigtable 是 2006 年那篇著名論文的服務版，Cloud Storage 對應其他雲的 S3。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考題給你一個情境（延遲、資料量、資料長相），問你選哪個。分不清「分析用」和「線上查詢用」，一定選錯。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-02-latency-budget.png" alt="線上預測的延遲預算算一次：端點要在 100 毫秒內回應，扣掉網路 20 毫秒和模型推論 30 毫秒，剩 50 毫秒查特徵；BigQuery 單筆查詢以秒計所以不行，Bigtable 毫秒級可以，Memorystore 次毫秒最快但容量小；旁邊是存什麼選哪個的決策表" class="wp-image-12884" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-02-latency-budget.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-02-latency-budget-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-02-latency-budget-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-02-latency-budget-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. 四個儲存服務，各自長什麼樣</h2>



<h3 class="wp-block-heading">BigQuery：分析與訓練的主場</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/bigquery/docs/introduction">官方</a>叫它「全代管、AI 就緒的資料平台」：<strong>無伺服器</strong>（白話：你不用開機器，丟 SQL 進去就跑），儲存和運算分開，查 TB 級資料幾秒、PB 級幾分鐘。</p>



<p class="wp-block-paragraph">跟機器學習有關的：</p>


<ul class="wp-block-list">
<li><strong>欄位式儲存</strong>：一次只讀用到的欄，算特徵快又便宜（第 15 篇 BigQuery ML 直接在裡面訓練）</li>

<li><strong>串流寫入</strong>：Storage Write API；Pub/Sub 有 <a href="https://docs.cloud.google.com/pubsub/docs/bigquery">BigQuery 訂閱</a>可以把訊息直接寫進表，不用 Dataflow</li>

<li><strong>Feature Store V2 的離線倉庫就是它</strong>（下一節）</li>

<li>站上有兩篇講過：<a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 跟資料庫差在哪</a>、<a href="https://dongdonggcp.com/2026/03/27/bigquery-billing-guide/">BigQuery 計費方式</a></li>
</ul>



<p class="wp-block-paragraph"><strong>不適合</strong>：單筆低延遲查詢。它是為掃全表設計的，查一筆也要排程啟動，通常以秒計。</p>



<h3 class="wp-block-heading">Cloud Storage：檔案、照片、模型檔</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/storage/docs/introduction">官方</a>：存<strong>非結構化資料</strong>的服務，資料是<strong>物件</strong>（object，白話就是一個檔案），放在<strong>值區</strong>（bucket，白話是資料夾的最上層）。耐久度 11 個 9（一年掉一個檔的機率是千億分之一）。</p>



<p class="wp-block-paragraph">機器學習用它放：訓練影像（第 13 篇的 TFRecords）、模型檔、管線的中間產物（第 18 篇）、TensorBoard 日誌（第 22 篇）。考試 3.2 寫「訓練資料放在 Cloud Storage 和 BigQuery」：<strong>表格資料放 BigQuery，檔案類放 Cloud Storage</strong>。</p>



<p class="wp-block-paragraph"><strong>儲存類別</strong>（<a href="https://docs.cloud.google.com/storage/docs/storage-classes">官方表</a>）是考點，差別在「多久拿一次」：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>類別</th><th>最短存放天數</th><th>取回費</th><th>適合</th></tr></thead><tbody><tr><td><strong>Rapid</strong></td><td>無</td><td>無</td><td>單一區域、AI／ML 訓練要極高吞吐，配 Rapid Bucket</td></tr><tr><td><strong>Standard</strong></td><td>無</td><td>無</td><td>常常讀的「熱」資料：正在訓練的資料集</td></tr><tr><td><strong>Nearline</strong></td><td>30 天</td><td>有</td><td>一個月碰一次：上個月的訓練快照</td></tr><tr><td><strong>Coldline</strong></td><td>90 天</td><td>有</td><td>一季碰一次：舊版訓練資料</td></tr><tr><td><strong>Archive</strong></td><td>365 天</td><td>有</td><td>一年碰不到一次：法規要留的原始資料</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">算一次給你看：照片放哪一級</h3>



<p class="wp-block-paragraph">飲料店 50 萬會員、每人 20 張照片、每張 2 MB（教學假設）：</p>



<pre class="wp-block-code"><code>50 萬 × 20 × 2 MB = 20,000,000 MB = 20 TB</code></pre>



<p class="wp-block-paragraph">訓練封膜檢查模型（第 14 篇）用過這批照片之後，接下來 90 天內不會再碰。選 <strong>Coldline</strong>（最短 90 天剛好）。如果貪便宜放 <strong>Archive</strong>，第 100 天要重訓拿出來：</p>


<ul class="wp-block-list">
<li>取回費要付</li>

<li>最短 365 天，<strong>就算第 100 天刪掉，也照 365 天收費</strong></li>
</ul>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：類別越冷，每 GB 月費越低，但最短天數和取回費越高。「多久拿一次」才是選擇依據，不是「現在想省多少」。不確定就開 <strong>Autoclass</strong>，讓 Cloud Storage 依存取頻率自動換類別。</p>



<h3 class="wp-block-heading">Bigtable：線上預測查特徵</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/bigtable/docs/overview">官方</a>：<strong>稀疏表</strong>，能到幾十億列、幾千欄，存 TB 到 PB，<strong>單一鍵值</strong>（single-keyed）資料的低延遲讀寫，高吞吐。</p>



<p class="wp-block-paragraph">白話：一張超大的表，每列有一個 <strong>row key</strong>（列鍵，像會員卡號），只能靠這個鍵快速查，查到就是毫秒級。欄沒用到不占空間，所以叫「稀疏」。適合時間序列、購買紀錄、IoT 資料，官方明寫「機器學習應用」。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>特色</th><th>白話</th></tr></thead><tbody><tr><td>加節點就變快</td><td>2,000 家分店同時刷，加機器就撐得住，不停機</td></tr><tr><td>HBase 相容</td><td>原本用 Hadoop 生態的程式搬過來不用改</td></tr><tr><td>自動擴縮</td><td>看 CPU 自動加減節點</td></tr><tr><td>免費試用</td><td>10 天、500 GB SSD、1 個節點，可延到 90 天</td></tr><tr><td>分層儲存（預覽）</td><td>不常用的資料放便宜的層；還有記憶體層做次毫秒讀取</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>不適合</strong>：問「誰買最多」這種要掃全表的分析，那是 BigQuery 的事。</p>



<h3 class="wp-block-heading">Memorystore：最快的那一層</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/memorystore/docs/redis/memorystore-for-redis-overview">官方</a>：全代管的 <strong>Redis</strong>（開源的記憶體資料庫），<strong>次毫秒</strong>存取。有 Redis、Redis Cluster，和較新的 <a href="https://docs.cloud.google.com/memorystore/docs/valkey/product-overview">Valkey</a>（Redis 的開源分支）三種。</p>



<p class="wp-block-paragraph">白話：資料放<strong>記憶體</strong>不放硬碟，所以最快；代價是貴、容量有限（單一 Redis 執行個體到 300 GB）。機器學習用它放：推薦結果的快取、熱門會員的特徵、Dataflow 串流處理的中間資料。</p>



<h3 class="wp-block-heading">四個放一起</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>BigQuery</strong></th><th><strong>Cloud Storage</strong></th><th><strong>Bigtable</strong></th><th><strong>Memorystore</strong></th></tr></thead><tbody><tr><td>存什麼</td><td>表格</td><td>檔案</td><td>鍵值、寬表</td><td>鍵值（記憶體）</td></tr><tr><td>怎麼查</td><td>SQL，掃全表</td><td>整個檔案拿</td><td>按 row key</td><td>按 key</td></tr><tr><td>延遲</td><td>秒</td><td>看檔案大小</td><td>毫秒</td><td>次毫秒</td></tr><tr><td>容量</td><td>PB</td><td>無上限</td><td>PB</td><td>GB 級</td></tr><tr><td>ML 用途</td><td>分析、特徵、訓練、BigQuery ML</td><td>影像、模型檔、管線產物</td><td>線上特徵、時間序列</td><td>快取、熱資料</td></tr><tr><td>飲料店</td><td>總部帳本</td><td>倉庫</td><td>會員卡機</td><td>櫃台抽屜</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">算一次給你看：延遲預算</h3>



<p class="wp-block-paragraph">線上預測端點（第 17 篇）要求 100 毫秒內回應（教學假設）：</p>



<pre class="wp-block-code"><code>總預算：100 ms
− 網路來回：20 ms
− 模型推論：30 ms
= 剩 50 ms 給「查特徵」

BigQuery 單筆查詢：通常 1,000 ms 以上 → 超出 20 倍，不行
Bigtable 單列讀取：毫秒級（假設 5 ms）→ 可以
Memorystore：次毫秒（假設 0.5 ms）→ 可以，但要放得下</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：預算越緊（例如要 20 毫秒），越要往記憶體靠；資料越大（幾 TB 的會員特徵），越要用 Bigtable 而不是 Memorystore。這題的答案不是「哪個最快」，是「<strong>在預算內、放得下、最便宜</strong>」。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. Feature Store：訓練和線上用同一份特徵</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Feature Store on Gemini Enterprise Agent Platform</strong>（舊名 Vertex AI Feature Store）：把算好的特徵集中管理，<strong>訓練時從 BigQuery 拿、線上預測時從 Bigtable 拿，兩邊是同一份</strong>。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/featurestore/latest/overview">官方</a>：它是 BigQuery 資料來源上面的一層<strong>中繼資料層</strong>，直接從 BigQuery 把最新特徵值搬去線上服務。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">中央廚房。各分店不自己熬珍珠（各團隊不自己算「90 天來店次數」），總部熬好一鍋（BigQuery 算好），配送到每家店的保溫桶（線上倉庫）。客人拿到的和品管抽驗的是同一鍋。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">第 20 篇講的<strong>訓練與服務偏差</strong>（training-serving skew）最常見的原因就是：訓練時特徵用 SQL 算，上線時工程師用另一套程式重算，兩邊不一樣。Feature Store 的存在理由就是讓它們<strong>只有一個來源</strong>。另一個理由是重用：推薦模型和流失模型都要「90 天來店次數」，算一次大家用。</p>



<h3 class="wp-block-heading">現在的版本（V2）長什麼樣</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>元件</th><th>白話</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>離線倉庫</strong></td><td>就是 <strong>BigQuery 的表或檢視</strong>，每欄一個特徵、有 ID 欄和時間戳記欄；<strong>不用另外複製</strong></td><td><code>member_features</code> 表</td></tr><tr><td><strong>Feature group／Feature</strong></td><td>把 BigQuery 表登記進<strong>特徵登錄表</strong>（registry），可選；登記了才能按時間戳記只給最新值、才能<strong>監控漂移</strong></td><td>登記「90 天來店次數」「距上次消費天數」</td></tr><tr><td><strong>Online store</strong></td><td>線上服務叢集</td><td>會員卡機</td></tr><tr><td><strong>Feature view</strong></td><td>從 registry 或 BigQuery 挑幾個特徵，掛到 online store，<strong>排程同步</strong></td><td>推薦模型要的 8 個特徵</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">線上服務有兩種：</p>


<ul class="wp-block-list">
<li><strong>Bigtable online serving</strong>：給 TB 級、常更新的資料，<strong>不支援嵌入</strong>（第 11 篇的向量）</li>

<li><strong>Optimized online serving</strong>：超低延遲、支援嵌入，但<strong>已在 2026 年 2 月 17 日淘汰、2027 年 2 月 17 日停用</strong>；<a href="https://docs.cloud.google.com/vertex-ai/docs/deprecations">淘汰公告</a>要你改用 Bigtable online serving，嵌入改用 <strong>Vector Search</strong></li>
</ul>



<p class="wp-block-paragraph"><strong>Vertex AI Feature Store（Legacy）</strong>，也就是舊題庫寫的 featurestore／entity type 那套，同樣 2026 年 2 月 17 日淘汰、2027 年 2 月 17 日停用，官方說要搬到 V2。</p>



<h3 class="wp-block-heading">算一次給你看：同步頻率</h3>



<p class="wp-block-paragraph">Feature view 排程從 BigQuery 同步到線上（教學假設）：</p>



<pre class="wp-block-code"><code>每小時同步一次 → 線上拿到的特徵最舊 60 分鐘
改成每 10 分鐘 → 最舊 10 分鐘，但同步次數 × 6，費用跟著上升</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：「特徵多新鮮」和「花多少錢」是對換的。流失模型看 90 天行為，一小時一次夠；要做「剛剛買了 A 就推 B」這種即時特徵，Feature Store 的排程同步不夠，要走第 4 節的 Dataflow 串流直接寫 Bigtable。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-03-feature-store-v2.png" alt="Feature Store V2 的結構：BigQuery 表就是離線倉庫不用另外複製，登記成 feature group 和 feature 後，feature view 排程同步到 online store 用 Bigtable online serving 給線上端點查，訓練直接從 BigQuery 拿，兩邊同一份避免訓練與服務偏差；Legacy 與 Optimized online serving 2027 年 2 月停用，嵌入改用 Vector Search" class="wp-image-12885" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-03-feature-store-v2.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-03-feature-store-v2-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-03-feature-store-v2-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-03-feature-store-v2-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 處理資料：BigQuery SQL、Dataflow、Spark、Python 怎麼選</h2>



<p class="wp-block-paragraph">考試指南 2.1 的原話：「依<strong>規模</strong>和<strong>複雜度</strong>選前處理工具（例如 BigQuery SQL、Dataflow、Apache Spark、記憶體內的 Python 框架）」。四個工具的分界：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>工具</th><th>白話</th><th>什麼時候選</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>Python（pandas）</strong></td><td>在筆記本裡、<strong>全部塞進記憶體</strong></td><td>資料幾 GB 以內，探索階段</td><td>抽 10 萬筆看分布</td></tr><tr><td><strong>BigQuery SQL</strong></td><td>資料已經在 BigQuery，<strong>用 SQL 做特徵</strong></td><td>表格、能用 SQL 表達的轉換，規模不是問題</td><td>算每個會員 90 天來店次數</td></tr><tr><td><strong>Dataflow</strong></td><td>Google 代管的 <strong>Apache Beam</strong>，<strong>批次和串流同一套程式</strong></td><td>要<strong>即時</strong>處理、要<strong>自訂程式邏輯</strong>、資料從 Pub/Sub 來</td><td>交易一進來就更新「最近一筆」特徵</td></tr><tr><td><strong>Managed Service for Apache Spark</strong></td><td>代管的 <strong>Spark／Hadoop</strong>（舊名 <strong>Dataproc</strong>）</td><td>已有 Spark 程式、要用 Spark MLlib、團隊熟 Spark</td><td>把舊的 Spark 特徵程式搬上雲</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Dataflow</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/dataflow/docs/overview">官方</a>：<strong>統一的串流與批次處理</strong>，全代管、自動擴縮，預設<strong>恰好一次</strong>（exactly-once）處理。用途包括「串流資料的即時 ML 分析」、ETL 進 BigQuery。</p>



<p class="wp-block-paragraph">白話：寫一次 Beam 程式，歷史資料用批次跑、新資料用串流跑，邏輯同一份，正好解決第 20 篇的偏差。它有<strong>範本</strong>（templates）：Pub/Sub 到 BigQuery 這種常見流程不用寫程式。</p>



<p class="wp-block-paragraph"><strong>Pub/Sub</strong> 是訊息佇列（站上有<a href="https://dongdonggcp.com/2025/08/06/cloud-pub-sub-tutorial-better-than-rabbitmq-mqtt/">教學</a>），白話是「郵筒」：POS 把交易丟進去，誰要就來收。<a href="https://docs.cloud.google.com/pubsub/docs/bigquery">官方</a>說：訊息<strong>不用處理</strong>直接進表，用 BigQuery 訂閱就好，省掉 Dataflow；要<strong>轉換、開窗、彙總</strong>才用 Dataflow。</p>



<h3 class="wp-block-heading">Managed Service for Apache Spark（舊名 Dataproc）</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/dataproc/docs/concepts/overview">官方</a>：叢集 90 秒內開好，每個 vCPU 每小時 1 美分加上機器費，整合 BigQuery、Cloud Storage、Bigtable。另有 <a href="https://docs.cloud.google.com/dataproc-serverless/docs/overview">Serverless 版</a>：不開叢集，丟批次工作或在 BigQuery Studio 筆記本開互動 session。站上有<a href="https://dongdonggcp.com/2025/04/23/whai-is-dataproc-architecture-and-usage-introduction/">Dataproc 是什麼</a>。</p>



<p class="wp-block-paragraph"><strong>Dataflow vs Spark 怎麼選</strong>（考試愛考）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>看到</th><th>選</th></tr></thead><tbody><tr><td>「串流」「即時」「Pub/Sub」「Beam」「批次串流同一套」</td><td><strong>Dataflow</strong></td></tr><tr><td>「已有 Spark／Hadoop 程式」「MLlib」「Hive」「搬遷」</td><td><strong>Managed Service for Apache Spark</strong></td></tr><tr><td>「不想管叢集」「偶爾跑一次 Spark」</td><td><strong>Serverless Spark</strong></td></tr><tr><td>「資料在 BigQuery、SQL 做得到」</td><td><strong>BigQuery SQL</strong>，最省事</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">不寫程式的：Data Fusion、Dataprep</h3>


<ul class="wp-block-list">
<li><strong>Cloud Data Fusion</strong>：<a href="https://docs.cloud.google.com/data-fusion/docs/concepts/overview">官方</a>說是「全代管的資料整合服務」，用開源 CDAP，<strong>拖拉點選</strong>建 ETL 管線，批次和即時都行。白話：給不想寫程式的資料工程師</li>

<li><strong>Dataprep</strong>：筆記寫的「資料清理與探索」工具，是 Trifacta（後來被 Alteryx 收購）的產品。現況：Google 的 Dataprep 產品頁已經<strong>導向 BigQuery</strong>，主控台裡以 <strong>Alteryx Designer Cloud</strong> 的名稱出現；Google 自己主推的是 <a href="https://docs.cloud.google.com/bigquery/docs/data-prep-introduction">BigQuery 內建的資料準備</a>，用 Gemini 看資料給清理建議，Dataform 排程。舊題庫看到 Dataprep，知道它是第三方工具、現在有 BigQuery 內建替代</li>
</ul>



<h3 class="wp-block-heading">排程與協調：Managed Service for Apache Airflow</h3>



<p class="wp-block-paragraph">第 18 篇講過，<strong>Cloud Composer</strong> 現在叫 <a href="https://docs.cloud.google.com/composer/docs/composer-3/composer-overview">Managed Service for Apache Airflow</a>，用 DAG 排整條資料流程：每天凌晨 Spark 算特徵 → BigQuery 更新 → Feature view 同步 → 觸發訓練管線。考試 5.1 把它和 Agent Platform Pipelines、Ray 並列為協調工具。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-04-processing-and-apis.png" alt="資料處理工具怎麼選：幾 GB 以內用 Python 在記憶體裡做、資料在 BigQuery 用 SQL 做特徵、要即時或自訂邏輯用 Dataflow 的 Beam 批次串流同一套、已有 Spark 程式用 Managed Service for Apache Spark 舊名 Dataproc、不寫程式用 Data Fusion；預訓練 AI API 一覽：Vision、Natural Language、Speech-to-Text、Translation、Document AI、AI Commerce Search" class="wp-image-12886" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-04-processing-and-apis.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-04-processing-and-apis-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-04-processing-and-apis-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-04-processing-and-apis-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 現成的 AI API：先問「有沒有人做好了」</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>預訓練 API</strong>（pre-trained API）：Google 已經用海量資料訓練好的模型，你<strong>丟資料進去拿結果</strong>，不用準備訓練資料、不用訓練。考試 1.2 寫「用產業專用 API（Document AI、Vision、Translate）建方案」。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">買現成的手搖飲料基底，而不是自己種茶葉。自己種（自訂訓練）只有在現成的味道不對時才值得。</p>



<h3 class="wp-block-heading">有哪些</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>API</th><th>做什麼</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>Vision API</strong></td><td><a href="https://docs.cloud.google.com/vision/docs/features-list">功能表</a>：OCR（一般文字、密集文件與手寫）、標籤、物件定位、logo、地標、裁切建議、以圖搜圖</td><td>讀發票、找出杯子上的 logo</td></tr><tr><td><strong>Natural Language API</strong></td><td><a href="https://docs.cloud.google.com/natural-language/docs/basics">功能</a>：情感、實體、實體情感、語法、內容分類，自動偵測語言</td><td>評論是正面還是負面、提到哪家分店</td></tr><tr><td><strong>Speech-to-Text</strong></td><td><a href="https://docs.cloud.google.com/speech-to-text/docs/basics">三種模式</a>：同步（1 分鐘內）、非同步（到 480 分鐘）、串流（邊講邊轉）；建議 16 kHz</td><td>客服電話轉文字</td></tr><tr><td><strong>Cloud Translation</strong></td><td><a href="https://docs.cloud.google.com/translate/docs/overview">兩版</a>：Basic 用 NMT 模型；Advanced 多了翻譯 LLM、詞彙表、文件翻譯、批次</td><td>菜單翻成日文，「珍珠」固定譯法用詞彙表</td></tr><tr><td><strong>Document AI</strong></td><td><a href="https://docs.cloud.google.com/document-ai/docs/overview">處理器</a>分三類：數位化（Enterprise Document OCR）、擷取（Form Parser、Layout Parser、自訂擷取器）、分類（自訂分類器、分割器）</td><td>供應商發票自動填進系統</td></tr><tr><td><strong>AI Commerce Search</strong></td><td>舊名 <strong>Recommendations AI</strong>、Vertex AI Search for Commerce；<a href="https://docs.cloud.google.com/retail/docs/overview">同一份</a>商品目錄＋使用者事件同時做推薦和搜尋</td><td>App 的「你可能也喜歡」</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">怎麼判斷「用 API 還是自己訓練」</h3>


<ol class="wp-block-list">
<li>任務是通用的（OCR、翻譯、情感）→ <strong>API</strong></li>

<li>API 做得到但類別要客製（「封膜有沒有破」不在 Vision 的標籤裡）→ 第 14 篇的 <strong>AutoML 影像</strong>，或 Document AI 的自訂擷取器</li>

<li>文字、影片的客製需求 → AutoML Text 和 Video 已停用，改 <strong>Gemini 調校</strong></li>

<li>以上都不行 → <strong>自訂訓練</strong>（第 16 篇）</li>
</ol>



<p class="wp-block-paragraph">Vision 文件自己也說：掃描文件要 OCR 加表單欄位擷取，去用 <strong>Document AI</strong>。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">6. 應用平台：程式跑在哪</h2>



<p class="wp-block-paragraph">筆記最後一塊「Cloud Functions、App Engine」，現況：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>服務</th><th>現在</th><th>ML 裡的角色</th></tr></thead><tbody><tr><td><strong>Cloud Functions</strong></td><td>改叫 <strong>Cloud Run functions</strong>（<a href="https://docs.cloud.google.com/run/docs/functions/comparison">對照</a>：原 2nd gen 直接部署成 Cloud Run 服務；1st gen 還在）</td><td><strong>事件觸發</strong>：Cloud Storage 有新檔 → 啟動訓練管線（第 19 篇）；輕量前處理</td></tr><tr><td><strong>App Engine</strong></td><td>還在，但<a href="https://docs.cloud.google.com/appengine/docs/an-overview-of-app-engine">官方</a>寫「新使用者建議改用 Cloud Run」</td><td>舊的 Web／API 前端</td></tr><tr><td><strong>Cloud Run</strong></td><td>現在的主力無伺服器平台</td><td><a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">第 17 篇</a>：自己包容器服務模型，或 Agent Platform 端點以外的選擇</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">Cloud Run functions 的規格：HTTP 觸發最長 60 分鐘、16 GiB 記憶體 4 vCPU、一個執行個體可以同時接 1,000 個請求，映像只能放 Artifact Registry（Container Registry 已淘汰）。站上有<a href="https://dongdonggcp.com/2025/07/20/cloud-run-functions-tutorials/">Cloud Run Functions 簡介</a>。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">飲料店的完整資料架構（2026 年 10 月）</h3>


<ol class="wp-block-list">
<li><strong>交易進來</strong>：POS → <strong>Pub/Sub</strong>。不用轉換的直接開 <strong>BigQuery 訂閱</strong>進 <code>transactions</code> 表；要算「最近 5 分鐘消費」這種開窗特徵的走 <strong>Dataflow</strong> 串流，直接寫 <strong>Bigtable</strong></li>

<li><strong>照片進來</strong>：App 上傳到 <strong>Cloud Storage</strong>（Standard），訓練完 90 天沒碰自動轉 Coldline（開 Autoclass）</li>

<li><strong>算特徵</strong>：每天凌晨 <strong>BigQuery SQL</strong> 算 90 天來店次數等慢特徵，寫 <code>member_features</code> 表；舊的 Spark 程式搬到 <strong>Managed Service for Apache Spark</strong>，用 <strong>Managed Service for Apache Airflow</strong> 排 DAG</li>

<li><strong>登記特徵</strong>：<code>member_features</code> 登記成 <strong>Feature group</strong>，開特徵監控抓漂移（第 20 篇）</li>

<li><strong>訓練</strong>：從 BigQuery 取特徵（第 15、16 篇），模型檔放 Cloud Storage，登錄 Model Registry（第 22 篇）</li>

<li><strong>上線</strong>：<strong>Feature view</strong> 每小時同步到 <strong>Bigtable online serving</strong>，端點（第 17 篇）50 毫秒內查到特徵；推薦結果快取到 <strong>Memorystore</strong></li>

<li><strong>現成的先用</strong>：發票用 <strong>Document AI</strong>、評論用 <strong>Natural Language API</strong>，不自己訓練</li>

<li><strong>觸發</strong>：Cloud Storage 新資料到 → <strong>Cloud Run functions</strong> → 啟動 Pipelines（第 19 篇）</li>
</ol>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>Vertex AI Feature Store（Legacy：featurestore、entity type）</td><td><strong>Feature Store on Gemini Enterprise Agent Platform（V2）</strong>；Legacy 2026 年 2 月淘汰、2027 年 2 月停用</td></tr><tr><td>Optimized online serving</td><td>2027 年 2 月停用，改 <strong>Bigtable online serving</strong>；嵌入改 <strong>Vector Search</strong></td></tr><tr><td>Dataproc</td><td><strong>Managed Service for Apache Spark</strong>（叢集版與 Serverless 版）</td></tr><tr><td>Cloud Composer</td><td><strong>Managed Service for Apache Airflow</strong></td></tr><tr><td>Cloud Functions</td><td><strong>Cloud Run functions</strong></td></tr><tr><td>Dataprep</td><td>主控台叫 <strong>Alteryx Designer Cloud</strong>（第三方）；Google 主推 <strong>BigQuery 資料準備</strong></td></tr><tr><td>Recommendations AI、Vertex AI Search for Commerce</td><td><strong>AI Commerce Search</strong>（Recommendations 從 Agent Search 提供）</td></tr><tr><td>Cloud Natural Language API、Cloud Vision API</td><td>名稱沒變；文件歸在 Agent Platform 的「預訓練 API」底下</td></tr><tr><td>Container Registry</td><td><strong>Artifact Registry</strong></td></tr><tr><td>Memorystore for Redis</td><td>還在；新增 <strong>Memorystore for Valkey</strong></td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 1 區：低程式碼 AI 方案（約 13%）</td><td>1.2 用<strong>產業專用 API</strong>（Document AI、Vision、Translate）建方案</td></tr><tr><td>第 2 區：跨團隊協作管理資料與模型（約 16%）</td><td>2.1 <strong>依規模與複雜度選前處理工具</strong>（BigQuery SQL、Dataflow、Spark、記憶體內 Python）；在 <strong>Feature Store</strong> 建立與整合特徵</td></tr><tr><td>第 3 區：把原型放大成 ML 模型（約 21%）</td><td>3.2 訓練資料放 <strong>Cloud Storage 和 BigQuery</strong>；從各種來源把結構化與非結構化資料餵進訓練管線</td></tr><tr><td>第 4 區：服務與擴展模型（約 20%）</td><td>4.2 用 <strong>Feature Store 管理與服務特徵</strong></td></tr><tr><td>第 5 區：自動化與協調 ML 管線（約 18%）</td><td>5.1 用 Pipelines、<strong>Managed Service for Apache Airflow</strong>、Ray 協調</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-05-exam-keywords.png" alt="PMLE 考試關鍵字：線上預測低延遲查特徵想到 Bigtable 或 Feature Store 線上服務、分析訓練 SQL 想到 BigQuery、影像模型檔想到 Cloud Storage、次毫秒快取想到 Memorystore、串流 Pub/Sub Beam 想到 Dataflow、已有 Spark 程式想到 Managed Service for Apache Spark、訓練與服務偏差想到 Feature Store、OCR 翻譯情感想到預訓練 API、表單發票想到 Document AI" class="wp-image-12887" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-05-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-05-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-05-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml23-05-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「線上預測」「低延遲查特徵」「毫秒」「row key」「高吞吐」</td><td><strong>Bigtable</strong>（或 Feature Store 的 Bigtable online serving）</td></tr><tr><td>「分析」「SQL」「資料倉儲」「掃全表」「訓練表格資料」</td><td><strong>BigQuery</strong></td></tr><tr><td>「影像」「影片」「模型檔」「非結構化」「TFRecords」</td><td><strong>Cloud Storage</strong></td></tr><tr><td>「很少存取」「保留一年」「最便宜」</td><td>Cloud Storage <strong>Coldline／Archive</strong>，注意最短天數與取回費</td></tr><tr><td>「次毫秒」「快取」「記憶體」「Redis」</td><td><strong>Memorystore</strong></td></tr><tr><td>「訓練和線上特徵不一致」「特徵重用」「集中管理特徵」</td><td><strong>Feature Store</strong></td></tr><tr><td>「嵌入」「向量相似搜尋」</td><td><strong>Vector Search</strong>（Feature Store 的 Optimized serving 停用）</td></tr><tr><td>「串流」「即時」「Pub/Sub」「Apache Beam」「批次串流同一套」</td><td><strong>Dataflow</strong></td></tr><tr><td>「Pub/Sub 直接進 BigQuery 不用轉換」</td><td><strong>BigQuery 訂閱</strong></td></tr><tr><td>「Spark」「Hadoop」「Hive」「搬遷既有程式」</td><td><strong>Managed Service for Apache Spark</strong>（Dataproc）</td></tr><tr><td>「資料小」「探索」「筆記本」</td><td><strong>記憶體內 Python</strong>（pandas）</td></tr><tr><td>「不寫程式的 ETL」「拖拉點選」</td><td><strong>Data Fusion</strong></td></tr><tr><td>「排程」「DAG」「跨服務的工作流」</td><td><strong>Managed Service for Apache Airflow</strong></td></tr><tr><td>「OCR」「翻譯」「情感分析」「語音轉文字」「不想訓練模型」</td><td><strong>預訓練 API</strong></td></tr><tr><td>「表單」「發票」「擷取欄位」</td><td><strong>Document AI</strong></td></tr><tr><td>「商品推薦」「電商搜尋」</td><td><strong>AI Commerce Search</strong>（Recommendations AI）</td></tr><tr><td>「新檔案到就觸發」「事件驅動」</td><td><strong>Cloud Run functions</strong></td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>線上預測去查 BigQuery</strong>：以秒計的延遲，端點會逾時。線上查特徵用 Bigtable、Memorystore，或 Feature Store 的線上服務</li>

<li><strong>把照片存進 BigQuery</strong>：非結構化檔案放 Cloud Storage，BigQuery 存路徑就好</li>

<li><strong>選 Feature Store（Legacy）的做法</strong>：entity type、featurestore 那套 2027 年 2 月停用，現在是 BigQuery 當離線倉庫的 V2</li>

<li><strong>串流也選 Spark</strong>：Spark 能做串流，但 Google Cloud 的標準答案是 Dataflow（Beam）；Spark 選在「已有 Spark 程式」</li>

<li><strong>自己訓練 OCR</strong>：Vision API 或 Document AI 一行呼叫，考試看到「最少工程量」就選 API</li>

<li><strong>Archive 當一般儲存</strong>：最短 365 天，提早刪也照收，加取回費</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店 App 的推薦模型部署成線上端點，每次要讀該會員的 8 個特徵，要求 50 毫秒內回應。特徵每天在 BigQuery 用 SQL 算好。該怎麼把特徵端給端點？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「50 毫秒」「線上」→ 不能直接查 BigQuery</li>

<li>「特徵已經在 BigQuery」→ <strong>Feature Store V2</strong>：BigQuery 表登記成 feature group，feature view 同步到 <strong>Bigtable online serving</strong></li>

<li>訓練時從同一張 BigQuery 表拿，沒有訓練與服務偏差</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">每天 300 萬筆交易從 POS 進 Pub/Sub，要算每位會員「最近 5 分鐘消費金額」當即時特徵，也要把原始交易存進 BigQuery 給分析用。工程量最小的做法？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「原始交易存 BigQuery、不用轉換」→ <strong>BigQuery 訂閱</strong>，不用寫程式</li>

<li>「最近 5 分鐘」是開窗彙總 → <strong>Dataflow</strong> 串流，算完寫 <strong>Bigtable</strong> 給線上用</li>

<li>不選 Spark：沒有既有 Spark 程式，Beam 一套程式批次串流都能用</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">供應商每月寄 2,000 張 PDF 發票，要自動抓出品項、金額、日期填進系統。團隊沒有 ML 工程師。該用什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「發票」「抓欄位」「沒有 ML 工程師」→ <strong>Document AI</strong>（發票是常見的預訓練解析器類型，或用 Form Parser）</li>

<li>不選 Vision API：它只給文字和座標，欄位要自己拼</li>

<li>不自己訓練：1.2 的重點就是先用產業 API</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">機器學習的訓練資料該放 BigQuery 還是 Cloud Storage？</h3>



<p class="wp-block-paragraph">表格資料放 BigQuery，用 SQL 做特徵、直接 BigQuery ML 訓練，或讓自訂訓練讀 BigQuery。影像、音訊、影片、模型檔、TFRecords 這些檔案放 Cloud Storage，BigQuery 只存路徑。考試指南 3.2 兩個都列，分界就是「表格」和「檔案」。</p>



<h3 class="wp-block-heading">Bigtable 和 BigQuery 差在哪？</h3>



<p class="wp-block-paragraph">BigQuery 是分析用的資料倉儲：用 SQL 掃全表，查 TB 級幾秒，但查一筆也以秒計。Bigtable 是 NoSQL 寬表：靠 row key 查，毫秒級、高吞吐、能到 PB，但不能做掃全表的分析。線上預測查特徵用 Bigtable，算特徵和訓練用 BigQuery。</p>



<h3 class="wp-block-heading">Feature Store 是什麼？為什麼需要？</h3>



<p class="wp-block-paragraph">集中管理特徵的服務，讓訓練和線上預測拿到同一份特徵，避免訓練與服務偏差，也讓不同模型重用特徵。現在的 V2 版以 BigQuery 的表當離線倉庫，不用另外複製；把表登記成 feature group 和 feature，用 feature view 排程同步到 online store 的 Bigtable online serving 給端點查。</p>



<h3 class="wp-block-heading">Vertex AI Feature Store（Legacy）還能用嗎？</h3>



<p class="wp-block-paragraph">2026 年 2 月 17 日淘汰，2027 年 2 月 17 日停用，官方要求搬到 Feature Store V2。同一天淘汰的還有 V2 的 Optimized online serving，改用 Bigtable online serving；要存和查嵌入向量改用 Vector Search。舊題庫寫的 featurestore、entity type 是 Legacy 的概念。</p>



<h3 class="wp-block-heading">Dataflow 和 Dataproc 怎麼選？</h3>



<p class="wp-block-paragraph">Dataflow 是代管的 Apache Beam，批次和串流同一套程式，自動擴縮，預設恰好一次處理，看到「串流」「即時」「Pub/Sub」就選它。Dataproc 現在叫 Managed Service for Apache Spark，是代管的 Spark／Hadoop，選在「已經有 Spark 程式要搬上雲」「要用 MLlib、Hive」；不想管叢集用 Serverless 版。資料已經在 BigQuery、SQL 做得到，就用 BigQuery SQL 最省事。</p>



<h3 class="wp-block-heading">資料前處理什麼時候用 Python 就好？</h3>



<p class="wp-block-paragraph">資料幾 GB 以內、能整個塞進記憶體、在探索階段，pandas 在筆記本裡最快。資料大到記憶體放不下，表格資料改 BigQuery SQL，要自訂邏輯或串流改 Dataflow，有 Spark 程式改 Managed Service for Apache Spark。考試指南 2.1 說的就是依規模和複雜度選。</p>



<h3 class="wp-block-heading">Cloud Storage 的儲存類別怎麼選？</h3>



<p class="wp-block-paragraph">看多久拿一次：常讀的用 Standard（無最短天數、無取回費）；一個月一次 Nearline（最短 30 天）；一季一次 Coldline（90 天）；一年一次 Archive（365 天）。冷的類別月費低但有取回費和最短天數，提早刪也照最短天數收費。AI／ML 訓練要極高吞吐有單一區域的 Rapid 類別。不確定就開 Autoclass 自動換。</p>



<h3 class="wp-block-heading">什麼時候該用預訓練 API 而不是自己訓練？</h3>



<p class="wp-block-paragraph">任務是通用的就用 API：OCR 和物件辨識用 Vision、情感和實體用 Natural Language、語音用 Speech-to-Text、翻譯用 Cloud Translation、表單發票用 Document AI、電商推薦和搜尋用 AI Commerce Search。類別要客製但影像為主用 AutoML 影像；文字和影片的客製改 Gemini 調校（AutoML Text、Video 已停用）；都不行才自訂訓練。</p>



<h3 class="wp-block-heading">Dataprep 現在還在嗎？</h3>



<p class="wp-block-paragraph">Google 的 Dataprep 產品頁已導向 BigQuery，主控台裡以第三方的 Alteryx Designer Cloud 名稱出現。Google 主推的替代是 BigQuery 內建的資料準備功能：用 Gemini 看資料樣本給清理和轉換建議，由 Dataform 排程。舊題庫看到 Dataprep 要知道它不是 Google 自家服務。</p>



<h3 class="wp-block-heading">Cloud Functions 改名了嗎？</h3>



<p class="wp-block-paragraph">改叫 Cloud Run functions：原本的 2nd gen 直接以 Cloud Run 服務部署，HTTP 觸發最長 60 分鐘、16 GiB 記憶體、一個執行個體可同時接 1,000 個請求；1st gen 還在。機器學習裡最常用在事件觸發：Cloud Storage 有新資料就啟動訓練管線。App Engine 還在，但官方建議新使用者改用 Cloud Run。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>三種動作三類服務</strong>：分析與訓練（<strong>BigQuery</strong>，秒級、掃全表）、線上查詢（<strong>Bigtable</strong> 毫秒、<strong>Memorystore</strong> 次毫秒）、放檔案（<strong>Cloud Storage</strong>，類別依多久拿一次選）</li>

<li><strong>延遲預算</strong>：100 ms − 網路 20 − 推論 30 = 剩 50 ms 查特徵，BigQuery 以秒計所以不行；答案是「預算內、放得下、最便宜」</li>

<li><strong>Feature Store V2</strong>：BigQuery 當離線倉庫、feature view 同步到 <strong>Bigtable online serving</strong>；Legacy 與 Optimized serving 2027 年 2 月停用，嵌入改 Vector Search</li>

<li><strong>前處理依規模與複雜度</strong>：Python（小）→ BigQuery SQL（表格）→ Dataflow（串流、自訂、Beam）→ Managed Service for Apache Spark（既有 Spark）；Pub/Sub 不轉換直接 BigQuery 訂閱</li>

<li><strong>現成的先用</strong>：Vision、Natural Language、Speech-to-Text、Translation、Document AI、AI Commerce Search；客製才 AutoML 影像、Gemini 調校、自訂訓練</li>

<li><strong>改名</strong>：Dataproc → Managed Service for Apache Spark、Composer → Managed Service for Apache Airflow、Cloud Functions → Cloud Run functions、Recommendations AI → AI Commerce Search</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>

<li>第 19 篇：<a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></li>

<li>第 20 篇：<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a></li>

<li>第 21 篇：<a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a></li>

<li>上一篇：第 22 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</a></li>

<li>下一篇：第 24 篇：<a href="https://dongdonggcp.com/2026/10/25/gcp-professional-machine-learning-engineer-certification-guide/">GCP ML 證照怎麼考？PMLE 考試範圍、準備地圖與 23 篇重點整理</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 是資料庫嗎？跟資料庫差在哪</a></li>

<li><a href="https://dongdonggcp.com/2026/03/27/bigquery-billing-guide/">BigQuery 計費方式完整指南</a></li>

<li><a href="https://dongdonggcp.com/2025/02/12/how-to-upload-data-to-bigquery/">把資料上傳到 BigQuery 的各種方法</a></li>

<li><a href="https://dongdonggcp.com/2025/04/23/whai-is-dataproc-architecture-and-usage-introduction/">Dataproc 是什麼？四大優勢與使用方法</a></li>

<li><a href="https://dongdonggcp.com/2025/08/06/cloud-pub-sub-tutorial-better-than-rabbitmq-mqtt/">Cloud Pub/Sub 教學</a></li>

<li><a href="https://dongdonggcp.com/2025/07/20/cloud-run-functions-tutorials/">Cloud Run Functions 簡介與基本操作</a></li>

<li><a href="https://dongdonggcp.com/2026/05/19/gcp-bill-explosion-prevention-guide/">GCP 帳單爆炸防護指南</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Roadmap</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">資料放對地方、算對地方，模型才跑得快又不燒錢。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "機器學習的訓練資料該放 BigQuery 還是 Cloud Storage？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "表格資料放 BigQuery，用 SQL 做特徵、直接 BigQuery ML 訓練，或讓自訂訓練讀 BigQuery。影像、音訊、影片、模型檔、TFRecords 這些檔案放 Cloud Storage，BigQuery 只存路徑。考試指南 3.2 兩個都列，分界就是「表格」和「檔案」。"
      }
    },
    {
      "@type": "Question",
      "name": "Bigtable 和 BigQuery 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "BigQuery 是分析用的資料倉儲：用 SQL 掃全表，查 TB 級幾秒，但查一筆也以秒計。Bigtable 是 NoSQL 寬表：靠 row key 查，毫秒級、高吞吐、能到 PB，但不能做掃全表的分析。線上預測查特徵用 Bigtable，算特徵和訓練用 BigQuery。"
      }
    },
    {
      "@type": "Question",
      "name": "Feature Store 是什麼？為什麼需要？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "集中管理特徵的服務，讓訓練和線上預測拿到同一份特徵，避免訓練與服務偏差，也讓不同模型重用特徵。現在的 V2 版以 BigQuery 的表當離線倉庫，不用另外複製；把表登記成 feature group 和 feature，用 feature view 排程同步到 online store 的 Bigtable online serving 給端點查。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex AI Feature Store（Legacy）還能用嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "2026 年 2 月 17 日淘汰，2027 年 2 月 17 日停用，官方要求搬到 Feature Store V2。同一天淘汰的還有 V2 的 Optimized online serving，改用 Bigtable online serving；要存和查嵌入向量改用 Vector Search。舊題庫寫的 featurestore、entity type 是 Legacy 的概念。"
      }
    },
    {
      "@type": "Question",
      "name": "Dataflow 和 Dataproc 怎麼選？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Dataflow 是代管的 Apache Beam，批次和串流同一套程式，自動擴縮，預設恰好一次處理，看到「串流」「即時」「Pub/Sub」就選它。Dataproc 現在叫 Managed Service for Apache Spark，是代管的 Spark／Hadoop，選在「已經有 Spark 程式要搬上雲」「要用 MLlib、Hive」；不想管叢集用 Serverless 版。資料已經在 BigQuery、SQL 做得到，就用 BigQuery SQL 最省事。"
      }
    },
    {
      "@type": "Question",
      "name": "資料前處理什麼時候用 Python 就好？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "資料幾 GB 以內、能整個塞進記憶體、在探索階段，pandas 在筆記本裡最快。資料大到記憶體放不下，表格資料改 BigQuery SQL，要自訂邏輯或串流改 Dataflow，有 Spark 程式改 Managed Service for Apache Spark。考試指南 2.1 說的就是依規模和複雜度選。"
      }
    },
    {
      "@type": "Question",
      "name": "Cloud Storage 的儲存類別怎麼選？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "看多久拿一次：常讀的用 Standard（無最短天數、無取回費）；一個月一次 Nearline（最短 30 天）；一季一次 Coldline（90 天）；一年一次 Archive（365 天）。冷的類別月費低但有取回費和最短天數，提早刪也照最短天數收費。AI／ML 訓練要極高吞吐有單一區域的 Rapid 類別。不確定就開 Autoclass 自動換。"
      }
    },
    {
      "@type": "Question",
      "name": "什麼時候該用預訓練 API 而不是自己訓練？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "任務是通用的就用 API：OCR 和物件辨識用 Vision、情感和實體用 Natural Language、語音用 Speech-to-Text、翻譯用 Cloud Translation、表單發票用 Document AI、電商推薦和搜尋用 AI Commerce Search。類別要客製但影像為主用 AutoML 影像；文字和影片的客製改 Gemini 調校（AutoML Text、Video 已停用）；都不行才自訂訓練。"
      }
    },
    {
      "@type": "Question",
      "name": "Dataprep 現在還在嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Google 的 Dataprep 產品頁已導向 BigQuery，主控台裡以第三方的 Alteryx Designer Cloud 名稱出現。Google 主推的替代是 BigQuery 內建的資料準備功能：用 Gemini 看資料樣本給清理和轉換建議，由 Dataform 排程。舊題庫看到 Dataprep 要知道它不是 Google 自家服務。"
      }
    },
    {
      "@type": "Question",
      "name": "Cloud Functions 改名了嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "改叫 Cloud Run functions：原本的 2nd gen 直接以 Cloud Run 服務部署，HTTP 觸發最長 60 分鐘、16 GiB 記憶體、一個執行個體可同時接 1,000 個請求；1st gen 還在。機器學習裡最常用在事件觸發：Cloud Storage 有新資料就啟動訓練管線。App Engine 還在，但官方建議新使用者改用 Cloud Run。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">ML 用哪個資料服務？BigQuery、Cloud Storage、Feature Store、Bigtable 怎麼選</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</title>
		<link>https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking</link>
					<comments>https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:45:30 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12882</guid>

					<description><![CDATA[<p>實驗怎麼追蹤？24 次訓練 840 個數字靠記憶一定漏。Experiments 記設定與分數、ML Metadata 記血緣、TensorBoard 畫曲線，筆記本環境怎麼選、Model Registry 管版本，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>實驗怎麼追蹤？Experiments 記每次訓練的設定與分數、ML Metadata 記來源血緣、TensorBoard 畫訓練曲線。</strong></p>



<p class="wp-block-paragraph">做機器學習不是訓練一次就結束。同一個流失模型，你會換學習率、換樹的深度、加一個新特徵，一週下來跑了幾十次。三週後老闆問：「上線那個版本是用哪份資料、哪組設定訓練的？」答不出來，就得全部重做。<strong>實驗追蹤</strong>（experiment tracking）就是幫你把每一次嘗試記下來的那本筆記。</p>



<p class="wp-block-paragraph">這篇講 Google Cloud 上做這件事的三個工具，和它們各管什麼：<strong>Experiments</strong>（記錄每次訓練的設定與分數）、<strong>ML Metadata</strong>（記錄資料、模型、步驟之間的來源關係）、<strong>TensorBoard</strong>（把訓練過程畫成圖）。還會講實驗在哪裡做（筆記本環境）、以及做完之後模型放哪裡（Model Registry）。</p>



<p class="wp-block-paragraph">照系列慣例，先說名稱：這些工具原本都掛在 <strong>Vertex AI</strong> 底下，Vertex AI 在 2026 年 4 月起改名為 <strong>Gemini Enterprise Agent Platform</strong>（簡稱 Agent Platform），工具名也跟著改。標題用 Vertex AI 是因為大家還是這樣搜；文中第一次出現時會附新名稱，文末有對照表。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店、50 萬名會員的連鎖飲料店當例子（教學假設）：資料團隊三個人，在調一個「會員會不會流失」的模型。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-01-three-tools.png" alt="實驗追蹤是什麼：像實驗室筆記本，每次訓練都記下設定、分數和用了哪份資料；Google Cloud 上分三個工具，Experiments 記每次訓練的參數與指標、ML Metadata 記資料與模型的血緣、TensorBoard 畫訓練曲線，最後把選中的版本登錄到 Model Registry" class="wp-image-12877" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-01-three-tools.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-01-three-tools-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-01-three-tools-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-01-three-tools-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>重現不了</strong>：三個人各自在筆記本裡跑，檔名叫 <code>model_final_v3_真的最後.pkl</code>。兩週後沒人記得 v3 的學習率是多少、用的是 9 月還是 10 月的資料。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/ml-metadata/introduction">官方文件</a>開頭就說：科學方法的關鍵是<strong>記下觀察和實驗的參數</strong>，資料科學也一樣</li>

<li><strong>選錯模型</strong>：沒有並排比較，常常是「印象中那次比較好」。有追蹤才能把 24 次訓練排成一張表，照分數排序</li>

<li><strong>稽核問不出來</strong>：金融、醫療會被問「這個預測是哪個模型版本做的？那個版本用什麼資料訓練？」這是 ML Metadata 的血緣（lineage）要回答的</li>

<li><strong>證照必考</strong>：PMLE 考試指南 2.2「用筆記本做模型原型」、2.3「追蹤與執行 ML 實驗」直接點名 Experiments 和 ML Metadata；4.1 的 Model Registry 版本管理也在這篇</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 先搞懂：實驗追蹤是什麼</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>實驗</strong>（experiment）在機器學習裡指「換一組設定，訓練一次，看分數」。<strong>實驗追蹤</strong>就是每做一次，就把<strong>用了什麼設定、跑出什麼分數、用了哪份資料、產出哪個模型檔</strong>記下來，之後能查、能比、能重跑。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">高中做化學實驗要寫實驗紀錄本：日期、藥品用量、溫度、觀察結果。沒寫的話，做出好結果也不知道怎麼做出來的。實驗追蹤就是機器學習的實驗紀錄本，差別是它由程式自動寫，不會漏。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">早期大家用 Excel 或檔名記：<code>lr0.1_depth6_auc0.61.pkl</code>。設定一多就亂掉，而且檔名記不了「用哪份資料」。開源社群陸續做出 MLflow、TensorBoard 這些工具；Google 把這套做法整合進 Vertex AI，分成 Experiments（記設定與分數）、ML Metadata（記關係）、TensorBoard（畫圖）三塊。它們底層是接在一起的：<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/experiments/intro-vertex-ai-experiments">Experiments 的文件</a>說，一個實驗就是 ML Metadata 裡的一個「情境」（context），時間序列指標則存在 TensorBoard。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考試 2.3「追蹤與比較模型的成品、版本與血緣」整段都是這篇；實務上沒追蹤，模型上線出問題時，你連「要回滾到哪一版」都說不出來。</p>



<h3 class="wp-block-heading">一次訓練要記四種東西</h3>



<p class="wp-block-paragraph">官方把一次執行（<strong>run</strong>）記的東西分成四類：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>記什麼</th><th>白話</th><th>飲料店流失模型的例子</th></tr></thead><tbody><tr><td><strong>參數</strong>（parameters）</td><td>這次訓練的<strong>設定</strong>，訓練前就決定好的</td><td>學習率 0.05、樹深度 8、用的特徵清單、資料日期 2026-09</td></tr><tr><td><strong>摘要指標</strong>（summary metrics）</td><td>訓練<strong>結束後一個數字</strong>的成績</td><td>測試集 AUC-PR 0.66、召回率 0.72</td></tr><tr><td><strong>時間序列指標</strong>（time series metrics）</td><td>訓練<strong>過程中每一步</strong>的數字，畫成曲線</td><td>第 1～300 輪的訓練 loss、驗證 loss</td></tr><tr><td><strong>成品</strong>（artifacts）</td><td>訓練<strong>用到和產出的檔案</strong></td><td>訓練資料的 BigQuery 表、模型檔在 Cloud Storage 的位置</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>參數</strong>和<strong>超參數</strong>是第 3 篇講的：模型自己學的叫參數（權重），人設定的叫超參數。Experiments 文件裡的「parameters」指的是後者，也就是你設定的東西。<strong>AUC-PR</strong> 是第 6 篇講的指標，流失是少數類，所以看 AUC-PR 不看 AUC-ROC。</p>



<h3 class="wp-block-heading">算一次給你看：為什麼靠記憶一定記不住</h3>



<p class="wp-block-paragraph">團隊想試：3 種學習率（0.1、0.05、0.01）× 4 種樹深度（4、6、8、10）× 2 種特徵組合（有沒有加「90 天來店次數」）。</p>



<pre class="wp-block-code"><code>組合數 = 3 × 4 × 2 = 24 次訓練
每次做 5 折交叉驗證（第 4 篇）：24 × 5 = 120 次模型訓練
每次要記 4 個參數 + 3 個指標 = 7 個數字
120 × 7 = 840 個數字</code></pre>



<p class="wp-block-paragraph">840 個數字，三個人分頭跑，靠 Excel 一定會漏、會打錯。這是追蹤工具存在的理由：<strong>它由訓練程式自動寫，一個不漏</strong>。數字變大的意義：組合數是<strong>相乘</strong>不是相加，多試一個維度就翻倍，所以第 16 篇的超參數調校會用 Vizier 這類演算法幫你挑，而不是全部跑過。</p>



<h3 class="wp-block-heading">三次 run 並排比較</h3>



<p class="wp-block-paragraph">追蹤之後，比較就是一張表（教學假設）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>run</th><th>學習率</th><th>樹深度</th><th>加「90 天來店次數」</th><th>測試集 AUC-PR</th><th>訓練時間</th></tr></thead><tbody><tr><td>run-01</td><td>0.1</td><td>6</td><td>否</td><td>0.61</td><td>4 分</td></tr><tr><td>run-02</td><td>0.05</td><td>8</td><td>否</td><td>0.66</td><td>9 分</td></tr><tr><td>run-03</td><td>0.05</td><td>8</td><td><strong>是</strong></td><td><strong>0.71</strong></td><td>10 分</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>怎麼讀</strong>：run-02 比 run-01 多 0.05，是調超參數的功勞；run-03 又多 0.05，是<strong>加特徵</strong>的功勞（第 11 篇的特徵工程）。沒有這張表，你只知道「run-03 最好」，不知道好在哪，下次就不知道該往哪個方向試。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-02-what-to-log.png" alt="一次實驗 run 要記四種東西：參數是訓練前決定的設定、摘要指標是訓練結束後的一個分數、時間序列指標是每一步的數字畫成曲線、成品是用到和產出的檔案；飲料店流失模型三次 run 並排比較，調超參數進步 0.05、加特徵再進步 0.05" class="wp-image-12878" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-02-what-to-log.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-02-what-to-log-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-02-what-to-log-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-02-what-to-log-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. Experiments：記設定與分數</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Experiments on Gemini Enterprise Agent Platform</strong>（舊名 Vertex AI Experiments）：Google 代管的實驗紀錄本。你在訓練程式裡呼叫幾行 SDK，它就把參數、指標、成品記到雲端，主控台上可以搜尋、排序、勾選幾個 run 並排比較。</p>



<p class="wp-block-paragraph"><strong>SDK</strong>（software development kit）是「給程式用的工具包」，這裡指 Python 套件 <code>google-cloud-aiplatform</code>，你 <code>import</code> 進來就能呼叫。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">Google 試算表版的實驗紀錄本：每個人的訓練程式都會自動在同一張表加一列，老闆打開就能看全隊的進度，不用收 Excel。</p>



<h3 class="wp-block-heading">概念：實驗、run、pipeline run</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/experiments/intro-vertex-ai-experiments">官方文件</a>的三個名詞：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>名詞</th><th>白話</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>實驗</strong>（experiment）</td><td>一個<strong>資料夾</strong>，裝一組相關的 run</td><td>「流失模型 2026-10」</td></tr><tr><td><strong>實驗 run</strong>（experiment run）</td><td><strong>一次訓練</strong>的紀錄：參數、摘要指標、時間序列指標、成品</td><td>run-01、run-02、run-03</td></tr><tr><td><strong>pipeline run</strong></td><td>第 18 篇的管線跑一次，也可以<strong>掛進</strong>實驗裡當一個 run，參數和指標從管線自動推出來</td><td>每週自動重訓那一次</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">所以手動在筆記本裡試的，和第 19 篇自動管線跑的，可以放在同一個實驗裡比。</p>



<h3 class="wp-block-heading">自動記錄（autolog）</h3>



<p class="wp-block-paragraph">最省事的用法是 <strong>autolog</strong>：開一個開關，SDK 自動把參數和指標記下來，不用一個一個寫。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/experiments/autolog-data">官方說</a>底層用的是 MLflow 的自動記錄，支援 Keras、scikit-learn、XGBoost、LightGBM、PyTorch Lightning、Spark、statsmodels、Fastai、Gluon。注意它<strong>只記參數和指標</strong>，成品要自己記。</p>



<pre class="wp-block-code"><code>from google.cloud import aiplatform

aiplatform.init(project="drink-shop", location="asia-east1",
                experiment="churn-2026-10",
                experiment_tensorboard="projects/.../tensorboards/123")
aiplatform.autolog()

aiplatform.start_run("run-03")
# ... 這裡放你平常的 XGBoost 訓練程式，參數和指標會自動被記下 ...
aiplatform.log_params({"features": "base+visits_90d", "data_month": "2026-09"})
aiplatform.log_metrics({"test_auc_pr": 0.71})
aiplatform.end_run()</code></pre>



<p class="wp-block-paragraph"><code>start_run</code> 到 <code>end_run</code> 之間發生的事都算這個 run 的。沒指定 run 名稱的話，SDK 會自動取名，格式是「框架名稱-時間戳記-亂碼」，例如 <code>xgboost-2026-10-24-10-30-15-a1b2c</code>。</p>



<h3 class="wp-block-heading">比較</h3>



<p class="wp-block-paragraph">主控台的 Experiments 頁面勾幾個 run 按「比較」，會出時間序列的疊圖和參數、指標對照表。用程式的話，<code>aiplatform.get_experiment_df()</code> 把整個實驗抓成一張 pandas 表（DataFrame，白話是「程式裡的試算表」），自己排序畫圖都行。</p>



<h3 class="wp-block-heading">費用</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/experiments/intro-vertex-ai-experiments">官方說明</a>：<strong>實驗 run 本身不另外收費</strong>，只付你訓練用掉的運算資源，加上底下 ML Metadata 和 TensorBoard 的儲存費（下面會算）。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. ML Metadata：記來源與血緣</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Agent Platform ML Metadata</strong>（舊名 Vertex ML Metadata）：一個記「<strong>什麼東西從哪裡來、被用到哪裡去</strong>」的資料庫。Experiments 記的是「這次分數多少」，ML Metadata 記的是「這個模型是哪份資料、哪個步驟做出來的，後來又被部署到哪」。</p>



<p class="wp-block-paragraph"><strong>中繼資料</strong>（metadata）白話是「關於資料的資料」：照片本身是資料，拍攝時間、地點、相機型號是中繼資料。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph"><strong>族譜</strong>。模型是一個人，族譜記它的爸媽（訓練資料、程式碼、超參數）、它的小孩（用它做出來的批次預測結果）。問「這個人的祖先裡有沒有 9 月那份有問題的資料？」，順著族譜往上查就知道。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">名字裡的 <strong>ML Metadata（MLMD）</strong> 是 TFX 團隊（第 18 篇）做的開源函式庫，Google 把它變成代管服務。它用<strong>圖</strong>（graph，白話是「點和線」）來存：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>元素</th><th>是點還是線</th><th>白話</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>成品</strong>（artifact）</td><td>點</td><td>一個檔案或資料</td><td>9 月會員表、流失模型 v3、預測結果表</td></tr><tr><td><strong>執行</strong>（execution）</td><td>點</td><td>一個步驟</td><td>「前處理」「訓練」「評估」「部署」</td></tr><tr><td><strong>事件</strong>（event）</td><td>線</td><td>成品是某個執行的<strong>輸入</strong>或<strong>輸出</strong></td><td>9 月會員表 → 訓練 → 模型 v3</td></tr><tr><td><strong>情境</strong>（context）</td><td>一個圈</td><td>把一群點和線<strong>框起來</strong></td><td>一次 pipeline run、一個實驗</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">畫出來就是：資料（點）→ 訓練（點）→ 模型（點）→ 部署（點）→ 預測結果（點），箭頭是事件。這張圖就叫<strong>血緣圖</strong>（lineage graph）。</p>



<h3 class="wp-block-heading">血緣能回答的問題</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/ml-metadata/introduction">官方文件</a>列的五個問題，每一個都是實際工作會被問的：</p>


<ol class="wp-block-list">
<li>某個模型是用<strong>哪份資料集</strong>訓練的？</li>

<li>公司裡<strong>哪些模型</strong>用過某份資料集？（那份資料後來發現有錯，要全部重訓）</li>

<li><strong>哪次 run</strong> 做出最準的模型，用了什麼超參數？</li>

<li>某個模型被<strong>部署到哪裡、什麼時候</strong>？</li>

<li>某個時間點的預測，是<strong>哪個版本</strong>的模型做的？</li>
</ol>



<p class="wp-block-paragraph">第 8 篇資料洩漏抓到了，問題 2 讓你一次找出所有受影響的模型；第 20 篇監控發現飄移，問題 5 讓你確認當時跑的是哪一版。</p>



<h3 class="wp-block-heading">結構與費用</h3>


<ul class="wp-block-list">
<li>所有紀錄放在一個 <strong>MetadataStore</strong>（每個專案、每個區域一個，通常全公司共用一個）</li>

<li>成品有<strong>型別</strong>（schema），例如 <code>system.Model</code>（記框架、版本、格式）、<code>system.Dataset</code>；型別用 YAML 寫，也可以自訂</li>

<li><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/pricing">定價</a>：<strong>每 GiB 每月 10 美元</strong>，按 MB 比例計費。中繼資料很小，官方舉例存 10 MB 一個月 0.1 美元</li>
</ul>



<h3 class="wp-block-heading">跟 Knowledge Catalog 的分工</h3>



<p class="wp-block-paragraph">Google 另有一個管全公司資料目錄的服務 <strong>Knowledge Catalog</strong>（之前叫 Dataplex Catalog、更早叫 Data Catalog），也能看血緣。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/lineage">Pipelines 血緣文件</a>的比較：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>ML Metadata</strong></th><th><strong>Knowledge Catalog</strong></th></tr></thead><tbody><tr><td>記什麼</td><td>管線的<strong>所有</strong>輸入輸出成品</td><td>能對到正式資源名稱的成品（模型、資料集、BigQuery 表）</td></tr><tr><td>範圍</td><td>單一區域、單一專案</td><td><strong>跨區域、跨專案</strong>，全組織</td></tr><tr><td>接哪些服務</td><td>Pipelines、Experiments、Model Registry、資料集</td><td>Agent Platform、BigQuery、Managed Service for Apache Airflow、Managed Service for Apache Spark</td></tr><tr><td>要不要開</td><td><strong>永遠開著</strong>，不用設定</td><td>每個專案開 Data Lineage API</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">白話：ML Metadata 是 ML 團隊自己的族譜；Knowledge Catalog 是全公司的戶政系統，連 BigQuery 表從哪張表算出來都記。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-03-lineage.png" alt="ML Metadata 的血緣圖：成品和執行是點、事件是線，9 月會員表經過訓練步驟產出流失模型 v3，再經部署產出預測結果；血緣能回答哪份資料訓練了哪個模型、哪些模型用過某份資料、哪次 run 最準、模型部署到哪裡、某筆預測是哪一版做的" class="wp-image-12879" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-03-lineage.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-03-lineage-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-03-lineage-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-03-lineage-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. TensorBoard：把訓練過程畫成圖</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Vertex AI TensorBoard</strong>（現在文件寫 TensorBoard in Gemini platform）：開源 TensorBoard 的代管版。TensorBoard 是 Google 開源的訓練視覺化工具，把訓練時每一步的 loss、準確率畫成曲線，還能看模型結構圖、權重分布、嵌入投影、影像和文字樣本。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph"><strong>心電圖</strong>。摘要指標是「最後血壓 120」，時間序列是「過程中每一秒的心跳」。心跳曲線才看得出中途有沒有異常：訓練 loss 一直降但驗證 loss 從第 150 輪開始往上，就是第 7 篇的過度擬合，要提前停止。</p>



<h3 class="wp-block-heading">它能畫什麼</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/experiments/tensorboard-introduction">官方列的</a>：</p>


<ul class="wp-block-list">
<li><strong>標量曲線</strong>：loss、準確率隨訓練步數變化（最常用）</li>

<li><strong>計算圖</strong>：模型每一層怎麼接</li>

<li><strong>直方圖</strong>：權重、偏差隨時間的分布，看有沒有爆掉或全變 0</li>

<li><strong>嵌入投影</strong>：把第 11 篇的嵌入向量投影到 2D、3D 看聚不聚</li>

<li><strong>樣本</strong>：影像、文字、音訊，看模型實際看到什麼</li>
</ul>



<p class="wp-block-paragraph">代管版多的東西：<strong>持久、可分享的連結</strong>（開源版要自己架伺服器，關掉就沒了）、跟 Experiments 整合（在主控台直接看時間序列）、企業級的權限控管。</p>



<h3 class="wp-block-heading">跟 Experiments 的關係</h3>



<p class="wp-block-paragraph">Experiments 的時間序列指標<strong>就是存在 TensorBoard 裡</strong>，Experiments 只存一個指向它的參照。所以前面程式碼 <code>aiplatform.init</code> 要給 <code>experiment_tensorboard</code>，<code>log_time_series_metrics()</code> 記的每一步 loss 才有地方放。</p>



<h3 class="wp-block-heading">費用：算一次給你看</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/pricing">定價頁</a>寫得很清楚：2023 年 8 月起，TensorBoard 從<strong>每個使用者每月 300 美元</strong>的授權制，改成<strong>每 GiB 每月 10 美元</strong>的儲存制。舊題庫或舊文章還會看到 300 美元，現在不是。</p>



<p class="wp-block-paragraph">飲料店那 24 次訓練（教學假設）：</p>



<pre class="wp-block-code"><code>每次 run 的 TensorBoard 日誌約 50 MB
24 次 × 50 MB = 1,200 MB
1 GiB = 1,024 MB → 1,200 ÷ 1,024 ≈ 1.17 GiB
1.17 GiB × 10 美元 = 每月約 11.7 美元

ML Metadata：每次 run 約 200 KB
24 × 200 KB = 4,800 KB ≈ 4.7 MB → 每月約 0.05 美元</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：中繼資料幾乎不花錢；花錢的是 TensorBoard 日誌，而且是<strong>每個月持續收</strong>。所以官方有一篇教你「刪除過期的 TensorBoard 實驗」。日誌量變大的原因通常是記太頻繁（每一步都記影像樣本）或實驗沒清，調低記錄頻率、定期清舊實驗就能壓下來。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 實驗在哪裡做：筆記本環境</h2>



<p class="wp-block-paragraph">實驗通常在 <strong>Jupyter 筆記本</strong>（notebook）裡做：一種可以一格一格執行程式、馬上看結果的工具，資料科學家的標配。Google Cloud 上有三種地方：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>Workbench instances</strong></th><th><strong>Colab Enterprise</strong></th><th><strong>Deep Learning VM</strong></th></tr></thead><tbody><tr><td>白話</td><td>Google 幫你開好的 <strong>JupyterLab 虛擬機</strong></td><td>Google 代管的 <strong>Colab</strong>，不用管機器</td><td>預裝好框架的<strong>虛擬機映像</strong>，自己開機器</td></tr><tr><td>管機器嗎</td><td>有一台 VM，但 Google 預裝、幫你顧</td><td><strong>完全不用</strong>，要用時自動開、閒置自動關</td><td>全部自己管</td></tr><tr><td>適合</td><td>要掛 GPU、要裝自己的環境、要排程跑筆記本</td><td>團隊協作、快速試東西、從 BigQuery 直接開筆記本</td><td>要完全控制作業系統的老手</td></tr><tr><td>特色</td><td>內建 Cloud Storage 和 BigQuery 瀏覽器、GitHub 同步、執行器把筆記本丟到自訂訓練排程跑</td><td>用 IAM 分享給同事、runtime 範本、Gemini 幫寫程式、排程執行</td><td>選 TensorFlow 或 PyTorch 映像，映像本身免費，只付 VM 錢</td></tr><tr><td>閒置自動關機</td><td>有，預設開</td><td>有，預設開</td><td>要自己設</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>虛擬機</strong>（VM）白話是「雲端上租的一台電腦」；<strong>IAM</strong> 是 Google Cloud 的權限系統，決定誰能看、誰能改。</p>



<h3 class="wp-block-heading">舊名稱注意</h3>



<p class="wp-block-paragraph">筆記裡寫的「Vertex AI Workbench」在<a href="https://docs.cloud.google.com/vertex-ai/docs/deprecations">淘汰清單</a>有兩個舊版本已經停用：</p>


<ul class="wp-block-list">
<li><strong>managed notebooks</strong> 和 <strong>user-managed notebooks</strong>：2025 年 4 月 14 日停止支援、不能再建；2026 年 3 月 30 日 managed 的全部刪除，user-managed 的轉成一般 Compute Engine VM</li>

<li>現在只有 <strong>Workbench instances</strong> 這一種</li>
</ul>



<p class="wp-block-paragraph">舊題庫看到「managed notebooks vs user-managed notebooks 怎麼選」，知道這是過去式就好。</p>



<h3 class="wp-block-heading">協作與安全的最佳實務</h3>



<p class="wp-block-paragraph">考試 2.2 寫「設定筆記本環境時的協作與安全最佳實務」，從<a href="https://docs.cloud.google.com/vertex-ai/docs/workbench/introduction">官方文件</a>和<a href="https://docs.cloud.google.com/colab/docs/introduction">Colab Enterprise 文件</a>整理：</p>


<ul class="wp-block-list">
<li><strong>權限用 IAM</strong>，不要共用帳號；Colab Enterprise 可以分享給個人、Google 群組或整個網域</li>

<li><strong>程式碼進 Git</strong>（Workbench 可以同步 GitHub），筆記本不是版本控制</li>

<li><strong>不要把金鑰寫在筆記本裡</strong>：筆記本預設用你的身分或服務帳戶去呼叫其他服務</li>

<li><strong>資料不出門</strong>：用第 12 篇的 VPC Service Controls 把筆記本放進服務邊界；要自己管金鑰就開 CMEK；資料在記憶體裡也要加密就開 Confidential Computing</li>

<li><strong>省錢</strong>：閒置自動關機別關掉；正式訓練不要在筆記本裡跑，用執行器丟到自訂訓練（第 16 篇），筆記本只做試驗</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">6. 選好了放哪裡：Model Registry</h2>



<p class="wp-block-paragraph">實驗比完、選出 run-03，下一步是把它變成正式的模型版本。<strong>Model Registry on Gemini Enterprise Agent Platform</strong>（舊名 Vertex AI Model Registry）是<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/model-registry/introduction">官方說的</a>「管理模型生命週期的中央倉庫」。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">App Store 的版本列表：同一個 App 有 1.0、1.1、2.0，每版有說明、有上架狀態；使用者下載的永遠是標「最新」的那個。</p>



<h3 class="wp-block-heading">它做什麼</h3>


<ul class="wp-block-list">
<li>一個模型底下有<strong>多個版本</strong>，每版有說明、標籤、評估指標</li>

<li><strong>別名</strong>（alias）：給版本貼標籤，例如 <code>default</code>（正式用）、<code>candidate</code>（候選）。第 17 篇的端點部署時指別名，換版本只要把別名移過去</li>

<li>從這裡直接<strong>部署到端點</strong>、跑批次推論、看評估</li>

<li><strong>BigQuery ML 訓練的模型可以直接登錄</strong>，不用匯出再匯入（第 15 篇）</li>

<li>可以用 Knowledge Catalog 跨專案搜尋模型</li>
</ul>



<p class="wp-block-paragraph">Model Registry 跟 ML Metadata 是接在一起的：登錄一個版本，血緣圖就多一個 <code>system.Model</code> 成品，從它往上能看到是哪個 run、哪份資料。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">完整流程（2026 年 10 月）</h3>


<ol class="wp-block-list">
<li><strong>開環境</strong>：團隊協作、快速試驗用 Colab Enterprise；要 GPU 或自訂環境用 Workbench instances。開閒置自動關機</li>

<li><strong>建實驗</strong>：<code>aiplatform.init(experiment="churn-2026-10", experiment_tensorboard=...)</code>，先建一個 TensorBoard 實例讓時間序列有地方放</li>

<li><strong>記錄</strong>：<code>aiplatform.autolog()</code> 開自動記錄；成品用 <code>aiplatform.log_params</code> 補資料來源、特徵清單；每一步 loss 用 <code>log_time_series_metrics</code></li>

<li><strong>比較</strong>：主控台 Experiments 頁勾選 run 比較，或 <code>get_experiment_df()</code> 拉成表排序</li>

<li><strong>看血緣</strong>：主控台 Metadata 頁點任一成品看血緣圖；要跨專案就在 Knowledge Catalog 搜</li>

<li><strong>登錄</strong>：選中的模型上傳到 Model Registry，別名設 <code>candidate</code>，第 17 篇的流量分割驗證過再改 <code>default</code></li>

<li><strong>自動化</strong>：第 18、19 篇的管線跑的每一次都掛進同一個實驗（pipeline run），手動和自動放在一起比</li>

<li><strong>清理</strong>：定期刪舊的 TensorBoard 實驗，儲存費才不會每月累加</li>
</ol>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>Vertex AI Experiments</td><td><strong>Experiments on Gemini Enterprise Agent Platform</strong></td></tr><tr><td>Vertex ML Metadata</td><td><strong>Agent Platform ML Metadata</strong>（定價頁寫 ML Metadata in Gemini platform）</td></tr><tr><td>Vertex AI TensorBoard</td><td><strong>TensorBoard in Gemini platform</strong>；2023 年 8 月起改按儲存量計費（10 美元／GiB／月），不再是 300 美元／人／月</td></tr><tr><td>Vertex AI Workbench（managed／user-managed notebooks）</td><td><strong>Workbench instances</strong>；舊的兩種 2025 年 4 月停止支援、2026 年 3 月刪除或轉為一般 VM</td></tr><tr><td>Vertex AI Model Registry</td><td><strong>Model Registry on Gemini Enterprise Agent Platform</strong></td></tr><tr><td>Deep Learning VMs</td><td><strong>Deep Learning VM Images</strong>，名稱沒變，掛在 Compute Engine 底下</td></tr><tr><td>Data Catalog／Dataplex Catalog</td><td><strong>Knowledge Catalog</strong></td></tr><tr><td>Gen AI evaluation service（評估生成式模型）</td><td><strong>Gemini Enterprise Agent Platform Evals</strong></td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-04-notebooks.png" alt="實驗在哪裡做：Workbench instances 是 Google 預裝好的 JupyterLab 虛擬機適合掛 GPU 和排程、Colab Enterprise 是完全代管的 Colab 適合協作與快速試驗、Deep Learning VM 是預裝框架的映像自己管機器；舊的 managed 和 user-managed notebooks 已於 2025 年 4 月停止支援" class="wp-image-12880" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-04-notebooks.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-04-notebooks-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-04-notebooks-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-04-notebooks-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 2 區：跨團隊協作管理資料與模型（約 16%）</td><td>2.2 <strong>用筆記本做模型原型</strong>（Workbench、Colab Enterprise）：協作與安全最佳實務；2.3 <strong>追蹤與執行 ML 實驗</strong>：依框架選環境（Experiments、Pipelines、Kubeflow Pipelines）、評估預測式與生成式方案（含 LLM 當評審）、<strong>追蹤比較成品、版本與血緣</strong>（Experiments、ML Metadata）</td></tr><tr><td>第 4 區：服務與擴展模型（約 20%）</td><td>4.1 在 <strong>Model Registry</strong> 組織與版本化模型</td></tr><tr><td>第 5 區：自動化與協調 ML 管線（約 18%）</td><td>5.1 管線的成品與血緣（跟第 18 篇重疊）</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">2.3 有一條「評估生成式 AI 方案，例如 LLM 當評審（LLM-as-a-judge）」：讓一個大型語言模型幫你打另一個模型輸出的分數。這屬於生成式 AI 的評估，工具是 Agent Platform Evals，概念上也是「每次改提示詞就是一次實驗，分數要記下來比」。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-05-exam-keywords.png" alt="PMLE 考試關鍵字：比較超參數和每次訓練的分數想到 Experiments、哪份資料訓練了哪個模型與血緣想到 ML Metadata、訓練曲線和過度擬合想到 TensorBoard、模型版本與別名想到 Model Registry、團隊協作不管機器想到 Colab Enterprise、要 GPU 和排程筆記本想到 Workbench instances、跨專案血緣想到 Knowledge Catalog" class="wp-image-12881" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-05-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-05-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-05-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml22-05-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「比較不同超參數的結果」「哪次訓練最好」「追蹤參數和指標」</td><td><strong>Experiments</strong></td></tr><tr><td>「自動記錄」「不想改訓練程式」</td><td><strong>autolog</strong></td></tr><tr><td>「哪份資料訓練了這個模型」「這份資料被哪些模型用過」「血緣」「可重現」「稽核」</td><td><strong>ML Metadata</strong></td></tr><tr><td>「跨專案」「跨區域的血緣」「連 BigQuery 表一起看」</td><td><strong>Knowledge Catalog</strong>（Data Lineage API）</td></tr><tr><td>「訓練曲線」「loss 隨步數變化」「視覺化」「過度擬合在第幾輪出現」</td><td><strong>TensorBoard</strong></td></tr><tr><td>「模型版本」「別名」「回滾到上一版」「BigQuery ML 模型要部署」</td><td><strong>Model Registry</strong></td></tr><tr><td>「團隊共用筆記本」「不想管基礎設施」「從 BigQuery 直接開筆記本」</td><td><strong>Colab Enterprise</strong></td></tr><tr><td>「筆記本要 GPU」「自訂 conda 環境」「排程跑筆記本」「同步 GitHub」</td><td><strong>Workbench instances</strong></td></tr><tr><td>「筆記本的安全」「資料不能外流」</td><td><strong>VPC Service Controls</strong>、CMEK、IAM 分權</td></tr><tr><td>「用 LLM 評分另一個模型的輸出」</td><td><strong>LLM-as-a-judge</strong>，Agent Platform Evals</td></tr><tr><td>「TensorBoard 費用怎麼算」</td><td><strong>按儲存量</strong>，10 美元／GiB／月</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">五個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>用 Model Monitoring 來比較實驗</strong>：Monitoring 是第 20 篇上線後的監控，比較訓練結果是 Experiments</li>

<li><strong>以為 Experiments 要另外付費</strong>：run 不收費，收的是 ML Metadata 和 TensorBoard 的儲存</li>

<li><strong>選 managed notebooks 或 user-managed notebooks</strong>：這兩種已經停用，現在是 Workbench instances</li>

<li><strong>血緣只想到 ML Metadata</strong>：題目說「跨專案、跨區域、包含 BigQuery 表」要選 Knowledge Catalog</li>

<li><strong>把正式訓練跑在筆記本裡</strong>：筆記本是試驗用的，正式訓練用自訂訓練或管線，筆記本可以用執行器把工作丟出去</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店三位資料科學家各自在筆記本裡調流失模型，用 XGBoost 和 scikit-learn，老闆要一張表看出哪組設定最好，而且不想大家改太多程式。該用什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「哪組設定最好」「一張表」→ <strong>Experiments</strong>，比較 run</li>

<li>「不想改太多程式」「XGBoost、scikit-learn」→ <strong>autolog</strong>（支援這兩個框架），<code>aiplatform.autolog()</code> 一行</li>

<li>三個人記到同一個實驗名稱，主控台就是一張表</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">稽核單位要求：任一筆流失預測，都要能回答「是哪一版模型做的、那版用哪份資料訓練」。模型是用 Pipelines 每週重訓。要靠什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「哪一版」「哪份資料」→ <strong>血緣</strong>，<strong>ML Metadata</strong>（Pipelines 的成品會自動記進去）</li>

<li>版本本身在 <strong>Model Registry</strong>，預測結果表是模型的下游成品</li>

<li>如果稽核要連 BigQuery 表的來源一起看、而且跨好幾個專案，加開 <strong>Knowledge Catalog</strong></li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">訓練一個神經網路，驗證分數很差。工程師想看訓練過程中 loss 怎麼變、權重有沒有異常。該用什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「訓練過程中」「loss 怎麼變」「權重分布」→ <strong>TensorBoard</strong>（標量曲線、直方圖）</li>

<li>訓練 loss 降、驗證 loss 升 → 第 7 篇過度擬合，加正則化或提前停止</li>

<li>權重直方圖全擠在 0 或爆到很大 → 學習率或初始化有問題</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">實驗追蹤是什麼？為什麼需要？</h3>



<p class="wp-block-paragraph">每訓練一次模型，就把用的設定（參數）、跑出的分數（指標）、過程曲線、用到和產出的檔案（成品）自動記下來，之後能查、能並排比較、能重跑。沒有追蹤，幾十次訓練後就不知道哪組設定最好、上線的版本是用哪份資料做的，稽核問起來答不出來。Google Cloud 上分三個工具：Experiments 記設定與分數、ML Metadata 記血緣、TensorBoard 畫曲線。</p>



<h3 class="wp-block-heading">Vertex AI Experiments 是什麼？</h3>



<p class="wp-block-paragraph">現在叫 Experiments on Gemini Enterprise Agent Platform，Google 代管的實驗紀錄本。一個實驗是一個資料夾，裡面每個 run 是一次訓練，記參數、摘要指標、時間序列指標和成品。用 Python SDK 的 aiplatform.init 指定實驗名稱，start_run 到 end_run 之間的紀錄都屬於那個 run；autolog 可以自動記常見框架的參數和指標。主控台能勾選多個 run 並排比較。run 本身不收費。</p>



<h3 class="wp-block-heading">Vertex ML Metadata 是什麼？血緣是什麼？</h3>



<p class="wp-block-paragraph">ML Metadata 是記「什麼東西從哪來、被用到哪去」的資料庫，用圖來存：成品（資料、模型）和執行（訓練、部署）是點，事件是線，情境把一次 pipeline run 或一個實驗框起來。血緣就是一個成品的所有祖先和後代：模型的訓練資料、超參數、程式碼，以及它產出的預測結果。能回答哪份資料訓練了哪個模型、哪些模型用過某份資料、某筆預測是哪一版做的。每 GiB 每月 10 美元。</p>



<h3 class="wp-block-heading">TensorBoard 是什麼？跟 Experiments 差在哪？</h3>



<p class="wp-block-paragraph">TensorBoard 是 Google 開源的訓練視覺化工具，畫 loss 和準確率隨訓練步數變化的曲線、模型結構圖、權重直方圖、嵌入投影、樣本。Vertex AI TensorBoard 是代管版，有持久可分享的連結和權限控管。Experiments 的時間序列指標就是存在 TensorBoard 裡，所以兩者是搭配用：Experiments 看「最後分數、哪組設定」，TensorBoard 看「過程中發生什麼」。</p>



<h3 class="wp-block-heading">TensorBoard 怎麼收費？</h3>



<p class="wp-block-paragraph">2023 年 8 月起改成按儲存量計費，每 GiB 每月 10 美元，不再是過去每個使用者每月 300 美元的授權制。24 次訓練各留 50 MB 日誌大約 1.17 GiB，每月約 11.7 美元。費用每月持續收，要定期刪過期的 TensorBoard 實驗。</p>



<h3 class="wp-block-heading">Workbench 和 Colab Enterprise 怎麼選？</h3>



<p class="wp-block-paragraph">Colab Enterprise 完全代管、不用管機器，用 IAM 分享給同事，可以從 BigQuery 直接開筆記本，適合協作和快速試驗。Workbench instances 是 Google 預裝好 JupyterLab 和深度學習套件的虛擬機，適合要掛 GPU、要自訂 conda 環境、要用執行器排程跑筆記本、要同步 GitHub 的情況。兩者都有閒置自動關機。舊的 managed notebooks 和 user-managed notebooks 已於 2025 年 4 月停止支援。</p>



<h3 class="wp-block-heading">Model Registry 是什麼？</h3>



<p class="wp-block-paragraph">管理模型版本的中央倉庫。一個模型底下有多個版本，可以貼別名（例如 default、candidate），從這裡直接部署到端點、跑批次推論、看評估指標。BigQuery ML 訓練的模型可以直接登錄不用匯出。登錄的版本會出現在 ML Metadata 的血緣圖裡，往上能追到是哪個 run、哪份資料。</p>



<h3 class="wp-block-heading">ML Metadata 和 Knowledge Catalog 的血緣差在哪？</h3>



<p class="wp-block-paragraph">ML Metadata 記管線的所有輸入輸出成品，但只限單一專案、單一區域，永遠開著不用設定，跟 Pipelines、Experiments、Model Registry 整合。Knowledge Catalog 是全公司的資料目錄，跨專案、跨區域，連 BigQuery、Managed Service for Apache Airflow、Managed Service for Apache Spark 的血緣都記，要每個專案開 Data Lineage API，只記能對到正式資源名稱的成品。</p>



<h3 class="wp-block-heading">筆記本環境的安全最佳實務有哪些？</h3>



<p class="wp-block-paragraph">權限用 IAM 分給個人或群組，不共用帳號；程式碼同步到 Git，不把筆記本當版本控制；不在筆記本裡寫金鑰，用執行身分或服務帳戶；敏感資料用 VPC Service Controls 設服務邊界、需要自管金鑰就用 CMEK、要加密記憶體就開 Confidential Computing；閒置自動關機不要關；正式訓練丟到自訂訓練或管線跑，不在筆記本裡跑。</p>



<h3 class="wp-block-heading">筆記寫的 Deep Learning VMs 還在嗎？</h3>



<p class="wp-block-paragraph">還在，現在叫 Deep Learning VM Images，是 Compute Engine 上預裝 TensorFlow、PyTorch、CUDA 的虛擬機映像，映像免費、只付 VM 錢。Workbench instances 就是在它上面再包一層代管。適合要完全控制作業系統的人；一般做實驗用 Workbench instances 或 Colab Enterprise 比較省事。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>實驗追蹤</strong>＝每次訓練自動記四種東西：<strong>參數</strong>（設定）、<strong>摘要指標</strong>（最後分數）、<strong>時間序列指標</strong>（過程曲線）、<strong>成品</strong>（用到和產出的檔案）；24 次訓練 × 5 折 × 7 個數字＝840 個數字，靠記憶一定漏</li>

<li><strong>Experiments</strong>：實驗是資料夾、run 是一次訓練、pipeline run 也能掛進來；<code>autolog</code> 自動記常見框架；run 不收費</li>

<li><strong>ML Metadata</strong>：成品和執行是點、事件是線、情境是圈，畫成<strong>血緣圖</strong>；回答「哪份資料訓練了哪個模型」「某筆預測是哪一版做的」；10 美元／GiB／月；跨專案用 <strong>Knowledge Catalog</strong></li>

<li><strong>TensorBoard</strong>：訓練曲線、直方圖、嵌入投影；Experiments 的時間序列就存在這；<strong>按儲存量計費</strong>（10 美元／GiB／月），不再是 300 美元／人／月</li>

<li><strong>筆記本</strong>：Colab Enterprise（協作、不管機器）、Workbench instances（GPU、排程、自訂環境）、Deep Learning VM Images（自己管）；managed／user-managed notebooks 已停用</li>

<li><strong>Model Registry</strong>：版本、別名、直接部署；BigQuery ML 模型可直接登錄；跟血緣圖相連</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>

<li>第 19 篇：<a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></li>

<li>第 20 篇：<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a></li>

<li>上一篇：第 21 篇：<a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a></li>

<li>下一篇：第 23 篇：<a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">ML 用哪個資料服務？BigQuery、Cloud Storage、Feature Store、Bigtable 怎麼選</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2025/04/14/vertex-ai-functions-agent-builder-model-builder-model-garden-introduction/">Vertex AI 核心功能 Agent Builder、Model Builder 和 Model Garden 介紹</a></li>

<li><a href="https://dongdonggcp.com/2024/11/27/how-to-build-a-ai-development-environment-on-gcp/">如何在 GCP 建立含 GPU 的 AI 開發環境</a></li>

<li><a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 是資料庫嗎？跟資料庫差在哪</a></li>

<li><a href="https://dongdonggcp.com/2025/08/12/what-is-end-to-end-training-in-machine-learning/">End-to-end Training 是什麼</a></li>

<li><a href="https://dongdonggcp.com/2026/05/19/gcp-bill-explosion-prevention-guide/">GCP 帳單爆炸防護指南</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Roadmap</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">實驗有記下來，模型才不只是「印象中那次比較好」，而是說得出為什麼好、用什麼做的。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "實驗追蹤是什麼？為什麼需要？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "每訓練一次模型，就把用的設定（參數）、跑出的分數（指標）、過程曲線、用到和產出的檔案（成品）自動記下來，之後能查、能並排比較、能重跑。沒有追蹤，幾十次訓練後就不知道哪組設定最好、上線的版本是用哪份資料做的，稽核問起來答不出來。Google Cloud 上分三個工具：Experiments 記設定與分數、ML Metadata 記血緣、TensorBoard 畫曲線。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex AI Experiments 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "現在叫 Experiments on Gemini Enterprise Agent Platform，Google 代管的實驗紀錄本。一個實驗是一個資料夾，裡面每個 run 是一次訓練，記參數、摘要指標、時間序列指標和成品。用 Python SDK 的 aiplatform.init 指定實驗名稱，start_run 到 end_run 之間的紀錄都屬於那個 run；autolog 可以自動記常見框架的參數和指標。主控台能勾選多個 run 並排比較。run 本身不收費。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex ML Metadata 是什麼？血緣是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "ML Metadata 是記「什麼東西從哪來、被用到哪去」的資料庫，用圖來存：成品（資料、模型）和執行（訓練、部署）是點，事件是線，情境把一次 pipeline run 或一個實驗框起來。血緣就是一個成品的所有祖先和後代：模型的訓練資料、超參數、程式碼，以及它產出的預測結果。能回答哪份資料訓練了哪個模型、哪些模型用過某份資料、某筆預測是哪一版做的。每 GiB 每月 10 美元。"
      }
    },
    {
      "@type": "Question",
      "name": "TensorBoard 是什麼？跟 Experiments 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "TensorBoard 是 Google 開源的訓練視覺化工具，畫 loss 和準確率隨訓練步數變化的曲線、模型結構圖、權重直方圖、嵌入投影、樣本。Vertex AI TensorBoard 是代管版，有持久可分享的連結和權限控管。Experiments 的時間序列指標就是存在 TensorBoard 裡，所以兩者是搭配用：Experiments 看「最後分數、哪組設定」，TensorBoard 看「過程中發生什麼」。"
      }
    },
    {
      "@type": "Question",
      "name": "TensorBoard 怎麼收費？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "2023 年 8 月起改成按儲存量計費，每 GiB 每月 10 美元，不再是過去每個使用者每月 300 美元的授權制。24 次訓練各留 50 MB 日誌大約 1.17 GiB，每月約 11.7 美元。費用每月持續收，要定期刪過期的 TensorBoard 實驗。"
      }
    },
    {
      "@type": "Question",
      "name": "Workbench 和 Colab Enterprise 怎麼選？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Colab Enterprise 完全代管、不用管機器，用 IAM 分享給同事，可以從 BigQuery 直接開筆記本，適合協作和快速試驗。Workbench instances 是 Google 預裝好 JupyterLab 和深度學習套件的虛擬機，適合要掛 GPU、要自訂 conda 環境、要用執行器排程跑筆記本、要同步 GitHub 的情況。兩者都有閒置自動關機。舊的 managed notebooks 和 user-managed notebooks 已於 2025 年 4 月停止支援。"
      }
    },
    {
      "@type": "Question",
      "name": "Model Registry 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "管理模型版本的中央倉庫。一個模型底下有多個版本，可以貼別名（例如 default、candidate），從這裡直接部署到端點、跑批次推論、看評估指標。BigQuery ML 訓練的模型可以直接登錄不用匯出。登錄的版本會出現在 ML Metadata 的血緣圖裡，往上能追到是哪個 run、哪份資料。"
      }
    },
    {
      "@type": "Question",
      "name": "ML Metadata 和 Knowledge Catalog 的血緣差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "ML Metadata 記管線的所有輸入輸出成品，但只限單一專案、單一區域，永遠開著不用設定，跟 Pipelines、Experiments、Model Registry 整合。Knowledge Catalog 是全公司的資料目錄，跨專案、跨區域，連 BigQuery、Managed Service for Apache Airflow、Managed Service for Apache Spark 的血緣都記，要每個專案開 Data Lineage API，只記能對到正式資源名稱的成品。"
      }
    },
    {
      "@type": "Question",
      "name": "筆記本環境的安全最佳實務有哪些？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "權限用 IAM 分給個人或群組，不共用帳號；程式碼同步到 Git，不把筆記本當版本控制；不在筆記本裡寫金鑰，用執行身分或服務帳戶；敏感資料用 VPC Service Controls 設服務邊界、需要自管金鑰就用 CMEK、要加密記憶體就開 Confidential Computing；閒置自動關機不要關；正式訓練丟到自訂訓練或管線跑，不在筆記本裡跑。"
      }
    },
    {
      "@type": "Question",
      "name": "筆記寫的 Deep Learning VMs 還在嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "還在，現在叫 Deep Learning VM Images，是 Compute Engine 上預裝 TensorFlow、PyTorch、CUDA 的虛擬機映像，映像免費、只付 VM 錢。Workbench instances 就是在它上面再包一層代管。適合要完全控制作業系統的人；一般做實驗用 Workbench instances 或 Colab Enterprise 比較省事。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</title>
		<link>https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=explainable-ai-shapley-integrated-gradients-xrai</link>
					<comments>https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:45:00 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[BigQuery]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12876</guid>

					<description><![CDATA[<p>可解釋 AI 是什麼？用分獎金算一次 Shapley 值，看三種特徵歸因方法各適合哪種模型；Vertex Explainable AI 2027 年停用後改用 SHAP、LIME 與 BigQuery ML，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>可解釋 AI 是算出每個特徵對預測貢獻多少：樹模型用 Sampled Shapley，神經網路用 Integrated Gradients。</strong></p>



<p class="wp-block-paragraph">模型說 M002 會流失、說這張封膜有問題，<strong>為什麼？</strong> 老闆問、客戶問、法規問，你答不出來，模型就只是一個黑盒子。可解釋 AI 就是打開黑盒子的工具：它不改模型，而是算出「這次預測，每個特徵各出了多少力」。</p>



<p class="wp-block-paragraph">這篇有一個重要的現況：Google 的 <strong>Vertex Explainable AI 已在 2026 年 3 月 16 日淘汰</strong>，2027 年 3 月 16 日停用。概念和方法沒變（考試還是考），但工具要換成 SHAP、LIME 這類開源套件，或 BigQuery ML 內建的解釋函數。文末會整理。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店、50 萬名會員的連鎖飲料店當例子（教學假設）：流失模型（表格）和封膜檢查模型（影像）。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-01-shapley.png" alt="可解釋 AI 是什麼：Shapley 值的概念是把每個特徵當成合作的玩家，依它在各種組合裡的平均貢獻分配功勞；兩位員工單獨做 10 和 20、合作做 40，Shapley 值是 15 和 25；線性模型的歸因等於權重乘標準化後的特徵值" class="wp-image-12872" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-01-shapley.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-01-shapley-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-01-shapley-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-01-shapley-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>法規和信任</strong>：金融、醫療、保險的模型，被拒絕的人有權知道原因。BigQuery 的<a href="https://docs.cloud.google.com/bigquery/docs/xai-overview">可解釋 AI 文件</a>說，特徵歸因可以用來「確認模型行為符合預期、找出偏見、改進模型和訓練資料」</li>

<li><strong>除錯</strong>：<a href="https://docs.cloud.google.com/vertex-ai/docs/explainable-ai/overview">Vertex Explainable AI 總覽</a>說，特徵歸因能抓到「標準評估方法通常會漏掉的資料問題」。第 8 篇的資料洩漏，常常是看到某個特徵貢獻大到不合理才發現的</li>

<li><strong>監控要用</strong>：第 20 篇的特徵歸因漂移、偏見監控，底層就是這篇的方法</li>

<li><strong>證照必考</strong>：PMLE 考試指南 6.1「Agent Platform 上的模型可解釋性」；3.1「依可解釋性需求選建模技術」；6.1「監控偏見」。筆記裡的採樣 Shapley、整合梯度、XRAI 三個名詞全在這篇</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：可解釋 AI 是什麼</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>可解釋 AI</strong>（Explainable AI，XAI）：讓人看懂模型<strong>為什麼</strong>做出某個預測的方法。最主要的做法是<strong>特徵歸因</strong>（feature attribution）：算出每個特徵對這次預測的貢獻值，有正有負，加起來等於預測值和基準值的差。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">一碗牛肉麵好吃，到底是湯、麵、肉、還是辣油的功勞？特徵歸因就是「給每樣材料打分數」：湯 +4、肉 +3、麵 +1、辣油 −1，加起來是這碗麵比「平均水準」好吃多少。</p>



<h3 class="wp-block-heading">兩種解釋：局部和全域</h3>



<p class="wp-block-paragraph">BigQuery 的文件分得很清楚：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>局部解釋</strong>（local）</th><th><strong>全域解釋</strong>（global）</th></tr></thead><tbody><tr><td>白話</td><td><strong>這一筆</strong>預測，每個特徵貢獻多少</td><td>模型<strong>整體</strong>最看重哪些特徵</td></tr><tr><td>怎麼算</td><td>對單一樣本算歸因</td><td>把全部樣本的歸因<strong>彙總</strong>（取絕對值平均）</td></tr><tr><td>飲料店</td><td>M002 為什麼被判會流失</td><td>流失模型整體最看「距上次消費天數」</td></tr><tr><td>BigQuery ML</td><td><code>ML.EXPLAIN_PREDICT</code></td><td><code>ML.GLOBAL_EXPLAIN</code>、<code>ML.FEATURE_IMPORTANCE</code></td></tr></tbody></table></figure>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">模型越強越像黑盒子：線性迴歸（第 2 篇）的權重一看就懂，但 XGBoost 幾百棵樹、神經網路幾百萬個參數，沒人看得懂。2017 年前後，SHAP、Integrated Gradients 這些方法陸續出來，Google 把它們整合進 Vertex AI 叫 Vertex Explainable AI。現在 Google 把它淘汰，建議回頭用開源的 SHAP 和 LIME，BigQuery ML 則把解釋功能內建在 SQL 函數裡。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考試 3.1 有一條「依可解釋性需求選建模技術」：題目說「法規要求能解釋每筆決定」，答案可能是選線性模型、樹模型這種<strong>本身就可解釋</strong>的，或是用特徵歸因。分不清就選錯。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. Shapley 值：公平分功勞的數學</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Shapley 值</strong>（Shapley value）：把每個特徵當成一個「玩家」，算它在<strong>所有可能的合作組合</strong>裡平均貢獻多少，當作它的功勞。<a href="https://docs.cloud.google.com/vertex-ai/docs/explainable-ai/overview">Vertex Explainable AI 文件</a>說，三種特徵歸因方法<strong>都是以 Shapley 值為基礎</strong>，它來自合作賽局理論（cooperative game theory），專門處理「一群人一起做出一個結果，功勞怎麼分」。</p>



<h3 class="wp-block-heading">算一次給你看：兩個員工分獎金</h3>



<p class="wp-block-paragraph">飲料店兩位員工 A、B，單獨做一天業績 A 是 10 杯、B 是 20 杯，<strong>一起做</strong>是 40 杯（有合作效應）。獎金怎麼分才公平？</p>



<p class="wp-block-paragraph">Shapley 的算法：考慮<strong>每種加入順序</strong>，看每個人「加入時多帶來多少」：</p>



<pre class="wp-block-code"><code>順序 1：A 先來，B 後來
  A 加入：0 → 10，帶來 10
  B 加入：10 → 40，帶來 30

順序 2：B 先來，A 後來
  B 加入：0 → 20，帶來 20
  A 加入：20 → 40，帶來 20

A 的 Shapley 值 = (10 + 20) ÷ 2 = 15
B 的 Shapley 值 = (30 + 20) ÷ 2 = 25
15 + 25 = 40 ✓（功勞加起來等於總業績）</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>A 單獨只做 10，但分到 15，因為他跟 B 合作時貢獻更大。這就是 Shapley 值的優點：<strong>考慮了交互作用</strong>（第 11 篇的特徵交叉）</li>

<li>功勞<strong>一定加總等於結果</strong>，這是它被選為特徵歸因標準的原因</li>
</ul>



<p class="wp-block-paragraph">套到模型：每個「玩家」是一個特徵，「業績」是預測值減掉基準值。</p>



<h3 class="wp-block-heading">線性模型的 Shapley 值：直接算</h3>



<p class="wp-block-paragraph">BigQuery 的文件給了一個簡單的公式：線性和邏輯迴歸的 Shapley 值＝<strong>模型權重 × 標準化後的特徵值</strong>（權重是用標準化特徵訓練出來的）。</p>



<p class="wp-block-paragraph">流失模型（邏輯迴歸，第 15 篇）的權重和會員 M002 的標準化特徵值（教學假設）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>特徵</th><th>權重</th><th>M002 標準化後的值</th><th>歸因＝權重 × 值</th></tr></thead><tbody><tr><td>距上次消費天數</td><td>+0.8</td><td>+2.0（比平均久很多）</td><td><strong>+1.6</strong></td></tr><tr><td>90 天來店次數</td><td>−0.6</td><td>−1.5（比平均少很多）</td><td><strong>+0.9</strong></td></tr><tr><td>平均客單價</td><td>−0.2</td><td>+0.5（略高）</td><td><strong>−0.1</strong></td></tr><tr><td><strong>合計</strong></td><td></td><td></td><td><strong>+2.4</strong></td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>標準化</strong>是第 10 篇講的：減平均、除以標準差，0 代表「平均的會員」。</p>



<p class="wp-block-paragraph"><strong>怎麼讀</strong>：</p>


<ul class="wp-block-list">
<li>基準是「平均的會員」，M002 比平均多了 +2.4 的流失分數（這是進 sigmoid 之前的分數，第 2 篇）</li>

<li><strong>+1.6 來自「太久沒來」</strong>，+0.9 來自「來得少」，客單價高一點點反而讓她稍微不像會流失（−0.1）</li>

<li>正負號是方向，絕對值是力道。給客服看就是：「M002 已經 75 天沒來，是主因」</li>
</ul>



<h3 class="wp-block-heading">特徵多了怎麼辦：Sampled Shapley</h3>



<p class="wp-block-paragraph">兩個玩家只有 2 種順序，10 個特徵有 10! ＝ 3,628,800 種順序，20 個特徵算不完。<strong>Sampled Shapley</strong>（採樣 Shapley）：<strong>隨機抽一些順序</strong>來算，用平均值估計真正的 Shapley 值。</p>



<p class="wp-block-paragraph">官方設定裡的 <strong>path count</strong>（路徑數）就是「抽幾條順序」，範圍 1 到 50：越多<strong>近似誤差越小</strong>，但越慢越貴。</p>



<p class="wp-block-paragraph"><strong>適合誰</strong>：官方說 Sampled Shapley 適合<strong>不可微分的模型</strong>，例如<strong>樹的集成</strong>（XGBoost、隨機森林）和 AutoML 表格模型（它是樹和神經網路的混合集成）。<strong>不可微分</strong>白話是「輸出對輸入沒有平滑的斜率」，樹模型是一堆 if-else，就是這種。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. Integrated Gradients：沿著一條路累積斜率</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Integrated Gradients</strong>（整合梯度，IG）：從一個<strong>基準輸入</strong>（例如全黑的圖、或全是中位數的表格）慢慢變成<strong>實際輸入</strong>，沿路每一步算「預測對每個特徵的斜率」（梯度），把斜率累積起來，就是每個特徵的貢獻。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">把一張照片的亮度從全黑慢慢調到正常，看模型的「貓」分數在哪些像素變亮時跳最多，那些像素就是模型認貓的依據。官方文件的說法：想像一個滑桿，把所有像素往黑色縮放。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">官方描述的步驟：</p>


<ol class="wp-block-list">
<li>在縮放參數的不同區間算梯度，區間大小用<strong>高斯求積法</strong>（一種數值積分技巧）決定</li>

<li>用加權平均近似積分</li>

<li>平均梯度<strong>逐元素乘上原始輸入</strong></li>
</ol>



<p class="wp-block-paragraph"><strong>梯度</strong>是第 3 篇講過的「該往哪調、調多少」，神經網路訓練本來就在算它，所以 IG 對神經網路特別自然。</p>



<h3 class="wp-block-heading">適合誰</h3>



<p class="wp-block-paragraph"><strong>可微分的模型</strong>：神經網路（TensorFlow、PyTorch）。表格和影像都能用。設定裡有 <strong>step count</strong>（步數），越多越準越慢，跟 Sampled Shapley 的路徑數是同樣的取捨。</p>



<h3 class="wp-block-heading">基準值很重要</h3>



<p class="wp-block-paragraph">兩種方法都要一個<strong>基準</strong>（baseline）：「沒有資訊」的輸入長什麼樣。官方說沒指定就用<strong>全零</strong>（影像是全黑）。但表格資料的全零常常不合理（客單價 0 元？），官方建議選有意義的基準，例如文件裡的腳踏車例子用「騎乘時間的中位數」。基準選錯，歸因的數字會跟著歪。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. XRAI：影像看區域，不看像素</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>XRAI</strong>：IG 算出來的是<strong>每個像素</strong>的貢獻，很碎、人看不懂。XRAI 把影像先切成一塊一塊的<strong>區域</strong>，把區域內像素的貢獻加總，排出「哪幾塊最重要」。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">IG 像拿著放大鏡看每一顆沙子，XRAI 像退後一步看「這片沙灘的哪一區」。</p>



<h3 class="wp-block-heading">官方的三步</h3>


<ol class="wp-block-list">
<li><strong>像素級歸因</strong>：用 IG，而且用<strong>黑色和白色兩種基準</strong>各算一次</li>

<li><strong>過度分割</strong>：用 Felzenszwalb 的圖論方法把影像切成很多小區塊（跟歸因無關，獨立做）</li>

<li><strong>選區域</strong>：把每個區塊裡的像素歸因加總算密度，排序，從最正的排到最不正的</li>
</ol>



<p class="wp-block-paragraph">輸出是一張疊在原圖上的熱圖，標出模型「看哪裡」。封膜檢查模型判「有問題」，XRAI 會標出封膜邊緣那一圈。如果它標的是杯子上的 logo，就知道模型學歪了（第 8 篇的洩漏：也許有問題的那批照片都是某家分店拍的）。</p>



<h3 class="wp-block-heading">適合誰</h3>



<p class="wp-block-paragraph"><strong>影像</strong>，而且官方說特別適合<strong>自然影像</strong>（照片）。表格資料不適用。</p>



<h3 class="wp-block-heading">三種方法一張表</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>Sampled Shapley</strong></th><th><strong>Integrated Gradients</strong></th><th><strong>XRAI</strong></th></tr></thead><tbody><tr><td>原理</td><td>抽樣估計 Shapley 值</td><td>從基準到輸入累積梯度</td><td>IG＋區域分割</td></tr><tr><td>適合的模型</td><td><strong>不可微分</strong>：樹集成、AutoML 表格</td><td><strong>可微分</strong>：神經網路</td><td>神經網路的<strong>影像</strong>模型</td></tr><tr><td>資料</td><td>表格</td><td>表格、影像</td><td>影像（自然照片）</td></tr><tr><td>輸出</td><td>每個特徵一個分數</td><td>每個特徵或像素一個分數</td><td>每個<strong>區域</strong>的重要性熱圖</td></tr><tr><td>旋鈕</td><td>path count（1～50）</td><td>step count</td><td>同 IG</td></tr><tr><td>飲料店</td><td>流失模型（XGBoost）</td><td>推薦模型（PyTorch 神經網路）</td><td>封膜檢查（影像）</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-02-three-methods.png" alt="三種特徵歸因方法比較：Sampled Shapley 抽樣估計 Shapley 值適合樹集成和 AutoML 表格這類不可微分模型；Integrated Gradients 從基準到輸入累積梯度適合神經網路的表格和影像；XRAI 在 IG 之上做區域分割只適合影像，輸出哪一區最重要的熱圖" class="wp-image-12873" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-02-three-methods.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-02-three-methods-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-02-three-methods-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-02-three-methods-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 範例式解釋：找最像的訓練樣本</h2>



<p class="wp-block-paragraph">Vertex Explainable AI 還有第二類：<strong>範例式解釋</strong>（example-based explanations）。做法是用<strong>最近鄰搜尋</strong>，從訓練集找出跟這筆輸入<strong>最像的幾個樣本</strong>。邏輯是「相似的輸入應該有相似的預測」。</p>



<p class="wp-block-paragraph">官方列的四個用途：</p>


<ul class="wp-block-list">
<li><strong>改進資料或模型</strong>：鳥被判成飛機，找出最像的訓練樣本，發現全是飛機的黑色剪影 → 要多加鳥的剪影；如果最像的都是鳥卻還判錯 → 模型太簡單，要加層</li>

<li><strong>解讀新類型的資料</strong>：訓練時只有鳥和飛機，上線遇到無人機，看它最像哪些已標記的樣本</li>

<li><strong>找異常值</strong>：跟所有訓練資料都不像的，就是離群值。神經網路對錯誤常常很有信心，這招能抓出來</li>

<li><strong>主動學習</strong>：最像的樣本一半是感冒一半是流感，代表這筆很難判，值得送給醫生標記</li>
</ul>



<p class="wp-block-paragraph">限制：只支援<strong>能輸出嵌入</strong>（embedding，第 11 篇）的 TensorFlow 模型，樹模型、PyTorch、XGBoost 不支援。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 淘汰之後怎麼辦：SHAP、LIME、BigQuery ML</h2>



<h3 class="wp-block-heading">Vertex Explainable AI 的時程</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/vertex-ai/docs/deprecations">官方淘汰清單</a>：2026 年 3 月 16 日起不再加新功能，<strong>2027 年 3 月 16 日</strong>完全停用、API 不再提供。替代方案官方點名：<strong>SHAP</strong> 和 <strong>LIME</strong>。</p>



<h3 class="wp-block-heading">SHAP</h3>



<p class="wp-block-paragraph"><a href="https://shap.readthedocs.io/">SHAP</a>（SHapley Additive exPlanations）：開源 Python 套件，Shapley 值的工業級實作。對樹模型有 <strong>Tree SHAP</strong>（算<strong>精確</strong>的 Shapley 值，不用抽樣），對任何模型有 Kernel SHAP（抽樣近似），對神經網路也有對應的版本。第 20 篇 Model Monitoring v2 的特徵歸因用的就是 SHAP 值。</p>



<h3 class="wp-block-heading">LIME</h3>



<p class="wp-block-paragraph"><a href="https://github.com/marcotcr/lime">LIME</a>（Local Interpretable Model-agnostic Explanations）：開源套件，<strong>不管模型是什麼</strong>（model-agnostic），只要它能吐出機率就能解釋。做法是在這筆資料附近製造很多擾動過的樣本，用一個簡單的線性模型去「局部模仿」黑盒子，線性模型的權重就是解釋。支援文字、表格、影像。官方範例：把「Host」和「NNTP」兩個字拿掉，分類器判「無神論」的機率從 0.58 降到 0.31。</p>



<h3 class="wp-block-heading">BigQuery ML：解釋內建在 SQL 裡</h3>



<p class="wp-block-paragraph">BigQuery ML 的解釋功能<strong>不受淘汰影響</strong>，<a href="https://docs.cloud.google.com/bigquery/docs/xai-overview">文件</a>列的方法：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>模型</th><th>方法</th><th>局部</th><th>全域</th></tr></thead><tbody><tr><td>線性／邏輯迴歸</td><td>Shapley 值（權重 × 標準化值）；另有標準誤和 p 值做顯著性檢定</td><td><code>ML.EXPLAIN_PREDICT</code></td><td><code>ML.GLOBAL_EXPLAIN</code>、<code>ML.ADVANCED_WEIGHTS</code></td></tr><tr><td>提升樹、隨機森林</td><td><strong>Tree SHAP</strong>（精確）；或近似特徵貢獻（更快）；Gini 重要性（訓練時每個特徵多有用）</td><td><code>ML.EXPLAIN_PREDICT</code></td><td><code>ML.GLOBAL_EXPLAIN</code>、<code>ML.FEATURE_IMPORTANCE</code></td></tr><tr><td>時間序列 ARIMA_PLUS</td><td>拆解趨勢、季節、假日</td><td><code>ML.EXPLAIN_FORECAST</code></td><td></td></tr></tbody></table></figure>



<p class="wp-block-paragraph">第 15 篇示範過 <code>ML.EXPLAIN_PREDICT</code> 的 <code>top_k_features</code>，訓練時開 <code>enable_global_explain = TRUE</code> 才能用 <code>ML.GLOBAL_EXPLAIN</code>。</p>



<h3 class="wp-block-heading">本身就可解釋的模型</h3>



<p class="wp-block-paragraph">考試 3.1「依可解釋性需求選建模技術」的另一個答案：<strong>直接選看得懂的模型</strong>。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>模型</th><th>可解釋性</th><th>代價</th></tr></thead><tbody><tr><td>線性／邏輯迴歸</td><td>權重直接讀</td><td>抓不到複雜關係</td></tr><tr><td>單棵決策樹</td><td>規則一路看下來</td><td>準確度通常較低</td></tr><tr><td>樹集成（XGBoost）</td><td>要靠 SHAP</td><td>準</td></tr><tr><td>神經網路</td><td>要靠 IG、SHAP</td><td>最準、最黑</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">法規嚴、解釋比準確度重要 → 前兩種；要準又要解釋 → 後兩種加特徵歸因。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-03-local-global-alternatives.png" alt="局部解釋看這一筆預測每個特徵貢獻多少、全域解釋看模型整體最看重哪些特徵；Vertex Explainable AI 2027 年 3 月停用，替代方案是 SHAP 的 Tree SHAP 和 Kernel SHAP、LIME 的局部線性模仿、BigQuery ML 內建的 ML.EXPLAIN_PREDICT 和 ML.GLOBAL_EXPLAIN" class="wp-image-12874" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-03-local-global-alternatives.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-03-local-global-alternatives-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-03-local-global-alternatives-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-03-local-global-alternatives-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">現在（2026 年 10 月）的建議路線</h3>


<ol class="wp-block-list">
<li><strong>表格模型在 BigQuery ML</strong>：訓練時 <code>enable_global_explain = TRUE</code>，用 <code>ML.EXPLAIN_PREDICT</code> 看單筆、<code>ML.GLOBAL_EXPLAIN</code> 看整體，最省事</li>

<li><strong>自訂訓練的模型</strong>：在訓練或推論程式裡裝 <code>shap</code>（樹模型用 TreeExplainer，神經網路用 DeepExplainer 或 GradientExplainer），把歸因跟預測一起存到 BigQuery，方便第 20 篇的監控和第 22 篇的追蹤</li>

<li><strong>影像模型</strong>：SHAP 有影像的解釋器，或用開源的 XRAI 實作（Google 的 saliency 套件），輸出熱圖</li>

<li><strong>還在用 Vertex Explainable AI 的</strong>：2027 年 3 月前遷移。Model Registry 裡模型的 explanation 設定（方法、path count、基準）要改成在程式裡做</li>

<li><strong>Model Monitoring v2</strong> 的特徵歸因目標用 SHAP，第 20 篇講過</li>
</ol>



<h3 class="wp-block-heading">基準值怎麼選</h3>


<ul class="wp-block-list">
<li>表格：用訓練資料的<strong>中位數或平均</strong>當基準，代表「一個典型的會員」</li>

<li>影像：黑圖是預設，XRAI 黑白各算一次</li>

<li>基準不同，歸因的絕對值會不同，<strong>比較歸因時要用同一個基準</strong></li>
</ul>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>Vertex Explainable AI（採樣 Shapley、整合梯度、XRAI）</td><td><strong>2026 年 3 月淘汰、2027 年 3 月停用</strong>；方法概念不變，工具改 SHAP、LIME</td></tr><tr><td>AI Explanations（AI Platform 時代）</td><td>更早的名字，已隨 AI Platform 關閉</td></tr><tr><td>BQML.EXPLAIN_PREDICT（筆記寫法）</td><td><code>ML.EXPLAIN_PREDICT</code>，不受淘汰影響</td></tr><tr><td>Vertex AI Model Monitoring 的特徵歸因</td><td>Model Monitoring v2，用 SHAP 值</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 3 區：把原型放大成 ML 模型（約 21%）</td><td>3.1 <strong>依可解釋性需求選建模技術</strong></td></tr><tr><td>第 6 區：監控 AI 方案（約 13%）</td><td>6.1 符合負責任 AI 實務（<strong>監控偏見</strong>）；<strong>Agent Platform 上的模型可解釋性</strong>（例如 Agent Platform Inference）</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">考試指南寫的還是「Agent Platform 上的模型可解釋性」，淘汰公告是 2026 年 3 月、指南是 6 月，題目可能還會出現舊功能的名字。方法名稱（Sampled Shapley、Integrated Gradients、XRAI）和適用情境是重點，不會變。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-04-exam-keywords.png" alt="PMLE 考試關鍵字：表格樹模型 AutoML 表格想到 Sampled Shapley、神經網路可微分想到 Integrated Gradients、影像哪一區重要想到 XRAI、每一筆預測的原因想到局部解釋 ML.EXPLAIN_PREDICT、整體最看重哪些特徵想到全域解釋、法規要求能解釋想到可解釋模型或特徵歸因、找最像的訓練樣本想到範例式解釋" class="wp-image-12875" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-04-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-04-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-04-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml21-04-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「表格」「XGBoost」「樹集成」「AutoML 表格」「不可微分」</td><td><strong>Sampled Shapley</strong></td></tr><tr><td>「神經網路」「可微分」「TensorFlow 模型的特徵歸因」</td><td><strong>Integrated Gradients</strong></td></tr><tr><td>「影像」「哪個區域」「熱圖」「自然照片」</td><td><strong>XRAI</strong></td></tr><tr><td>「每一筆預測為什麼」「客戶問原因」</td><td><strong>局部解釋</strong>，<code>ML.EXPLAIN_PREDICT</code></td></tr><tr><td>「模型整體最看重什麼」「哪些特徵可以拿掉」</td><td><strong>全域解釋</strong>，<code>ML.GLOBAL_EXPLAIN</code>、<code>ML.FEATURE_IMPORTANCE</code></td></tr><tr><td>「法規要求能解釋」「解釋比準確重要」</td><td>選<strong>可解釋模型</strong>（線性、單棵樹），或加特徵歸因</td></tr><tr><td>「歸因太慢」「近似誤差」</td><td>調 <strong>path count／step count</strong>（少＝快、多＝準）</td></tr><tr><td>「歸因數字怪怪的」「全零不合理」</td><td><strong>基準值</strong>選錯，改用中位數</td></tr><tr><td>「找出最像的訓練樣本」「異常值」「哪些該人工標記」</td><td><strong>範例式解釋</strong>（最近鄰）</td></tr><tr><td>「某個特徵貢獻大到不合理」</td><td>可能是<strong>資料洩漏</strong>（第 8 篇）</td></tr><tr><td>「敏感特徵（性別、年齡）貢獻很大」</td><td><strong>偏見</strong>，6.1</td></tr><tr><td>「Vertex Explainable AI 要停用了」</td><td><strong>SHAP、LIME</strong>，BigQuery ML 內建函數</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>樹模型選 Integrated Gradients</strong>：IG 要可微分，樹模型用 Sampled Shapley（或 Tree SHAP）</li>

<li><strong>表格資料選 XRAI</strong>：XRAI 只給影像</li>

<li><strong>用全零當表格的基準</strong>：客單價 0 元不是「典型會員」，歸因會歪</li>

<li><strong>把歸因當因果</strong>：歸因是「模型怎麼想」，不是「世界怎麼運作」。模型看重「城市」可能是訓練資料的偏見</li>

<li><strong>以為解釋功能都沒了</strong>：淘汰的是 Vertex Explainable AI 這個服務，方法還在，SHAP 和 BigQuery ML 都能做</li>

<li><strong>path count 設 50 跑正式推論</strong>：每筆預測都要抽 50 條路徑，延遲和費用暴增，線上用小一點、離線分析再開大</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店的流失模型是 XGBoost，客服部門要求每一筆「會流失」的判斷都要附三個主要原因。應該怎麼做？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「XGBoost」「每一筆」→ <strong>局部解釋</strong>，樹模型用 <strong>Sampled Shapley</strong>（或 SHAP 的 Tree SHAP）</li>

<li>在 BigQuery ML 的話，<code>ML.EXPLAIN_PREDICT</code> 加 <code>top_k_features = 3</code></li>

<li>自訂訓練的話，推論程式裡用 <code>shap.TreeExplainer</code>，把前三名存進結果表</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">封膜檢查模型（神經網路）把一批正常的杯子判成有問題。工程師想知道模型到底在看照片的哪裡。應該用什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「影像」「看哪裡」→ <strong>XRAI</strong>（區域熱圖）；如果要到像素級細節用 Integrated Gradients</li>

<li>熱圖標在 logo 而不是封膜 → 訓練資料有洩漏，回頭查（第 8 篇）</li>

<li>也可以用<strong>範例式解釋</strong>找出最像的訓練照片，看是不是某家分店的拍法特殊</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">保險公司要用機器學習審核理賠，法規要求每個拒絕都能用人看得懂的規則解釋，而且模型要能被稽核。該怎麼選模型？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「人看得懂的規則」「稽核」→ 3.1 的<strong>可解釋性需求</strong>，優先選<strong>本身可解釋的模型</strong>：邏輯迴歸（權重直接讀）或單棵決策樹（規則一路看）</li>

<li>準確度不夠才升級到樹集成＋SHAP，但要能證明歸因方法</li>

<li>敏感特徵（年齡、性別）的歸因要監控（6.1 偏見）</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">可解釋 AI 是什麼？</h3>



<p class="wp-block-paragraph">讓人看懂模型為什麼做出某個預測的方法，主要做法是特徵歸因：算出每個特徵對這次預測的貢獻值，有正有負，加起來等於預測值和基準值的差。分局部解釋（這一筆每個特徵貢獻多少）和全域解釋（模型整體最看重什麼）。用途是確認模型行為合理、找偏見、除錯、改進資料，也是法規要求的解釋依據。</p>



<h3 class="wp-block-heading">Shapley 值是什麼？</h3>



<p class="wp-block-paragraph">來自合作賽局理論的分功勞方法：把每個特徵當玩家，算它在所有加入順序裡平均帶來多少增量，當作它的貢獻。好處是考慮交互作用，而且所有特徵的貢獻加總一定等於結果。兩位員工單獨做 10 和 20 杯、合作做 40 杯，Shapley 值是 15 和 25。線性模型的 Shapley 值等於權重乘標準化後的特徵值。</p>



<h3 class="wp-block-heading">Sampled Shapley、Integrated Gradients、XRAI 怎麼選？</h3>



<p class="wp-block-paragraph">Sampled Shapley 抽樣估計 Shapley 值，適合不可微分的模型：樹集成（XGBoost、隨機森林）、AutoML 表格。Integrated Gradients 從基準到輸入累積梯度，適合可微分的神經網路，表格和影像都能用。XRAI 在 IG 之上做區域分割，只適合影像，輸出哪一區最重要的熱圖。三種都以 Shapley 值為基礎。</p>



<h3 class="wp-block-heading">基準值（baseline）是什麼？為什麼重要？</h3>



<p class="wp-block-paragraph">「沒有資訊」的輸入長什麼樣，歸因算的是「從基準變成實際輸入，每個特徵帶來多少變化」。預設是全零（影像是全黑），但表格資料全零常不合理（客單價 0 元），官方建議選有意義的基準，例如中位數。基準不同歸因的絕對值不同，比較時要用同一個基準。</p>



<h3 class="wp-block-heading">什麼是範例式解釋？</h3>



<p class="wp-block-paragraph">用最近鄰搜尋從訓練集找出跟這筆輸入最像的幾個樣本，邏輯是相似輸入應有相似預測。用途：找出模型判錯的原因（最像的樣本都是另一類代表資料不夠）、解讀訓練時沒見過的新類型資料、找異常值、挑出值得人工標記的困難樣本。只支援能輸出嵌入的 TensorFlow 模型。</p>



<h3 class="wp-block-heading">Vertex Explainable AI 淘汰了，還能怎麼做解釋？</h3>



<p class="wp-block-paragraph">Vertex Explainable AI 2026 年 3 月 16 日淘汰、2027 年 3 月 16 日停用。官方建議改用開源的 SHAP（樹模型有精確的 Tree SHAP，任何模型有 Kernel SHAP）和 LIME（不管模型是什麼，在資料附近用線性模型局部模仿）。BigQuery ML 的 ML.EXPLAIN_PREDICT、ML.GLOBAL_EXPLAIN、ML.FEATURE_IMPORTANCE 不受影響。Model Monitoring v2 的特徵歸因也是用 SHAP。</p>



<h3 class="wp-block-heading">BigQuery ML 怎麼做解釋？</h3>



<p class="wp-block-paragraph">線性和邏輯迴歸用 Shapley 值（權重乘標準化值），另有標準誤和 p 值；提升樹和隨機森林用 Tree SHAP（精確）或近似特徵貢獻（更快），還有 Gini 重要性；ARIMA_PLUS 用 ML.EXPLAIN_FORECAST 拆趨勢季節假日。局部用 ML.EXPLAIN_PREDICT，全域用 ML.GLOBAL_EXPLAIN（訓練時要開 enable_global_explain）和 ML.FEATURE_IMPORTANCE。</p>



<h3 class="wp-block-heading">法規要求模型能解釋，該怎麼選模型？</h3>



<p class="wp-block-paragraph">考試指南 3.1 的「依可解釋性需求選建模技術」。解釋比準確度重要時，直接選本身可解釋的模型：邏輯迴歸的權重直接讀，單棵決策樹的規則一路看。要準又要解釋，用樹集成或神經網路加特徵歸因（SHAP、IG），但要能說明方法。敏感特徵的歸因要監控有沒有偏見。</p>



<h3 class="wp-block-heading">特徵歸因可以當成因果關係嗎？</h3>



<p class="wp-block-paragraph">不行。歸因說的是「模型怎麼想」，不是「世界怎麼運作」。模型看重「城市」可能只是訓練資料裡某個城市的流失率剛好高。歸因大到不合理反而是警訊：可能是資料洩漏（答案混進特徵），或模型學到了偏見。</p>



<h3 class="wp-block-heading">path count 和 step count 要設多少？</h3>



<p class="wp-block-paragraph">Sampled Shapley 的 path count 是抽幾條順序，1 到 50；Integrated Gradients 的 step count 是沿路算幾步。越多近似誤差越小但越慢越貴。線上推論每筆都要算，設小一點顧延遲；離線分析或除錯再開大。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>可解釋 AI</strong>＝<strong>特徵歸因</strong>：每個特徵對這次預測的貢獻，加總等於預測值減基準值；<strong>局部</strong>（這一筆）vs <strong>全域</strong>（整體）</li>

<li><strong>Shapley 值</strong>：合作賽局分功勞，考慮所有加入順序的平均增量，考慮交互作用、加總等於結果；線性模型＝權重 × 標準化值</li>

<li><strong>三種方法</strong>：<strong>Sampled Shapley</strong>（不可微分：樹集成、AutoML 表格）、<strong>Integrated Gradients</strong>（可微分：神經網路，表格與影像）、<strong>XRAI</strong>（影像區域熱圖）；旋鈕 path count／step count；<strong>基準值</strong>要選有意義的</li>

<li><strong>範例式解釋</strong>：最近鄰找最像的訓練樣本，除錯、新資料、異常值、主動學習；只支援 TensorFlow 嵌入</li>

<li><strong>Vertex Explainable AI 2027 年 3 月停用</strong>：改用 <strong>SHAP</strong>（Tree SHAP）、<strong>LIME</strong>；BigQuery ML 的 <code>ML.EXPLAIN_PREDICT</code>、<code>ML.GLOBAL_EXPLAIN</code> 不受影響</li>

<li><strong>選模型</strong>：法規要解釋 → 線性、單棵樹；要準 → 集成或神經網路＋歸因。歸因不是因果</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>

<li>第 19 篇：<a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></li>

<li>上一篇：第 20 篇：<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a></li>

<li>下一篇：第 22 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">實驗怎麼追蹤？Vertex AI Experiments、Metadata、TensorBoard</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 是資料庫嗎？跟資料庫差在哪</a></li>

<li><a href="https://dongdonggcp.com/2025/04/14/vertex-ai-functions-agent-builder-model-builder-model-garden-introduction/">Vertex AI 核心功能 Agent Builder、Model Builder 和 Model Garden 介紹</a></li>

<li><a href="https://dongdonggcp.com/2025/08/12/what-is-end-to-end-training-in-machine-learning/">End-to-end Training 是什麼</a></li>

<li><a href="https://dongdonggcp.com/2026/04/22/gcp-organization-policy-introduction/">GCP Organization Policy 完全攻略</a></li>

<li><a href="https://dongdonggcp.com/2025/08/04/cloud-architect-without-coding/">不會寫程式，可以轉職雲端架構師嗎？</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Roadmap</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">模型說得出「為什麼」，才能被信任、被稽核、被改好。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "可解釋 AI 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "讓人看懂模型為什麼做出某個預測的方法，主要做法是特徵歸因：算出每個特徵對這次預測的貢獻值，有正有負，加起來等於預測值和基準值的差。分局部解釋（這一筆每個特徵貢獻多少）和全域解釋（模型整體最看重什麼）。用途是確認模型行為合理、找偏見、除錯、改進資料，也是法規要求的解釋依據。"
      }
    },
    {
      "@type": "Question",
      "name": "Shapley 值是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "來自合作賽局理論的分功勞方法：把每個特徵當玩家，算它在所有加入順序裡平均帶來多少增量，當作它的貢獻。好處是考慮交互作用，而且所有特徵的貢獻加總一定等於結果。兩位員工單獨做 10 和 20 杯、合作做 40 杯，Shapley 值是 15 和 25。線性模型的 Shapley 值等於權重乘標準化後的特徵值。"
      }
    },
    {
      "@type": "Question",
      "name": "Sampled Shapley、Integrated Gradients、XRAI 怎麼選？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Sampled Shapley 抽樣估計 Shapley 值，適合不可微分的模型：樹集成（XGBoost、隨機森林）、AutoML 表格。Integrated Gradients 從基準到輸入累積梯度，適合可微分的神經網路，表格和影像都能用。XRAI 在 IG 之上做區域分割，只適合影像，輸出哪一區最重要的熱圖。三種都以 Shapley 值為基礎。"
      }
    },
    {
      "@type": "Question",
      "name": "基準值（baseline）是什麼？為什麼重要？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "「沒有資訊」的輸入長什麼樣，歸因算的是「從基準變成實際輸入，每個特徵帶來多少變化」。預設是全零（影像是全黑），但表格資料全零常不合理（客單價 0 元），官方建議選有意義的基準，例如中位數。基準不同歸因的絕對值不同，比較時要用同一個基準。"
      }
    },
    {
      "@type": "Question",
      "name": "什麼是範例式解釋？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "用最近鄰搜尋從訓練集找出跟這筆輸入最像的幾個樣本，邏輯是相似輸入應有相似預測。用途：找出模型判錯的原因（最像的樣本都是另一類代表資料不夠）、解讀訓練時沒見過的新類型資料、找異常值、挑出值得人工標記的困難樣本。只支援能輸出嵌入的 TensorFlow 模型。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex Explainable AI 淘汰了，還能怎麼做解釋？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Vertex Explainable AI 2026 年 3 月 16 日淘汰、2027 年 3 月 16 日停用。官方建議改用開源的 SHAP（樹模型有精確的 Tree SHAP，任何模型有 Kernel SHAP）和 LIME（不管模型是什麼，在資料附近用線性模型局部模仿）。BigQuery ML 的 ML.EXPLAIN_PREDICT、ML.GLOBAL_EXPLAIN、ML.FEATURE_IMPORTANCE 不受影響。Model Monitoring v2 的特徵歸因也是用 SHAP。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 怎麼做解釋？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "線性和邏輯迴歸用 Shapley 值（權重乘標準化值），另有標準誤和 p 值；提升樹和隨機森林用 Tree SHAP（精確）或近似特徵貢獻（更快），還有 Gini 重要性；ARIMA_PLUS 用 ML.EXPLAIN_FORECAST 拆趨勢季節假日。局部用 ML.EXPLAIN_PREDICT，全域用 ML.GLOBAL_EXPLAIN（訓練時要開 enable_global_explain）和 ML.FEATURE_IMPORTANCE。"
      }
    },
    {
      "@type": "Question",
      "name": "法規要求模型能解釋，該怎麼選模型？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "考試指南 3.1 的「依可解釋性需求選建模技術」。解釋比準確度重要時，直接選本身可解釋的模型：邏輯迴歸的權重直接讀，單棵決策樹的規則一路看。要準又要解釋，用樹集成或神經網路加特徵歸因（SHAP、IG），但要能說明方法。敏感特徵的歸因要監控有沒有偏見。"
      }
    },
    {
      "@type": "Question",
      "name": "特徵歸因可以當成因果關係嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "不行。歸因說的是「模型怎麼想」，不是「世界怎麼運作」。模型看重「城市」可能只是訓練資料裡某個城市的流失率剛好高。歸因大到不合理反而是警訊：可能是資料洩漏（答案混進特徵），或模型學到了偏見。"
      }
    },
    {
      "@type": "Question",
      "name": "path count 和 step count 要設多少？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Sampled Shapley 的 path count 是抽幾條順序，1 到 50；Integrated Gradients 的 step count 是沿路算幾步。越多近似誤差越小但越慢越貴。線上推論每筆都要算，設小一點顧延遲；離線分析或除錯再開大。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>模型上線後會變笨？Drift 與 Training-Serving Skew 監控</title>
		<link>https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=model-monitoring-drift-training-serving-skew</link>
					<comments>https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:44:30 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[BigQuery]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12871</guid>

					<description><![CDATA[<p>模型上線後會變笨？用飲料店的流失模型分清偏差、資料漂移、概念漂移、特徵歸因漂移四種變法，Model Monitoring 怎麼量距離、L-infinity 算一次、門檻視窗取樣率怎麼設、警報怎麼接重訓，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>模型上線後會變笨，因為資料變了：跟訓練時不一樣叫偏差，隨時間變叫漂移，Model Monitoring 量距離超過門檻就警報。</strong></p>



<p class="wp-block-paragraph">前兩篇把模型做成管線、自動重訓、自動上線。但有一件事還沒處理：<strong>模型上線之後，怎麼知道它還準不準？</strong> 沒人盯，模型會在你不知道的情況下慢慢變笨，推薦越來越不準、流失名單越來越離譜，等到老闆問才發現。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店、50 萬名會員的連鎖飲料店當例子（教學假設）：會員流失模型和推薦模型都上線了，這篇講怎麼監控它們。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-01-four-ways.png" alt="模型上線後會變笨的四種方式：訓練服務偏差是上線資料跟訓練資料不一樣、資料漂移是上線資料隨時間變、概念漂移是特徵和答案的關係變了、特徵歸因漂移是重要特徵的貢獻變了" class="wp-image-12867" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-01-four-ways.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-01-four-ways-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-01-four-ways-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-01-four-ways-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>Google 自己的例子</strong>：<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/model-monitoring/overview">Model Monitoring 總覽</a>說，預測客戶終身價值的模型，客戶習慣一變，當初用來訓練的特徵可能就不再適用。這種資料的偏移叫<strong>漂移</strong></li>

<li><strong>等級 0 的致命傷</strong>：第 18 篇講 MLOps 等級 0 時，官方列的問題之一就是「沒有主動監控模型效能」。模型壞了沒人知道，是最常見的事故</li>

<li><strong>監控是重訓的觸發器</strong>：第 19 篇的「效能下降就重訓」「漂移就重訓」，靠的就是這篇的警報</li>

<li><strong>證照必考</strong>：PMLE 考試指南第 6 區「監控 AI 方案」佔 <strong>13%</strong>，6.2 直接寫「設定和使用 Model Monitoring 建立正式模型的持續評估指標」「監控常見問題（<strong>訓練／服務偏差、資料漂移、概念漂移、特徵歸因漂移</strong>）」；6.1 的「監控偏見」也在這篇</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：模型變笨的四種方式</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph">模型是用<strong>過去的資料</strong>學出來的規則。世界一變，規則就不準。官方和考試指南把「變」分成四種：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>名稱</th><th>白話</th><th>什麼變了</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>訓練／服務偏差</strong>（training-serving skew）</td><td><strong>上線時餵的資料，跟訓練時的不一樣</strong></td><td>訓練 vs 上線</td><td>訓練時客單價單位是「元」，上線 API 傳來的是「百元」</td></tr><tr><td><strong>資料漂移</strong>（data drift，也叫 feature drift）</td><td>上線後，<strong>輸入資料的分布隨時間變了</strong></td><td>上線初期 vs 現在</td><td>夏天來了，冰飲比例從 40% 變 80%</td></tr><tr><td><strong>概念漂移</strong>（concept drift）</td><td>輸入沒變，但<strong>輸入和答案的關係變了</strong></td><td>規則本身</td><td>疫情後，「兩週沒來」不再代表流失，因為大家都改外送</td></tr><tr><td><strong>特徵歸因漂移</strong>（feature attribution drift）</td><td><strong>哪些特徵重要</strong>變了</td><td>模型的依據</td><td>以前「距上次消費天數」最重要，現在變成「是否用外送」</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">另外還有<strong>預測漂移</strong>（prediction drift）：模型<strong>輸出</strong>的分布變了，例如判「會流失」的比例從 5% 跳到 30%。它是結果，前四種是原因。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">流感快篩試劑：</p>


<ul class="wp-block-list">
<li><strong>偏差</strong>：試劑是用成年人的樣本校正的，結果拿去給嬰兒用（訓練和上線的對象不同）</li>

<li><strong>資料漂移</strong>：今年流行的病毒株變了，試劑對新株不敏感（輸入資料變了）</li>

<li><strong>概念漂移</strong>：以前「發燒」幾乎等於流感，現在很多發燒是別的病（症狀和疾病的關係變了）</li>
</ul>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">Google 的<a href="https://developers.google.com/machine-learning/guides/rules-of-ml">機器學習規則</a>對訓練／服務偏差的定義：「訓練時的表現和服務時的表現之間的差異」，原因有兩種：</p>


<ol class="wp-block-list">
<li><strong>訓練和服務的管線處理資料的方式不一樣</strong></li>

<li><strong>訓練和服務之間，資料本身變了</strong></li>
</ol>



<p class="wp-block-paragraph">第 1 種是工程問題（第 10、15 篇講的前處理不一致），第 2 種就是漂移。Model Monitoring 主要抓第 2 種。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考試 6.2 把這四個詞並列，題目會描述一個症狀問你「這是哪一種、該怎麼辦」。認得出來，才知道該修程式（偏差）、該重訓（漂移）、還是該重新定義問題（概念漂移）。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 偏差的第一種原因：訓練和上線的處理不一樣</h2>



<p class="wp-block-paragraph">這一種<strong>監控抓不到</strong>，因為資料看起來「正常」，只是單位、編碼、順序不一樣。要在設計時就防：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>做法</th><th>本系列哪一篇</th></tr></thead><tbody><tr><td>BigQuery ML 的 <strong>TRANSFORM 子句</strong>：訓練怎麼轉，預測自動一樣轉</td><td>第 15 篇</td></tr><tr><td>TFX 的 <strong>Transform</strong>（TFT）：前處理寫一次，訓練和服務共用</td><td>第 18 篇</td></tr><tr><td><strong>Feature Store</strong>：特徵算一次存起來，訓練和線上都從這裡拿</td><td><a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">第 23 篇</a></td></tr><tr><td>機器學習規則第 29 條：<strong>把服務時用的特徵記下來</strong>，拿去訓練，就能比對一致性</td><td></td></tr><tr><td>機器學習規則第 32 條：<strong>訓練和服務的程式碼盡量共用</strong></td><td></td></tr></tbody></table></figure>



<p class="wp-block-paragraph">飲料店那個「元 vs 百元」的錯，上線第一天流失模型就會把所有人判成「會流失」，監控會看到<strong>預測漂移</strong>（判流失的比例暴增），但根本原因要回去查管線。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. Model Monitoring 怎麼量「變了多少」</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Model Monitoring</strong>（Vertex AI Model Monitoring，現在叫 Model Monitoring on Gemini Enterprise Agent Platform）：Google 的服務，定期把<strong>上線時收到的請求</strong>拿來跟<strong>基準</strong>比，算一個「差多少」的分數，超過門檻就通知你。</p>



<h3 class="wp-block-heading">兩個版本</h3>



<p class="wp-block-paragraph">官方總覽說有兩個版本：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>v1</strong>（正式版，GA）</th><th><strong>v2</strong>（預覽）</th></tr></thead><tbody><tr><td>綁在哪</td><td>Agent Platform 的<strong>端點</strong>上</td><td><strong>模型版本</strong>上</td></tr><tr><td>監控什麼</td><td>線上推論的輸入特徵</td><td>線上、批次、甚至<strong>不在 Agent Platform 上的模型</strong></td></tr><tr><td>目標</td><td>偏差、漂移</td><td>輸入特徵漂移、<strong>輸出推論漂移</strong>、<strong>特徵歸因</strong></td></tr><tr><td>建議</td><td>需要正式支援、模型部署在端點</td><td>其他情況</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">v1 不用遷移，兩版可以並行。筆記裡的「Vertex AI Model Monitoring 監測 Prediction Drift／Feature Drift／Training-Serving Skew」對應的是 v1 的偏差與漂移，加上 v2 的輸出漂移。</p>



<h3 class="wp-block-heading">v1 的流程</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/model-monitoring/using-model-monitoring">官方說明</a>：</p>


<ol class="wp-block-list">
<li>模型部署到端點、開啟監控後，<strong>每一筆推論請求記錄到 BigQuery</strong> 表</li>

<li>依<strong>取樣率</strong>抽一部分來分析（省錢）</li>

<li>每個<strong>監控視窗</strong>（預設 24 小時，最小 1 小時）算一次最近請求的特徵分布</li>

<li>跟<strong>基準分布</strong>比：<ul class="wp-block-list">
<li><strong>偏差偵測</strong>的基準＝<strong>訓練資料</strong>的分布（所以要提供訓練資料的 BigQuery 或 Cloud Storage 路徑）</li>

<li><strong>漂移偵測</strong>的基準＝<strong>過去在上線環境看到</strong>的分布（沒有訓練資料也能用）</li>
</ul>
</li>

<li>算<strong>距離分數</strong>：類別特徵用 <strong>L-infinity 距離</strong>，數值特徵用 <strong>Jensen-Shannon 散度</strong></li>

<li>分數超過<strong>警報門檻</strong>（預設每個特徵 <strong>0.3</strong>，可各自設）→ 寄 email、寫 Cloud Logging、送 Cloud Monitoring 的通知管道（PagerDuty、Slack、Pub/Sub）</li>

<li>Pub/Sub 接第 19 篇的 Cloud Run 函式 → 自動重訓</li>
</ol>



<p class="wp-block-paragraph">分布怎麼算：類別特徵數每個值的比例；數值特徵把範圍切成等寬區間、數每個區間的比例。基準在建監控工作時算一次，之後只有更新訓練資料才重算。自訂模型要給<strong>分析結構描述</strong>（schema），沒給的話監控會等<strong>前 1,000 筆請求</strong>自動解析。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-02-monitoring-flow.png" alt="Model Monitoring 的流程：推論請求記錄到 BigQuery，依取樣率抽樣，每個監控視窗算特徵分布，跟基準比，偏差的基準是訓練資料、漂移的基準是過去的上線資料，類別特徵算 L-infinity 距離、數值特徵算 Jensen-Shannon 散度，超過門檻就寄 email、寫 Cloud Logging、送 Pub/Sub 觸發重訓" class="wp-image-12868" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-02-monitoring-flow.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-02-monitoring-flow-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-02-monitoring-flow-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-02-monitoring-flow-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">支援哪些模型</h3>



<p class="wp-block-paragraph">v1 只支援<strong>表格</strong>模型：AutoML 表格，或匯入的自訂表格模型；同一端點上的模型都要是這兩種。影像、文字模型要用別的方法（例如自己記錄預測、定期人工抽查）。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. 算一次給你看：L-infinity 距離</h2>



<p class="wp-block-paragraph"><strong>L-infinity 距離</strong>：兩個分布裡，<strong>每個類別的比例差，取最大的那個</strong>。白話：找出「差最多的那一格」。</p>



<p class="wp-block-paragraph">流失模型的特徵 <code>city</code>（城市），訓練資料的分布：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>城市</th><th>訓練資料</th><th>第 1 個月上線</th><th>差</th></tr></thead><tbody><tr><td>台北</td><td>50%</td><td>35%</td><td>0.15</td></tr><tr><td>台中</td><td>30%</td><td>30%</td><td>0.00</td></tr><tr><td>高雄</td><td>20%</td><td>35%</td><td>0.15</td></tr></tbody></table></figure>



<pre class="wp-block-code"><code>L-infinity = max(0.15, 0.00, 0.15) = 0.15
0.15 &lt; 門檻 0.3 → 不警報</code></pre>



<p class="wp-block-paragraph">第 6 個月（高雄大舉展店）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>城市</th><th>訓練資料</th><th>第 6 個月上線</th><th>差</th></tr></thead><tbody><tr><td>台北</td><td>50%</td><td>10%</td><td>0.40</td></tr><tr><td>台中</td><td>30%</td><td>30%</td><td>0.00</td></tr><tr><td>高雄</td><td>20%</td><td>60%</td><td>0.40</td></tr></tbody></table></figure>



<pre class="wp-block-code"><code>L-infinity = max(0.40, 0.00, 0.40) = 0.40
0.40 &gt; 門檻 0.3 → 警報：city 這個特徵有偏差</code></pre>



<p class="wp-block-paragraph"><strong>數值特徵</strong>（客單價、天數）用 <strong>Jensen-Shannon 散度</strong>，也是 0 到 1 的分數，概念一樣：兩個分布越不像分數越高，超過門檻就警報。算法用到對數，這裡不展開。</p>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>門檻 <strong>0.3</strong> 是官方預設，不是真理。<strong>重要特徵設低</strong>（0.1 就警報），<strong>本來就會波動的特徵設高</strong></li>

<li>偏差警報不一定代表模型壞了：高雄會員變多，模型對高雄會員本來就會算，只是<strong>跟訓練時的母體不同</strong>，要看效能有沒有跟著掉</li>

<li><strong>多個特徵同時警報</strong>，通常是上游資料管線出問題（偏差的第 1 種原因），不是世界變了</li>
</ul>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-03-l-infinity.png" alt="L-infinity 距離算一次：城市分布訓練時台北 50 台中 30 高雄 20，上線第 1 個月台北 35 台中 30 高雄 35，每格的差取最大是 0.15 低於門檻 0.3 不警報；第 6 個月台北 10 高雄 60，差最大 0.40 超過門檻警報" class="wp-image-12869" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-03-l-infinity.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-03-l-infinity-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-03-l-infinity-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-03-l-infinity-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 門檻、視窗、取樣率：三個旋鈕</h2>



<p class="wp-block-paragraph">官方的「使用 Model Monitoring 的考量」列了三個可以調的東西：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>旋鈕</th><th>預設</th><th>調低</th><th>調高</th></tr></thead><tbody><tr><td><strong>警報門檻</strong></td><td>每個特徵 0.3</td><td>更敏感，但<strong>誤報多</strong></td><td>省心，但<strong>漏掉小變化</strong></td></tr><tr><td><strong>監控視窗</strong>（頻率）</td><td>24 小時</td><td>反應快，但單一視窗樣本少、<strong>噪音大</strong></td><td>穩定，但<strong>發現得慢</strong></td></tr><tr><td><strong>取樣率</strong></td><td>自己設</td><td>省錢，但<strong>小變化看不到</strong></td><td>準，但 BigQuery 記錄和分析費用高</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">飲料店的做法：推薦模型一天 100 萬次請求，取樣 10% 就有 10 萬筆，夠準又省錢；流失模型每週才跑一次批次，用 v2 監控批次推論的輸出就好。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 監控看不到的：概念漂移和真正的效能</h2>



<h3 class="wp-block-heading">問題</h3>



<p class="wp-block-paragraph">Model Monitoring 看的是<strong>輸入的分布</strong>。概念漂移是「輸入沒變、關係變了」，輸入分布<strong>完全正常</strong>，監控不會響。</p>



<h3 class="wp-block-heading">解法：持續評估</h3>



<p class="wp-block-paragraph"><strong>持續評估</strong>（continuous evaluation）：等<strong>真實答案</strong>回來，算模型的真實分數。</p>


<ul class="wp-block-list">
<li>流失模型今天說 M002 會流失，<strong>下個月</strong>才知道她有沒有真的沒來</li>

<li>把預測記下來（Model Monitoring 本來就記在 BigQuery），一個月後跟真實結果 JOIN，算 AUC、召回率（第 5、6 篇）</li>

<li>分數掉了，就是概念漂移或其他問題，觸發重訓或重新設計特徵</li>
</ul>



<p class="wp-block-paragraph">筆記裡的「持續評估（Continuous Evaluation）e.g., Mean Average Precision」就是這個概念；mAP 是物件偵測常用的指標。考試指南 6.2 寫的「用 Model Monitoring <strong>建立持續評估指標</strong>」，v2 的做法是定期跑監控工作，把指標畫成時間序列看趨勢。</p>



<p class="wp-block-paragraph"><strong>延遲標籤</strong>（delayed label）是這裡的難點：答案越晚回來，效能監控越慢。所以兩種監控要並用：輸入漂移監控<strong>早期預警</strong>，持續評估<strong>確認真的壞了</strong>。</p>



<h3 class="wp-block-heading">生成式 AI 也要監控</h3>



<p class="wp-block-paragraph">考試 6.2 最後一條「監控、測試、評估生成式 AI 方案」：大型語言模型沒有「正確答案」可以 JOIN，常用的做法是<strong>用另一個模型當評審</strong>（LLM-as-a-judge，考試指南 2.3 點名）打分、抽樣人工審核、記錄使用者的回饋（按讚、重問）。Model Armor（第 12 篇）則是監控提示詞和回答裡的安全問題。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">6. 偏見監控</h2>



<p class="wp-block-paragraph">考試 6.1「符合負責任 AI 實務（例如<strong>監控偏見</strong>）」。<strong>偏見</strong>（bias）是模型對某些群體系統性地不公平，例如流失模型對某個城市的會員一律判「會流失」，害他們收到更多騷擾簡訊。</p>



<p class="wp-block-paragraph">做法：</p>


<ul class="wp-block-list">
<li><strong>分段評估</strong>：第 19 篇驗證關卡那一招，各群體（城市、年齡層、新舊會員）分開算指標，差太多就是警訊。TFX 的 TFMA 切片評估就是做這個</li>

<li><strong>特徵歸因監控</strong>：v2 的「特徵歸因」目標，用 <strong>SHAP 值</strong>追蹤每個特徵的貢獻。某個敏感特徵（例如性別）的貢獻突然變大，就要查。第 21 篇可解釋 AI 會講 SHAP</li>

<li>注意：v1 的特徵歸因功能依賴 <strong>Vertex Explainable AI</strong>，而它在 2026 年 3 月 16 日<strong>淘汰</strong>、2027 年 3 月 16 日停用，官方建議改用 SHAP、LIME 這類開源工具。第 21 篇細講</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">v1：端點上開監控</h3>


<ol class="wp-block-list">
<li>模型（表格 AutoML 或自訂表格）部署到端點</li>

<li>建監控工作：選<strong>偏差</strong>（要給訓練資料的 BigQuery 或 Cloud Storage 路徑）和／或<strong>漂移</strong>；設每個特徵的門檻（或用預設 0.3）、監控視窗、取樣率、email、通知管道</li>

<li>自訂模型給分析結構描述，或等前 1,000 筆自動解析</li>

<li>主控台看每個特徵的分布隨時間變化</li>

<li>警報 → Cloud Logging → Pub/Sub → Cloud Run 函式 → 重訓管線（第 19 篇）</li>
</ol>



<pre class="wp-block-code"><code>gcloud ai model-monitoring-jobs create \
  --region=asia-east1 \
  --endpoint=ENDPOINT_ID \
  --display-name=churn-monitor \
  --emails=ml-team@example.com \
  --feature-thresholds=city=0.2,avg_spend=0.3 \
  --monitoring-frequency=24 \
  --bigquery-uri=bq://PROJECT.drink.member_features_train</code></pre>



<h3 class="wp-block-heading">v2：模型版本上建監控器</h3>


<ol class="wp-block-list">
<li>模型註冊到 Model Registry（不在 Agent Platform 上服務的模型也可以，不用上傳模型檔）</li>

<li>建<strong>模型監控器</strong>（model monitor）綁模型版本，定義 schema（AutoML 自動有）</li>

<li>設預設的監控目標（輸入漂移、輸出漂移、特徵歸因）、訓練資料集當基準、輸出位置、通知</li>

<li>跑<strong>一次性</strong>或<strong>排程</strong>的監控工作，指標畫成時間序列</li>

<li>預覽期間 v2 本身不收費，但 BigQuery、Cloud Storage、批次推論、Cloud Logging 照收</li>
</ol>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>Vertex AI Model Monitoring</td><td>Model Monitoring on Gemini Enterprise Agent Platform（v1 GA、v2 預覽）</td></tr><tr><td>Vertex Explainable AI（特徵歸因用）</td><td>2026 年 3 月淘汰、2027 年 3 月停用，改用 SHAP、LIME</td></tr><tr><td>Prediction Drift</td><td>Output Inference Drift（v2 的叫法）</td></tr><tr><td>Continuous Evaluation（舊的獨立功能）</td><td>用 Model Monitoring v2 的排程工作和自己的 BigQuery 查詢實作</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 6 區：監控 AI 方案（約 13%）</td><td>6.1 符合負責任 AI 實務（<strong>監控偏見</strong>）。6.2 <strong>設定和使用 Model Monitoring 建立正式模型的持續評估指標</strong>；<strong>監控常見問題（訓練／服務偏差、資料漂移、概念漂移、特徵歸因漂移）</strong>；監控、測試、評估生成式 AI 方案</td></tr><tr><td>第 5 區：自動化與編排（約 18%）</td><td>5.1 確保訓練和服務的前處理一致（偏差的第 1 種原因）；5.2 重訓政策（監控觸發）</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-04-exam-keywords.png" alt="PMLE 考試關鍵字：上線資料跟訓練資料不一樣想到訓練服務偏差要提供訓練資料、上線後資料慢慢變想到資料漂移不用訓練資料、輸入正常但準確率掉想到概念漂移要持續評估、重要特徵的貢獻變了想到特徵歸因漂移、訓練和上線前處理不一致想到 TRANSFORM 或 Feature Store、警報要觸發重訓想到 Cloud Logging 到 Pub/Sub" class="wp-image-12870" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-04-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-04-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-04-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml20-04-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「上線的輸入分布跟訓練資料不一樣」「有訓練資料可以比」</td><td><strong>訓練／服務偏差</strong>偵測，給訓練資料路徑</td></tr><tr><td>「上線後輸入分布隨時間變」「沒有訓練資料」</td><td><strong>資料漂移</strong>偵測，基準是過去的上線資料</td></tr><tr><td>「輸入看起來正常，但準確率掉了」</td><td><strong>概念漂移</strong>，要<strong>持續評估</strong>（等真實標籤）</td></tr><tr><td>「重要特徵的貢獻突然變了」</td><td><strong>特徵歸因漂移</strong>（v2，SHAP）</td></tr><tr><td>「預測為正的比例突然暴增」</td><td><strong>預測／輸出漂移</strong>，先查上游管線有沒有壞</td></tr><tr><td>「訓練時標準化、上線時沒有」「單位不一樣」</td><td>偏差的第 1 種原因：<strong>TRANSFORM、TFT、Feature Store</strong>、共用程式碼</td></tr><tr><td>「類別特徵的距離」</td><td><strong>L-infinity</strong></td></tr><tr><td>「數值特徵的距離」</td><td><strong>Jensen-Shannon 散度</strong></td></tr><tr><td>「警報太多」</td><td>門檻調高、視窗拉長</td></tr><tr><td>「監控費用太高」</td><td>降<strong>取樣率</strong></td></tr><tr><td>「警報要自動觸發重訓」</td><td>email 以外，<strong>Cloud Logging → Pub/Sub</strong> → 重訓管線</td></tr><tr><td>「模型不是部署在 Agent Platform 端點」「批次推論也要監控」</td><td><strong>Model Monitoring v2</strong></td></tr><tr><td>「某個群體被系統性誤判」</td><td><strong>偏見</strong>：分段評估、特徵歸因監控</td></tr><tr><td>「大型語言模型的輸出品質」</td><td><strong>LLM-as-a-judge</strong>、人工抽查、Model Armor</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>以為輸入分布正常就沒事</strong>：概念漂移監控看不到，要持續評估</li>

<li><strong>沒有訓練資料卻選偏差偵測</strong>：偏差要訓練資料當基準，沒有就用漂移</li>

<li><strong>所有特徵都用預設 0.3</strong>：重要特徵要更敏感</li>

<li><strong>一有警報就重訓</strong>：先查是不是上游管線壞了（偏差第 1 種原因），重訓不會修好程式錯誤</li>

<li><strong>用 v1 監控影像模型</strong>：v1 只支援表格模型</li>

<li><strong>警報只寄 email</strong>：要接 Pub/Sub 才能自動重訓</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店的流失模型部署在 Agent Platform 端點三個月了，團隊有當初的訓練資料。他們想知道現在進來的會員資料是不是跟訓練時差很多，差太多要收到通知。應該怎麼設？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「有訓練資料」「跟訓練時比」→ <strong>偏差偵測</strong>（v1），<code>--bigquery-uri</code> 指向訓練資料</li>

<li>「收到通知」→ email＋Cloud Logging，之後接 Pub/Sub</li>

<li>重要特徵（距上次消費天數）門檻設低一點</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">推薦模型的監控三個月都沒警報，但行銷部門說推薦的點擊率從 8% 掉到 5%。問題可能是什麼？該怎麼抓？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「輸入沒警報、效果變差」→ <strong>概念漂移</strong>（輸入和答案的關係變了）</li>

<li>解法：<strong>持續評估</strong>，把預測和真實點擊 JOIN，定期算指標；用 v2 的排程監控工作畫趨勢</li>

<li>也檢查<strong>特徵歸因</strong>有沒有變（v2）</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">某天早上流失模型突然把 40% 的會員判成會流失（平常 5%），同時 <code>avg_spend</code> 和 <code>visits_90d</code> 兩個特徵一起觸發偏差警報。應該先做什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「突然」「多個特徵同時」「預測比例暴增」→ 大概率是<strong>上游資料管線壞了</strong>（單位、欄位錯），不是世界變了</li>

<li>先<strong>查管線</strong>（偏差第 1 種原因），不是重訓</li>

<li>若是真的資料變了，再走重訓</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">模型上線後為什麼會變笨？</h3>



<p class="wp-block-paragraph">模型是用過去的資料學出來的規則，世界一變規則就不準。四種變法：訓練／服務偏差（上線資料跟訓練資料不一樣）、資料漂移（上線後輸入分布隨時間變）、概念漂移（輸入沒變但輸入和答案的關係變了）、特徵歸因漂移（重要特徵的貢獻變了）。Google 的例子是客戶習慣改變後，當初訓練用的特徵不再適用。</p>



<h3 class="wp-block-heading">Training-serving skew 和 drift 差在哪？</h3>



<p class="wp-block-paragraph">偏差是「上線 vs 訓練」的差異，基準是訓練資料的分布，所以要提供訓練資料；漂移是「現在 vs 之前」的差異，基準是過去在上線環境看到的分布，沒有訓練資料也能用。Google 的機器學習規則補充，偏差還有一種原因是訓練和服務的管線處理資料的方式不一樣，這種要在設計時用 TRANSFORM、Feature Store 防，監控抓不到。</p>



<h3 class="wp-block-heading">概念漂移是什麼？怎麼發現？</h3>



<p class="wp-block-paragraph">輸入資料的分布沒變，但輸入和答案之間的關係變了，例如疫情後「兩週沒來」不再代表流失。因為輸入分布正常，Model Monitoring 的偏差和漂移偵測不會響，要靠持續評估：等真實答案回來，把預測和真實結果 JOIN 算 AUC、召回率，分數掉了才知道。難點是答案常常要等很久（延遲標籤）。</p>



<h3 class="wp-block-heading">Model Monitoring 怎麼算「差多少」？</h3>



<p class="wp-block-paragraph">v1 用 TFDV 算分布：類別特徵數每個值的比例，數值特徵切成等寬區間數比例。然後算最新分布和基準分布的距離：類別特徵用 L-infinity 距離（每格比例差取最大），數值特徵用 Jensen-Shannon 散度，都是 0 到 1。超過你設的門檻（預設每個特徵 0.3）就判定為偏差或漂移並警報。</p>



<h3 class="wp-block-heading">Model Monitoring v1 和 v2 差在哪？</h3>



<p class="wp-block-paragraph">v1 是正式版，綁在 Agent Platform 端點上，監控線上推論輸入特徵的偏差和漂移，只支援表格模型，警報寄 email、Cloud Logging、Cloud Monitoring 通知管道。v2 是預覽版，綁在模型版本上，多了輸出推論漂移和特徵歸因（SHAP），可以監控批次推論和不在 Agent Platform 上服務的模型，用一次性或排程的監控工作把指標畫成時間序列。v1 不用遷移，兩版可並行。</p>



<h3 class="wp-block-heading">警報門檻、監控視窗、取樣率要怎麼設？</h3>



<p class="wp-block-paragraph">門檻預設每個特徵 0.3，重要特徵設低（更敏感）、本來就會波動的設高（少誤報）。監控視窗預設 24 小時、最小 1 小時，短的反應快但樣本少噪音大。取樣率決定分析多少比例的請求，低省錢但小變化看不到；請求量大的模型取樣 10% 通常就夠。</p>



<h3 class="wp-block-heading">監控警報怎麼自動觸發重訓？</h3>



<p class="wp-block-paragraph">v1 的警報除了 email，可以寫 Cloud Logging、送 Cloud Monitoring 的通知管道（PagerDuty、Slack、Pub/Sub）。設 Cloud Logging 的篩選條件或直接用 Pub/Sub 管道，Cloud Run 函式訂閱後啟動重訓管線，這是第 19 篇講的架構。但收到警報先確認不是上游管線壞了，再決定重訓。</p>



<h3 class="wp-block-heading">影像或文字模型怎麼監控？</h3>



<p class="wp-block-paragraph">Model Monitoring v1 只支援表格模型。影像、文字模型可以用 v2（綁模型版本、不限端點）監控輸出分布和特徵歸因，或自己記錄預測和信心分數到 BigQuery、定期人工抽查、等真實標籤回來做持續評估。生成式 AI 則用 LLM-as-a-judge 打分、人工審核、使用者回饋。</p>



<h3 class="wp-block-heading">怎麼監控模型有沒有偏見？</h3>



<p class="wp-block-paragraph">兩招：分段評估，把各群體（城市、年齡、新舊會員）分開算指標，差太多就是警訊，TFX 的 TFMA 切片評估做這個；特徵歸因監控，用 v2 的 SHAP 值追蹤每個特徵的貢獻，敏感特徵的貢獻突然變大就要查。考試指南 6.1 把「監控偏見」列在負責任 AI 底下。</p>



<h3 class="wp-block-heading">Vertex Explainable AI 淘汰了，特徵歸因監控還能用嗎？</h3>



<p class="wp-block-paragraph">Vertex Explainable AI 在 2026 年 3 月 16 日淘汰、2027 年 3 月 16 日停用，官方建議改用 SHAP、LIME 等開源工具。Model Monitoring v2 的特徵歸因目標用的是 SHAP 值。第 21 篇可解釋 AI 會細講替代方案。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>四種變笨</strong>：<strong>偏差</strong>（上線 vs 訓練）、<strong>資料漂移</strong>（現在 vs 之前）、<strong>概念漂移</strong>（關係變了，輸入正常）、<strong>特徵歸因漂移</strong>（重要性變了）；另有<strong>預測漂移</strong>是結果</li>

<li><strong>偏差的第 1 種原因</strong>（處理不一致）監控抓不到，靠 TRANSFORM、TFT、Feature Store、共用程式碼防</li>

<li><strong>Model Monitoring</strong>：請求記到 BigQuery → 取樣 → 每個視窗算分布 → 跟基準比（偏差＝訓練資料、漂移＝過去上線）→ 距離（類別 <strong>L-infinity</strong>、數值 <strong>Jensen-Shannon</strong>）→ 超過門檻（預設 <strong>0.3</strong>）→ email、Cloud Logging、Pub/Sub</li>

<li><strong>算一次</strong>：城市分布差最大的那格 0.15 不警報、0.40 警報</li>

<li><strong>三個旋鈕</strong>：門檻（敏感 vs 誤報）、視窗（快 vs 噪音）、取樣率（省錢 vs 漏）</li>

<li><strong>概念漂移</strong>要<strong>持續評估</strong>（等真實標籤 JOIN 算指標）；生成式 AI 用 LLM-as-a-judge</li>

<li><strong>v1</strong> GA、端點、表格；<strong>v2</strong> 預覽、模型版本、批次與外部模型、輸出漂移與 SHAP 特徵歸因；Explainable AI 2027 年停用</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>

<li>上一篇：第 19 篇：<a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></li>

<li>下一篇：第 21 篇：<a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">可解釋 AI 是什麼？Shapley、Integrated Gradients、XRAI</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 是資料庫嗎？跟資料庫差在哪</a></li>

<li><a href="https://dongdonggcp.com/2025/04/14/vertex-ai-functions-agent-builder-model-builder-model-garden-introduction/">Vertex AI 核心功能 Agent Builder、Model Builder 和 Model Garden 介紹</a></li>

<li><a href="https://dongdonggcp.com/2024/03/18/gcp-9-security-threats-and-how-to-resolve/">GCP 9 大資訊安全威脅與因應方案</a></li>

<li><a href="https://dongdonggcp.com/2026/07/29/cloud-jobs-comparison/">雲端職缺大解析：雲端工程師、架構師、SRE、DevOps、資料工程師差在哪？</a></li>

<li><a href="https://dongdonggcp.com/2026/05/19/gcp-bill-explosion-prevention-guide/">GCP 帳單爆炸防護指南</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Roadmap</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">模型上線不是結束，是開始盯著它的第一天。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "模型上線後為什麼會變笨？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "模型是用過去的資料學出來的規則，世界一變規則就不準。四種變法：訓練／服務偏差（上線資料跟訓練資料不一樣）、資料漂移（上線後輸入分布隨時間變）、概念漂移（輸入沒變但輸入和答案的關係變了）、特徵歸因漂移（重要特徵的貢獻變了）。Google 的例子是客戶習慣改變後，當初訓練用的特徵不再適用。"
      }
    },
    {
      "@type": "Question",
      "name": "Training-serving skew 和 drift 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "偏差是「上線 vs 訓練」的差異，基準是訓練資料的分布，所以要提供訓練資料；漂移是「現在 vs 之前」的差異，基準是過去在上線環境看到的分布，沒有訓練資料也能用。Google 的機器學習規則補充，偏差還有一種原因是訓練和服務的管線處理資料的方式不一樣，這種要在設計時用 TRANSFORM、Feature Store 防，監控抓不到。"
      }
    },
    {
      "@type": "Question",
      "name": "概念漂移是什麼？怎麼發現？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "輸入資料的分布沒變，但輸入和答案之間的關係變了，例如疫情後「兩週沒來」不再代表流失。因為輸入分布正常，Model Monitoring 的偏差和漂移偵測不會響，要靠持續評估：等真實答案回來，把預測和真實結果 JOIN 算 AUC、召回率，分數掉了才知道。難點是答案常常要等很久（延遲標籤）。"
      }
    },
    {
      "@type": "Question",
      "name": "Model Monitoring 怎麼算「差多少」？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "v1 用 TFDV 算分布：類別特徵數每個值的比例，數值特徵切成等寬區間數比例。然後算最新分布和基準分布的距離：類別特徵用 L-infinity 距離（每格比例差取最大），數值特徵用 Jensen-Shannon 散度，都是 0 到 1。超過你設的門檻（預設每個特徵 0.3）就判定為偏差或漂移並警報。"
      }
    },
    {
      "@type": "Question",
      "name": "Model Monitoring v1 和 v2 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "v1 是正式版，綁在 Agent Platform 端點上，監控線上推論輸入特徵的偏差和漂移，只支援表格模型，警報寄 email、Cloud Logging、Cloud Monitoring 通知管道。v2 是預覽版，綁在模型版本上，多了輸出推論漂移和特徵歸因（SHAP），可以監控批次推論和不在 Agent Platform 上服務的模型，用一次性或排程的監控工作把指標畫成時間序列。v1 不用遷移，兩版可並行。"
      }
    },
    {
      "@type": "Question",
      "name": "警報門檻、監控視窗、取樣率要怎麼設？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "門檻預設每個特徵 0.3，重要特徵設低（更敏感）、本來就會波動的設高（少誤報）。監控視窗預設 24 小時、最小 1 小時，短的反應快但樣本少噪音大。取樣率決定分析多少比例的請求，低省錢但小變化看不到；請求量大的模型取樣 10% 通常就夠。"
      }
    },
    {
      "@type": "Question",
      "name": "監控警報怎麼自動觸發重訓？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "v1 的警報除了 email，可以寫 Cloud Logging、送 Cloud Monitoring 的通知管道（PagerDuty、Slack、Pub/Sub）。設 Cloud Logging 的篩選條件或直接用 Pub/Sub 管道，Cloud Run 函式訂閱後啟動重訓管線，這是第 19 篇講的架構。但收到警報先確認不是上游管線壞了，再決定重訓。"
      }
    },
    {
      "@type": "Question",
      "name": "影像或文字模型怎麼監控？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Model Monitoring v1 只支援表格模型。影像、文字模型可以用 v2（綁模型版本、不限端點）監控輸出分布和特徵歸因，或自己記錄預測和信心分數到 BigQuery、定期人工抽查、等真實標籤回來做持續評估。生成式 AI 則用 LLM-as-a-judge 打分、人工審核、使用者回饋。"
      }
    },
    {
      "@type": "Question",
      "name": "怎麼監控模型有沒有偏見？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "兩招：分段評估，把各群體（城市、年齡、新舊會員）分開算指標，差太多就是警訊，TFX 的 TFMA 切片評估做這個；特徵歸因監控，用 v2 的 SHAP 值追蹤每個特徵的貢獻，敏感特徵的貢獻突然變大就要查。考試指南 6.1 把「監控偏見」列在負責任 AI 底下。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex Explainable AI 淘汰了，特徵歸因監控還能用嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Vertex Explainable AI 在 2026 年 3 月 16 日淘汰、2027 年 3 月 16 日停用，官方建議改用 SHAP、LIME 等開源工具。Model Monitoring v2 的特徵歸因目標用的是 SHAP 值。第 21 篇可解釋 AI 會細講替代方案。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</title>
		<link>https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ml-ci-cd-continuous-training-auto-retrain</link>
					<comments>https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:44:00 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12866</guid>

					<description><![CDATA[<p>機器學習的 CI/CD 怎麼做？分清 CI、CD、CT 和兩條管線：程式改了用 Cloud Build 自動測試部署；資料來了用排程 API、Pub/Sub 加 Cloud Run 函式觸發重訓；重訓政策與驗證關卡算一次，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>機器學習的 CI/CD：程式改了，Cloud Build 自動測試、部署管線；資料來了，排程或 Pub/Sub 觸發自動重訓。</strong></p>



<p class="wp-block-paragraph">上一篇把訓練流程做成管線（MLOps 等級 1）。這篇往前走一步到<strong>等級 2</strong>：管線<strong>本身</strong>改版時怎麼自動測試、自動上線；以及管線要<strong>什麼時候自己跑</strong>：每週固定、新資料到了、模型變笨了。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店的連鎖飲料店當例子（教學假設）：會員流失模型每週一重訓，推薦模型每天重訓，而且分析師每隔幾週會改特徵工程的程式。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-01-ci-cd-ct.png" alt="機器學習的 CI、CD、CT 三個詞：CI 持續整合是程式改了自動測試打包，CD 持續交付是自動把新管線和新模型部署上線，CT 持續訓練是資料來了用既有管線自動重訓；CI/CD 管線部署的是管線本身，CT 管線產出的是新模型" class="wp-image-12862" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-01-ci-cd-ct.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-01-ci-cd-ct-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-01-ci-cd-ct-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-01-ci-cd-ct-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>管線也會改</strong>：分析師加一個特徵、換一個模型架構，管線的程式就變了。沒有 CI/CD，新版管線還是靠人手動測試、手動上傳，等級 1 做到一半</li>

<li><strong>重訓的時機是錢</strong>：重訓太勤是浪費 GPU，太懶是模型變笨。「什麼時候重訓」要有政策，不是感覺</li>

<li><strong>筆記裡的三條都要更新</strong>：「Cloud Build＋Cloud Source Repositories」的後者已不開放新客戶；「Cloud Storage 觸發＋Cloud Function」現在叫 Cloud Run functions；「Cloud Scheduler 定期觸發」還在，但 Pipelines 自己也有排程 API</li>

<li><strong>證照必考</strong>：PMLE 考試指南第 5.2 節「<strong>自動化模型重訓</strong>」：決定適當的<strong>重訓政策</strong>；用 <strong>CI/CD/CT 管線</strong>（例如 Cloud Build）部署模型。整個第 5 區佔 18%</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：CI、CD、CT 三個詞</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>縮寫</th><th>全名</th><th>白話</th><th>觸發</th><th>產出</th></tr></thead><tbody><tr><td><strong>CI</strong></td><td>持續整合（Continuous Integration）</td><td><strong>程式一改</strong>，自動跑測試、自動打包</td><td>程式碼推到版本庫</td><td>測過的程式包、容器映像檔</td></tr><tr><td><strong>CD</strong></td><td>持續交付（Continuous Delivery）</td><td>打包好的東西<strong>自動部署</strong>到正式環境</td><td>CI 成功</td><td>上線的新管線、新模型服務</td></tr><tr><td><strong>CT</strong></td><td>持續訓練（Continuous Training）</td><td><strong>資料一來</strong>，用既有管線自動重訓</td><td>排程、新資料、效能下降</td><td>新模型</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">CI 和 CD 是軟體界本來就有的，CT 是 ML 特有的：<strong>程式沒改，但資料變了，也要重做一次</strong>。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">連鎖飲料店的總部：</p>


<ul class="wp-block-list">
<li><strong>CI</strong>：研發部改了配方，先在中央廚房<strong>試做、試喝</strong>（測試），通過才印成新的配方卡（打包）</li>

<li><strong>CD</strong>：新配方卡<strong>自動發到 2,000 間分店</strong>（部署），不用總部一間一間打電話</li>

<li><strong>CT</strong>：配方沒改，但<strong>每天早上進新鮮水果</strong>，各店照既有配方重新備料（重訓）</li>
</ul>



<h3 class="wp-block-heading">來龍去脈：兩條不同的管線</h3>



<p class="wp-block-paragraph">Google 的 <a href="https://docs.cloud.google.com/architecture/architecture-for-mlops-using-tfx-kubeflow-pipelines-and-cloud-build">MLOps 架構文件</a>特別區分兩件事：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>CT 管線</strong></th><th><strong>CI/CD 管線</strong></th></tr></thead><tbody><tr><td>做什麼</td><td>用新資料<strong>訓練新模型</strong></td><td><strong>部署新的管線實作</strong></td></tr><tr><td>跑的是</td><td>已經部署好的那條管線</td><td>建置、測試、部署管線的流程</td></tr><tr><td>什麼時候</td><td>排程、新資料、效能下降</td><td>管線程式碼改了</td></tr><tr><td>產出</td><td>新模型（推到 Model Registry）、新的預測服務</td><td>新版管線（包含新的元件、新的 DAG）</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">官方原話：「要用新資料訓練新模型，執行<strong>先前部署的 CT 管線</strong>；不部署新的管線或元件。」「要部署新的管線實作，需要 <strong>CI/CD 管線</strong>。」考題常把這兩條混在一起問，分清楚就能選對。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">等級 2 的定義就是「CI/CD 管線自動化」。考試 5.2 寫「用 CI/CD/CT 管線部署模型」，三個字母一起考。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 什麼時候重訓：重訓政策</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>重訓政策</strong>（retraining policy）：事先決定「什麼情況下重新訓練模型」。考試 5.2 第一條就是「決定適當的重訓政策」。</p>



<p class="wp-block-paragraph">官方 MLOps 文件列的五種觸發：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>觸發</th><th>白話</th><th>適合</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>手動</strong></td><td>有人按按鈕</td><td>剛起步、模型很少變</td><td>第一次上線</td></tr><tr><td><strong>排程</strong></td><td>每天／每週／每月固定跑</td><td>新標好的資料<strong>規律地</strong>出現</td><td>流失模型每週一（上週誰沒回來已經確定）</td></tr><tr><td><strong>新資料到了</strong></td><td>資料不定期出現，到了就跑</td><td>資料來源不規律</td><td>新菜單上架、新分店開幕</td></tr><tr><td><strong>效能下降</strong></td><td>線上模型分數明顯變差</td><td>有監控（第 20 篇）</td><td>推薦點擊率連續三天掉</td></tr><tr><td><strong>資料分布改變</strong></td><td>特徵的分布跑掉（概念漂移）</td><td>有監控</td><td>夏天來了，冰飲比例暴增</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">官方補充：排程的頻率看<strong>資料模式變化多快</strong>和<strong>重訓多貴</strong>。</p>



<h3 class="wp-block-heading">算一次給你看：重訓多勤才划算</h3>



<p class="wp-block-paragraph">推薦模型一次重訓 110 元（第 18 篇算過的管線費用）。每天重訓 vs 每週重訓：</p>



<pre class="wp-block-code"><code>每天：365 × 110 = 40,150 元／年
每週：52 × 110 = 5,720 元／年
每天比每週多花 34,430 元／年</code></pre>



<p class="wp-block-paragraph">值不值得，看模型<strong>不重訓會壞多快</strong>。假設推薦模型一週不更新，點擊率平均掉 0.1%（教學假設）：</p>



<pre class="wp-block-code"><code>一天 100 萬次推薦 × 0.1% = 1,000 次點擊／天
一年少 1,000 × 365 = 365,000 次點擊</code></pre>



<p class="wp-block-paragraph">只要一次點擊的價值超過 34,430 ÷ 365,000 ≈ <strong>0.09 元</strong>，每天重訓就划算。飲料店一次點擊帶來的訂單遠超過這個數，所以推薦模型<strong>每天重訓</strong>。</p>



<p class="wp-block-paragraph">反過來，封膜檢查模型的資料（封膜機沒換、鏡頭沒換）幾乎不變，每天重訓是浪費，<strong>只在監控發現效能下降時重訓</strong>。</p>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>資料變化快（使用者行為、季節）→ 重訓勤</li>

<li>資料幾乎不變（物理規則、設備）→ 靠監控觸發</li>

<li>重訓越貴（大模型、多 GPU）→ 越要用「效能下降」而不是「固定排程」</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. 程式改了：Cloud Build 做 CI/CD</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/build/docs/overview">Cloud Build</a>：Google 代管的「建置機器」。你寫一份設定檔（<code>cloudbuild.yaml</code>）列出步驟，它從版本庫抓程式、照步驟執行（跑測試、打包容器）、產出成品。官方說每個<strong>建置步驟都在一個 Docker 容器裡跑</strong>，像在腳本裡執行指令一樣。</p>



<p class="wp-block-paragraph"><strong>版本庫</strong>（repository）是存程式碼、記錄每次修改的地方，GitHub 是最常見的。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">總部的試做間。研發部一交新配方（推程式碼），試做間自動：試做（測試）→ 印配方卡（打包容器）→ 存進配方庫（Artifact Registry）→ 通知各店換新 SOP（部署管線）。</p>



<h3 class="wp-block-heading">觸發：什麼時候建置</h3>



<p class="wp-block-paragraph">官方<a href="https://docs.cloud.google.com/build/docs/automating-builds/create-manage-triggers">觸發條件文件</a>：連接 GitHub、Bitbucket 等版本庫，設定<strong>建置觸發條件</strong>（build trigger）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>觸發</th><th>白話</th></tr></thead><tbody><tr><td><strong>推到分支</strong>（push to a branch）</td><td>程式碼推到某個分支（例如 <code>main</code>）就建置</td></tr><tr><td><strong>推新標籤</strong>（push new tag）</td><td>打了版本標籤（例如 <code>v2.0</code>）才建置，適合正式發布</td></tr><tr><td><strong>拉取請求</strong>（pull request）</td><td>有人提出合併請求時先建置測試，過了才准合併</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>分支</strong>是程式碼的平行版本（開發用一條、正式用一條），<strong>合併請求</strong>是「我改好了，請審核後併進去」。可以設不同分支觸發不同的建置流程（開發分支只跑測試、主分支才部署）。</p>



<h3 class="wp-block-heading">一次建置做什麼：官方的步驟</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/architecture/architecture-for-mlops-using-tfx-kubeflow-pipelines-and-cloud-build">MLOps 架構文件</a>列的 ML 管線 CI/CD 典型步驟：</p>


<ol class="wp-block-list">
<li>把版本庫複製到 Cloud Build 的工作目錄</li>

<li>跑<strong>單元測試和整合測試</strong>（元件裡的函數對不對、整條管線接不接得起來）</li>

<li>可選：<strong>靜態分析</strong>（Pylint 檢查程式風格和明顯錯誤）</li>

<li>測試過了，<strong>每個管線元件各建一個容器映像檔</strong>，用 <code>$COMMIT_SHA</code>（這次修改的識別碼）當標籤</li>

<li>映像檔推到 <strong>Artifact Registry</strong></li>

<li>把元件設定裡的映像檔網址換成新的</li>

<li><strong>編譯管線</strong>成 YAML（第 18 篇講的）</li>

<li>編譯好的管線上傳到 Artifact Registry（當範本）</li>

<li>可選：用測試參數<strong>跑一次管線</strong>當整合測試</li>
</ol>



<p class="wp-block-paragraph">官方的版本庫通常放：管線定義的 Python、各元件的程式和規格、每個元件的 Dockerfile、測試、<code>cloudbuild.yaml</code>、設定檔、探索用的筆記本。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-02-cloud-build.png" alt="程式改了之後 Cloud Build 做什麼：推到 GitHub 觸發建置，跑單元與整合測試，每個元件建容器映像檔用 COMMIT_SHA 標籤推到 Artifact Registry，編譯管線成 YAML 上傳當範本，可選跑一次管線做整合測試" class="wp-image-12863" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-02-cloud-build.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-02-cloud-build-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-02-cloud-build-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-02-cloud-build-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">變數替換</h3>



<p class="wp-block-paragraph">Cloud Build 提供建置時才知道的變數：<code>$COMMIT_SHA</code>、<code>$REPO_NAME</code>、<code>$BRANCH_NAME</code>、<code>$TAG_NAME</code>、<code>$PROJECT_ID</code>、<code>$BUILD_ID</code>。用途是讓映像檔標籤、管線名稱帶上版本資訊，之後追血緣（<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">第 22 篇</a>）才知道這個模型是哪次修改訓練出來的。</p>



<h3 class="wp-block-heading">Cloud Source Repositories 怎麼了</h3>



<p class="wp-block-paragraph">筆記寫「Cloud Build＋Cloud Source Repositories（程式碼變更觸發）」。Cloud Source Repositories 是 Google 自家的 Git 版本庫，但<a href="https://docs.cloud.google.com/source-repositories/docs">現在的文件首頁</a>第一條就是「遷移說明」，<strong>已不開放給新客戶</strong>。現在的標準做法是 <strong>GitHub（或 GitLab、Bitbucket）＋Cloud Build</strong>，考題看到 Cloud Source Repositories 就把它當 GitHub 理解。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. 資料來了、時間到了：觸發 CT 管線</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph">管線部署好了，要讓它<strong>自己跑</strong>。官方架構文件的做法（Figure 6）：</p>



<pre class="wp-block-code"><code>Cloud Scheduler ─┐
Managed Airflow ─┼→ Pub/Sub 主題 → Cloud Run 函式 → Agent Platform SDK 啟動管線
Cloud Logging ───┘</code></pre>



<p class="wp-block-paragraph">三個名詞：</p>


<ul class="wp-block-list">
<li><strong>Pub/Sub</strong>：Google 的訊息服務，像公司的<strong>公告欄</strong>。誰都可以貼公告（發布訊息到主題），訂閱的人看到公告就行動</li>

<li><strong>Cloud Run functions</strong>（舊名 Cloud Functions）：<strong>一小段程式</strong>，有事件發生才執行、跑完就收。這裡它訂閱公告欄，看到訊息就呼叫 Agent Platform SDK 的 <code>PipelineJob</code> 跑管線。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/trigger-pubsub">官方有一篇教學</a>就是這個做法</li>

<li><strong>Agent Platform SDK</strong>：用 Python 操作 Agent Platform 的套件，<code>PipelineJob</code> 可以建立、執行管線</li>
</ul>



<h3 class="wp-block-heading">誰來貼公告</h3>



<p class="wp-block-paragraph">官方列了三個發布者，對應三種觸發：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>發布者</th><th>對應的觸發</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>Cloud Scheduler</strong></td><td><strong>排程</strong>：到時間就貼公告</td><td>每週一 06:00 貼「重訓流失模型」</td></tr><tr><td><strong>Managed Service for Apache Airflow</strong>（舊名 Cloud Composer）</td><td><strong>新資料到了</strong>：資料工程流程的最後一步貼公告，例如 BigQuery 匯入完新資料</td><td>每天交易資料匯進 BigQuery 完成後貼「重訓推薦模型」</td></tr><tr><td><strong>Cloud Logging</strong></td><td><strong>效能下降／漂移</strong>：日誌符合條件就貼公告，例如 Model Monitoring（第 20 篇）發出偏差或漂移警報</td><td>監控發現夏天冰飲比例暴增，貼「重訓」</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/scheduler/docs/overview">Cloud Scheduler</a> 是代管的 cron（定時器）服務，目標可以是 HTTP 端點、Pub/Sub 主題。官方提醒它是「<strong>至少一次</strong>」送達，極少情況會重複送，所以<strong>管線要能承受重複執行</strong>（跑兩次結果一樣，叫冪等）。</p>



<h3 class="wp-block-heading">更簡單的排程：Pipelines 自己的排程 API</h3>



<p class="wp-block-paragraph">純排程的話，不用繞 Pub/Sub。Agent Platform Pipelines 有<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/schedule-pipeline-run">排程 API</a>：用 <strong>cron 表達式</strong>（例如 <code>0 6 * * 1</code> 是每週一 06:00）設定頻率，可以指定開始和結束時間、<strong>暫停</strong>和<strong>恢復</strong>、限制同時執行數。</p>



<h3 class="wp-block-heading">筆記的「Cloud Storage 觸發＋Cloud Function」現在怎麼做</h3>



<p class="wp-block-paragraph">新資料是<strong>檔案</strong>（例如每天一批封膜照片丟進 Cloud Storage）時，用 <a href="https://docs.cloud.google.com/eventarc/docs/overview">Eventarc</a>：它是 Google 的事件路由服務，Cloud Storage「新檔案建立」的事件可以直接觸發一個 Cloud Run 函式，函式再啟動管線。這就是筆記那條的現代版。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-03-triggers.png" alt="觸發 CT 管線的架構：Cloud Scheduler 排程、Managed Service for Apache Airflow 資料流程完成、Cloud Logging 監控警報三種發布者把訊息貼到 Pub/Sub 主題，Cloud Run 函式訂閱後用 Agent Platform SDK 啟動管線；純排程可直接用 Pipelines 的排程 API，新檔案進 Cloud Storage 用 Eventarc" class="wp-image-12864" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-03-triggers.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-03-triggers-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-03-triggers-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-03-triggers-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">三種做法怎麼選</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>情況</th><th>做法</th></tr></thead><tbody><tr><td>只是固定時間跑</td><td>Pipelines <strong>排程 API</strong> 最簡單</td></tr><tr><td>很多來源都可能觸發、或要接現有的資料流程</td><td><strong>Pub/Sub＋Cloud Run 函式</strong>，大家貼同一個公告欄</td></tr><tr><td>新檔案進 Cloud Storage 就跑</td><td><strong>Eventarc＋Cloud Run 函式</strong></td></tr><tr><td>整間公司的資料流程最後一步要重訓</td><td><strong>Managed Service for Apache Airflow</strong> 的 DAG 最後呼叫管線或貼公告</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 重訓完要不要上線：模型驗證關卡</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph">自動重訓的風險：新資料有問題、新模型比舊的差，管線照樣把它部署上去。所以 CT 管線裡一定要有<strong>模型驗證</strong>（model validation）這一步，官方 MLOps 文件把它列為等級 1 的必要元件。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">新一批珍奶煮好了，<strong>先給店長試喝、跟昨天的比</strong>，比昨天好才上架。差了就倒掉，繼續賣昨天的。</p>



<h3 class="wp-block-heading">驗證什麼</h3>



<p class="wp-block-paragraph">官方列的三件事：</p>


<ol class="wp-block-list">
<li><strong>評估指標</strong>跟基準比：新模型的分數（第 5、6 篇的 AUC、召回率）要比<strong>目前上線的模型</strong>好，或至少不差</li>

<li><strong>分段表現</strong>：整體分數好，但某一群（新會員、某個城市）變差也不行。TFX 的 TFMA 切片評估（第 18 篇）就是做這個</li>

<li><strong>基礎設施相容</strong>：模型真的能被服務載入、回應正常（TFX 的 InfraValidator）</li>
</ol>



<p class="wp-block-paragraph">通過的模型才註冊到 Model Registry、部署（通常先用第 17 篇的流量分割做金絲雀）。TFX 把「通過驗證」叫 <strong>blessing</strong>（祝福），沒被祝福的模型 Pusher 不會推。</p>



<h3 class="wp-block-heading">算一次給你看</h3>



<p class="wp-block-paragraph">流失模型目前上線版 AUC 0.850。驗證門檻設「新模型要比舊的高 0.005 以上才換」：</p>



<pre class="wp-block-code"><code>新模型 A：AUC 0.862 → 0.862 − 0.850 = 0.012 ≥ 0.005 → 部署
新模型 B：AUC 0.853 → 0.853 − 0.850 = 0.003 &lt; 0.005 → 不部署，繼續用舊的
新模型 C：AUC 0.871，但「新會員」這一段 AUC 從 0.80 掉到 0.72 → 整體好、分段差 → 不部署</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>門檻設 0 代表「不比舊的差就換」，太寬鬆，隨機波動也會換；設太高永遠換不了。常見做法是用驗證集的波動範圍來定</li>

<li><strong>分段檢查</strong>是防「平均掩蓋問題」，第 9 篇的類別不平衡在這裡會再咬你一次</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">飲料店的完整架構</h3>


<ol class="wp-block-list">
<li><strong>版本庫</strong>：GitHub 放管線程式、元件、Dockerfile、測試、<code>cloudbuild.yaml</code></li>

<li><strong>CI/CD</strong>：Cloud Build 觸發條件設「推到 <code>main</code>」→ 測試 → 建元件映像檔推 Artifact Registry → 編譯管線上傳範本</li>

<li><strong>CT 觸發</strong>：<ul class="wp-block-list">
<li>流失模型：Pipelines 排程 API，每週一 06:00</li>

<li>推薦模型：Airflow 的資料匯入 DAG 最後一步發 Pub/Sub → Cloud Run 函式啟動管線</li>

<li>封膜模型：Model Monitoring 警報 → Cloud Logging → Pub/Sub → 重訓</li>
</ul>
</li>

<li><strong>管線內容</strong>：驗證資料（TFDV 或自己寫）→ 訓練 → 評估並<strong>跟舊模型比</strong>→ 通過才註冊 Model Registry → 部署到端點（流量分割 10%）</li>

<li><strong>監控</strong>（第 20 篇）回頭觸發第 3 步</li>
</ol>



<h3 class="wp-block-heading">權限</h3>



<p class="wp-block-paragraph">Cloud Build 和 Cloud Run 函式各自用<strong>服務帳戶</strong>執行，要有啟動管線、寫 Artifact Registry、部署模型的權限。官方文件提醒，Cloud Run 函式部署時會自動用到 Cloud Storage、Cloud Build、Artifact Registry，權限要一起給。</p>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>Cloud Source Repositories</td><td><strong>已不開放新客戶</strong>，改用 GitHub、GitLab、Bitbucket＋Cloud Build</td></tr><tr><td>Cloud Functions</td><td><strong>Cloud Run functions</strong></td></tr><tr><td>Cloud Storage Trigger（觸發 Cloud Function）</td><td><strong>Eventarc</strong> 觸發 Cloud Run 函式</td></tr><tr><td>Cloud Composer</td><td><strong>Managed Service for Apache Airflow</strong></td></tr><tr><td>Container Registry</td><td><strong>Artifact Registry</strong></td></tr><tr><td>Vertex AI Pipelines、Vertex AI Model Monitoring</td><td>Agent Platform Pipelines、Model Monitoring on Agent Platform</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 5 區：自動化與編排 ML 管線（約 18%）</td><td>5.2 <strong>自動化模型重訓</strong>：<strong>決定適當的重訓政策</strong>；<strong>在 CI/CD/CT 管線中部署模型</strong>（例如 Cloud Build）。5.1 建立和編排管線（第 18 篇）</td></tr><tr><td>第 6 區：監控 AI 方案（約 13%）</td><td>6.2 監控結果觸發重訓（第 20 篇）</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-04-exam-keywords.png" alt="PMLE 考試關鍵字：程式碼推上去自動測試打包想到 Cloud Build 觸發條件、每週固定重訓想到 Pipelines 排程 API 或 Cloud Scheduler、新資料匯入完就重訓想到 Pub/Sub 加 Cloud Run 函式、新檔案進 Cloud Storage 想到 Eventarc、監控警報觸發重訓想到 Cloud Logging 到 Pub/Sub、新模型比舊的差不該上線想到模型驗證關卡" class="wp-image-12865" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-04-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-04-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-04-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml19-04-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「程式碼推上去就自動測試、打包、部署管線」</td><td><strong>Cloud Build</strong> 觸發條件（推到分支／標籤／PR）</td></tr><tr><td>「管線本身改版」「新元件」</td><td><strong>CI/CD 管線</strong>（不是 CT）</td></tr><tr><td>「程式沒改、用新資料重訓」</td><td><strong>CT 管線</strong>，跑既有管線</td></tr><tr><td>「每週固定重訓」「cron」</td><td><strong>Pipelines 排程 API</strong>，或 Cloud Scheduler</td></tr><tr><td>「資料匯入 BigQuery 完成後重訓」「多個來源都可能觸發」</td><td><strong>Pub/Sub＋Cloud Run 函式</strong>啟動管線</td></tr><tr><td>「新檔案進 Cloud Storage 就重訓」</td><td><strong>Eventarc</strong> 觸發 Cloud Run 函式</td></tr><tr><td>「整間公司的資料流程最後一步」</td><td><strong>Managed Service for Apache Airflow</strong></td></tr><tr><td>「監控發現漂移就重訓」</td><td>Model Monitoring 警報 → <strong>Cloud Logging → Pub/Sub</strong></td></tr><tr><td>「什麼時候該重訓」「重訓頻率」</td><td><strong>重訓政策</strong>：資料變化速度 × 重訓成本</td></tr><tr><td>「新模型比舊的差卻上線了」</td><td>管線缺<strong>模型驗證</strong>，加「跟上線模型比」的關卡</td></tr><tr><td>「整體分數好但某群人變差」</td><td><strong>分段評估</strong>（TFMA 切片）</td></tr><tr><td>「模型是哪次程式修改訓練的」</td><td>映像檔標 <strong>$COMMIT_SHA</strong>，血緣追蹤</td></tr><tr><td>「排程重複觸發」</td><td>Cloud Scheduler 至少一次送達，管線要<strong>冪等</strong></td></tr><tr><td>「Cloud Source Repositories」</td><td>已不開放新客戶，當 <strong>GitHub</strong> 理解</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>把「用新資料重訓」答成要重新部署管線</strong>：那是 CT，跑既有管線就好</li>

<li><strong>所有模型都每天重訓</strong>：封膜檢查這種資料不變的，靠監控觸發就好</li>

<li><strong>自動重訓沒有驗證關卡</strong>：壞模型直接上線</li>

<li><strong>只看整體 AUC</strong>：分段變差沒抓到</li>

<li><strong>新資料進 Cloud Storage 還用 Cloud Scheduler 輪詢</strong>：事件驅動（Eventarc）才對</li>

<li><strong>Cloud Functions、Cloud Composer、Container Registry 的舊名</strong>：考題用新名，認不出來就選錯</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店的分析師改了推薦模型的特徵工程程式，推到 GitHub 的主分支。團隊希望自動跑測試、重新打包元件、更新正式環境的管線，不要人工介入。應該怎麼做？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「程式改了」「自動測試、打包、更新管線」→ <strong>CI/CD 管線</strong>，用 <strong>Cloud Build</strong></li>

<li>觸發條件設「推到主分支」；步驟：測試 → 建映像檔（標 $COMMIT_SHA）→ 推 Artifact Registry → 編譯管線 → 上傳範本</li>

<li>不是 CT：這題沒有新資料</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">每天凌晨交易資料匯進 BigQuery，匯入是 Managed Service for Apache Airflow 管的。團隊要在匯入完成後自動重訓推薦模型，而且未來可能有別的系統也要能觸發重訓。應該怎麼接？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「匯入完成後」「未來別的系統也要觸發」→ <strong>Pub/Sub 主題</strong>當公告欄，<strong>Cloud Run 函式</strong>訂閱後啟動管線</li>

<li>Airflow 的 DAG 最後一步發布訊息</li>

<li>不用 Cloud Scheduler：時間不固定（看匯入何時完成）</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">自動重訓上線兩個月後，發現有一週上線的模型比前一週差很多，但管線沒有擋下來。應該加什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「比前一週差卻上線」→ 缺<strong>模型驗證關卡</strong></li>

<li>加一步：新模型跟<strong>目前上線的模型</strong>在同一份驗證資料上比，差超過門檻才部署；加<strong>分段評估</strong></li>

<li>部署時用<strong>流量分割</strong>金絲雀（第 17 篇），再差也只影響 10%</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">機器學習的 CI/CD 是什麼？跟一般軟體差在哪？</h3>



<p class="wp-block-paragraph">CI 是程式一改就自動測試、打包，CD 是自動部署到正式環境，這兩個跟一般軟體一樣。ML 多了 CT 持續訓練：程式沒改但資料變了，就用既有管線自動重訓。Google 的 MLOps 文件把「部署新管線實作」的 CI/CD 管線和「用新資料訓練」的 CT 管線分開，前者在管線程式碼改版時跑，後者在排程、新資料、效能下降時跑。</p>



<h3 class="wp-block-heading">什麼時候該重訓模型？</h3>



<p class="wp-block-paragraph">考試叫這個「重訓政策」。五種觸發：手動、排程（每天／每週）、新資料到了、效能下降、資料分布改變。選哪種看資料變化多快和重訓多貴：使用者行為這種變得快的每天重訓，設備資料這種幾乎不變的靠監控觸發。可以算一次：每天比每週多花的重訓費，跟不重訓造成的損失比。</p>



<h3 class="wp-block-heading">Cloud Build 在 ML 裡做什麼？</h3>



<p class="wp-block-paragraph">它是 CI/CD 的核心：從 GitHub 這類版本庫抓程式，照 cloudbuild.yaml 的步驟在容器裡執行。ML 管線的典型步驟：跑單元和整合測試、每個元件建容器映像檔並用 $COMMIT_SHA 標籤、推到 Artifact Registry、編譯管線成 YAML 上傳當範本、可選跑一次管線做整合測試。觸發條件可設推到分支、推新標籤、拉取請求。</p>



<h3 class="wp-block-heading">Cloud Source Repositories 還能用嗎？</h3>



<p class="wp-block-paragraph">Google 自家的 Git 版本庫，現在文件首頁第一條就是遷移說明，已不開放給新客戶。現在的做法是 GitHub、GitLab 或 Bitbucket 接 Cloud Build。舊題庫看到 Cloud Source Repositories，當 GitHub 理解就好。</p>



<h3 class="wp-block-heading">管線怎麼定期自動跑？</h3>



<p class="wp-block-paragraph">兩種做法。簡單的：Agent Platform Pipelines 自己的排程 API，用 cron 表達式設頻率，可設開始結束時間、暫停恢復。通用的：Cloud Scheduler 定時發訊息到 Pub/Sub 主題，Cloud Run 函式訂閱後用 Agent Platform SDK 的 PipelineJob 啟動管線。Cloud Scheduler 是至少一次送達，管線要能承受重複執行。</p>



<h3 class="wp-block-heading">新資料到了怎麼自動觸發重訓？</h3>



<p class="wp-block-paragraph">看資料怎麼來。資料工程流程匯入 BigQuery 完成：Managed Service for Apache Airflow 的 DAG 最後一步發 Pub/Sub 訊息，Cloud Run 函式啟動管線。新檔案進 Cloud Storage：Eventarc 把「新檔案建立」事件送給 Cloud Run 函式。筆記裡的「Cloud Storage Trigger 加 Cloud Function」就是後者的舊說法。</p>



<h3 class="wp-block-heading">監控發現模型變差怎麼自動重訓？</h3>



<p class="wp-block-paragraph">Model Monitoring（第 20 篇）發出偏差或漂移警報時會寫進 Cloud Logging，設一個日誌篩選條件，符合就發布到 Pub/Sub 主題，Cloud Run 函式收到後啟動重訓管線。官方架構文件把 Cloud Logging 列為三種發布者之一。</p>



<h3 class="wp-block-heading">自動重訓怎麼避免壞模型上線？</h3>



<p class="wp-block-paragraph">CT 管線裡加模型驗證關卡：新模型跟目前上線的模型在同一份驗證資料上比，評估指標要好過門檻；分段（新會員、各城市）也要檢查，避免整體好但某群人變差；還要確認模型能被服務正常載入。TFX 的 Evaluator 和 InfraValidator 做這些，通過叫 blessing，Pusher 才推。部署再用流量分割做金絲雀。</p>



<h3 class="wp-block-heading">Cloud Functions 改名了嗎？</h3>



<p class="wp-block-paragraph">是，現在叫 Cloud Run functions，併入 Cloud Run 底下。部署時會自動用 Cloud Storage 存原始碼、Cloud Build 建映像檔、Artifact Registry 存映像檔。事件觸發走 Eventarc 或 Pub/Sub。同時期 Cloud Composer 改名 Managed Service for Apache Airflow，Container Registry 由 Artifact Registry 取代。</p>



<h3 class="wp-block-heading">MLOps 等級 2 跟等級 1 差在哪？</h3>



<p class="wp-block-paragraph">等級 1 是訓練流程做成管線、自動持續訓練，但管線程式碼改版還是手動測試、手動部署。等級 2 把這一段也自動化：程式推上版本庫就由 Cloud Build 測試、打包、部署新管線，監控結果回頭觸發新一輪。官方列的六個階段：開發實驗、管線 CI、管線 CD、自動觸發、模型 CD、監控。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>三個詞</strong>：<strong>CI</strong> 程式改了自動測試打包、<strong>CD</strong> 自動部署、<strong>CT</strong> 資料來了自動重訓（ML 特有）</li>

<li><strong>兩條管線</strong>：<strong>CT 管線</strong>跑既有管線產出新模型；<strong>CI/CD 管線</strong>部署新的管線實作。考題最愛混</li>

<li><strong>重訓政策</strong>：手動、排程、新資料、效能下降、漂移；看資料變化速度 × 重訓成本；算一次每天 vs 每週的差額</li>

<li><strong>程式改了</strong>：GitHub → <strong>Cloud Build</strong> 觸發（推分支／標籤／PR）→ 測試 → 建映像檔標 <code>$COMMIT_SHA</code> 推 <strong>Artifact Registry</strong> → 編譯管線上傳範本。<strong>Cloud Source Repositories 已不開放新客戶</strong></li>

<li><strong>資料來了</strong>：<strong>排程 API</strong>（純排程）；<strong>Pub/Sub＋Cloud Run 函式</strong>（多來源：Cloud Scheduler、Airflow、Cloud Logging 警報）；<strong>Eventarc</strong>（新檔案進 Cloud Storage）</li>

<li><strong>驗證關卡</strong>：新模型跟上線模型比、分段檢查、服務相容；通過才部署，再用流量分割金絲雀</li>

<li><strong>改名</strong>：Cloud Functions → Cloud Run functions；Cloud Composer → Managed Service for Apache Airflow；Container Registry → Artifact Registry</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>上一篇：第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>

<li>下一篇：第 20 篇：<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">模型上線後會變笨？Drift 與 Training-Serving Skew 監控</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2026/07/29/what-is-container-technology-docker-guide/">容器技術是什麼？從零開始看懂 Docker 與容器化應用</a></li>

<li><a href="https://dongdonggcp.com/2026/07/29/cloud-jobs-comparison/">雲端職缺大解析：雲端工程師、架構師、SRE、DevOps、資料工程師差在哪？</a></li>

<li><a href="https://dongdonggcp.com/2026/07/21/what-is-kubernetes/">Kubernetes 是什麼？白話解釋＋判斷你是否真的需要它</a></li>

<li><a href="https://dongdonggcp.com/2025/04/14/tips-when-developing-with-gcp-service-account/">使用 GCP Service Account 開發程式的小技巧和注意事項</a></li>

<li><a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 是資料庫嗎？跟資料庫差在哪</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Roadmap</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">程式改了自己測、資料來了自己訓、壞模型自己擋，這才叫自動化。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "機器學習的 CI/CD 是什麼？跟一般軟體差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "CI 是程式一改就自動測試、打包，CD 是自動部署到正式環境，這兩個跟一般軟體一樣。ML 多了 CT 持續訓練：程式沒改但資料變了，就用既有管線自動重訓。Google 的 MLOps 文件把「部署新管線實作」的 CI/CD 管線和「用新資料訓練」的 CT 管線分開，前者在管線程式碼改版時跑，後者在排程、新資料、效能下降時跑。"
      }
    },
    {
      "@type": "Question",
      "name": "什麼時候該重訓模型？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "考試叫這個「重訓政策」。五種觸發：手動、排程（每天／每週）、新資料到了、效能下降、資料分布改變。選哪種看資料變化多快和重訓多貴：使用者行為這種變得快的每天重訓，設備資料這種幾乎不變的靠監控觸發。可以算一次：每天比每週多花的重訓費，跟不重訓造成的損失比。"
      }
    },
    {
      "@type": "Question",
      "name": "Cloud Build 在 ML 裡做什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "它是 CI/CD 的核心：從 GitHub 這類版本庫抓程式，照 cloudbuild.yaml 的步驟在容器裡執行。ML 管線的典型步驟：跑單元和整合測試、每個元件建容器映像檔並用 $COMMIT_SHA 標籤、推到 Artifact Registry、編譯管線成 YAML 上傳當範本、可選跑一次管線做整合測試。觸發條件可設推到分支、推新標籤、拉取請求。"
      }
    },
    {
      "@type": "Question",
      "name": "Cloud Source Repositories 還能用嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Google 自家的 Git 版本庫，現在文件首頁第一條就是遷移說明，已不開放給新客戶。現在的做法是 GitHub、GitLab 或 Bitbucket 接 Cloud Build。舊題庫看到 Cloud Source Repositories，當 GitHub 理解就好。"
      }
    },
    {
      "@type": "Question",
      "name": "管線怎麼定期自動跑？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "兩種做法。簡單的：Agent Platform Pipelines 自己的排程 API，用 cron 表達式設頻率，可設開始結束時間、暫停恢復。通用的：Cloud Scheduler 定時發訊息到 Pub/Sub 主題，Cloud Run 函式訂閱後用 Agent Platform SDK 的 PipelineJob 啟動管線。Cloud Scheduler 是至少一次送達，管線要能承受重複執行。"
      }
    },
    {
      "@type": "Question",
      "name": "新資料到了怎麼自動觸發重訓？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "看資料怎麼來。資料工程流程匯入 BigQuery 完成：Managed Service for Apache Airflow 的 DAG 最後一步發 Pub/Sub 訊息，Cloud Run 函式啟動管線。新檔案進 Cloud Storage：Eventarc 把「新檔案建立」事件送給 Cloud Run 函式。筆記裡的「Cloud Storage Trigger 加 Cloud Function」就是後者的舊說法。"
      }
    },
    {
      "@type": "Question",
      "name": "監控發現模型變差怎麼自動重訓？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Model Monitoring（第 20 篇）發出偏差或漂移警報時會寫進 Cloud Logging，設一個日誌篩選條件，符合就發布到 Pub/Sub 主題，Cloud Run 函式收到後啟動重訓管線。官方架構文件把 Cloud Logging 列為三種發布者之一。"
      }
    },
    {
      "@type": "Question",
      "name": "自動重訓怎麼避免壞模型上線？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "CT 管線裡加模型驗證關卡：新模型跟目前上線的模型在同一份驗證資料上比，評估指標要好過門檻；分段（新會員、各城市）也要檢查，避免整體好但某群人變差；還要確認模型能被服務正常載入。TFX 的 Evaluator 和 InfraValidator 做這些，通過叫 blessing，Pusher 才推。部署再用流量分割做金絲雀。"
      }
    },
    {
      "@type": "Question",
      "name": "Cloud Functions 改名了嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "是，現在叫 Cloud Run functions，併入 Cloud Run 底下。部署時會自動用 Cloud Storage 存原始碼、Cloud Build 建映像檔、Artifact Registry 存映像檔。事件觸發走 Eventarc 或 Pub/Sub。同時期 Cloud Composer 改名 Managed Service for Apache Airflow，Container Registry 由 Artifact Registry 取代。"
      }
    },
    {
      "@type": "Question",
      "name": "MLOps 等級 2 跟等級 1 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "等級 1 是訓練流程做成管線、自動持續訓練，但管線程式碼改版還是手動測試、手動部署。等級 2 把這一段也自動化：程式推上版本庫就由 Cloud Build 測試、打包、部署新管線，監控結果回頭觸發新一輪。官方列的六個階段：開發實驗、管線 CI、管線 CD、自動觸發、模型 CD、監控。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</title>
		<link>https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-is-mlops-vertex-ai-pipelines-kubeflow-tfx</link>
					<comments>https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:43:30 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12861</guid>

					<description><![CDATA[<p>MLOps 是什麼？用飲料店每週重訓的模型帶你看 Google 的三個成熟度等級、ML 管線的 DAG、Vertex AI Pipelines 怎麼跑、Kubeflow 和 TFX 差在哪、管線快取省多少算一次，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>MLOps 是把機器學習變成可重複的自動化管線：驗證、訓練、評估、部署寫成步驟，用 Vertex AI Pipelines 跑。</strong></p>



<p class="wp-block-paragraph">前面 17 篇把「一個模型從資料到上線」走完了。問題是：這些步驟你是<strong>手動做</strong>的。資料更新了要重訓、換了特徵要重跑、上線要再部署一次，每次都靠人記得順序、靠人按按鈕。模型一多、重訓一頻繁，就會出事。</p>



<p class="wp-block-paragraph"><strong>MLOps</strong> 就是解決這件事的方法，<strong>管線</strong>（pipeline）是它的核心工具。這篇講 MLOps 是什麼、管線長什麼樣、Google Cloud 上的 Vertex AI Pipelines（現在叫 Agent Platform Pipelines）怎麼用、Kubeflow 和 TFX 這兩個框架差在哪。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店的連鎖飲料店當例子（教學假設）：會員流失模型每週要用新資料重訓一次，推薦模型每天重訓。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-01-mlops-levels.png" alt="MLOps 是什麼：三個成熟度等級，等級 0 全部手動在筆記本裡做、一年發布幾次；等級 1 把訓練流程做成自動管線、用新資料持續訓練；等級 2 連管線本身的改版都走 CI/CD 自動測試部署" class="wp-image-12857" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-01-mlops-levels.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-01-mlops-levels-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-01-mlops-levels-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-01-mlops-levels-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>模型上線後會壞</strong>：Google 的 <a href="https://docs.cloud.google.com/architecture/mlops-continuous-delivery-and-automation-pipelines-in-machine-learning">MLOps 架構文件</a>說得很直接，模型在真實世界常常壞掉，因為環境變了、資料變了，模型沒跟著變。解法是<strong>頻繁重訓</strong>，而頻繁重訓靠手動做不到</li>

<li><strong>手動流程的隱形成本</strong>：飲料店兩個模型，一個每週、一個每天重訓，一年要手動跑 400 多次，每次十幾個步驟。漏一步、順序錯一步，上線的就是壞模型</li>

<li><strong>筆記裡的名稱改了</strong>：Vertex AI Pipelines 現在叫 Agent Platform Pipelines，Cloud Composer 改名 Managed Service for Apache Airflow</li>

<li><strong>證照必考</strong>：PMLE 考試指南第 5 區「自動化與編排 ML 管線」佔 <strong>18%</strong>，5.1 要你會「驗證資料和模型」「用代管或非代管服務、從範本或自訂方案建管線（Agent Platform Pipelines、Managed Service for Apache Airflow、Ray）」；第 2.3 節也考「選實驗環境（Experiments、Pipelines、Kubeflow Pipelines）」</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：MLOps 是什麼</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>MLOps</strong>（Machine Learning Operations）：把軟體工程界管程式的那套方法（<strong>DevOps</strong>）搬到機器學習上，讓模型的建立、測試、上線、重訓變成<strong>自動、可重複、可追蹤</strong>的流程。</p>



<p class="wp-block-paragraph"><strong>DevOps</strong> 是「開發」（Development）和「維運」（Operations）合在一起的做法：程式一改，自動測試、自動部署，而不是工程師手動上傳檔案。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">一間手搖飲店，老闆自己調配方、自己煮，口味靠經驗。要開到 2,000 間分店，就得把配方寫成 <strong>SOP</strong>（標準作業流程）：第一步秤糖、第二步煮茶、第三步封膜，每間店照做、品質一樣，配方改了只要更新 SOP。</p>



<p class="wp-block-paragraph">MLOps 就是把「做模型」寫成 SOP，而且是<strong>機器會自己照做</strong>的 SOP。</p>



<h3 class="wp-block-heading">來龍去脈：跟 DevOps 差在哪</h3>



<p class="wp-block-paragraph">官方文件說 ML 系統跟一般軟體有幾個不同：團隊成員不是軟體工程師（資料科學家）、要做很多實驗、測試要多測資料和模型、部署的不只是程式而是<strong>一整條會自動重訓的管線</strong>、模型會因為資料變化而<strong>衰退</strong>。</p>



<p class="wp-block-paragraph">所以 MLOps 比 DevOps 多了一個 <strong>CT</strong>（持續訓練，Continuous Training）：程式沒改，但資料變了，就自動重訓。</p>



<h3 class="wp-block-heading">三個成熟度等級</h3>



<p class="wp-block-paragraph">官方文件把 MLOps 分成三級，這是考題和實務都常用的框架：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>等級</th><th>名稱</th><th>長什麼樣</th><th>飲料店</th></tr></thead><tbody><tr><td><strong>0</strong></td><td><strong>手動流程</strong></td><td>每一步都在筆記本裡手動做；資料科學家做完模型「交接」給工程師部署；一年才發布幾次；沒有 CI／CD；<strong>沒有監控</strong></td><td>分析師在筆記本跑完，把模型檔丟給 IT 上線</td></tr><tr><td><strong>1</strong></td><td><strong>ML 管線自動化</strong></td><td>訓練流程做成<strong>管線</strong>，自動用新資料<strong>持續訓練</strong>；實驗環境和正式環境用同一條管線；元件模組化、容器化；有資料和模型驗證、觸發器、中繼資料</td><td>每週自動抓新資料、驗證、訓練、評估、部署</td></tr><tr><td><strong>2</strong></td><td><strong>CI/CD 管線自動化</strong></td><td>連<strong>管線本身的改版</strong>都自動化：改了程式碼就自動測試、打包、部署新管線</td><td>分析師改了特徵工程，推上去自動測試、自動上線新管線</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>筆記本</strong>（notebook）是在網頁上邊寫程式邊看結果的工具，例如 Agent Platform Workbench、Colab。</p>



<p class="wp-block-paragraph">等級 0 的最大問題，官方點出三個：模型沒人<strong>監控</strong>品質；沒有<strong>頻繁重訓</strong>；沒有<strong>持續實驗</strong>新做法。等級 1 解決前兩個，等級 2 解決第三個。這篇講等級 1 的核心工具（管線），第 19 篇講等級 2 的 CI/CD，<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">第 20 篇</a>講監控。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考題會描述一個團隊的現狀（「資料科學家在筆記本訓練好交給工程師」「每季手動重訓」），問你「該怎麼改善」，答案幾乎都是「建管線」。認得出這是等級 0 的症狀，就能選對。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 管線：把步驟串成一張圖</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>ML 管線</strong>（ML pipeline）：把機器學習的工作流程寫成<strong>一連串的步驟</strong>，每一步做一件事（準備資料、訓練、評估、部署），步驟之間用「輸出接輸入」串起來。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/introduction">官方 Pipelines 簡介</a>的定義：「一個可攜、可擴展的 MLOps 工作流程描述，由一系列叫做管線任務的步驟組成」。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">工廠的生產線。原料進來，第一站洗、第二站切、第三站包裝，每一站只管自己的事，上一站的成品是下一站的原料。</p>



<h3 class="wp-block-heading">兩個名詞</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>名詞</th><th>白話</th><th>比喻</th></tr></thead><tbody><tr><td><strong>元件</strong>（component）</td><td>一段<strong>獨立的程式</strong>，做一件事，有輸入、有輸出，通常包成容器</td><td>一台機器（切菜機）</td></tr><tr><td><strong>任務</strong>（task）</td><td>元件<strong>加上具體的輸入</strong>，變成管線裡的一步</td><td>這台切菜機今天切這批菜</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">官方說元件有三部分：輸入（參數或<strong>成品</strong>）、輸出、邏輯（程式碼，容器化的話還包含容器映像檔）。<strong>成品</strong>（artifact）是步驟產生的東西：資料集、模型檔、評估報告。</p>



<h3 class="wp-block-heading">管線是一張圖：DAG</h3>



<p class="wp-block-paragraph">步驟之間的依賴關係形成一張 <strong>DAG</strong>（有向無環圖）。白話：箭頭有方向（A 做完才能做 B）、不會繞圈（B 不能又回頭等 A）。</p>



<p class="wp-block-paragraph">官方的例子，四個步驟：</p>



<pre class="wp-block-code"><code>準備資料 → 訓練模型 → 評估模型
                   └→ 部署模型</code></pre>


<ul class="wp-block-list">
<li><strong>準備資料</strong>不依賴任何步驟，可以第一個跑（或跟別的平行）</li>

<li><strong>訓練模型</strong>要等準備資料的輸出</li>

<li><strong>評估</strong>和<strong>部署</strong>都只要訓練好的模型，所以<strong>可以同時跑</strong></li>
</ul>



<p class="wp-block-paragraph">官方特別說：預設任務是<strong>平行</strong>跑的，有依賴才會串起來。這是管線比「照順序執行的腳本」快的原因。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-02-pipeline-dag.png" alt="ML 管線是一張 DAG：準備資料、訓練模型、評估模型、部署模型四個任務用輸出接輸入串起來，評估和部署都只依賴訓練好的模型所以可以平行跑；每個任務是一個元件加上具體輸入" class="wp-image-12858" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-02-pipeline-dag.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-02-pipeline-dag-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-02-pipeline-dag-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-02-pipeline-dag-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考試 5.1 的「建立和編排管線」就是在問這個。而且<strong>元件可以重用</strong>：飲料店的「從 BigQuery 抓資料並驗證」元件，流失模型和推薦模型都能用。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. Vertex AI Pipelines：無伺服器地跑管線</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>Vertex AI Pipelines</strong>（2026 年 4 月起叫 <strong>Gemini Enterprise Agent Platform Pipelines</strong>）：Google 代管的管線執行服務。你定義好管線，它負責開機器、照 DAG 跑每一步、記錄每一步的輸入輸出。官方用語是「以<strong>無伺服器</strong>的方式自動化、監控、治理 ML 系統」，無伺服器就是你不用管機器（第 14 篇）。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">你寫好 SOP，Google 提供工廠和工人，照 SOP 生產，每一批都有生產紀錄。</p>



<h3 class="wp-block-heading">用哪個框架寫管線</h3>



<p class="wp-block-paragraph">Agent Platform Pipelines 可以跑<strong>兩種框架</strong>定義的管線：<strong>Kubeflow Pipelines（KFP）</strong> 和 <strong>TensorFlow Extended（TFX）</strong>。兩個下面會分別講。</p>



<h3 class="wp-block-heading">一條管線的生命週期</h3>



<p class="wp-block-paragraph">官方分四個階段：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>階段</th><th>做什麼</th></tr></thead><tbody><tr><td><strong>定義</strong>（Define）</td><td>選框架（KFP 或 TFX），寫元件、組管線</td></tr><tr><td><strong>編譯</strong>（Compile）</td><td>把 Python 定義的管線<strong>編譯成一份 YAML 檔</strong>（一種設定檔格式）。這份 YAML 可以上傳成<strong>管線範本</strong>（pipeline template）放到 Artifact Registry 的 Kubeflow Pipelines 儲存庫，做版本控制、重複使用</td></tr><tr><td><strong>執行</strong>（Run）</td><td>用 YAML 或範本建一次<strong>管線執行</strong>（pipeline run）。可以跑一次、用<strong>排程 API</strong> 定期跑、或複製之前的執行</td></tr><tr><td><strong>監控</strong></td><td>看每次執行的狀態、效能、費用；看 DAG 圖；查每個成品的來源</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>任務在哪裡算</strong>：官方說任務可以用 Agent Platform 的隨需運算（底層是 Kubernetes），也可以<strong>委派給別的引擎</strong>：BigQuery、Dataflow、Managed Service for Apache Spark。例如「準備資料」那一步其實是一句 BigQuery SQL，管線只是去觸發它、等它做完。</p>



<h3 class="wp-block-heading">預建元件：Google Cloud Pipeline Components</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/components-introduction">GCPC</a> 是 Google 做好的一組 KFP 元件，官方列的功能：建資料集、匯出資料到 Cloud Storage、用 AutoML 訓練、跑自訂訓練工作、上傳模型做批次推論、建端點部署線上推論。</p>



<p class="wp-block-paragraph">好處（官方列的）：</p>


<ul class="wp-block-list">
<li><strong>好除錯</strong>：直接顯示元件底下啟動的資源</li>

<li><strong>標準成品型態</strong>：輸入輸出用統一的型態，ML Metadata 自動追蹤血緣</li>

<li><strong>帳單標籤自動傳遞</strong>：元件啟動的資源會帶上管線的標籤，配合帳單匯出到 BigQuery 就能算出<strong>一次管線執行花多少錢</strong></li>

<li><strong>省成本</strong>：它直接啟動 Google Cloud 資源，不用先開一個容器在那邊空等</li>
</ul>



<h3 class="wp-block-heading">中繼資料和血緣</h3>



<p class="wp-block-paragraph">每一次執行，Agent Platform <strong>ML Metadata</strong> 會記下每一步用了什麼輸入、產出什麼成品。所以你可以回答「上線的這個模型是用哪天的資料、哪個版本的程式訓練的」。這個<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">第 22 篇</a>會專門講。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考題看到「無伺服器」「代管」「ML 專用的管線」「追蹤成品血緣」，就是 Agent Platform Pipelines。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. Kubeflow Pipelines：框架中立的管線</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><a href="https://www.kubeflow.org/docs/components/pipelines/overview/">Kubeflow Pipelines（KFP）</a>：開源的管線框架，官方定義是「用容器在 Kubernetes 系統上建立和部署可攜、可擴展的 ML 工作流程的平台」。</p>



<p class="wp-block-paragraph"><strong>Kubernetes</strong> 是管理大量容器的系統，站上有一篇<a href="https://dongdonggcp.com/2026/07/21/what-is-kubernetes/">Kubernetes 是什麼</a>。<strong>可攜</strong>是「寫一次，換個地方也能跑」。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">樂高積木。每個元件是一塊積木（一個容器），用 Python 把積木拼成管線，拼好的東西可以搬到任何支援 KFP 的地方跑。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">Kubeflow 原本是 Google 內部「在 Kubernetes 上跑 TensorFlow」的專案開源出來的，後來變成一整套 ML 平台，Pipelines 是其中最常用的一塊。2025 年 Kubeflow 成為 CNCF（雲端原生運算基金會）的畢業專案，代表它是業界標準等級的開源軟體。</p>



<p class="wp-block-paragraph"><strong>Agent Platform Pipelines 跑的就是 KFP 格式的管線</strong>，差別是你不用自己架 Kubernetes。筆記裡的「Vertex AI Pipelines（KFP 託管服務）」就是這個意思。</p>



<h3 class="wp-block-heading">怎麼寫：Python 函數就是元件</h3>



<p class="wp-block-paragraph">KFP 的 SDK 讓你用 <strong>Python 函數</strong>定義元件（叫 lightweight component），不用自己做容器：</p>



<pre class="wp-block-code"><code>from kfp import dsl

@dsl.component(packages_to_install=["google-cloud-bigquery"])
def prepare_data(project: str, out_table: str) -&gt; str:
    # 用 SQL 從 BigQuery 整理出會員特徵表
    ...
    return out_table

@dsl.component(base_image="asia-docker.pkg.dev/vertex-ai/training/pytorch-gpu.2-4.py310:latest")
def train_model(table: str, model_dir: dsl.Output[dsl.Model]):
    # 訓練，把模型存到 model_dir.path
    ...

@dsl.pipeline(name="churn-weekly")
def churn_pipeline(project: str):
    data = prepare_data(project=project, out_table="drink.member_features")
    train_model(table=data.output)</code></pre>


<ul class="wp-block-list">
<li><code>@dsl.component</code>：這個函數是一個元件，可以指定要裝的套件或用哪個容器映像檔</li>

<li><code>@dsl.pipeline</code>：這個函數描述管線，裡面呼叫元件、把輸出接到輸入，KFP 自動算出 DAG</li>

<li>編譯成 YAML 後，用 Agent Platform 的 <code>PipelineJob</code> 執行</li>
</ul>



<p class="wp-block-paragraph">要用 Google 的服務（AutoML、自訂訓練、部署端點），直接拿 GCPC 的預建元件來接，不用自己寫。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">KFP <strong>不綁框架</strong>：PyTorch、scikit-learn、XGBoost 的程式都能包成元件。飲料店的 PyTorch 推薦模型（第 16 篇）要做成管線，用 KFP。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. TFX：TensorFlow 的全家桶管線</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><a href="https://www.tensorflow.org/tfx/guide">TFX（TensorFlow Extended）</a>：Google 用來部署正式 ML 管線的平台，<strong>專為 TensorFlow 設計</strong>，附一整套<strong>標準元件</strong>，從讀資料到部署都幫你定義好。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">KFP 是樂高積木，自己拼；TFX 是<strong>模型套件</strong>（已經切好的零件＋組裝說明書），照著組就是一台完整的車，但零件是 TensorFlow 規格的。</p>



<h3 class="wp-block-heading">標準元件：一條標準的管線長這樣</h3>



<p class="wp-block-paragraph">TFX 官方指南列的標準元件，照順序：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>元件</th><th>做什麼</th><th>對應本系列</th></tr></thead><tbody><tr><td><strong>ExampleGen</strong></td><td>把資料讀進管線（輸出 TFRecord 格式的樣本）</td><td>第 13 篇</td></tr><tr><td><strong>StatisticsGen</strong></td><td>算資料的統計量（每欄的分布、遺失值比例）</td><td>第 10 篇</td></tr><tr><td><strong>SchemaGen</strong></td><td>從統計量推出<strong>資料結構</strong>（schema）：每欄什麼型態、值域多少</td><td></td></tr><tr><td><strong>ExampleValidator</strong></td><td>用 schema 檢查新資料有沒有<strong>異常</strong>：遺失值、型態不對、分布跑掉</td><td>第 20 篇的偏差</td></tr><tr><td><strong>Transform</strong></td><td><strong>特徵工程</strong>，而且訓練和服務用同一套轉換</td><td>第 10、11 篇</td></tr><tr><td><strong>Trainer</strong></td><td>訓練模型</td><td>第 16 篇</td></tr><tr><td><strong>Tuner</strong></td><td>調超參數</td><td>第 16 篇</td></tr><tr><td><strong>Evaluator</strong></td><td>深入分析訓練結果，<strong>驗證模型</strong>夠不夠好才能上線</td><td>第 5、6 篇</td></tr><tr><td><strong>InfraValidator</strong></td><td>確認模型真的能在服務環境載入、回應</td><td>第 17 篇</td></tr><tr><td><strong>Pusher</strong></td><td>把模型推到服務環境</td><td>第 17 篇</td></tr><tr><td><strong>BulkInferrer</strong></td><td>批次推論</td><td>第 17 篇</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">背後的四個函式庫</h3>


<ul class="wp-block-list">
<li><strong>TFDV</strong>（TensorFlow Data Validation）：StatisticsGen、SchemaGen、ExampleValidator 用的，<strong>資料驗證</strong>。筆記裡的「TFX SDK（標準化組件，TFDV）」就是這個</li>

<li><strong>TFT</strong>（TensorFlow Transform）：Transform 用的，前處理寫一次，訓練和服務都套用，解決訓練／服務偏差</li>

<li><strong>TFMA</strong>（TensorFlow Model Analysis）：Evaluator 用的，可以<strong>切片評估</strong>（例如只看台北的會員、只看新會員），找出整體分數好但某群人很差的情況</li>

<li><strong>MLMD</strong>（ML Metadata）：記錄每一步的成品和血緣</li>
</ul>



<h3 class="wp-block-heading">要搭配什麼</h3>



<p class="wp-block-paragraph">官方說 TFX 的資料處理靠 <strong>Apache Beam</strong>（Dataflow 跑的就是 Beam，<a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">第 23 篇</a>），<strong>編排器</strong>可以選 Apache Airflow、Kubeflow Pipelines，或 Agent Platform Pipelines。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考題看到「<strong>資料驗證</strong>」「<strong>schema</strong>」「偵測資料異常」「TensorFlow 全家桶」「標準化元件」，就是 TFX（或它的 TFDV）。考試指南 5.1 第一條「驗證資料和模型」，TFX 的 ExampleValidator 和 Evaluator 就是標準答案之一。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. KFP、TFX、Airflow、Ray：怎麼選</h2>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-03-tools.png" alt="管線工具怎麼選：Agent Platform Pipelines 是無伺服器的執行服務，跑 KFP 或 TFX 定義的管線；KFP 框架中立用 Python 函數當元件；TFX 專為 TensorFlow 有標準元件和資料驗證；Managed Service for Apache Airflow 是通用工作流排程，舊名 Cloud Composer；Ray 是分散式 Python" class="wp-image-12859" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-03-tools.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-03-tools-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-03-tools-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-03-tools-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>KFP</strong></th><th><strong>TFX</strong></th><th><strong>Managed Service for Apache Airflow</strong></th><th><strong>Ray on Agent Platform</strong></th></tr></thead><tbody><tr><td>是什麼</td><td>ML 管線框架</td><td>TensorFlow 的管線框架＋標準元件</td><td>通用的<strong>工作流排程</strong>服務，舊名 <strong>Cloud Composer</strong></td><td>分散式 Python 運算框架</td></tr><tr><td>框架</td><td><strong>中立</strong>（PyTorch、sklearn、XGBoost 都行）</td><td><strong>TensorFlow</strong></td><td>任何（它只是排程）</td><td>Python</td></tr><tr><td>元件</td><td>自己寫（Python 函數）＋GCPC 預建</td><td>標準元件現成</td><td>Airflow 的 operator</td><td>Ray 的任務</td></tr><tr><td>強項</td><td>彈性、框架中立</td><td>資料驗證、訓練服務一致、切片評估</td><td>跨系統的資料工程流程（ETL、排程）</td><td>大規模平行 Python</td></tr><tr><td>在哪跑</td><td>Agent Platform Pipelines、自管 Kubernetes 上的 Kubeflow</td><td>Agent Platform Pipelines、Airflow、KFP</td><td>它自己是代管服務</td><td>Agent Platform</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>怎麼選</strong>：</p>


<ul class="wp-block-list">
<li>ML 流程、要血緣追蹤、無伺服器 → <strong>Agent Platform Pipelines</strong>（用 KFP 或 TFX 寫）</li>

<li>全 TensorFlow、要標準的資料驗證和評估 → <strong>TFX</strong></li>

<li>PyTorch 或混合框架 → <strong>KFP</strong></li>

<li>整個公司的資料流程（每天從十個系統抓資料、清洗、再觸發 ML）→ <strong>Managed Service for Apache Airflow</strong>，它也可以在流程裡觸發一條 Agent Platform 管線</li>

<li>已經有自己的 Kubernetes 團隊、要完全控制 → <strong>GKE 上的 Kubeflow</strong>（考試指南 3.2 有列）</li>

<li>大量平行的 Python 運算（例如大規模資料處理或強化學習）→ <strong>Ray</strong></li>
</ul>



<p class="wp-block-paragraph"><strong>Managed Service for Apache Airflow</strong> 是 Google 在 2026 年把 Cloud Composer 改的名字，<a href="https://docs.cloud.google.com/composer/docs">官方文件</a>寫「Cloud Composer 正演變為 Managed Service for Apache Airflow」。舊題庫看到 Cloud Composer 就是它。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">6. 管線快取：沒改的步驟不要重跑</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/configure-caching">管線快取</a>：管線執行時，每一步先看 ML Metadata 裡有沒有「一模一樣的執行」，有就<strong>直接拿上次的輸出、跳過這一步</strong>。</p>



<p class="wp-block-paragraph"><strong>快取鍵</strong>（判斷「一模一樣」的依據）是三樣東西的組合：</p>


<ol class="wp-block-list">
<li>這一步的<strong>輸入</strong>：參數的值、輸入成品的 ID</li>

<li>這一步的<strong>輸出定義</strong>：輸出參數和成品的名稱</li>

<li><strong>元件規格</strong>：映像檔、指令、參數、環境變數，連順序都算</li>
</ol>



<p class="wp-block-paragraph">而且只有<strong>同名的管線</strong>才共用快取。</p>



<h3 class="wp-block-heading">算一次給你看</h3>



<p class="wp-block-paragraph">飲料店的流失模型管線五步（數字是教學假設）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>步驟</th><th>時間</th><th>費用</th></tr></thead><tbody><tr><td>準備資料（BigQuery）</td><td>10 分鐘</td><td>5 元</td></tr><tr><td>驗證資料</td><td>5 分鐘</td><td>2 元</td></tr><tr><td>訓練（GPU）</td><td>60 分鐘</td><td>100 元</td></tr><tr><td>評估</td><td>5 分鐘</td><td>2 元</td></tr><tr><td>部署</td><td>5 分鐘</td><td>1 元</td></tr><tr><td><strong>全部</strong></td><td><strong>85 分鐘</strong></td><td><strong>110 元</strong></td></tr></tbody></table></figure>



<p class="wp-block-paragraph">分析師只改了<strong>評估</strong>那一步的門檻（第 6 篇），重跑管線：</p>



<pre class="wp-block-code"><code>前三步的輸入、輸出定義、元件規格都沒變 → 命中快取，跳過
只跑評估 + 部署 = 5 + 5 = 10 分鐘，2 + 1 = 3 元
省下 75 分鐘（88%）、107 元（97%）</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>越前面、越貴的步驟（訓練）越常被快取省掉，因為它的輸入通常沒變</li>

<li><strong>反過來的陷阱</strong>：每週的新資料如果用<strong>同一個表名</strong>、同樣的參數，「準備資料」這一步的輸入看起來一樣，快取會<strong>跳過它</strong>，整條管線用上週的資料重訓，你還以為更新了。解法：抓資料那一步<strong>關掉快取</strong>（<code>task.set_caching_options(False)</code>），或把日期當參數傳進去，讓快取鍵不一樣</li>

<li>整條管線關快取：<code>PipelineJob(..., enable_caching=False)</code></li>
</ul>



<p class="wp-block-paragraph">筆記裡的「管道快取（Pipeline Caching）減少重複運行時間／成本」就是這個，考試會從正反兩面考。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">建第一條管線</h3>


<ol class="wp-block-list">
<li>把現有的筆記本程式<strong>拆成函數</strong>：抓資料、訓練、評估各一個</li>

<li>用 KFP 的 <code>@dsl.component</code> 包成元件；要用 AutoML、自訂訓練、部署端點，直接接 GCPC 元件</li>

<li><code>@dsl.pipeline</code> 組起來，<code>kfp.compiler.Compiler().compile()</code> 編成 YAML</li>

<li>用 <code>aiplatform.PipelineJob(template_path="pipeline.yaml", ...).run()</code> 跑一次，在主控台看 DAG 圖和每一步的日誌</li>

<li>跑順了，上傳 YAML 到 Artifact Registry 當<strong>範本</strong>，用<strong>排程 API</strong> 設每週一跑（第 19 篇講其他觸發方式）</li>

<li>抓資料那一步<strong>關快取</strong></li>
</ol>



<h3 class="wp-block-heading">觸發方式</h3>



<p class="wp-block-paragraph">官方 MLOps 文件列的五種：<strong>手動</strong>、<strong>排程</strong>（每天／每週有新標好的資料）、<strong>新資料到了</strong>（不定期）、<strong>模型效能下降</strong>（第 20 篇的監控觸發）、<strong>資料分布明顯改變</strong>（概念漂移）。第 19 篇會講在 GCP 上各怎麼接。</p>



<h3 class="wp-block-heading">費用</h3>



<p class="wp-block-paragraph">管線執行本身有執行費，加上每一步啟動的資源費（訓練的 GPU、BigQuery 的查詢）。用 GCPC 元件，資源會自動帶管線的標籤，帳單匯出到 BigQuery 就能算每一次執行的總花費。</p>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>Vertex AI Pipelines</td><td>Gemini Enterprise Agent Platform Pipelines</td></tr><tr><td>Vertex ML Metadata</td><td>Gemini Enterprise Agent Platform ML Metadata</td></tr><tr><td>Vertex AI Experiments</td><td>Experiments on Gemini Enterprise Agent Platform</td></tr><tr><td>Cloud Composer</td><td><strong>Managed Service for Apache Airflow</strong></td></tr><tr><td>Dataproc Serverless（Spark）</td><td>Managed Service for Apache Spark</td></tr><tr><td>Kubeflow Pipelines（KFP）、TFX</td><td>名稱沒變，都是開源專案</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 2 區：跨團隊管理資料與模型（約 16%）</td><td>2.3 依框架<strong>選開發和實驗環境</strong>（Experiments on Agent Platform、Agent Platform Pipelines、Kubeflow Pipelines）</td></tr><tr><td>第 3 區：把原型放大成 ML 模型（約 21%）</td><td>3.1 選產品（含 Agent Platform Pipelines）；3.2 用不同 SDK 訓練（含 GKE 上的 Kubeflow）</td></tr><tr><td>第 5 區：自動化與編排 ML 管線（約 18%）</td><td>5.1 <strong>驗證資料和模型</strong>；<strong>用代管或非代管服務、從範本或自訂方案建立和編排管線</strong>（Agent Platform Pipelines、Managed Service for Apache Airflow、Ray on Agent Platform）；<strong>確保訓練和服務的前處理一致</strong>。5.2 自動重訓（第 19 篇）</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-04-exam-keywords.png" alt="PMLE 考試關鍵字：筆記本手動流程一年發布幾次想到 MLOps 等級 0 要建管線、無伺服器 ML 管線追蹤血緣想到 Agent Platform Pipelines、資料驗證 schema 異常想到 TFX 的 TFDV、PyTorch 框架中立想到 KFP、通用排程資料工程想到 Managed Service for Apache Airflow、沒改的步驟別重跑想到管線快取" class="wp-image-12860" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-04-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-04-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-04-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml18-04-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「資料科學家在筆記本訓練好交給工程師」「每季手動重訓」「沒有監控」</td><td><strong>MLOps 等級 0</strong>，要建<strong>管線</strong>（等級 1）</td></tr><tr><td>「改了管線程式碼要自動測試、部署」</td><td><strong>等級 2</strong>，CI/CD（第 19 篇）</td></tr><tr><td>「無伺服器」「代管的 ML 管線」「追蹤成品血緣」「可重複」</td><td><strong>Agent Platform Pipelines</strong></td></tr><tr><td>「資料驗證」「schema」「偵測異常」「統計量」</td><td><strong>TFX</strong> 的 <strong>TFDV</strong>（ExampleValidator）</td></tr><tr><td>「全 TensorFlow」「標準元件」「切片評估」</td><td><strong>TFX</strong>（TFMA）</td></tr><tr><td>「PyTorch」「scikit-learn」「框架中立」「Python 函數當元件」</td><td><strong>KFP</strong></td></tr><tr><td>「用 AutoML／自訂訓練／部署的現成元件」</td><td><strong>Google Cloud Pipeline Components</strong></td></tr><tr><td>「通用工作流」「跨系統資料流程」「Airflow DAG」「Cloud Composer」</td><td><strong>Managed Service for Apache Airflow</strong></td></tr><tr><td>「自己管 Kubernetes」「完全控制」</td><td><strong>GKE 上的 Kubeflow</strong></td></tr><tr><td>「大規模平行 Python」</td><td><strong>Ray on Agent Platform</strong></td></tr><tr><td>「沒改的步驟不要重跑」「省時間省錢」</td><td><strong>管線快取</strong></td></tr><tr><td>「用了舊資料卻沒發現」「資料更新但管線跳過」</td><td>抓資料那步<strong>關快取</strong>，或把日期當參數</td></tr><tr><td>「訓練和服務的前處理一致」</td><td>TFX <strong>Transform</strong>（TFT）、BigQuery ML TRANSFORM（第 15 篇）</td></tr><tr><td>「這個模型用哪份資料訓練的」</td><td><strong>ML Metadata</strong> 血緣（第 22 篇）</td></tr><tr><td>「管線定義要版本控制、重複使用」</td><td><strong>管線範本</strong>放 Artifact Registry</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>把管線當成排程腳本</strong>：管線的重點是元件化、平行、血緣追蹤，不只是「定時跑」</li>

<li><strong>抓資料的步驟沒關快取</strong>：每週重訓其實都用同一份舊資料</li>

<li><strong>PyTorch 專案選 TFX</strong>：TFX 是 TensorFlow 專用，混合框架用 KFP</li>

<li><strong>整個公司的 ETL 流程硬塞進 Agent Platform Pipelines</strong>：那是 Airflow 的事，ML 管線可以被 Airflow 觸發</li>

<li><strong>等級 1 就以為做完了</strong>：管線程式碼本身的改版還是手動部署，要到等級 2 才算完整</li>

<li><strong>忘記 Cloud Composer 改名了</strong>：考題寫 Managed Service for Apache Airflow 就是它</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店的資料科學家每週一早上手動在筆記本跑完流失模型，把模型檔用 email 寄給工程師部署。上個月有兩次忘了跑，一次寄錯版本。應該怎麼改善？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「手動」「筆記本」「寄檔案」「忘了跑」→ <strong>MLOps 等級 0</strong> 的典型症狀</li>

<li>解法：把步驟做成 <strong>Agent Platform Pipelines</strong> 管線（KFP 元件），<strong>排程</strong>每週一自動跑，評估通過就自動部署</li>

<li>模型進 Model Registry（第 17 篇）而不是 email</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">推薦模型用 PyTorch，流失模型用 XGBoost，團隊想用同一套方式管兩條管線，而且要知道每個上線的模型是用哪份資料訓練的。應該用什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「PyTorch＋XGBoost」→ <strong>KFP</strong>（框架中立），不是 TFX</li>

<li>「同一套方式」「哪份資料」→ <strong>Agent Platform Pipelines</strong>，ML Metadata 自動記血緣</li>

<li>訓練、部署用 <strong>GCPC</strong> 預建元件</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">團隊全用 TensorFlow，最近兩次重訓後模型變差，追查發現上游系統改了欄位格式，但管線照樣訓練上線了。應該加什麼？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「欄位格式變了沒被擋下」→ 缺<strong>資料驗證</strong></li>

<li>「全 TensorFlow」→ <strong>TFX</strong>，加 StatisticsGen → SchemaGen → <strong>ExampleValidator</strong>，異常就停止管線</li>

<li>再加 <strong>Evaluator</strong> 比較新舊模型，沒變好不部署（第 19 篇）</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">MLOps 是什麼？</h3>



<p class="wp-block-paragraph">把軟體工程的 DevOps 做法搬到機器學習上，讓模型的建立、測試、上線、重訓變成自動、可重複、可追蹤的流程。比 DevOps 多一個 CT（持續訓練）：程式沒改但資料變了就自動重訓。Google 的 MLOps 文件分三級：等級 0 全手動在筆記本做，等級 1 訓練流程做成自動管線持續訓練，等級 2 連管線程式碼的改版都走 CI/CD。</p>



<h3 class="wp-block-heading">ML 管線是什麼？跟寫一個腳本差在哪？</h3>



<p class="wp-block-paragraph">管線是把 ML 工作流程寫成一連串步驟（任務），每步是一個元件加具體輸入，步驟之間用輸出接輸入，形成一張 DAG。跟腳本的差別：沒有依賴的步驟自動平行跑；元件可以在不同管線重用；每一步的輸入輸出都被 ML Metadata 記下來可以追血緣；沒改的步驟可以用快取跳過。</p>



<h3 class="wp-block-heading">Vertex AI Pipelines 是什麼？</h3>



<p class="wp-block-paragraph">Google 代管、無伺服器的管線執行服務，2026 年 4 月起叫 Gemini Enterprise Agent Platform Pipelines。它可以跑 Kubeflow Pipelines 或 TFX 定義的管線：你定義、編譯成 YAML、建一次執行或排程重複執行，它負責開機器、照 DAG 跑、記錄血緣。任務可以委派給 BigQuery、Dataflow、Spark 算。Google Cloud Pipeline Components 提供 AutoML、自訂訓練、部署等預建元件。</p>



<h3 class="wp-block-heading">Kubeflow Pipelines 和 TFX 差在哪？</h3>



<p class="wp-block-paragraph">KFP 是框架中立的管線框架，用 Python 函數或容器當元件，PyTorch、scikit-learn、XGBoost 都能用，彈性高。TFX 是 TensorFlow 專用的管線平台，附一整套標準元件（ExampleGen、StatisticsGen、SchemaGen、ExampleValidator、Transform、Trainer、Evaluator、Pusher 等）和函式庫（TFDV 資料驗證、TFT 轉換、TFMA 評估），全 TensorFlow 的團隊照著組就有完整管線。兩種都能在 Agent Platform Pipelines 上跑。</p>



<h3 class="wp-block-heading">TFDV 是什麼？</h3>



<p class="wp-block-paragraph">TensorFlow Data Validation，TFX 裡做資料驗證的函式庫。StatisticsGen 用它算統計量，SchemaGen 用它推出資料結構（每欄型態、值域），ExampleValidator 用它檢查新資料有沒有異常（遺失值、型態不對、分布跑掉）。考試看到資料驗證、schema、偵測異常，就是它。</p>



<h3 class="wp-block-heading">Cloud Composer 和 Vertex AI Pipelines 怎麼選？</h3>



<p class="wp-block-paragraph">Cloud Composer 現在叫 Managed Service for Apache Airflow，是通用的工作流排程服務，適合整個公司的資料工程流程（每天從多個系統抓資料、清洗、觸發下游）。Agent Platform Pipelines 是 ML 專用，有元件、成品、血緣追蹤、快取。常見的組合是 Airflow 管整體流程，其中一步觸發一條 Agent Platform 管線。</p>



<h3 class="wp-block-heading">管線快取是什麼？什麼時候要關？</h3>



<p class="wp-block-paragraph">管線執行時，每一步先查 ML Metadata 有沒有輸入、輸出定義、元件規格都一樣的執行，有就直接用上次的輸出、跳過這步，省時間和錢。要關的情況：抓資料那一步，因為資料更新了但表名和參數沒變，快取會跳過它、用舊資料重訓。用 task.set_caching_options(False) 關單步，或 PipelineJob 的 enable_caching=False 關整條。</p>



<h3 class="wp-block-heading">管線怎麼定期自動跑？</h3>



<p class="wp-block-paragraph">編譯好的 YAML 上傳到 Artifact Registry 當管線範本，用 Agent Platform 的排程 API 設定每天或每週執行。其他觸發方式：新資料到了、模型效能下降、資料分布改變，第 19 篇講怎麼接 Cloud Build、Pub/Sub、Cloud Scheduler。</p>



<h3 class="wp-block-heading">一定要用 Google 的管線服務嗎？</h3>



<p class="wp-block-paragraph">不一定。考試指南 5.1 寫「代管或非代管服務」：代管是 Agent Platform Pipelines、Managed Service for Apache Airflow；非代管是自己在 GKE 上架 Kubeflow，要完全控制或已經有 Kubernetes 團隊才值得。另有 Ray on Agent Platform 給大規模平行 Python 運算。</p>



<h3 class="wp-block-heading">Vertex AI Pipelines 改名了嗎？</h3>



<p class="wp-block-paragraph">是。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，Vertex AI Pipelines 改叫 Agent Platform Pipelines，Vertex ML Metadata 改叫 Agent Platform ML Metadata，Vertex AI Experiments 改叫 Experiments on Agent Platform。同時期 Cloud Composer 改名 Managed Service for Apache Airflow，Dataproc Serverless 改名 Managed Service for Apache Spark。KFP 和 TFX 是開源專案，名稱沒變。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>MLOps</strong>：DevOps 搬到 ML，多了 <strong>CT 持續訓練</strong>；三級：<strong>0 手動筆記本</strong>、<strong>1 管線自動化</strong>、<strong>2 管線本身也 CI/CD</strong></li>

<li><strong>管線</strong>：元件（獨立程式）＋輸入＝任務，串成 <strong>DAG</strong>，沒依賴的平行跑；成品被 ML Metadata 記血緣</li>

<li><strong>Agent Platform Pipelines</strong>（原 Vertex AI Pipelines）：無伺服器跑 <strong>KFP 或 TFX</strong> 管線；定義 → 編譯 YAML → 執行（一次／排程／範本）→ 監控；任務可委派 BigQuery、Dataflow、Spark；<strong>GCPC</strong> 預建元件</li>

<li><strong>KFP</strong>：框架中立，Python 函數當元件；<strong>TFX</strong>：TensorFlow 全家桶，標準元件 ExampleGen → StatisticsGen → SchemaGen → ExampleValidator → Transform → Trainer → Evaluator → Pusher，函式庫 <strong>TFDV／TFT／TFMA／MLMD</strong></li>

<li><strong>怎麼選</strong>：ML 管線 → Agent Platform Pipelines；TensorFlow＋資料驗證 → TFX；混合框架 → KFP；通用資料流程 → <strong>Managed Service for Apache Airflow</strong>（舊名 Cloud Composer）；自管 → GKE 上的 Kubeflow；平行 Python → Ray</li>

<li><strong>快取</strong>：輸入＋輸出定義＋元件規格一樣就跳過；只改評估步驟可省近九成；<strong>抓資料那步要關</strong></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>上一篇：第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>

<li>下一篇：第 19 篇：<a href="https://dongdonggcp.com/2026/10/25/ml-ci-cd-continuous-training-auto-retrain/">機器學習的 CI/CD：程式改了、資料來了，模型自動重訓</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2026/07/21/what-is-kubernetes/">Kubernetes 是什麼？白話解釋＋判斷你是否真的需要它</a></li>

<li><a href="https://dongdonggcp.com/2026/07/29/what-is-container-technology-docker-guide/">容器技術是什麼？從零開始看懂 Docker 與容器化應用</a></li>

<li><a href="https://dongdonggcp.com/2024/11/23/what-is-dataflow-vs-apache-beam/">Dataflow 是什麼？跟 Apache Beam 有什麼關係？</a></li>

<li><a href="https://dongdonggcp.com/2026/07/29/cloud-jobs-comparison/">雲端職缺大解析：雲端工程師、架構師、SRE、DevOps、資料工程師差在哪？</a></li>

<li><a href="https://dongdonggcp.com/2025/08/12/what-is-end-to-end-training-in-machine-learning/">End-to-end Training 是什麼</a></li>

<li><a href="https://dongdonggcp.com/2025/04/27/gcp-learning-roadmap/">GCP 學習路徑 Roadmap</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">把做模型的步驟寫成機器會自己照做的 SOP，模型才能一直是新的。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "MLOps 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "把軟體工程的 DevOps 做法搬到機器學習上，讓模型的建立、測試、上線、重訓變成自動、可重複、可追蹤的流程。比 DevOps 多一個 CT（持續訓練）：程式沒改但資料變了就自動重訓。Google 的 MLOps 文件分三級：等級 0 全手動在筆記本做，等級 1 訓練流程做成自動管線持續訓練，等級 2 連管線程式碼的改版都走 CI/CD。"
      }
    },
    {
      "@type": "Question",
      "name": "ML 管線是什麼？跟寫一個腳本差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "管線是把 ML 工作流程寫成一連串步驟（任務），每步是一個元件加具體輸入，步驟之間用輸出接輸入，形成一張 DAG。跟腳本的差別：沒有依賴的步驟自動平行跑；元件可以在不同管線重用；每一步的輸入輸出都被 ML Metadata 記下來可以追血緣；沒改的步驟可以用快取跳過。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex AI Pipelines 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Google 代管、無伺服器的管線執行服務，2026 年 4 月起叫 Gemini Enterprise Agent Platform Pipelines。它可以跑 Kubeflow Pipelines 或 TFX 定義的管線：你定義、編譯成 YAML、建一次執行或排程重複執行，它負責開機器、照 DAG 跑、記錄血緣。任務可以委派給 BigQuery、Dataflow、Spark 算。Google Cloud Pipeline Components 提供 AutoML、自訂訓練、部署等預建元件。"
      }
    },
    {
      "@type": "Question",
      "name": "Kubeflow Pipelines 和 TFX 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "KFP 是框架中立的管線框架，用 Python 函數或容器當元件，PyTorch、scikit-learn、XGBoost 都能用，彈性高。TFX 是 TensorFlow 專用的管線平台，附一整套標準元件（ExampleGen、StatisticsGen、SchemaGen、ExampleValidator、Transform、Trainer、Evaluator、Pusher 等）和函式庫（TFDV 資料驗證、TFT 轉換、TFMA 評估），全 TensorFlow 的團隊照著組就有完整管線。兩種都能在 Agent Platform Pipelines 上跑。"
      }
    },
    {
      "@type": "Question",
      "name": "TFDV 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "TensorFlow Data Validation，TFX 裡做資料驗證的函式庫。StatisticsGen 用它算統計量，SchemaGen 用它推出資料結構（每欄型態、值域），ExampleValidator 用它檢查新資料有沒有異常（遺失值、型態不對、分布跑掉）。考試看到資料驗證、schema、偵測異常，就是它。"
      }
    },
    {
      "@type": "Question",
      "name": "Cloud Composer 和 Vertex AI Pipelines 怎麼選？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Cloud Composer 現在叫 Managed Service for Apache Airflow，是通用的工作流排程服務，適合整個公司的資料工程流程（每天從多個系統抓資料、清洗、觸發下游）。Agent Platform Pipelines 是 ML 專用，有元件、成品、血緣追蹤、快取。常見的組合是 Airflow 管整體流程，其中一步觸發一條 Agent Platform 管線。"
      }
    },
    {
      "@type": "Question",
      "name": "管線快取是什麼？什麼時候要關？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "管線執行時，每一步先查 ML Metadata 有沒有輸入、輸出定義、元件規格都一樣的執行，有就直接用上次的輸出、跳過這步，省時間和錢。要關的情況：抓資料那一步，因為資料更新了但表名和參數沒變，快取會跳過它、用舊資料重訓。用 task.set_caching_options(False) 關單步，或 PipelineJob 的 enable_caching=False 關整條。"
      }
    },
    {
      "@type": "Question",
      "name": "管線怎麼定期自動跑？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "編譯好的 YAML 上傳到 Artifact Registry 當管線範本，用 Agent Platform 的排程 API 設定每天或每週執行。其他觸發方式：新資料到了、模型效能下降、資料分布改變，第 19 篇講怎麼接 Cloud Build、Pub/Sub、Cloud Scheduler。"
      }
    },
    {
      "@type": "Question",
      "name": "一定要用 Google 的管線服務嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "不一定。考試指南 5.1 寫「代管或非代管服務」：代管是 Agent Platform Pipelines、Managed Service for Apache Airflow；非代管是自己在 GKE 上架 Kubeflow，要完全控制或已經有 Kubernetes 團隊才值得。另有 Ray on Agent Platform 給大規模平行 Python 運算。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex AI Pipelines 改名了嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "是。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，Vertex AI Pipelines 改叫 Agent Platform Pipelines，Vertex ML Metadata 改叫 Agent Platform ML Metadata，Vertex AI Experiments 改叫 Experiments on Agent Platform。同時期 Cloud Composer 改名 Managed Service for Apache Airflow，Dataproc Serverless 改名 Managed Service for Apache Spark。KFP 和 TFX 是開源專案，名稱沒變。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>模型部署怎麼選？線上預測 vs 批次預測、流量分割</title>
		<link>https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=model-deployment-online-vs-batch-prediction-traffic-split</link>
					<comments>https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:43:00 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12856</guid>

					<description><![CDATA[<p>模型部署怎麼選？線上預測要先部署到端點、即時回應但機器一直算錢；批次預測不用端點、算完就收。用飲料店推薦和流失模型帶你看端點四種類型、流量分割做金絲雀、自動擴展和批次副本數算一次，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>模型部署怎麼選？要即時回應就部署到端點做線上預測，一次算一大批就用批次預測不用端點，換新版本用流量分割慢慢切。</strong></p>



<p class="wp-block-paragraph">模型訓練好了（第 14 到 16 篇），接下來要讓它<strong>真的能用</strong>：App 要能問它「這位會員會不會流失」，行銷部門要能拿到一整張名單。這篇講的就是「模型怎麼上線」：兩種拿到預測的方式、端點怎麼設、新舊版本怎麼換、機器怎麼自動增減、要花多少錢。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店、50 萬名會員的連鎖飲料店當例子（教學假設），兩個模型：</p>


<ul class="wp-block-list">
<li><strong>猜你想點</strong>推薦模型：會員一打開 App 就要看到推薦，等不了</li>

<li><strong>會員流失</strong>預測模型：行銷部門每週一早上要一張「這週該追誰」的名單</li>
</ul>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-01-online-vs-batch.png" alt="模型部署怎麼選：線上預測像櫃台現點現做，要先部署到端點、同步回應、低延遲；批次預測像中央廚房晚上一次做好，不用端點、非同步、處理累積的資料" class="wp-image-12852" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-01-online-vs-batch.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-01-online-vs-batch-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-01-online-vs-batch-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-01-online-vs-batch-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>模型不上線等於沒做</strong>：訓練完的模型只是 Cloud Storage 裡的一個檔案，要有人能呼叫它才有價值</li>

<li><strong>部署比訓練更花錢</strong>：訓練跑完機器就收掉；線上端點的機器<strong>只要部署著就一直算錢</strong>，不管有沒有人用。選錯方式，一個月帳單比訓練貴十倍</li>

<li><strong>筆記裡的名稱改了</strong>：Vertex AI Endpoints、Online Prediction、Batch Prediction 現在叫 Agent Platform Inference、線上推論、批次推論；更早的 AI Platform Prediction 已在 2025 年 4 月關閉</li>

<li><strong>證照必考</strong>：PMLE 考試指南第 4 區「服務與擴展模型」佔 <strong>20%</strong>，4.1 部署批次和線上推論、容器、Model Registry、<strong>推出策略（A/B 測試、金絲雀部署）</strong>、前後處理；4.2 擴展線上服務、公開和私人端點、硬體選擇</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：推論是什麼、兩種拿法</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>推論</strong>（inference）：把新資料丟進訓練好的模型，拿到它的輸出。以前叫<strong>預測</strong>（prediction），Google 的文件現在統一用「推論」，這篇兩個詞混用，意思一樣。</p>



<p class="wp-block-paragraph">Google 的<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/overview">推論總覽</a>說，拿推論有兩種方法：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>線上推論</strong>（online inference）</th><th><strong>批次推論</strong>（batch inference）</th></tr></thead><tbody><tr><td>白話</td><td>一筆一筆問，馬上回答</td><td>一大批一起算，算完通知你</td></tr><tr><td>官方定義</td><td><strong>同步</strong>請求，送給<strong>已部署到端點</strong>的模型</td><td><strong>非同步</strong>請求，<strong>不用部署</strong>，直接對模型送一個批次推論工作</td></tr><tr><td>什麼時候用</td><td>回應應用程式的輸入、需要即時結果</td><td>不需要立刻回應、想用一次請求處理累積的資料</td></tr><tr><td>飲料店</td><td>猜你想點</td><td>會員流失名單</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>同步</strong>是「送出請求、站在那裡等答案」；<strong>非同步</strong>是「送出請求先走，好了再來拿」。</p>



<h3 class="wp-block-heading">比喻</h3>


<ul class="wp-block-list">
<li><strong>線上推論</strong>是<strong>櫃台現點現做</strong>：客人站在櫃台等，店員要隨時在、飲料機要隨時開著，就算半夜沒客人也要有人顧店</li>

<li><strong>批次推論</strong>是<strong>中央廚房</strong>：晚上把明天 2,000 間店的食材一次備好，白天配送。不用隨時待命，但客人現在點的東西拿不到</li>
</ul>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">線上推論要先<strong>部署</strong>（deploy）：把模型放到一台或多台隨時開著的機器上，等請求進來。這些機器叫<strong>端點</strong>（endpoint），本質上是一個網址，應用程式把資料 POST 過去就拿到答案。</p>



<p class="wp-block-paragraph">批次推論不用端點：你告訴 Agent Platform「模型在這、資料在那（BigQuery 表或 Cloud Storage 檔案）、結果放哪」，它臨時開機器算完、把結果寫到你指定的地方、機器收掉。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考題最常考的判斷就是這個：看到「即時」「App 回應」「低延遲」選線上；看到「每天晚上」「整批」「不急」選批次。選錯不只考試扣分，實務上帳單差十倍。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 線上推論：端點怎麼設</h2>



<h3 class="wp-block-heading">部署時決定的三件事</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/general/deployment">官方部署文件</a>說，部署模型時會建三種資源，各決定一件事：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>資源</th><th>決定什麼</th><th>白話</th></tr></thead><tbody><tr><td><strong>Endpoint</strong>（端點）</td><td>在哪個<strong>區域</strong>跑</td><td>櫃台開在哪</td></tr><tr><td><strong>Model</strong>（模型）</td><td>用哪個<strong>容器</strong>（ModelContainerSpec）</td><td>飲料機是哪一台</td></tr><tr><td><strong>DeployedModel</strong>（已部署的模型）</td><td>用什麼<strong>運算資源</strong>（機型、GPU、副本數）</td><td>幾個店員、幾台機器</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>副本</strong>（replica）就是「跑著同一個模型的一台機器」，開 3 個副本就是 3 台機器同時接請求。</p>



<p class="wp-block-paragraph">官方提醒：<strong>部署後這些設定不能改</strong>，要改就重新部署。例外是擴展設定（最少／最多副本數、擴展指標）可以不重新部署直接改。</p>



<h3 class="wp-block-heading">端點有四種</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/choose-endpoint-type">官方端點類型文件</a>的比較表，整理成白話：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>專用公開端點</strong>（推薦）</th><th>共用公開端點</th><th><strong>專用私人端點</strong>（Private Service Connect，推薦）</th><th>私人端點（VPC 對等互連）</th></tr></thead><tbody><tr><td>誰能連</td><td>網際網路</td><td>網際網路</td><td>只有你的內網</td><td>只有你的內網</td></tr><tr><td>跟別人共用網路嗎</td><td>不共用，有自己的網路層</td><td>共用</td><td>不共用</td><td>不共用</td></tr><tr><td>請求大小上限</td><td>10 MB</td><td><strong>1.5 MB</strong></td><td>10 MB</td><td>10 MB</td></tr><tr><td>逾時</td><td>可設到 1 小時</td><td><strong>60 秒</strong></td><td>可設到 1 小時</td><td>60 秒</td></tr><tr><td>每分鐘請求數配額</td><td>無上限</td><td>30,000</td><td>無上限</td><td>無上限</td></tr><tr><td>串流回應</td><td>有</td><td>無</td><td>有</td><td>無</td></tr><tr><td>流量分割</td><td>有</td><td>有</td><td>有</td><td><strong>無</strong></td></tr><tr><td>VPC Service Controls（第 12 篇）</td><td><strong>不支援</strong></td><td>支援</td><td>支援</td><td>支援</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>怎麼選</strong>：</p>


<ul class="wp-block-list">
<li>一般情況選<strong>專用公開端點</strong>，官方說它更快、跟其他使用者的流量隔離、請求可以更大、逾時更長</li>

<li>公司內部系統呼叫、不想走公網 → <strong>Private Service Connect 端點</strong></li>

<li>要放進 VPC Service Controls 的邊界 → 共用公開或私人端點</li>

<li>微調過的 Gemini 模型只能部署到共用公開端點</li>
</ul>



<p class="wp-block-paragraph"><strong>Private Service Connect</strong>（私人服務連線）是讓你的內網直接接到 Google 的服務，不經過公開網際網路，不需要公開 IP。</p>



<h3 class="wp-block-heading">容器：預建、自訂、還是自訂推論例程</h3>



<p class="wp-block-paragraph">跟訓練一樣（第 16 篇），模型要包在容器裡才能跑：</p>


<ul class="wp-block-list">
<li><strong>預建推論容器</strong>：Google 準備好的 TensorFlow（含效能最佳化版）、PyTorch、scikit-learn、XGBoost 容器，模型檔放 Cloud Storage 就能用</li>

<li><strong>自訂容器</strong>：自己寫 HTTP 伺服器。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/custom-container-requirements">官方要求</a>：監聽 <code>AIP_HTTP_PORT</code> 環境變數指定的埠、提供<strong>健康檢查</strong>路徑（10 秒內回 200 才算活著）和<strong>推論</strong>路徑、請求格式是 <code>{"instances": [...]}</code>、回應是 <code>{"predictions": [...]}</code></li>

<li><strong>自訂推論例程</strong>（Custom Prediction Routine，CPR）：中間地帶。<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/custom-prediction-routines">官方說明</a>：你只寫<strong>前處理</strong>和<strong>後處理</strong>的 Python 程式（實作 Predictor 介面），HTTP 伺服器和 Dockerfile 它幫你準備，還能先在本機部署測試</li>
</ul>



<p class="wp-block-paragraph"><strong>前處理</strong>是「資料進模型前先整理」（例如第 10 篇的標準化），<strong>後處理</strong>是「模型輸出後再加工」（例如把機率換成「高／中／低」風險等級，或套商業規則）。考試指南 4.1 直接寫「開發推論前處理和後處理的解決方案」，答案就是 CPR 或自訂容器。</p>



<p class="wp-block-paragraph">筆記裡的「自訂預測例程（CPR）」現在的正式名稱是 custom inference routine，縮寫沒變。</p>



<h3 class="wp-block-heading">Model Registry：模型的倉庫</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/model-registry/introduction">Model Registry</a> 是集中管理模型的地方：匯入模型、管版本、貼<strong>別名</strong>（例如把要上線的版本標成 <code>default</code>）、從這裡部署到端點或跑批次推論、看評估結果。</p>


<ul class="wp-block-list">
<li>自訂訓練的模型要先<strong>匯入</strong>才會出現；AutoML 的模型訓練完<strong>自動</strong>進來；BigQuery ML 的模型用 <code>model_registry = 'VERTEX_AI'</code> 註冊（第 15 篇）</li>

<li>官方部署文件寫明：模型要<strong>在 Model Registry 看得到才能部署</strong></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. 流量分割：新版本怎麼換上去</h2>



<h3 class="wp-block-heading">問題</h3>



<p class="wp-block-paragraph">推薦模型 v2 訓練好了，離線評估比 v1 好。但離線好不代表上線好（第 8 篇的資料洩漏、<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">第 20 篇</a>的偏差都可能讓分數虛高）。直接全換，萬一 v2 有問題，所有會員同時受影響。</p>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>流量分割</strong>（traffic split）：同一個端點上放兩個以上的模型，設定每個模型接多少比例的請求。</p>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/general/deployment">官方的說法</a>：把新模型加到<strong>同一個端點</strong>，先服務<strong>一小部分流量</strong>，逐步提高比例，直到 100%。好處是應用程式<strong>不用改端點網址</strong>，也不會突然大變。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">新配方的珍奶，先在 10% 的訂單裡用新配方，看客人反應和退貨率，沒問題再 50%、再 100%。客人還是走同一個櫃台，不知道後面換了配方。</p>



<h3 class="wp-block-heading">兩種常見用法</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>用法</th><th>白話</th><th>怎麼設</th></tr></thead><tbody><tr><td><strong>金絲雀部署</strong>（canary deployment）</td><td>新版本先吃一小口流量，觀察沒問題再加</td><td>v1 90%、v2 10% → 50／50 → 0／100</td></tr><tr><td><strong>A/B 測試</strong>（A/B testing）</td><td>兩個版本各接一半，比較哪個商業指標好</td><td>v1 50%、v2 50%，持續一段時間</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>金絲雀</strong>這個名字來自礦工帶金絲雀下礦坑，鳥先倒就知道有毒氣：用一小部分流量當探子。</p>



<p class="wp-block-paragraph">考試指南 4.1 直接點名「實作模型推出策略（例如 A/B 測試和金絲雀部署）來比較模型版本」，在 Agent Platform 上的做法就是流量分割。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-02-traffic-split.png" alt="流量分割怎麼做：同一個端點放 v1 和 v2，金絲雀部署先 90 比 10 再 50 比 50 最後 0 比 100，應用程式不用改網址；A/B 測試則各 50 比較商業指標；也可以一個模型部署到測試和正式兩個端點" class="wp-image-12853" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-02-traffic-split.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-02-traffic-split-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-02-traffic-split-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-02-traffic-split-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">反過來：一個模型、多個端點</h3>



<p class="wp-block-paragraph">官方也列了「一個模型部署到多個端點」的理由：測試環境和正式環境用不同資源；不同應用程式有不同的效能要求（SLO，服務水準目標），要求高的部署到機器多的端點，要省錢的部署到機器少的端點。</p>



<h3 class="wp-block-heading">滾動部署（預覽功能）</h3>



<p class="wp-block-paragraph">要<strong>同一個模型換新版本</strong>、沿用原本的機器，可以用<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/rolling-deployment">滾動部署</a>：新版本的副本一台一台換掉舊的，流量依「準備好的副本數」比例逐漸移過去。新副本的健康檢查一直不過，就自動<strong>退回</strong>舊版本。</p>



<h3 class="wp-block-heading">算一次給你看：金絲雀怎麼看數字</h3>



<p class="wp-block-paragraph">推薦模型 v1 的點擊率（推薦的飲料真的被點）是 8%，v2 離線評估說會到 10%。上線用 90／10 流量分割，一天 100 萬次推薦：</p>



<pre class="wp-block-code"><code>v2 分到的流量 = 1,000,000 × 10% = 100,000 次
v2 實際點擊率 7.5% → 7,500 次點擊
v1 的 900,000 次 × 8% = 72,000 次點擊</code></pre>



<p class="wp-block-paragraph">v2 實際比 v1 <strong>差</strong>（7.5% &lt; 8%），但只影響了 10 萬次，損失是 100,000 × (8% − 7.5%) = <strong>500 次點擊</strong>。如果直接全換，損失是 1,000,000 × 0.5% = <strong>5,000 次</strong>。</p>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>分給新版本的比例越小，風險越小，但要<strong>更久</strong>才累積到夠多樣本做判斷。10% 一天 10 萬次，統計上已經夠；如果一天只有 1,000 次推薦，10% 只有 100 次，要跑好幾天</li>

<li>看的指標要是<strong>商業指標</strong>（點擊率、轉換率），不是離線的 AUC。這就是 A/B 測試的意義</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. 自動擴展：機器怎麼自己增減</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>自動擴展</strong>（autoscaling）：請求變多就自動加副本，變少就減，你只設上下限。</p>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/autoscaling">官方自動擴展文件</a>的規則：</p>


<ul class="wp-block-list">
<li><strong>預設目標</strong>：沒有 GPU 的部署，讓 <strong>CPU 使用率維持 60%</strong>；有 GPU 的部署，看 <strong>CPU 或 GPU 使用率較高的那個</strong>維持 60%</li>

<li>可以用 <code>autoscalingMetricSpecs</code> 改指標和目標，例如 GPU 的 <code>accelerator/duty_cycle</code> 目標 70%</li>

<li>設 <code>minReplicaCount</code>（最少幾台）和 <code>maxReplicaCount</code>（最多幾台）</li>

<li><strong>每 15 秒</strong>算一次目標副本數，但採用<strong>過去 5 分鐘內最高</strong>的那個目標。所以突然的尖峰會讓它 15 秒內加機器，但要等尖峰過了 5 分鐘才會減</li>
</ul>



<p class="wp-block-paragraph">筆記裡的「自動擴展根據流量／CPU 調整 minReplicaCount」就是這個。</p>



<h3 class="wp-block-heading">算一次給你看</h3>



<p class="wp-block-paragraph">官方給的公式：</p>



<pre class="wp-block-code"><code>目標副本數 = 向上取整（目前副本數 × 目前使用率 ÷ 目標使用率）</code></pre>



<p class="wp-block-paragraph"><strong>向上取整</strong>是小數一律進位（3.33 → 4）。</p>



<p class="wp-block-paragraph">推薦模型現在 2 個副本，中午尖峰 CPU 衝到 100%：</p>



<pre class="wp-block-code"><code>目標 = 向上取整（2 × 100% ÷ 60%）= 向上取整（3.33）= 4 個副本</code></pre>



<p class="wp-block-paragraph">半夜 10 個副本，使用率掉到 1%：</p>



<pre class="wp-block-code"><code>目標 = 向上取整（10 × 1% ÷ 60%）= 向上取整（0.17）= 1 個副本</code></pre>



<p class="wp-block-paragraph">但如果你設了 <code>minReplicaCount = 2</code>，半夜最少還是 2 台。</p>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>目標使用率設<strong>低</strong>（例如 40%），機器會多開、反應快但貴；設<strong>高</strong>（例如 80%），省錢但尖峰時延遲可能飆高</li>

<li>新機器<strong>開起來要時間</strong>（官方說調整副本數之後還有啟動延遲），所以不能把 minReplicaCount 設到剛好，要留餘裕</li>

<li>每個副本只跑<strong>一個容器</strong>，容器如果只用一條執行緒，多核心機器也吃不滿，使用率上不去就不會擴展。官方建議從「一個核心一個 worker」開始調</li>
</ul>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-03-autoscaling.png" alt="自動擴展算一次：目標副本數等於向上取整目前副本數乘以目前使用率除以目標使用率，2 台 100% 變 4 台，10 台 1% 變 1 台；預設目標 60%，每 15 秒調整但看過去 5 分鐘最高值；批次推論不會自動擴展，副本數用公式 N 除以 T 乘 60 除 Tb 估" class="wp-image-12854" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-03-autoscaling.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-03-autoscaling-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-03-autoscaling-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-03-autoscaling-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">縮到零（預覽功能）</h3>



<p class="wp-block-paragraph">官方文件有一節「Scale To Zero」，沒流量時副本降到 0，不算錢。目前是預覽階段，用之前要確認你的區域和機型支援。沒有這個功能的話，<strong>線上端點最少 1 個副本一直在算錢</strong>，這是線上和批次最大的費用差別。</p>



<h3 class="wp-block-heading">機型怎麼選</h3>



<p class="wp-block-paragraph">官方的<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/configure-compute">運算資源文件</a>：</p>


<ul class="wp-block-list">
<li>線上推論沒有公式，建議<strong>把模型放到幾種機型上實測</strong>延遲、成本、併發、吞吐量，有範例筆記本可以跑</li>

<li>每個副本會保留約 1 個 vCPU 給系統，所以單核機器等於沒得用</li>

<li><strong>大機器可能總成本更低</strong>：因為副本數少。GPU 每小時貴，但延遲低、總成本可能反而低</li>

<li>推論也支援 <strong>Spot VM</strong> 和<strong>預留</strong>，跟訓練一樣（第 16 篇）</li>

<li>GPU 選項從 T4、L4 到 A100、H100 都有，也支援 <strong>TPU</strong> 做線上推論</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 批次推論：不用端點，算完就走</h2>



<h3 class="wp-block-heading">怎麼做</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/predictions/get-batch-predictions">官方批次推論文件</a>：建一個 <strong>BatchPredictionJob</strong>，指定模型、輸入、輸出、機型、副本數。</p>



<p class="wp-block-paragraph"><strong>輸入格式</strong>：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>格式</th><th>說明</th></tr></thead><tbody><tr><td><strong>BigQuery 表</strong></td><td>直接指定 <code>專案.資料集.表</code>，最適合表格資料。會員流失名單就用這個</td></tr><tr><td><strong>JSON Lines</strong></td><td>每行一筆 JSON，放 Cloud Storage</td></tr><tr><td><strong>TFRecord</strong>（第 13 篇）</td><td>放 Cloud Storage，要<strong>自己切成多個檔</strong>，檔數至少等於副本數</td></tr><tr><td><strong>CSV</strong></td><td>可以，但官方<strong>不建議</strong>用在吞吐量敏感的工作，因為 CSV 不能自動分區</td></tr><tr><td><strong>檔案清單</strong></td><td>一行一個 Cloud Storage 路徑，給圖片這類資料</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><strong>三個限制</strong>：</p>


<ul class="wp-block-list">
<li>輸入、輸出、模型要在<strong>同一個區域</strong>（或多區域）</li>

<li>批次推論<strong>不會自動擴展</strong>：資料一開始就知道多少，系統直接切給 <code>starting_replica_count</code> 個副本，<code>max_replica_count</code> 會被忽略</li>

<li>BigQuery ML 的模型要先註冊到 Model Registry 才能這樣跑</li>
</ul>



<h3 class="wp-block-heading">副本數怎麼算：算一次</h3>



<p class="wp-block-paragraph">官方建議：用<strong>最小的機型</strong>、靠<strong>增加副本數</strong>來提高吞吐量（比換大機器更線性、更好預測）。而且工作<strong>至少跑 10 分鐘</strong>才划算，因為每個副本啟動要約 5 分鐘，這 5 分鐘也算錢。</p>



<p class="wp-block-paragraph">官方公式：</p>



<pre class="wp-block-code"><code>副本數 = N ÷ (T × (60 ÷ Tb))
N：批次數（筆數 ÷ 每批筆數）
T：希望幾分鐘跑完
Tb：一個副本處理一批要幾秒</code></pre>



<p class="wp-block-paragraph">飲料店 50 萬名會員，每批 100 筆，希望 10 分鐘內跑完，實測一個副本 1 秒處理一批：</p>



<pre class="wp-block-code"><code>N = 500,000 ÷ 100 = 5,000 批
副本數 = 5,000 ÷ (10 × (60 ÷ 1)) = 5,000 ÷ 600 ≈ 8.3 → 9 個副本</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>官方的經驗值：幾千筆 → 副本數<strong>幾十</strong>；幾百萬筆 → <strong>幾百</strong></li>

<li>想 5 分鐘跑完就要 17 個副本，但每個副本啟動就要 5 分鐘，不划算。<strong>批次推論不是越快越好，是夠用就好</strong></li>

<li>跑完機器就收掉，<strong>沒有閒置費用</strong>。這就是流失名單用批次的理由：一週跑一次，每次十幾分鐘，其他時間一毛不花</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 不一定要用 Agent Platform 的端點</h2>



<p class="wp-block-paragraph">考試指南 4.1 列了四個部署的地方：「Agent Platform、Model Garden、Cloud Run、GKE」。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>地方</th><th>白話</th><th>什麼時候</th></tr></thead><tbody><tr><td><strong>Agent Platform 端點</strong></td><td>這篇講的，全代管的 ML 服務</td><td>自訂模型、AutoML 模型、要流量分割和監控（第 20 篇）</td></tr><tr><td><strong>Model Garden</strong></td><td>模型超市，Gemini 和開源模型（Llama、Gemma）一鍵部署</td><td>用現成的大模型，不自己訓練</td></tr><tr><td><strong>Cloud Run</strong></td><td>Google 的無伺服器容器平台，<a href="https://docs.cloud.google.com/run/docs/configuring/services/gpu">現在也有 GPU</a>（L4、RTX PRO 6000），<strong>沒流量可以縮到零</strong>，約 5 秒啟動</td><td>輕量的模型服務、自己包的 API、想省閒置費用</td></tr><tr><td><strong>GKE</strong></td><td>自己管 Kubernetes 叢集，站上有<a href="https://dongdonggcp.com/2026/07/21/what-is-kubernetes/">Kubernetes 是什麼</a></td><td>要完全控制、已經有 Kubernetes 團隊、超大規模</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">Cloud Run 的 GPU 規則：一個執行個體一張 GPU，L4 至少要配 4 個 CPU 和 16 GiB 記憶體，不用預留。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">線上推論的流程</h3>


<ol class="wp-block-list">
<li>模型進 <strong>Model Registry</strong>（匯入、AutoML 自動、BQML 註冊）</li>

<li>建<strong>端點</strong>（選專用公開，或 Private Service Connect）</li>

<li><strong>部署</strong>：選模型版本、機型、GPU、minReplicaCount／maxReplicaCount、流量比例</li>

<li>應用程式對端點網址送 <code>{"instances": [...]}</code>，拿到 <code>{"predictions": [...]}</code>。專用端點用 <code>use_dedicated_endpoint=True</code></li>

<li>換版本：加第二個模型到同一端點，調流量比例；或用滾動部署</li>

<li>不用了<strong>解除部署</strong>，不然副本一直算錢</li>
</ol>



<pre class="wp-block-code"><code>gcloud ai endpoints deploy-model ENDPOINT_ID \
  --region=asia-east1 \
  --model=MODEL_ID \
  --display-name=recsys-v2 \
  --machine-type=n1-standard-4 \
  --min-replica-count=2 \
  --max-replica-count=10 \
  --traffic-split=0=90,DEPLOYED_MODEL_V1_ID=10</code></pre>



<h3 class="wp-block-heading">批次推論的流程</h3>


<ol class="wp-block-list">
<li>模型在 Model Registry</li>

<li>資料整理成 BigQuery 表（或 JSON Lines、TFRecord 放 Cloud Storage），跟模型同區域</li>

<li>建 BatchPredictionJob：機型用小的、副本數用公式估</li>

<li>結果寫到 BigQuery 表或 Cloud Storage，行銷部門直接查</li>

<li>要定期跑，接 Cloud Scheduler 或 Pipelines（第 18、19 篇）</li>
</ol>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>AI Platform Prediction</td><td>2025 年 4 月關閉</td></tr><tr><td>Vertex AI Prediction、Vertex AI Endpoints</td><td>Gemini Enterprise Agent Platform <strong>Inference</strong></td></tr><tr><td>Online Prediction、Batch Prediction</td><td>Online Inference、Batch Inference（線上推論、批次推論）</td></tr><tr><td>Custom Prediction Routine（CPR）</td><td>Custom Inference Routine，縮寫 CPR 沿用</td></tr><tr><td>Vertex AI Model Registry</td><td>Gemini Enterprise Agent Platform Model Registry</td></tr><tr><td>Vertex AI Feature Store（線上特徵服務，<a href="https://dongdonggcp.com/2026/10/25/gcp-data-services-for-ml-bigquery-cloud-storage-feature-store-bigtable/">第 23 篇</a>）</td><td>舊版（Legacy）2027 年 2 月停用，改用 Feature Store V2</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 4 區：服務與擴展模型（約 20%）</td><td>4.1 用適當的服務（Agent Platform、Model Garden、Cloud Run、GKE）<strong>部署批次和線上推論</strong>；用預建和自訂容器打包不同框架的模型；在 <strong>Model Registry</strong> 組織和版本化模型；<strong>推出策略（A/B 測試、金絲雀部署）</strong>；<strong>推論的前處理和後處理</strong>。4.2 用 Feature Store 管理特徵；部署到<strong>公開和私人端點</strong>；選硬體（CPU、GPU、TPU、邊緣）；依吞吐量<strong>擴展服務後端</strong>；調整模型讓訓練和服務更有效率</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-04-exam-keywords.png" alt="PMLE 考試關鍵字：即時回應低延遲想到線上推論部署到端點、整批不急想到批次推論不用端點、新舊版本逐步切換想到流量分割金絲雀、不想走公網想到 Private Service Connect 端點、推論前後處理想到自訂推論例程 CPR、沒流量可縮到零想到 Cloud Run" class="wp-image-12855" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-04-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-04-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-04-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml17-04-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「即時」「App 回應」「低延遲」「同步」</td><td><strong>線上推論</strong>，部署到端點</td></tr><tr><td>「每天晚上」「整批」「不急」「幾百萬筆」「省錢」</td><td><strong>批次推論</strong>，不用端點</td></tr><tr><td>「新版本逐步切換」「不改應用程式網址」「先給 10%」</td><td><strong>流量分割</strong>（金絲雀）</td></tr><tr><td>「比較兩個版本的商業指標」</td><td><strong>A/B 測試</strong>，流量分割各 50%</td></tr><tr><td>「同一模型換版本、沿用機器、失敗自動退回」</td><td><strong>滾動部署</strong></td></tr><tr><td>「測試和正式環境分開」「不同 SLO」</td><td><strong>一個模型部署到多個端點</strong></td></tr><tr><td>「不經過公開網際網路」「內網呼叫」</td><td><strong>Private Service Connect 端點</strong></td></tr><tr><td>「請求超過 1.5 MB」「逾時超過 60 秒」「串流」</td><td><strong>專用公開端點</strong>（不是共用）</td></tr><tr><td>「尖峰時自動加機器」</td><td><strong>自動擴展</strong>，設 min／max replica，預設 60%</td></tr><tr><td>「推論前要整理資料、推論後要套規則」</td><td><strong>自訂推論例程（CPR）</strong>或自訂容器</td></tr><tr><td>「自訂容器的健康檢查」</td><td>健康路徑 10 秒內回 200，監聽 <code>AIP_HTTP_PORT</code></td></tr><tr><td>「沒流量時不想付錢的輕量 API」</td><td><strong>Cloud Run</strong>（縮到零）</td></tr><tr><td>「批次推論副本數」</td><td>小機型＋多副本，至少跑 10 分鐘，公式 N ÷ (T × 60 ÷ Tb)</td></tr><tr><td>「批次推論輸入是 CSV 很慢」</td><td>改 <strong>BigQuery 表或 JSON Lines</strong>（CSV 不能自動分區）</td></tr><tr><td>「模型不在清單裡不能部署」</td><td>先進 <strong>Model Registry</strong></td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>每週跑一次的名單用線上端點</strong>：副本 24 小時算錢，批次推論跑十幾分鐘就收掉</li>

<li><strong>要即時回應卻選批次</strong>：批次是非同步，App 等不到</li>

<li><strong>新版本直接全量換</strong>：沒有流量分割，出問題全部受影響</li>

<li><strong>私人端點（VPC 對等互連）想做流量分割</strong>：官方明寫一個私人端點只能一個模型、不支援流量分割；要私人又要分割，用 Private Service Connect 端點</li>

<li><strong>批次推論設了 max_replica_count 以為會自動擴展</strong>：批次不會，只看 starting_replica_count</li>

<li><strong>部署了忘記解除</strong>：測試完的端點放著，每個月默默扣錢</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店的推薦模型要在 App 裡即時顯示，尖峰在中午和晚上，半夜幾乎沒人用。工程師部署了 v2，想先確認不會比 v1 差。應該怎麼做？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「即時」→ <strong>線上推論</strong>，專用公開端點</li>

<li>「尖峰、半夜沒人」→ <strong>自動擴展</strong>，minReplicaCount 設小（例如 1 或 2）、maxReplicaCount 設大</li>

<li>「先確認 v2」→ <strong>流量分割</strong>，v1 90%、v2 10%，看點擊率，沒問題再加</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">行銷部門每週一早上要一張「可能流失的會員」名單，50 萬名會員的特徵表在 BigQuery。應該怎麼做？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「每週一次」「整張表」→ <strong>批次推論</strong>，不用端點</li>

<li>「BigQuery」→ 輸入直接指定 BigQuery 表，輸出也寫 BigQuery</li>

<li>副本數用公式估，小機型、跑 10 分鐘左右；接 Cloud Scheduler 每週自動跑</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">公司的 ERP 系統（在自家機房）要呼叫模型，資安要求不能經過公開網際網路，而且之後要能做新舊版本的流量分割。應該用哪種端點？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「不經過公網」→ 私人的兩種</li>

<li>「要流量分割」→ 私人端點（VPC 對等互連）<strong>不支援</strong>，選 <strong>Private Service Connect 專用私人端點</strong></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">模型部署怎麼選線上預測還是批次預測？</h3>



<p class="wp-block-paragraph">看要不要馬上拿到答案。應用程式要即時回應（App 一打開就推薦、客服機器人回話）用線上推論：先把模型部署到端點，機器一直開著，同步回應。一次處理累積的大量資料、不急著要（每週名單、每晚重算分數）用批次推論：不用端點，建一個批次推論工作，臨時開機器算完寫到 BigQuery 或 Cloud Storage，機器收掉。線上端點只要部署著就算錢，批次只付跑的時間。</p>



<h3 class="wp-block-heading">端點是什麼？有哪幾種？</h3>



<p class="wp-block-paragraph">端點是部署好的模型對外的網址，應用程式把資料送過去就拿到預測。四種：專用公開端點（推薦，10 MB、逾時可到 1 小時、串流、流量隔離）、共用公開端點（1.5 MB、60 秒、每分鐘 30,000 次）、Private Service Connect 專用私人端點（推薦，內網、不走公網、支援流量分割）、私人端點（VPC 對等互連，一個端點只能一個模型、不支援流量分割）。專用公開端點不支援 VPC Service Controls。</p>



<h3 class="wp-block-heading">流量分割是什麼？怎麼做金絲雀部署？</h3>



<p class="wp-block-paragraph">同一個端點放兩個以上的模型，設定每個接多少比例的請求。金絲雀部署是新版本先接一小部分（例如 10%），看商業指標沒問題再逐步加到 100%，應用程式不用改網址。A/B 測試則是兩版各接一半，比較哪個指標好。要換同一個模型的新版本、沿用原本機器，可以用滾動部署（預覽），健康檢查失敗會自動退回。</p>



<h3 class="wp-block-heading">自動擴展怎麼運作？</h3>



<p class="wp-block-paragraph">你設最少和最多副本數，Agent Platform 依使用率自動增減。預設目標是 CPU 使用率 60%，有 GPU 則看 CPU 或 GPU 較高者；可以改成 GPU duty cycle 之類的指標和目標。每 15 秒用公式「向上取整（目前副本數 × 目前使用率 ÷ 目標使用率）」算目標，但採用過去 5 分鐘內最高的目標，所以加機器快、減機器慢。縮到零目前是預覽功能。批次推論不會自動擴展。</p>



<h3 class="wp-block-heading">批次推論的副本數要設多少？</h3>



<p class="wp-block-paragraph">官方建議用最小的機型、靠增加副本數提高吞吐量，而且工作至少跑 10 分鐘才划算，因為每個副本啟動約 5 分鐘也計費。公式是副本數 = 批次數 ÷（希望的分鐘數 × 60 ÷ 一個副本處理一批的秒數）。例如 50 萬筆、每批 100 筆、10 分鐘、每批 1 秒，算出約 9 個副本。幾千筆大約幾十個副本，幾百萬筆大約幾百個。</p>



<h3 class="wp-block-heading">自訂推論例程（CPR）是什麼？</h3>



<p class="wp-block-paragraph">介於預建容器和自訂容器之間：你只寫前處理和後處理的 Python 程式（實作 Predictor 介面，需要時再加 Handler），HTTP 伺服器和 Dockerfile 由 Agent Platform SDK 幫你產生，還能先在本機部署測試。前處理像把輸入標準化、呼叫外部服務補資料，後處理像把模型輸出轉成業務格式或套商業規則。考試指南 4.1 的「推論前處理和後處理」就是指這個。</p>



<h3 class="wp-block-heading">自訂推論容器有什麼要求？</h3>



<p class="wp-block-paragraph">要自己跑一個 HTTP 伺服器，監聽 AIP_HTTP_PORT 環境變數指定的埠；提供健康檢查路徑，10 秒內回 200 才算健康，否則會被視為不健康；提供推論路徑，請求格式是 {&#8220;instances&#8221;: [&#8230;]}，回應是 {&#8220;predictions&#8221;: [&#8230;]}。映像檔要放在 Artifact Registry。</p>



<h3 class="wp-block-heading">一定要用 Vertex AI 的端點嗎？</h3>



<p class="wp-block-paragraph">不一定。考試指南列了四個地方：Agent Platform 端點（全代管、有流量分割和監控）、Model Garden（Gemini 和開源模型一鍵部署）、Cloud Run（無伺服器容器，有 L4 和 RTX PRO 6000 GPU，沒流量可縮到零，適合輕量服務）、GKE（自己管 Kubernetes，要完全控制或超大規模）。輕量 API 想省閒置費用，Cloud Run 常是更便宜的選擇。</p>



<h3 class="wp-block-heading">部署後哪些設定可以改？</h3>



<p class="wp-block-paragraph">官方說部署時決定的區域、容器、運算資源部署後不能改，要改就重新部署。例外是擴展設定：最少副本數、最多副本數、必要副本數和擴展指標可以用 mutateDeployedModel 直接改，不用重新部署；機型不能改。</p>



<h3 class="wp-block-heading">Vertex AI Endpoints 改名了嗎？</h3>



<p class="wp-block-paragraph">是。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，Vertex AI Prediction 和 Endpoints 現在叫 Agent Platform Inference，Online Prediction 和 Batch Prediction 改稱 Online Inference 和 Batch Inference，Model Registry 改叫 Agent Platform Model Registry。更早的 AI Platform Prediction 已在 2025 年 4 月 7 日關閉，所有模型和部署都已刪除。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>兩種推論</strong>：<strong>線上</strong>（同步、先部署到端點、低延遲、機器一直算錢）vs <strong>批次</strong>（非同步、不用端點、處理累積資料、跑完收機器）</li>

<li><strong>部署的三件事</strong>：端點決定區域、模型決定容器、DeployedModel 決定機器；部署後只有擴展設定能改</li>

<li><strong>端點四種</strong>：專用公開（推薦）、共用公開（1.5 MB、60 秒）、Private Service Connect（推薦，內網）、私人（VPC 對等互連，不能流量分割）</li>

<li><strong>流量分割</strong>：同一端點多模型；<strong>金絲雀</strong> 90／10 逐步加，<strong>A/B</strong> 各 50；一模型多端點分測試／正式；<strong>滾動部署</strong>換版本沿用機器</li>

<li><strong>自動擴展</strong>：預設 60%，目標副本 = 向上取整（目前 × 使用率 ÷ 目標）；每 15 秒看 5 分鐘最高；批次不自動擴展</li>

<li><strong>批次副本數</strong>：小機型多副本、至少跑 10 分鐘；N ÷ (T × 60 ÷ Tb)</li>

<li><strong>容器</strong>：預建、自訂（AIP_HTTP_PORT、健康檢查 10 秒）、<strong>CPR</strong> 只寫前後處理</li>

<li><strong>別的地方</strong>：Model Garden、<strong>Cloud Run</strong>（GPU、縮到零）、GKE；Vertex AI Prediction 現在叫 <strong>Agent Platform Inference</strong></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>上一篇：第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>

<li>下一篇：第 18 篇：<a href="https://dongdonggcp.com/2026/10/25/what-is-mlops-vertex-ai-pipelines-kubeflow-tfx/">MLOps 是什麼？Vertex AI Pipelines、Kubeflow、TFX 介紹</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2026/07/29/what-is-container-technology-docker-guide/">容器技術是什麼？從零開始看懂 Docker 與容器化應用</a></li>

<li><a href="https://dongdonggcp.com/2026/07/21/what-is-kubernetes/">Kubernetes 是什麼？白話解釋＋判斷你是否真的需要它</a></li>

<li><a href="https://dongdonggcp.com/2025/04/14/vertex-ai-functions-agent-builder-model-builder-model-garden-introduction/">Vertex AI 核心功能 Agent Builder、Model Builder 和 Model Garden 介紹</a></li>

<li><a href="https://dongdonggcp.com/2026/04/21/gcp-cloud-armor-complete-guide-features-setup-rules/">GCP Cloud Armor 完整教學</a></li>

<li><a href="https://dongdonggcp.com/2026/05/19/gcp-bill-explosion-prevention-guide/">GCP 帳單爆炸防護指南</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">模型上線的方式選對，帳單和使用者體驗才會都好看。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "模型部署怎麼選線上預測還是批次預測？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "看要不要馬上拿到答案。應用程式要即時回應（App 一打開就推薦、客服機器人回話）用線上推論：先把模型部署到端點，機器一直開著，同步回應。一次處理累積的大量資料、不急著要（每週名單、每晚重算分數）用批次推論：不用端點，建一個批次推論工作，臨時開機器算完寫到 BigQuery 或 Cloud Storage，機器收掉。線上端點只要部署著就算錢，批次只付跑的時間。"
      }
    },
    {
      "@type": "Question",
      "name": "端點是什麼？有哪幾種？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "端點是部署好的模型對外的網址，應用程式把資料送過去就拿到預測。四種：專用公開端點（推薦，10 MB、逾時可到 1 小時、串流、流量隔離）、共用公開端點（1.5 MB、60 秒、每分鐘 30,000 次）、Private Service Connect 專用私人端點（推薦，內網、不走公網、支援流量分割）、私人端點（VPC 對等互連，一個端點只能一個模型、不支援流量分割）。專用公開端點不支援 VPC Service Controls。"
      }
    },
    {
      "@type": "Question",
      "name": "流量分割是什麼？怎麼做金絲雀部署？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "同一個端點放兩個以上的模型，設定每個接多少比例的請求。金絲雀部署是新版本先接一小部分（例如 10%），看商業指標沒問題再逐步加到 100%，應用程式不用改網址。A/B 測試則是兩版各接一半，比較哪個指標好。要換同一個模型的新版本、沿用原本機器，可以用滾動部署（預覽），健康檢查失敗會自動退回。"
      }
    },
    {
      "@type": "Question",
      "name": "自動擴展怎麼運作？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "你設最少和最多副本數，Agent Platform 依使用率自動增減。預設目標是 CPU 使用率 60%，有 GPU 則看 CPU 或 GPU 較高者；可以改成 GPU duty cycle 之類的指標和目標。每 15 秒用公式「向上取整（目前副本數 × 目前使用率 ÷ 目標使用率）」算目標，但採用過去 5 分鐘內最高的目標，所以加機器快、減機器慢。縮到零目前是預覽功能。批次推論不會自動擴展。"
      }
    },
    {
      "@type": "Question",
      "name": "批次推論的副本數要設多少？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "官方建議用最小的機型、靠增加副本數提高吞吐量，而且工作至少跑 10 分鐘才划算，因為每個副本啟動約 5 分鐘也計費。公式是副本數 = 批次數 ÷（希望的分鐘數 × 60 ÷ 一個副本處理一批的秒數）。例如 50 萬筆、每批 100 筆、10 分鐘、每批 1 秒，算出約 9 個副本。幾千筆大約幾十個副本，幾百萬筆大約幾百個。"
      }
    },
    {
      "@type": "Question",
      "name": "自訂推論例程（CPR）是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "介於預建容器和自訂容器之間：你只寫前處理和後處理的 Python 程式（實作 Predictor 介面，需要時再加 Handler），HTTP 伺服器和 Dockerfile 由 Agent Platform SDK 幫你產生，還能先在本機部署測試。前處理像把輸入標準化、呼叫外部服務補資料，後處理像把模型輸出轉成業務格式或套商業規則。考試指南 4.1 的「推論前處理和後處理」就是指這個。"
      }
    },
    {
      "@type": "Question",
      "name": "自訂推論容器有什麼要求？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "要自己跑一個 HTTP 伺服器，監聽 AIP_HTTP_PORT 環境變數指定的埠；提供健康檢查路徑，10 秒內回 200 才算健康，否則會被視為不健康；提供推論路徑，請求格式是 {\"instances\": [...]}，回應是 {\"predictions\": [...]}。映像檔要放在 Artifact Registry。"
      }
    },
    {
      "@type": "Question",
      "name": "一定要用 Vertex AI 的端點嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "不一定。考試指南列了四個地方：Agent Platform 端點（全代管、有流量分割和監控）、Model Garden（Gemini 和開源模型一鍵部署）、Cloud Run（無伺服器容器，有 L4 和 RTX PRO 6000 GPU，沒流量可縮到零，適合輕量服務）、GKE（自己管 Kubernetes，要完全控制或超大規模）。輕量 API 想省閒置費用，Cloud Run 常是更便宜的選擇。"
      }
    },
    {
      "@type": "Question",
      "name": "部署後哪些設定可以改？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "官方說部署時決定的區域、容器、運算資源部署後不能改，要改就重新部署。例外是擴展設定：最少副本數、最多副本數、必要副本數和擴展指標可以用 mutateDeployedModel 直接改，不用重新部署；機型不能改。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex AI Endpoints 改名了嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "是。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，Vertex AI Prediction 和 Endpoints 現在叫 Agent Platform Inference，Online Prediction 和 Batch Prediction 改稱 Online Inference 和 Batch Inference，Model Registry 改叫 Agent Platform Model Registry。更早的 AI Platform Prediction 已在 2025 年 4 月 7 日關閉，所有模型和部署都已刪除。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</title>
		<link>https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vertex-ai-custom-training-containers-distributed-gpu-tpu</link>
					<comments>https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:42:30 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12851</guid>

					<description><![CDATA[<p>Vertex AI 自訂訓練怎麼做？預建容器還是自訂容器、CustomJob 怎麼設機型和 GPU、CPU／GPU／TPU 怎麼選、多台機器怎麼分工、4 張 GPU 省多少時間和錢算一次，附 Spot VM、超參數調校與 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>Vertex AI 自訂訓練是把訓練程式打包成容器，交給 Agent Platform 開機器、裝 GPU 或 TPU、跑完收機器。</strong></p>



<p class="wp-block-paragraph">第 14 篇說，AutoML 和 BigQuery ML 做不到的事（自訂架構、特定框架、幾十張 GPU）就走自訂訓練。這篇把它拆開：程式怎麼打包、機器怎麼選、多台怎麼分工、超參數怎麼自動調、要花多少錢。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店的連鎖飲料店當例子（教學假設）：研究團隊用 <strong>PyTorch</strong> 寫好了「猜你想點」推薦模型，有自訂的損失函數，資料是 50 萬名會員三年的交易紀錄，放在 Cloud Storage。現在要把它放到雲端上跑。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-01-flow.png" alt="Vertex AI 自訂訓練流程：寫訓練程式、打包成容器推到 Artifact Registry、建 CustomJob 指定機型 GPU 和台數、Agent Platform 開機器跑完收機器、模型存到 Cloud Storage 再註冊到 Model Registry" class="wp-image-12845" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-01-flow.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-01-flow-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-01-flow-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-01-flow-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>GPU 很貴，選錯更貴</strong>：一張高階 GPU 一小時的租金，比一台普通機器一天還貴。機型選錯、該用 Spot 沒用、4 張 GPU 跑出 1 張的效果，錢就這樣燒掉</li>

<li><strong>這是「自己煮」的那條路</strong>：第 14 篇的比喻，Google 只出爐子。爐子有幾種、怎麼開、幾個人一起炒，都要自己決定</li>

<li><strong>筆記裡的名稱全改了</strong>：Vertex AI Training 現在叫 Agent Platform Managed Training，底下分無伺服器訓練和訓練叢集；更早的 AI Platform Training 已經在 2025 年 4 月關閉</li>

<li><strong>證照必考</strong>：PMLE 考試指南第 3.2 節「用不同 SDK 訓練模型（Agent Platform 自訂訓練、GKE 上的 Kubeflow…）」「排除訓練失敗」「超參數調校」，第 3.3 節「評估 CPU、GPU、TPU」「GPU 和 TPU 上的資料平行與模型平行分散式訓練」。整個第 3 區佔 21%，是最大的一區</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：自訂訓練是什麼</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>自訂訓練</strong>（custom training）：你自己寫訓練程式，用任何框架；Agent Platform 負責開虛擬機器、裝加速器、把你的程式跑起來、跑完把機器收掉，只收用到的時間。</p>



<p class="wp-block-paragraph"><strong>虛擬機器</strong>（VM）是雲端上租來的一台電腦，站上有一篇 <a href="https://dongdonggcp.com/2024/10/23/what-is-google-vm-compute-engine-introduction/">Compute Engine 是什麼</a>。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">自己煮，但廚房是租的、按小時算。你帶著食譜（程式）和食材（資料）進去，想用幾個爐（GPU）、幾間廚房（機器）自己說，煮完走人，只付用到的時間。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">官方<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/containers-overview">容器總覽</a>描述的流程：</p>


<ol class="wp-block-list">
<li>用你選的框架寫訓練程式</li>

<li>決定用<strong>預建容器</strong>還是<strong>自訂容器</strong></li>

<li>資料放在 Agent Platform 讀得到的地方（Cloud Storage、Bigtable），<strong>跟訓練同一個專案和區域</strong></li>

<li>建好 Docker 映像檔，推到 Artifact Registry</li>

<li>建<strong>自訂工作</strong>（CustomJob）送出</li>

<li>Agent Platform 依設定開一台或多台機器（叫訓練執行個體），跑你的映像檔</li>

<li>成功或遇到無法復原的錯誤，就停掉所有程序、清掉資源</li>
</ol>



<p class="wp-block-paragraph">名稱的演變：最早叫 <strong>AI Platform Training</strong>（舊題庫還看得到，<a href="https://docs.cloud.google.com/vertex-ai/docs/deprecations">官方淘汰清單</a>寫 2025 年 4 月 7 日關閉）→ <strong>Vertex AI custom training</strong> → 2026 年 4 月起叫 <strong>Gemini Enterprise Agent Platform Managed Training</strong>，底下分兩種跑法（第 6 節）。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">這是 PMLE 第 3 區的主軸，也是「能不能真的把一個研究模型放上雲端」的分水嶺。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 容器：預建的還是自己做</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>容器</strong>（container）：把程式和它需要的所有東西（框架、函式庫、系統工具）打包成一個標準箱子，到哪台機器都能原樣跑。<strong>Docker</strong> 是做這種箱子最常用的工具，箱子的設計圖叫 <strong>Dockerfile</strong>，做好的箱子叫<strong>映像檔</strong>（image）。站上有一篇<a href="https://dongdonggcp.com/2026/07/29/what-is-container-technology-docker-guide/">容器是什麼</a>。</p>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">出國比賽的行李箱。裡面裝好球拍、球鞋、水壺，到了場地打開就能上場，不用在當地到處找器材。</p>



<h3 class="wp-block-heading">預建容器：Google 幫你裝好了</h3>



<p class="wp-block-paragraph">Google 提供<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/pre-built-containers">預建容器</a>，常用框架都有：<strong>TensorFlow、PyTorch、scikit-learn、XGBoost</strong>，分 CPU 和 GPU 版本，映像檔名稱像 <code>pytorch-gpu.2-x</code>、<code>tf-gpu.2-17</code>、<code>xgboost-cpu.2-1</code>。</p>



<p class="wp-block-paragraph">用預建容器時，你不用碰 Docker，只要把訓練程式打包成 Python 套件放到 Cloud Storage，建工作時指定「用哪個預建容器」就好。</p>



<h3 class="wp-block-heading">自訂容器：四種情況才需要</h3>



<p class="wp-block-paragraph">官方容器總覽列的好處，反過來就是「什麼時候要自己做」：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>情況</th><th>例子</th></tr></thead><tbody><tr><td><strong>預建容器沒有你要的框架或版本</strong></td><td>要用 tf-nightly 這種最新版、要用 JAX</td></tr><tr><td><strong>有非 ML 的相依套件或二進位檔</strong></td><td>程式要呼叫某個 C++ 工具</td></tr><tr><td><strong>想要更快啟動</strong></td><td>相依套件事先裝好，不用每次啟動再裝</td></tr><tr><td><strong>用任意框架做分散式訓練</strong></td><td>預建容器以外的框架要多台跑</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">套回飲料店：研究團隊的 PyTorch 模型如果只用標準套件，<strong>預建的 PyTorch GPU 容器就夠</strong>；如果用了特殊的推薦系統函式庫，就要自訂。</p>



<p class="wp-block-paragraph"><strong>做 GPU 容器有一個特別要求</strong>：官方建議用 <code>nvidia/cuda</code> 當基底映像檔，裡面已經裝好對應版本的 CUDA 和 cuDNN（NVIDIA 讓程式能用 GPU 的兩個基礎套件），環境變數也設好了。</p>



<h3 class="wp-block-heading">自訂容器的流程</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/create-custom-container">官方步驟</a>：寫 Dockerfile（裝相依套件、複製訓練程式、設定進入點）→ 本機 build → 推到 <strong>Artifact Registry</strong>（Google 的映像檔倉庫，可以想成放 Docker 箱子的雲端儲物櫃）→ 建工作時用這個映像檔的網址。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">考題看到「預建容器不支援的框架」「特定版本」「非 ML 相依」就是自訂容器；看到「標準 TensorFlow／PyTorch 程式、最少設定」就是預建容器。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. CustomJob：告訴 Google 要幾台、什麼機器</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>自訂工作</strong>（CustomJob）是一張「訂單」，寫清楚：用哪個容器、幾台機器、每台什麼規格、幾張 GPU、跑多久要停。</p>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/create-custom-job">官方文件</a>的核心欄位是 <strong>WorkerPoolSpec</strong>（工作池規格）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>欄位</th><th>白話</th><th>飲料店的推薦模型</th></tr></thead><tbody><tr><td><code>machineSpec.machineType</code></td><td>機型（CPU 幾核、記憶體多大）</td><td><code>n1-standard-16</code></td></tr><tr><td><code>machineSpec.acceleratorType</code></td><td>GPU 或 TPU 的種類</td><td><code>NVIDIA_TESLA_T4</code></td></tr><tr><td><code>machineSpec.acceleratorCount</code></td><td>每台機器幾張</td><td>2</td></tr><tr><td><code>replicaCount</code></td><td>這種機器開幾台</td><td>1</td></tr><tr><td><code>containerSpec.imageUri</code> 或 <code>pythonPackageSpec</code></td><td>自訂容器的映像檔，或預建容器＋Python 套件</td><td>預建 PyTorch GPU 容器</td></tr><tr><td><code>scheduling.timeout</code></td><td>最多跑多久</td><td>12 小時</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">用指令建一個工作長這樣：</p>



<pre class="wp-block-code"><code>gcloud ai custom-jobs create \
  --region=asia-east1 \
  --display-name=drink-recsys \
  --worker-pool-spec=machine-type=n1-standard-16,replica-count=1,accelerator-type=NVIDIA_TESLA_T4,accelerator-count=2,executor-image-uri=asia-docker.pkg.dev/vertex-ai/training/pytorch-gpu.2-4.py310:latest,local-package-path=.,script=train.py</code></pre>



<h3 class="wp-block-heading">程式裡拿得到的環境變數</h3>



<p class="wp-block-paragraph">訓練程式不用寫死路徑，Agent Platform 會給三個<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/code-requirements">環境變數</a>（程式啟動時可以讀到的設定值）：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>變數</th><th>用途</th></tr></thead><tbody><tr><td><code>AIP_MODEL_DIR</code></td><td>訓練完的模型存這裡（Cloud Storage 路徑），之後上傳到 Model Registry 會直接用</td></tr><tr><td><code>AIP_CHECKPOINT_DIR</code></td><td>存<strong>檢查點</strong>（訓練中途的進度存檔）</td></tr><tr><td><code>AIP_TENSORBOARD_LOG_DIR</code></td><td>存 TensorBoard 的紀錄（<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-experiments-ml-metadata-tensorboard-experiment-tracking/">第 22 篇</a>）</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">資料怎麼讀，第 13 篇講過：Cloud Storage 會掛在 <code>/gcs/</code> 底下。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. CPU、GPU 還是 TPU：怎麼選</h2>



<h3 class="wp-block-heading">三種硬體的白話</h3>


<ul class="wp-block-list">
<li><strong>CPU</strong>：電腦的大腦，什麼都會做，但同時只能做幾件事</li>

<li><strong>GPU</strong>：原本畫遊戲畫面的晶片，擅長同時做幾千個簡單算術，NVIDIA 做的最常見</li>

<li><strong>TPU</strong>：Google 自己設計、專門做機器學習的晶片。<a href="https://docs.cloud.google.com/tpu/docs/intro-to-tpu">官方簡介</a>說它專門做「大型矩陣運算」，有晶片上的高頻寬記憶體，可以接成一組（叫 slice）擴大規模。程式要先經過 <strong>XLA</strong> 編譯器翻成 TPU 能跑的機器碼</li>
</ul>



<p class="wp-block-paragraph"><strong>矩陣運算</strong>可以想成「一大批數字同時相乘相加」，神經網路的每一層就是在做這件事。</p>



<h3 class="wp-block-heading">官方的選擇指南</h3>



<p class="wp-block-paragraph">Cloud TPU 簡介直接列了三種硬體各適合什麼：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th>適合的情況</th></tr></thead><tbody><tr><td><strong>CPU</strong></td><td>快速原型、需要最大彈性；小模型、訓練不久；很多自訂 C++ 運算；被 I/O 或網路頻寬卡住的模型</td></tr><tr><td><strong>GPU</strong></td><td>有很多自訂 PyTorch／JAX 運算、要部分在 CPU 跑；用到 TPU 不支援的 TensorFlow 運算；中大型模型、較大的批次</td></tr><tr><td><strong>TPU</strong></td><td>以矩陣運算為主；主訓練迴圈裡沒有自訂運算；要訓練幾週幾個月；大模型、大批次；進階推薦和排序系統常見的超大嵌入</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">TPU <strong>不適合</strong>：需要頻繁分支或大量逐元素運算的程式、需要高精度算術、主訓練迴圈有自訂運算。</p>



<p class="wp-block-paragraph">套回飲料店：推薦模型有<strong>自訂損失函數</strong>（自訂運算）、用 PyTorch，而且不是訓練幾週的規模 → <strong>GPU</strong>。要是改成標準架構、資料大到要訓練好幾天，才考慮 TPU。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-02-hardware.png" alt="CPU、GPU、TPU 怎麼選：CPU 適合快速原型和小模型，GPU 適合有自訂運算的中大型模型，TPU 適合矩陣運算為主、沒有自訂運算、要訓練數週的大模型和超大嵌入；TPU 不適合分支多、高精度、自訂運算" class="wp-image-12846" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-02-hardware.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-02-hardware-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-02-hardware-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-02-hardware-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">GPU 有哪些、怎麼搭機型</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/configure-compute">官方運算資源文件</a>列的 GPU（2026 年 10 月）：從入門的 <strong>T4、L4</strong>，到 <strong>V100、A100（40GB／80GB）</strong>，再到 <strong>H100、H200、B200、GB200</strong> 這些訓練大型語言模型用的。P100 在 2026 年 9 月 15 日停止支援。</p>



<p class="wp-block-paragraph">三個規則：</p>


<ul class="wp-block-list">
<li><strong>GPU 要配對的機型</strong>：A2、N1 或 G2 系列。例如 A100 配 <code>a2-highgpu-1g</code>（1 張）到 <code>a2-megagpu-16g</code>（16 張），L4 配 <code>g2-standard-*</code>，T4、V100 配 <code>n1-*</code></li>

<li><strong>張數有固定選項</strong>：T4 可以 2 張或 4 張，<strong>不能 3 張</strong></li>

<li><strong>機型要撐得起 GPU</strong>：官方的例子是 <code>n1-standard-32</code>（32 核、120 GB 記憶體）配 V100 至少要 4 張，因為每張 V100 最多只能搭配 12 核、76 GB，2 張不夠、3 張不行</li>

<li>機型太小（例如 <code>n1-highmem-2</code>）配 GPU，CPU 不夠可能連日誌都寫不出來</li>
</ul>



<h3 class="wp-block-heading">TPU 的設定方式</h3>



<p class="wp-block-paragraph">TPU 在自訂訓練裡<strong>只能用一個工作池、一個副本</strong>。各世代的設定：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>世代</th><th>機型</th><th>備註</th></tr></thead><tbody><tr><td>v2、v3</td><td><code>cloud-tpu</code>＋<code>TPU_V2</code>／<code>TPU_V3</code>，count 8（單顆）或 32 的倍數（Pod）</td><td>第 13 篇講的「8 核心」就是這個</td></tr><tr><td>v5e</td><td><code>ct5lp-hightpu-1t</code>／<code>4t</code>／<code>8t</code>＋<code>tpuTopology</code></td><td>需要 JAX 0.4.6+、TensorFlow 2.15+、PyTorch 2.1+</td></tr><tr><td>v6e</td><td><code>ct6e</code>＋<code>tpuTopology</code></td><td>需要 Python 3.10+</td></tr><tr><td>7x</td><td><code>tpu7x-standard-4t</code>＋<code>tpuTopology</code></td><td>需要 Python 3.12+</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">控制費用的三個開關</h3>



<p class="wp-block-paragraph">官方運算資源文件開頭就講「管理成本與可用性」：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>開關</th><th>白話</th><th>代價</th></tr></thead><tbody><tr><td><strong>Spot VM</strong></td><td>用 Google 多出來的閒置機器，<strong>大幅折扣</strong></td><td>隨時可能被收回，程式要會存檢查點、重啟後接著跑</td></tr><tr><td><strong>預留</strong>（Reservation）</td><td>先訂好機器，保證有</td><td>訂了就算錢</td></tr><tr><td><strong>Dynamic Workload Scheduler</strong></td><td>要 GPU 的工作先排隊，等有空再跑</td><td>不能馬上開始</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">Spot 和 Dynamic Workload Scheduler 都是在 CustomJob 的 <code>scheduling.strategy</code> 設定。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 分散式訓練：多台一起跑</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph">一台機器、一張 GPU 跑太慢，就讓很多台一起跑。分兩種分法：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>資料平行</strong>（data parallelism）</th><th><strong>模型平行</strong>（model parallelism）</th></tr></thead><tbody><tr><td>白話</td><td>每台拿到<strong>完整的模型</strong>，但各算<strong>不同的資料</strong></td><td>模型太大一台裝不下，<strong>切成幾塊</strong>放不同機器</td></tr><tr><td>比喻</td><td>四個廚師各做同一道菜，食材分四份</td><td>一道菜太複雜，前菜一個人、主菜一個人</td></tr><tr><td>什麼時候</td><td>絕大多數情況</td><td>大型語言模型這種記憶體裝不下的</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">考試指南 3.3 兩個詞都點名了，但考題以資料平行為主。</p>



<h3 class="wp-block-heading">同步還是非同步</h3>



<p class="wp-block-paragraph">TensorFlow 的<a href="https://www.tensorflow.org/guide/distributed_training">分散式指南</a>把資料平行再分兩種：</p>


<ul class="wp-block-list">
<li><strong>同步</strong>：所有機器各算一批，<strong>等大家都算完</strong>，把梯度（第 3 篇講的「該往哪調」）加總平均，一起更新。靠 <strong>all-reduce</strong> 演算法交換梯度，GPU 之間預設用 NVIDIA 的 <strong>NCCL</strong> 函式庫</li>

<li><strong>非同步</strong>：各機器自己算、自己更新，靠<strong>參數伺服器</strong>（parameter server）存共同的模型參數。快但不穩</li>
</ul>



<h3 class="wp-block-heading">常見的策略</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>框架</th><th>策略</th><th>情況</th></tr></thead><tbody><tr><td>TensorFlow</td><td><code>MirroredStrategy</code></td><td><strong>一台機器、多張 GPU</strong>，同步</td></tr><tr><td>TensorFlow</td><td><code>MultiWorkerMirroredStrategy</code></td><td><strong>多台機器、各多張 GPU</strong>，同步。筆記點名的就是它</td></tr><tr><td>TensorFlow</td><td><code>TPUStrategy</code></td><td>TPU 上，跟 MirroredStrategy 同一套邏輯</td></tr><tr><td>TensorFlow</td><td><code>ParameterServerStrategy</code></td><td>非同步、參數伺服器架構</td></tr><tr><td>PyTorch</td><td><code>DistributedDataParallel</code>（DDP）</td><td>多 GPU、多機器的同步資料平行</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Agent Platform 怎麼分工</h3>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/distributed-training">官方分散式訓練文件</a>：你在 CustomJob 裡列出<strong>最多四個工作池</strong>（<code>workerPoolSpecs[]</code>），<strong>順序決定角色</strong>：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>位置</th><th>角色</th><th>做什麼</th></tr></thead><tbody><tr><td><code>workerPoolSpecs[0]</code></td><td><strong>主要副本</strong>（primary、chief）</td><td>一定要有、只能一個。協調其他機器、回報整個工作的狀態</td></tr><tr><td><code>workerPoolSpecs[1]</code></td><td><strong>工作者</strong>（workers）</td><td>各做自己那一份</td></tr><tr><td><code>workerPoolSpecs[2]</code></td><td><strong>參數伺服器</strong>或 <strong>Reduction Server</strong></td><td>存模型參數、協調共享狀態</td></tr><tr><td><code>workerPoolSpecs[3]</code></td><td><strong>評估者</strong>（evaluators）</td><td>負責評估，TensorFlow 通常只用一個</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">Agent Platform 會把這個結構寫進 <code>CLUSTER_SPEC</code> 或 <code>TF_CONFIG</code> 環境變數，程式讀它就知道自己是誰、同伴在哪。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-03-distributed.png" alt="分散式訓練的角色：workerPoolSpecs 第 0 個是主要副本負責協調，第 1 個是工作者各算一份資料，第 2 個是參數伺服器或 Reduction Server，第 3 個是評估者；同步訓練用 all-reduce 交換梯度" class="wp-image-12847" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-03-distributed.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-03-distributed-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-03-distributed-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-03-distributed-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">Reduction Server：讓 GPU 少花時間傳梯度</h3>



<p class="wp-block-paragraph">多台 GPU 同步訓練時，每一步都要把梯度傳來傳去，機器越多、傳得越久。Google 的 <strong>Reduction Server</strong> 是專門幫忙「加總梯度」的一群便宜機器，讓 GPU 專心算。</p>



<p class="wp-block-paragraph">官方的條件：GPU 工作者、TensorFlow 或 PyTorch 的多機訓練、容器要支援（預建的 TF／PyTorch 容器，或自訂容器裝 NCCL 2.7 以上和 Google 的 fast socket）。做法是在<strong>第三個工作池</strong>放 Reduction Server 的映像檔（<code>asia-docker.pkg.dev/vertex-ai-restricted/training/reductionserver:latest</code>），<strong>不用 GPU</strong>，官方建議用 <code>n1-highcpu-16</code> 這種頻寬高的機型，而且 reducer 的總出口頻寬要跟 worker 相當。</p>



<h3 class="wp-block-heading">算一次給你看：多 GPU 到底省多少</h3>



<p class="wp-block-paragraph">飲料店的推薦模型，單張 T4 要跑 <strong>10 小時</strong>。改成 4 張 GPU 做同步資料平行（數字是教學假設）：</p>



<pre class="wp-block-code"><code>理想狀況：10 小時 ÷ 4 = 2.5 小時
實際有梯度交換的開銷，假設效率 85%
實際時間 = 10 ÷ (4 × 0.85) ≈ 2.9 小時</code></pre>



<p class="wp-block-paragraph">費用（假設一張 GPU 每小時 100 元，教學假設）：</p>



<pre class="wp-block-code"><code>1 張 × 10 小時 × 100 元 = 1,000 元
4 張 × 2.9 小時 × 100 元 = 1,176 元
多付 18%，換 3.4 倍快</code></pre>



<p class="wp-block-paragraph">再開 Spot VM（假設打 6 折）：</p>



<pre class="wp-block-code"><code>1,176 × 0.6 ≈ 706 元
比單張全價還便宜，而且快 3.4 倍</code></pre>



<p class="wp-block-paragraph"><strong>批次大小也要跟著變</strong>：每張 GPU 一批 64 張，4 張同時算，<strong>全局批次</strong>變成 64 × 4 = 256。批次變大，常見的做法是學習率（第 3 篇）也按比例調大，不然收斂會變慢。</p>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>效率 85% 是「梯度交換」吃掉的，機器越多、網路越慢，這個數字越低。Reduction Server 就是在拉高它</li>

<li>加 GPU 不會無限變快：16 張時效率可能掉到 60%，10 ÷ (16 × 0.6) ≈ 1 小時，但費用 16 × 1 × 100 = 1,600 元。<strong>要時間就加機器，要省錢就少機器＋Spot</strong></li>

<li>Spot 的前提是程式會<strong>存檢查點</strong>（<code>AIP_CHECKPOINT_DIR</code>），被收回時才不用從頭來</li>
</ul>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-04-scaling.png" alt="多 GPU 算一次：單張 GPU 10 小時 1,000 元，4 張同步資料平行效率 85% 變 2.9 小時 1,176 元，再開 Spot VM 打 6 折 706 元；全局批次 64 乘 4 等於 256" class="wp-image-12848" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-04-scaling.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-04-scaling-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-04-scaling-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-04-scaling-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 超參數調校：讓 Google 幫你試</h2>



<p class="wp-block-paragraph">第 15 篇講過 BigQuery ML 用 <code>num_trials</code> 自動試超參數。自訂訓練也有對應的服務：<a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/hyperparameter-tuning-overview"><strong>超參數調校工作</strong></a>（HyperparameterTuningJob）。</p>



<p class="wp-block-paragraph">官方定義的三種資料：<strong>輸入資料</strong>（訓練資料）、<strong>參數</strong>（模型訓練中學到的權重）、<strong>超參數</strong>（控制訓練過程本身的設定，例如幾層、每層幾個節點、學習率）。超參數在一次訓練中通常固定，要調它就得跑很多次訓練。</p>



<h3 class="wp-block-heading">怎麼運作</h3>


<ol class="wp-block-list">
<li>你定義<strong>要調哪些超參數</strong>和範圍（例如學習率 0.0001 到 0.1、隱藏層 1 到 4 層）</li>

<li>定義<strong>目標指標</strong>和方向（例如最大化準確率、最小化損失）</li>

<li>Agent Platform 跑很多次<strong>試驗</strong>（trial），每次用不同的值，記錄結果，用結果決定下一次試什麼</li>

<li>跑完回報最好的那組和每一次的摘要</li>
</ol>



<h3 class="wp-block-heading">程式要配合兩件事</h3>


<ul class="wp-block-list">
<li>每個要調的超參數做成<strong>命令列參數</strong>（程式啟動時從外面給的值），用 <code>argparse</code> 接</li>

<li>用 <code>cloudml-hypertune</code> 套件的 <code>report_hyperparameter_tuning_metric</code> 把每次的分數<strong>回報</strong>給 Agent Platform</li>
</ul>



<h3 class="wp-block-heading">演算法</h3>



<p class="wp-block-paragraph">預設是<strong>貝氏最佳化</strong>（Bayesian optimization）：根據前幾次的結果，猜下一組最可能更好的值，比亂試省很多次。也可以選 <code>GRID_SEARCH</code>（格狀搜尋，所有組合都試）或 <code>RANDOM_SEARCH</code>（隨機）。官方還提到，對相似的模型反覆調校時，它會跨工作學習、越調越有效率。</p>



<p class="wp-block-paragraph">另有<strong>條件式超參數</strong>：例如「訓練方法選 DNN 時才需要調層數」。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">6. 兩種跑法：無伺服器訓練 vs 訓練叢集</h2>



<p class="wp-block-paragraph">第 14 篇提過，自訂訓練現在分兩種模式：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th></th><th><strong>無伺服器訓練</strong>（Serverless Training）</th><th><strong>訓練叢集</strong>（Training Clusters）</th></tr></thead><tbody><tr><td>白話</td><td>送出 CustomJob，Google 開機器、跑完收掉</td><td>先保留一批專屬的高階 GPU（A100、H100）</td></tr><tr><td>比喻</td><td>叫計程車</td><td>包月租車</td></tr><tr><td>適合</td><td>實驗、原型、不需要保證馬上有機器的正式工作</td><td>大規模、長時間、不能排隊等的關鍵訓練</td></tr><tr><td>收費</td><td>用多少付多少</td><td>保留期間都算</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/training/training-clusters/overview">訓練叢集的官方文件</a>補充的特色：用開源的 <strong>Slurm</strong> 介面（高效能運算界的標準排程工具）管工作；自動處理硬體故障（偵測錯誤、重啟或更換節點、從檢查點續跑）；內建 Llama、Gemma 這類模型的訓練配方。<strong>目前要聯絡業務申請才能用</strong>。</p>



<p class="wp-block-paragraph">第三條路 <strong>Ray on Agent Platform</strong>：用開源的 Ray 框架做分散式 Python，本來就用 Ray 的團隊適合。</p>



<p class="wp-block-paragraph">飲料店的推薦模型是每週重訓一次的正式工作、不能排隊 → 第 14 篇的練習情境選了訓練叢集；如果只是研究團隊的實驗，無伺服器訓練＋Spot 就好。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">整條流程</h3>


<ol class="wp-block-list">
<li><strong>寫程式</strong>：模型存到 <code>AIP_MODEL_DIR</code>，檢查點存到 <code>AIP_CHECKPOINT_DIR</code>，程式能從檢查點<strong>續跑</strong>（Spot 被收回、機器重啟都靠這個，官方文件有一節就叫「確保能承受重啟」）</li>

<li><strong>選容器</strong>：標準框架用預建容器＋Python 套件；特殊需求做自訂容器推到 Artifact Registry</li>

<li><strong>資料</strong>：Cloud Storage 或 BigQuery，<strong>跟訓練同一區域</strong>（第 13 篇）</li>

<li><strong>建 CustomJob</strong>：主控台、<code>gcloud ai custom-jobs create</code>、Python SDK 都行；設機型、GPU、台數、timeout、Spot</li>

<li><strong>多台</strong>：第二個工作池放 workers，有需要在第三個放 Reduction Server</li>

<li><strong>要調參</strong>：改建 HyperparameterTuningJob，程式加 <code>cloudml-hypertune</code></li>

<li><strong>看進度</strong>：日誌在 Cloud Logging，TensorBoard 看曲線（第 22 篇）</li>

<li><strong>跑完</strong>：模型在 Cloud Storage，註冊到 <strong>Model Registry</strong>，部署（第 17 篇）</li>
</ol>



<h3 class="wp-block-heading">權限</h3>



<p class="wp-block-paragraph">訓練工作預設用 Agent Platform 的服務代理身分存取同專案的 Cloud Storage；要限制存取範圍，可以指定自訂的<strong>服務帳戶</strong>（給程式用的身分，第 12 篇提過）。</p>



<h3 class="wp-block-heading">改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱（筆記、舊題庫）</th><th>現在</th></tr></thead><tbody><tr><td>AI Platform Training</td><td>2025 年 4 月關閉，改用 Agent Platform 自訂訓練</td></tr><tr><td>Vertex AI Training、Vertex AI custom training</td><td>Gemini Enterprise Agent Platform <strong>Managed Training</strong></td></tr><tr><td>Vertex AI Serverless Training</td><td>Gemini Enterprise Agent Platform <strong>Serverless Training</strong></td></tr><tr><td>Vertex AI Training Clusters（VTC）</td><td>Managed Training Clusters on Gemini Enterprise Agent Platform</td></tr><tr><td>Ray on Vertex AI</td><td>Ray on Gemini Enterprise Agent Platform</td></tr><tr><td>Container Registry（舊的映像檔倉庫）</td><td><strong>Artifact Registry</strong></td></tr><tr><td>Cloud TPU API</td><td>已淘汰，改透過 Compute Engine、GKE、Agent Platform 用 TPU</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 3 區：把原型放大成 ML 模型（約 21%）</td><td>3.2 <strong>用不同 SDK 訓練模型</strong>（Agent Platform 自訂訓練、GKE 上的 Kubeflow、AutoML、Tabular Workflows）；<strong>排除訓練失敗的問題</strong>；<strong>超參數調校</strong>。3.3 <strong>評估 CPU、GPU、TPU</strong>；<strong>用資料平行和模型平行在 GPU、TPU 上做分散式訓練</strong></td></tr><tr><td>第 4 區：服務與擴展模型（約 20%）</td><td>4.1 用預建和自訂容器打包不同框架的模型（容器的概念跟訓練端一樣）</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-05-exam-keywords-1.png" alt="PMLE 考試關鍵字：預建容器沒有的框架想到自訂容器、矩陣運算為主訓練數週想到 TPU、自訂運算 PyTorch 想到 GPU、多台多 GPU 想到 MultiWorkerMirroredStrategy、梯度傳輸是瓶頸想到 Reduction Server、省錢可中斷想到 Spot VM 加檢查點、自動找學習率想到超參數調校工作" class="wp-image-12850" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-05-exam-keywords-1.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-05-exam-keywords-1-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-05-exam-keywords-1-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml16-05-exam-keywords-1-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「預建容器沒有的框架」「特定版本」「非 ML 相依」「啟動更快」</td><td><strong>自訂容器</strong></td></tr><tr><td>「標準 TensorFlow／PyTorch 程式」「最少設定」</td><td><strong>預建容器</strong>＋Python 套件</td></tr><tr><td>「矩陣運算為主」「訓練好幾週」「超大嵌入」「沒有自訂運算」</td><td><strong>TPU</strong></td></tr><tr><td>「自訂運算」「PyTorch／JAX 自訂 op」「TPU 不支援的 op」「中大型模型」</td><td><strong>GPU</strong></td></tr><tr><td>「快速原型」「小模型」「很多自訂 C++ 運算」</td><td><strong>CPU</strong></td></tr><tr><td>「一台多 GPU」</td><td><code>MirroredStrategy</code></td></tr><tr><td>「多台多 GPU」「同步」</td><td><code>MultiWorkerMirroredStrategy</code>（PyTorch 用 DDP）</td></tr><tr><td>「模型太大裝不下一張 GPU」</td><td><strong>模型平行</strong></td></tr><tr><td>「梯度傳輸是瓶頸」「多節點 GPU 訓練變慢」</td><td><strong>Reduction Server</strong>（放第三個工作池）</td></tr><tr><td>「省錢」「可以被中斷」「能從檢查點續跑」</td><td><strong>Spot VM</strong></td></tr><tr><td>「保證有機器」「不能排隊」「H100」</td><td><strong>預留</strong>或<strong>訓練叢集</strong></td></tr><tr><td>「GPU 不一定馬上有」「可以等」</td><td><strong>Dynamic Workload Scheduler</strong></td></tr><tr><td>「自動找最佳學習率」「試很多組」</td><td><strong>超參數調校工作</strong>，<code>cloudml-hypertune</code> 回報指標</td></tr><tr><td>「訓練中途失敗要從頭來」</td><td>存<strong>檢查點</strong>到 <code>AIP_CHECKPOINT_DIR</code></td></tr><tr><td>「訓練機器讀不到資料」</td><td>資料和訓練<strong>同區域</strong>、服務帳戶權限</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>TPU 當萬靈丹</strong>：有自訂運算、需要高精度、分支多的程式，TPU 反而慢或跑不了</li>

<li><strong>GPU 張數亂填</strong>：T4 只能 2 或 4 張，填 3 會失敗；機型 CPU 太小配 GPU 連日誌都出不來</li>

<li><strong>多 GPU 卻沒改程式</strong>：沒用分散式策略，4 張 GPU 只有 1 張在動</li>

<li><strong>用 Spot 卻不存檢查點</strong>：被收回就從頭來，省的錢全賠回去</li>

<li><strong>分散式工作池順序放錯</strong>：第 0 個一定是主要副本，第 2 個才是參數伺服器／Reduction Server</li>

<li><strong>調校時忘了回報指標</strong>：沒呼叫 <code>report_hyperparameter_tuning_metric</code>，Agent Platform 不知道哪組好</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">研究團隊用 PyTorch 寫了推薦模型，有自訂損失函數，單張 GPU 要跑 10 小時。他們想在 3 小時內跑完，預算有限，而且這只是實驗，可以中斷重跑。應該怎麼設？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「PyTorch」「自訂損失函數」→ <strong>GPU</strong>（不是 TPU），預建 PyTorch GPU 容器</li>

<li>「3 小時內」→ <strong>4 張 GPU 同步資料平行</strong>（DDP），一台 4 張用 <code>MirroredStrategy</code> 等級的設定就好，不用多台</li>

<li>「預算有限」「可以中斷」→ <strong>Spot VM</strong>，程式要存<strong>檢查點</strong></li>

<li>無伺服器訓練即可，不需要訓練叢集</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">同一個模型要變成每週重訓的正式工作，資料成長到用 8 台機器、每台 8 張 GPU。工程師發現加了機器之後，每一步大部分時間在等梯度傳輸。應該怎麼做？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「等梯度傳輸」「多節點 GPU」→ <strong>Reduction Server</strong>，放在 <code>workerPoolSpecs[2]</code>，用 <code>n1-highcpu-16</code> 不配 GPU</li>

<li>「正式工作」「每週」→ 考慮<strong>預留</strong>或<strong>訓練叢集</strong>保證有機器</li>

<li>容器要是預建 TF／PyTorch，或自訂容器裝 NCCL 2.7+</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">團隊要訓練一個標準架構的大型語言模型，要跑三週，沒有自訂運算，批次很大。應該選什麼硬體？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「矩陣運算為主」「三週」「大批次」「沒有自訂運算」→ <strong>TPU</strong></li>

<li>自訂訓練用 TPU：<strong>一個工作池、一個副本</strong>，選 v5e／v6e 機型＋<code>tpuTopology</code></li>

<li>框架版本要符合（v5e 要 TensorFlow 2.15+ 或 PyTorch 2.1+ 或 JAX 0.4.6+）</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">Vertex AI 自訂訓練是什麼？</h3>



<p class="wp-block-paragraph">你自己寫訓練程式（任何框架），打包成容器，Agent Platform 負責開虛擬機器、裝 GPU 或 TPU、跑程式、跑完收機器，只收用到的時間。流程是：寫程式、選預建或自訂容器、資料放同區域的 Cloud Storage、建 CustomJob 指定機型和台數、模型存到 Cloud Storage。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，這個服務現在叫 Agent Platform Managed Training。</p>



<h3 class="wp-block-heading">預建容器和自訂容器怎麼選？</h3>



<p class="wp-block-paragraph">預建容器是 Google 裝好的 TensorFlow、PyTorch、scikit-learn、XGBoost 映像檔，分 CPU 和 GPU 版，標準程式直接用、不用碰 Docker。四種情況才需要自訂容器：預建的沒有你要的框架或版本、有非 ML 的相依套件或二進位檔、想預先裝好相依套件讓啟動更快、要用任意框架做分散式訓練。GPU 用的自訂容器建議以 nvidia/cuda 當基底映像檔。</p>



<h3 class="wp-block-heading">訓練該用 CPU、GPU 還是 TPU？</h3>



<p class="wp-block-paragraph">官方 TPU 簡介的指南：CPU 適合快速原型、小模型、很多自訂 C++ 運算、被 I/O 卡住的模型；GPU 適合有自訂 PyTorch 或 JAX 運算、用到 TPU 不支援的運算、中大型模型；TPU 適合矩陣運算為主、主訓練迴圈沒有自訂運算、要訓練幾週、大模型大批次、超大嵌入。TPU 不適合分支多、需要高精度、有自訂運算的程式。</p>



<h3 class="wp-block-heading">資料平行和模型平行差在哪？</h3>



<p class="wp-block-paragraph">資料平行是每台機器都有完整的模型，各算不同的資料，每步把梯度加總平均再更新，絕大多數情況用這種；模型平行是模型太大一張 GPU 裝不下，把模型切成幾塊放不同機器，大型語言模型才需要。資料平行又分同步（all-reduce 等大家算完一起更新，GPU 間用 NCCL）和非同步（參數伺服器，各自更新）。</p>



<h3 class="wp-block-heading">MultiWorkerMirroredStrategy 是什麼？</h3>



<p class="wp-block-paragraph">TensorFlow 的分散式策略之一，做多台機器、每台多張 GPU 的同步資料平行訓練：每台都有模型的完整複本，用 all-reduce 交換梯度。一台機器多張 GPU 用 MirroredStrategy，TPU 用 TPUStrategy，非同步的參數伺服器架構用 ParameterServerStrategy。PyTorch 對應的是 DistributedDataParallel。Agent Platform 會把機器結構寫進 TF_CONFIG 環境變數給程式讀。</p>



<h3 class="wp-block-heading">Reduction Server 是什麼？</h3>



<p class="wp-block-paragraph">Google 提供的一群專門幫忙加總梯度的機器，讓多台 GPU 同步訓練時 GPU 不用花時間互傳梯度。條件是 GPU 工作者、TensorFlow 或 PyTorch 多機訓練、容器支援（預建 TF／PyTorch 容器或裝了 NCCL 2.7 以上的自訂容器）。做法是在 CustomJob 的第三個工作池放 Reduction Server 映像檔，不用 GPU，官方建議 n1-highcpu-16 這種頻寬高的機型。</p>



<h3 class="wp-block-heading">Spot VM 可以用來訓練嗎？</h3>



<p class="wp-block-paragraph">可以，而且是省錢的主要方法。Spot VM 是 Google 多出來的閒置機器，大幅折扣，但隨時可能被收回。前提是訓練程式要定期把檢查點存到 AIP_CHECKPOINT_DIR，被收回重啟後從檢查點續跑。在 CustomJob 的 scheduling.strategy 設定。要保證有機器則用預留，GPU 不急可以用 Dynamic Workload Scheduler 排隊等。</p>



<h3 class="wp-block-heading">自訂訓練怎麼調超參數？</h3>



<p class="wp-block-paragraph">建超參數調校工作（HyperparameterTuningJob）：定義要調的超參數和範圍、目標指標和方向（最大化準確率或最小化損失）、試驗次數。程式要把每個超參數做成命令列參數，並用 cloudml-hypertune 套件回報每次的指標。預設用貝氏最佳化，也可選格狀或隨機搜尋，還支援條件式超參數。BigQuery ML 的對應做法是 num_trials。</p>



<h3 class="wp-block-heading">無伺服器訓練和訓練叢集差在哪？</h3>



<p class="wp-block-paragraph">無伺服器訓練是送出 CustomJob 後 Google 開機器、跑完收掉、用多少付多少，適合實驗和不需要保證馬上有機器的工作。訓練叢集是先保留一批專屬高階 GPU，用 Slurm 介面管工作、自動處理硬體故障、內建大模型訓練配方，適合大規模長時間的關鍵訓練，目前要聯絡業務申請。另有 Ray on Agent Platform 給用 Ray 框架的團隊。</p>



<h3 class="wp-block-heading">訓練程式要存到哪裡？</h3>



<p class="wp-block-paragraph">Agent Platform 給三個環境變數：AIP_MODEL_DIR 存訓練完的模型（之後註冊到 Model Registry 直接用）、AIP_CHECKPOINT_DIR 存檢查點、AIP_TENSORBOARD_LOG_DIR 存 TensorBoard 紀錄，都是 Cloud Storage 路徑。訓練資料則掛在 /gcs/ 底下讀，要跟訓練同一個區域。</p>



<h3 class="wp-block-heading">Vertex AI Training 改名了嗎？</h3>



<p class="wp-block-paragraph">是。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，Vertex AI Training 改叫 Agent Platform Managed Training，底下分 Serverless Training（無伺服器訓練）和 Training Clusters（訓練叢集）。更早的 AI Platform Training 已在 2025 年 4 月 7 日關閉。舊題庫的 Vertex AI custom training 就是現在的 Agent Platform 自訂訓練，功能一樣。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>自訂訓練</strong>：自己寫程式、打包容器，Agent Platform 開機器、跑完收掉；舊名 Vertex AI Training，現在叫 <strong>Agent Platform Managed Training</strong></li>

<li><strong>容器</strong>：預建（TensorFlow、PyTorch、scikit-learn、XGBoost）夠用就不用自己做；框架不支援、特定版本、非 ML 相依、要更快啟動才做<strong>自訂容器</strong>，推到 Artifact Registry</li>

<li><strong>CustomJob</strong>：WorkerPoolSpec 設機型、GPU 種類與張數、台數、容器；程式用 <code>AIP_MODEL_DIR</code>、<code>AIP_CHECKPOINT_DIR</code></li>

<li><strong>硬體</strong>：CPU 原型小模型；GPU 自訂運算、中大型；TPU 矩陣運算為主、訓練數週、大批次，不適合自訂運算與高精度。GPU 要配 A2／N1／G2 機型、張數有固定選項</li>

<li><strong>分散式</strong>：資料平行（同步 all-reduce、非同步參數伺服器）vs 模型平行；工作池順序＝角色（主要副本、工作者、參數伺服器／Reduction Server、評估者）；<code>MultiWorkerMirroredStrategy</code>、DDP</li>

<li><strong>算一次</strong>：4 張 GPU 效率 85% → 2.9 小時，多付 18% 換 3.4 倍快；開 Spot 再打折，但要存檢查點</li>

<li><strong>超參數調校工作</strong>：命令列參數＋<code>cloudml-hypertune</code> 回報指標，預設貝氏最佳化</li>

<li><strong>兩種跑法</strong>：無伺服器訓練（計程車）vs 訓練叢集（包月租車，Slurm，要申請）</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>上一篇：第 15 篇：<a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a></li>

<li>下一篇：第 17 篇：<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">模型部署怎麼選？線上預測 vs 批次預測、流量分割</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2024/11/27/how-to-build-a-ai-development-environment-on-gcp/">如何在 GCP 上建立含 GPU 的 AI 開發環境</a></li>

<li><a href="https://dongdonggcp.com/2026/07/29/what-is-container-technology-docker-guide/">容器技術是什麼？從零開始看懂 Docker 與容器化應用</a></li>

<li><a href="https://dongdonggcp.com/2026/07/21/what-is-kubernetes/">Kubernetes 是什麼？白話解釋＋判斷你是否真的需要它</a></li>

<li><a href="https://dongdonggcp.com/2024/10/23/what-is-google-vm-compute-engine-introduction/">Google VM 平台 Compute Engine 是什麼？</a></li>

<li><a href="https://dongdonggcp.com/2024/03/06/gcp-is-expensive-really/">很多人嫌 GCP 的主機價格很貴？真的貴嗎？</a></li>

<li><a href="https://dongdonggcp.com/2026/05/19/gcp-bill-explosion-prevention-guide/">GCP 帳單爆炸防護指南</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">機器選對、程式打包好，模型才跑得起來、錢才花得值。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "Vertex AI 自訂訓練是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "你自己寫訓練程式（任何框架），打包成容器，Agent Platform 負責開虛擬機器、裝 GPU 或 TPU、跑程式、跑完收機器，只收用到的時間。流程是：寫程式、選預建或自訂容器、資料放同區域的 Cloud Storage、建 CustomJob 指定機型和台數、模型存到 Cloud Storage。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，這個服務現在叫 Agent Platform Managed Training。"
      }
    },
    {
      "@type": "Question",
      "name": "預建容器和自訂容器怎麼選？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "預建容器是 Google 裝好的 TensorFlow、PyTorch、scikit-learn、XGBoost 映像檔，分 CPU 和 GPU 版，標準程式直接用、不用碰 Docker。四種情況才需要自訂容器：預建的沒有你要的框架或版本、有非 ML 的相依套件或二進位檔、想預先裝好相依套件讓啟動更快、要用任意框架做分散式訓練。GPU 用的自訂容器建議以 nvidia/cuda 當基底映像檔。"
      }
    },
    {
      "@type": "Question",
      "name": "訓練該用 CPU、GPU 還是 TPU？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "官方 TPU 簡介的指南：CPU 適合快速原型、小模型、很多自訂 C++ 運算、被 I/O 卡住的模型；GPU 適合有自訂 PyTorch 或 JAX 運算、用到 TPU 不支援的運算、中大型模型；TPU 適合矩陣運算為主、主訓練迴圈沒有自訂運算、要訓練幾週、大模型大批次、超大嵌入。TPU 不適合分支多、需要高精度、有自訂運算的程式。"
      }
    },
    {
      "@type": "Question",
      "name": "資料平行和模型平行差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "資料平行是每台機器都有完整的模型，各算不同的資料，每步把梯度加總平均再更新，絕大多數情況用這種；模型平行是模型太大一張 GPU 裝不下，把模型切成幾塊放不同機器，大型語言模型才需要。資料平行又分同步（all-reduce 等大家算完一起更新，GPU 間用 NCCL）和非同步（參數伺服器，各自更新）。"
      }
    },
    {
      "@type": "Question",
      "name": "MultiWorkerMirroredStrategy 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "TensorFlow 的分散式策略之一，做多台機器、每台多張 GPU 的同步資料平行訓練：每台都有模型的完整複本，用 all-reduce 交換梯度。一台機器多張 GPU 用 MirroredStrategy，TPU 用 TPUStrategy，非同步的參數伺服器架構用 ParameterServerStrategy。PyTorch 對應的是 DistributedDataParallel。Agent Platform 會把機器結構寫進 TF_CONFIG 環境變數給程式讀。"
      }
    },
    {
      "@type": "Question",
      "name": "Reduction Server 是什麼？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Google 提供的一群專門幫忙加總梯度的機器，讓多台 GPU 同步訓練時 GPU 不用花時間互傳梯度。條件是 GPU 工作者、TensorFlow 或 PyTorch 多機訓練、容器支援（預建 TF／PyTorch 容器或裝了 NCCL 2.7 以上的自訂容器）。做法是在 CustomJob 的第三個工作池放 Reduction Server 映像檔，不用 GPU，官方建議 n1-highcpu-16 這種頻寬高的機型。"
      }
    },
    {
      "@type": "Question",
      "name": "Spot VM 可以用來訓練嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "可以，而且是省錢的主要方法。Spot VM 是 Google 多出來的閒置機器，大幅折扣，但隨時可能被收回。前提是訓練程式要定期把檢查點存到 AIP_CHECKPOINT_DIR，被收回重啟後從檢查點續跑。在 CustomJob 的 scheduling.strategy 設定。要保證有機器則用預留，GPU 不急可以用 Dynamic Workload Scheduler 排隊等。"
      }
    },
    {
      "@type": "Question",
      "name": "自訂訓練怎麼調超參數？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "建超參數調校工作（HyperparameterTuningJob）：定義要調的超參數和範圍、目標指標和方向（最大化準確率或最小化損失）、試驗次數。程式要把每個超參數做成命令列參數，並用 cloudml-hypertune 套件回報每次的指標。預設用貝氏最佳化，也可選格狀或隨機搜尋，還支援條件式超參數。BigQuery ML 的對應做法是 num_trials。"
      }
    },
    {
      "@type": "Question",
      "name": "無伺服器訓練和訓練叢集差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "無伺服器訓練是送出 CustomJob 後 Google 開機器、跑完收掉、用多少付多少，適合實驗和不需要保證馬上有機器的工作。訓練叢集是先保留一批專屬高階 GPU，用 Slurm 介面管工作、自動處理硬體故障、內建大模型訓練配方，適合大規模長時間的關鍵訓練，目前要聯絡業務申請。另有 Ray on Agent Platform 給用 Ray 框架的團隊。"
      }
    },
    {
      "@type": "Question",
      "name": "訓練程式要存到哪裡？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Agent Platform 給三個環境變數：AIP_MODEL_DIR 存訓練完的模型（之後註冊到 Model Registry 直接用）、AIP_CHECKPOINT_DIR 存檢查點、AIP_TENSORBOARD_LOG_DIR 存 TensorBoard 紀錄，都是 Cloud Storage 路徑。訓練資料則掛在 /gcs/ 底下讀，要跟訓練同一個區域。"
      }
    },
    {
      "@type": "Question",
      "name": "Vertex AI Training 改名了嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "是。Vertex AI 在 2026 年 4 月改名為 Gemini Enterprise Agent Platform，Vertex AI Training 改叫 Agent Platform Managed Training，底下分 Serverless Training（無伺服器訓練）和 Training Clusters（訓練叢集）。更早的 AI Platform Training 已在 2025 年 4 月 7 日關閉。舊題庫的 Vertex AI custom training 就是現在的 Agent Platform 自訂訓練，功能一樣。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>BigQuery ML 入門：只會 SQL 也能訓練模型</title>
		<link>https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bigquery-ml-tutorial-train-model-with-sql</link>
					<comments>https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Oct 2026 05:42:00 +0000</pubDate>
				<category><![CDATA[AI 和機器學習]]></category>
		<category><![CDATA[證照考試]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[BigQuery]]></category>
		<category><![CDATA[GCP 證照]]></category>
		<category><![CDATA[PMLE]]></category>
		<category><![CDATA[Vertex AI]]></category>
		<category><![CDATA[機器學習]]></category>
		<guid isPermaLink="false">https://dongdonggcp.com/?p=12844</guid>

					<description><![CDATA[<p>BigQuery ML 入門：三句 SQL 做完會員流失預測。CREATE MODEL 訓練、ML.PREDICT 預測，自動前處理、TRANSFORM、資料切分規則、ARIMA_PLUS 與費用算一次，附 PMLE 考點。</p>
<p>The post <a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></description>
										<content:encoded><![CDATA[<p class="wp-block-paragraph"><strong>BigQuery ML 入門只要三句 SQL：CREATE MODEL 訓練、ML.EVALUATE 評估、ML.PREDICT 預測。</strong></p>



<p class="wp-block-paragraph">上一篇說，資料已經在 BigQuery、團隊會 SQL，就用 BigQuery ML。這篇就把它從頭到尾做一遍：怎麼寫、它背後幫你做了什麼、資料怎麼切、超參數怎麼調、要花多少錢。</p>



<p class="wp-block-paragraph">一樣用有 2,000 間分店、50 萬名會員的連鎖飲料店當例子（教學假設），要做的是<strong>會員流失預測</strong>：哪些會員下個月不會再來？會員表和交易表都已經在 BigQuery 裡。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-01-three-steps.png" alt="BigQuery ML 入門三步驟：CREATE MODEL 用 SQL 訓練模型、ML.EVALUATE 看準確率召回率 AUC、ML.PREDICT 對整張表批次預測，資料全程留在 BigQuery" class="wp-image-12840" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-01-three-steps.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-01-three-steps-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-01-three-steps-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-01-three-steps-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">為什麼你需要知道</h2>


<ul class="wp-block-list">
<li><strong>最低門檻的機器學習</strong>：Google 官方<a href="https://docs.cloud.google.com/bigquery/docs/bqml-introduction">簡介</a>說得很直接，以前做 ML 要會 Python 和 ML 框架，把「最懂資料的人」排除在外；BigQuery ML 讓會 SQL 的人也能做。官方的「需要什麼知識」那段寫著：用預設設定，<strong>沒什麼 ML 知識也能建模型</strong></li>

<li><strong>資料不用搬</strong>：幾 TB 的表搬去 Python 環境，光搬就要半天。BigQuery ML 把 ML 帶到資料旁邊</li>

<li><strong>前面 14 篇學的東西都用得上</strong>：資料切分（第 4 篇）、評估指標（第 5、6 篇）、過度擬合（第 7 篇）、類別不平衡（第 9 篇）、前處理（第 10 篇）、特徵工程（第 11 篇）在 BigQuery ML 裡都有對應的開關。這篇會一個一個對回去</li>

<li><strong>證照必考</strong>：PMLE 考試指南第 1.1 節整節都是它：用 BigQuery ML 建分類、迴歸、預測、分群模型；用 BigQuery ML 做特徵工程和特徵選擇；用 BigQuery ML 產生預測</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">先搞懂：BigQuery ML 是什麼</h2>



<h3 class="wp-block-heading">白話是什麼</h3>



<p class="wp-block-paragraph"><strong>BigQuery ML</strong>：在 BigQuery 裡用 SQL 指令建立、訓練、使用機器學習模型。模型跟表格一樣存在 BigQuery 的資料集裡。</p>



<p class="wp-block-paragraph">幾個名詞先講：</p>


<ul class="wp-block-list">
<li><strong>BigQuery</strong>：Google 的資料倉儲，存大量表格資料、用 SQL 查，站上有<a href="https://dongdonggcp.com/2024/11/23/what-is-bigquery-functions-advantages/">BigQuery 是什麼</a></li>

<li><strong>SQL</strong>：查詢表格的語言。<code>SELECT 姓名 FROM 會員表 WHERE 年齡 &gt; 30</code> 這種句子</li>

<li><strong>資料集</strong>（dataset）：BigQuery 裡放表格的資料夾；<strong>表</strong>（table）就是一張表格；<strong>檢視</strong>（view）是存起來的查詢結果，看起來像表</li>

<li><strong>NULL</strong>：欄位裡的「空值」，代表沒填或不知道</li>
</ul>



<h3 class="wp-block-heading">比喻</h3>



<p class="wp-block-paragraph">倉庫旁邊的廚房（上一篇的比喻）。這篇要講的是這間廚房的爐子怎麼開、菜單上有什麼、哪些調味是自動的、瓦斯費怎麼算。</p>



<h3 class="wp-block-heading">來龍去脈</h3>



<p class="wp-block-paragraph">BigQuery ML 剛推出時只有線性迴歸和邏輯迴歸兩種，現在<a href="https://docs.cloud.google.com/bigquery/docs/e2e-journey">官方清單</a>已經有十幾種：監督式的線性／邏輯迴歸、DNN、Wide &amp; Deep、提升樹、隨機森林、AutoML；非監督式的 K-means、矩陣分解、自動編碼器、PCA；時間序列的 ARIMA_PLUS；還能匯入外面訓練的模型、遠端呼叫 Gemini。</p>



<h3 class="wp-block-heading">為什麼要學</h3>



<p class="wp-block-paragraph">這是 Google Cloud 上<strong>最快能看到結果</strong>的機器學習方式。會 SQL 的人，一個下午就能從資料表做出第一個模型。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">1. 三句 SQL 做完一個模型</h2>



<h3 class="wp-block-heading">第 0 步：準備一張表</h3>



<p class="wp-block-paragraph">機器學習要的是「一列一個樣本、每欄一個特徵、其中一欄是答案」（第 3 篇）。先用 SQL 把會員表和交易表整理成這樣：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>member_id</th><th>visits_90d</th><th>avg_spend</th><th>days_since_last</th><th>member_months</th><th>city</th><th>churned</th></tr></thead><tbody><tr><td>M001</td><td>12</td><td>65</td><td>3</td><td>18</td><td>台北</td><td>0</td></tr><tr><td>M002</td><td>1</td><td>80</td><td>75</td><td>4</td><td>台中</td><td>1</td></tr><tr><td>…</td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table></figure>


<ul class="wp-block-list">
<li><code>visits_90d</code>：最近 90 天來幾次；<code>avg_spend</code>：平均客單價；<code>days_since_last</code>：距離上次消費幾天；<code>member_months</code>：加入幾個月；<code>city</code>：城市</li>

<li><code>churned</code>：<strong>標籤</strong>，1 代表這位會員接下來一個月沒再來（流失），0 代表有來</li>
</ul>



<p class="wp-block-paragraph">答案欄怎麼來？用歷史資料「回頭看」：拿去年 6 月的會員狀態當特徵、7 月有沒有來當答案。這一步要小心<strong>資料洩漏</strong>（第 8 篇），特徵只能用 6 月以前知道的事。</p>



<h3 class="wp-block-heading">第 1 句：CREATE MODEL 訓練</h3>



<pre class="wp-block-code"><code>CREATE OR REPLACE MODEL `drink.churn_model`
OPTIONS (
  model_type = 'LOGISTIC_REG',
  input_label_cols = ['churned'],
  auto_class_weights = TRUE,
  enable_global_explain = TRUE
) AS
SELECT visits_90d, avg_spend, days_since_last, member_months, city, churned
FROM `drink.member_features`;</code></pre>



<p class="wp-block-paragraph">一行一行翻譯：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>這一行</th><th>白話</th></tr></thead><tbody><tr><td><code>CREATE OR REPLACE MODEL</code></td><td>建一個模型，已經有同名的就覆蓋</td></tr><tr><td><code>model_type = 'LOGISTIC_REG'</code></td><td>用<strong>邏輯迴歸</strong>（第 2 篇講的分類模型）。要做迴歸就改 <code>LINEAR_REG</code>，要用 XGBoost 改 <code>BOOSTED_TREE_CLASSIFIER</code></td></tr><tr><td><code>input_label_cols = ['churned']</code></td><td>哪一欄是<strong>答案</strong></td></tr><tr><td><code>auto_class_weights = TRUE</code></td><td>流失的會員比沒流失的少很多（第 9 篇的<strong>類別不平衡</strong>），這個開關會自動把少數類別加權。官方說明：依類別出現頻率的反比加權</td></tr><tr><td><code>enable_global_explain = TRUE</code></td><td>訓練完順便算「哪些特徵整體最重要」，後面 <code>ML.GLOBAL_EXPLAIN</code> 會用到</td></tr><tr><td><code>AS SELECT ...</code></td><td><strong>訓練資料就是這個查詢的結果</strong>。沒選進來的欄位不會被用到</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">注意 <code>member_id</code> 沒有被 SELECT 進去。會員編號對「會不會流失」沒有意義，放進去只會讓模型記答案（第 7 篇過度擬合）。</p>



<h3 class="wp-block-heading">第 2 句：ML.EVALUATE 評估</h3>



<pre class="wp-block-code"><code>SELECT * FROM ML.EVALUATE(MODEL `drink.churn_model`);</code></pre>



<p class="wp-block-paragraph">不給它資料，它會自動用訓練時<strong>切出來的評估資料</strong>算分數（切法下一節講）。分類模型會回傳一列：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>欄位</th><th>就是第 5、6 篇的</th></tr></thead><tbody><tr><td><code>precision</code></td><td>精確率</td></tr><tr><td><code>recall</code></td><td>召回率</td></tr><tr><td><code>accuracy</code></td><td>準確率</td></tr><tr><td><code>f1_score</code></td><td>F1</td></tr><tr><td><code>log_loss</code></td><td>對數損失（越小越好）</td></tr><tr><td><code>roc_auc</code></td><td>AUC-ROC</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">迴歸模型回傳的是 <code>mean_absolute_error</code>（MAE）、<code>mean_squared_error</code>、<code>r2_score</code> 這些（第 2 篇）。</p>



<p class="wp-block-paragraph">要用別的<strong>門檻</strong>（第 6 篇），加 <code>STRUCT(0.3 AS threshold)</code> 這個參數；預設是 0.5。想看整張混淆矩陣用 <code>ML.CONFUSION_MATRIX</code>，想畫 ROC 曲線用 <code>ML.ROC_CURVE</code>。</p>



<h3 class="wp-block-heading">第 3 句：ML.PREDICT 預測</h3>



<pre class="wp-block-code"><code>SELECT member_id, predicted_churned, predicted_churned_probs
FROM ML.PREDICT(
  MODEL `drink.churn_model`,
  TABLE `drink.member_features_today`,
  STRUCT(0.3 AS threshold)
);</code></pre>


<ul class="wp-block-list">
<li>輸入是今天的會員特徵表，<strong>欄位名稱要跟訓練時一樣</strong></li>

<li>輸出多兩欄：<code>predicted_churned</code>（預測的答案，0 或 1）和 <code>predicted_churned_probs</code>（每個類別的機率）。欄位名稱規則是 <code>predicted_</code> 加上標籤欄的名字</li>

<li><code>threshold</code> 設 0.3：機率超過 30% 就判定會流失。流失預測寧可多抓（第 5 篇講的「追召回率」），門檻就調低</li>
</ul>



<p class="wp-block-paragraph">這是<strong>批次預測</strong>：一次對整張表算完，結果就是一張新的表，可以直接拿去寄挽留優惠。要做「會員一打開 App 就即時算」的線上預測，要走 Model Registry，<a href="https://dongdonggcp.com/2026/10/25/model-deployment-online-vs-batch-prediction-traffic-split/">第 17 篇</a>講。</p>



<h3 class="wp-block-heading">加碼：ML.EXPLAIN_PREDICT 看為什麼</h3>



<pre class="wp-block-code"><code>SELECT * FROM ML.EXPLAIN_PREDICT(
  MODEL `drink.churn_model`,
  TABLE `drink.member_features_today`,
  STRUCT(3 AS top_k_features)
);</code></pre>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-explain-predict">官方說明</a>：它是 <code>ML.PREDICT</code> 的加強版，每一列多回傳「哪幾個特徵對這筆預測貢獻最大」，<code>top_k_features</code> 預設 5 個。例如 M002 被判會流失，是因為 <code>days_since_last = 75</code>（75 天沒來）貢獻最大。<a href="https://dongdonggcp.com/2026/10/25/explainable-ai-shapley-integrated-gradients-xrai/">第 21 篇</a>可解釋 AI 會細講。</p>



<p class="wp-block-paragraph"><strong>筆記裡寫的「BQML.PREDICT」「BQML.EXPLAIN_PREDICT」</strong>，正確名稱是 <code>ML.PREDICT</code> 和 <code>ML.EXPLAIN_PREDICT</code>。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">2. 它幫你自動做了什麼：前處理</h2>



<p class="wp-block-paragraph">第 10 篇講的標準化、遺失值、One-hot，BigQuery ML 在 <code>CREATE MODEL</code> 時<strong>預設就自動做</strong>。<a href="https://docs.cloud.google.com/bigquery/docs/auto-preprocessing">官方自動前處理文件</a>：</p>



<h3 class="wp-block-heading">遺失值（NULL）怎麼補</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>欄位型態</th><th>自動補法</th></tr></thead><tbody><tr><td>數字</td><td>用該欄的<strong>平均值</strong>補（訓練和預測都一樣）</td></tr><tr><td>文字、布林（One-hot 過的）</td><td>當成一個<strong>額外的類別</strong>「NULL」；預測時遇到沒看過的值，權重給 0</td></tr><tr><td>時間戳記</td><td>混合用：Unix 時間用平均值，其他拆出來的部分歸到 NULL 類別</td></tr></tbody></table></figure>



<p class="wp-block-paragraph">套回例子：某位會員 <code>avg_spend</code> 是 NULL（從沒消費過），自動補成所有會員的平均客單價。這不一定是你要的（沒消費過跟平均客單價差很多），要自己控制就用下面的 TRANSFORM。</p>



<h3 class="wp-block-heading">特徵怎麼轉換</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>輸入型態</th><th>自動轉換</th><th>例外</th></tr></thead><tbody><tr><td>數字（INT64、FLOAT64…）</td><td><strong>標準化</strong>（第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></td><td>提升樹、隨機森林不做；K-means 由 <code>STANDARDIZE_FEATURES</code> 選項決定</td></tr><tr><td>文字、布林、日期</td><td><strong>One-hot 編碼</strong>（每個值一欄）</td><td>提升樹、隨機森林改用標籤編碼（每個值換一個數字）</td></tr><tr><td>陣列</td><td>Multi-hot 編碼（每個元素一欄）</td><td></td></tr><tr><td>時間戳記</td><td>拆成年、月、星期幾等，數字的標準化、類別的 One-hot</td><td></td></tr></tbody></table></figure>



<p class="wp-block-paragraph">所以 <code>city</code> 這種文字欄直接丟進去就好，它會自動變成「台北、台中、高雄…」各一欄。</p>



<h3 class="wp-block-heading">想自己控制：TRANSFORM 子句</h3>



<p class="wp-block-paragraph">第 11 篇講的特徵工程，用 <code>TRANSFORM</code> 寫在 <code>CREATE MODEL</code> 裡：</p>



<pre class="wp-block-code"><code>CREATE OR REPLACE MODEL `drink.churn_model_v2`
TRANSFORM (
  ML.QUANTILE_BUCKETIZE(avg_spend, 5) OVER () AS spend_bucket,
  ML.FEATURE_CROSS(STRUCT(city, spend_bucket)) AS city_x_spend,
  visits_90d, days_since_last, member_months, churned
)
OPTIONS (model_type = 'LOGISTIC_REG', input_label_cols = ['churned']) AS
SELECT * FROM `drink.member_features`;</code></pre>


<ul class="wp-block-list">
<li><code>ML.QUANTILE_BUCKETIZE(avg_spend, 5)</code>：客單價切成 5 個等人數的<strong>分桶</strong>（第 10 篇）</li>

<li><code>ML.FEATURE_CROSS</code>：城市 × 客單價桶的<strong>特徵交叉</strong>（第 11 篇）</li>

<li><a href="https://docs.cloud.google.com/bigquery/docs/manual-preprocessing">官方手動前處理文件</a>列的函數還有 <code>ML.STANDARD_SCALER</code>、<code>ML.MIN_MAX_SCALER</code>、<code>ML.BUCKETIZE</code>、<code>ML.IMPUTER</code>（自己決定遺失值怎麼補）、<code>ML.NGRAMS</code> 等</li>
</ul>



<p class="wp-block-paragraph"><strong>TRANSFORM 最大的好處</strong>：訓練時怎麼轉，<code>ML.PREDICT</code> 時<strong>自動用同樣的方式轉</strong>，連分桶的切點都沿用訓練時算的。這正是第 10 篇講的「訓練和上線前後不一致」（training-serving skew，<a href="https://dongdonggcp.com/2026/10/25/model-monitoring-drift-training-serving-skew/">第 20 篇</a>會再講）的解法。官方特別寫了一句：分析函數在 TRANSFORM 裡用，訓練時收集的統計值會自動套用到預測輸入。</p>



<p class="wp-block-paragraph">想把「轉換」和「訓練」分開管理，可以建一個<strong>只做轉換的模型</strong>（transform-only model），用 <code>ML.TRANSFORM</code> 看它轉出來的結果長什麼樣。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">3. 資料怎麼切：AUTO_SPLIT 的規則</h2>



<p class="wp-block-paragraph">第 4 篇講過訓練集、驗證集要分開。BigQuery ML 用 <code>DATA_SPLIT_METHOD</code> 選項控制，<a href="https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-create-glm">官方說明</a>的預設值是 <code>AUTO_SPLIT</code>，規則是：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>輸入資料列數</th><th>怎麼切</th></tr></thead><tbody><tr><td><strong>少於 500 列</strong></td><td>全部拿來訓練，不切</td></tr><tr><td><strong>500 到 50,000 列</strong></td><td>隨機 <strong>20%</strong> 當評估資料、80% 訓練</td></tr><tr><td><strong>超過 50,000 列</strong></td><td>隨機抽 <strong>10,000 列</strong>當評估資料，其餘訓練</td></tr><tr><td>有開超參數調校（超過 500 列）</td><td>80% 訓練、10% 評估、10% 測試</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">算一次</h3>



<pre class="wp-block-code"><code>飲料店 50 萬名會員 → 超過 50,000 列
評估資料 = 10,000 列（固定）
訓練資料 = 500,000 − 10,000 = 490,000 列
評估比例 = 10,000 ÷ 500,000 = 2%</code></pre>



<p class="wp-block-paragraph">資料越多，評估比例越小，因為 10,000 列已經夠算出穩定的分數，多切只是浪費訓練資料。</p>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-02-auto-split.png" alt="BigQuery ML 的 AUTO_SPLIT 資料切分規則：少於 500 列全部訓練、500 到 50,000 列切 20% 評估、超過 50,000 列固定抽 10,000 列評估、開超參數調校時 80 訓練 10 評估 10 測試，時間序列要用 SEQ" class="wp-image-12841" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-02-auto-split.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-02-auto-split-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-02-auto-split-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-02-auto-split-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">其他切法</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>選項</th><th>什麼時候用</th></tr></thead><tbody><tr><td><code>RANDOM</code></td><td>自己指定評估比例（<code>DATA_SPLIT_EVAL_FRACTION</code>）</td></tr><tr><td><code>SEQ</code></td><td><strong>依順序切</strong>，最後面的當評估資料。第 4 篇講的時間序列不能亂切，就用這個，搭配 <code>DATA_SPLIT_COL</code> 指定時間欄</td></tr><tr><td><code>CUSTOM</code></td><td>自己加一欄 TRUE／FALSE 標哪些是評估資料</td></tr><tr><td><code>NO_SPLIT</code></td><td>全部訓練，自己另外準備評估資料給 <code>ML.EVALUATE</code></td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/bigquery/docs/logistic-regression-prediction">官方邏輯迴歸教學</a>用的就是自己切：加一欄 <code>dataframe</code>，標 training、evaluation、prediction 三種，訓練時只選 training 的列，評估時把 evaluation 的列餵給 <code>ML.EVALUATE</code>。</p>



<p class="wp-block-paragraph">評估資料的用途，官方寫得很清楚：<strong>用提前停止來避免過度擬合</strong>（第 7 篇）。每一輪訓練完看評估資料的損失有沒有進步，進步幅度小於 <code>MIN_REL_PROGRESS</code> 就停，開關是 <code>EARLY_STOP</code>（預設開）。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">4. 超參數怎麼調</h2>



<p class="wp-block-paragraph">第 3 篇說超參數是「訓練前自己決定的設定」，例如正則化強度 <code>L1_REG</code>、<code>L2_REG</code>（第 7 篇）、學習率。手動一個一個試很累，BigQuery ML 的<a href="https://docs.cloud.google.com/bigquery/docs/hp-tuning-overview">超參數調校</a>讓它自己試：</p>



<pre class="wp-block-code"><code>CREATE OR REPLACE MODEL `drink.churn_model_tuned`
OPTIONS (
  model_type = 'LOGISTIC_REG',
  input_label_cols = ['churned'],
  num_trials = 20,
  l1_reg = HPARAM_RANGE(0, 1),
  l2_reg = HPARAM_CANDIDATES([0, 0.1, 1, 10])
) AS
SELECT * FROM `drink.member_features`;</code></pre>


<ul class="wp-block-list">
<li><code>num_trials = 20</code>：試 20 組</li>

<li><code>HPARAM_RANGE(0, 1)</code>：在 0 到 1 之間找</li>

<li><code>HPARAM_CANDIDATES([...])</code>：從這幾個值裡挑</li>

<li>跑完用 <code>ML.TRIAL_INFO</code> 看每一組的分數，<code>ML.EVALUATE</code> 預設回傳最好的那組</li>
</ul>



<p class="wp-block-paragraph">支援調校的模型：線性／邏輯迴歸、K-means、矩陣分解、自動編碼器、提升樹、隨機森林、DNN、Wide &amp; Deep。AutoML 本來就內建自動調校；ARIMA_PLUS 用 <code>AUTO_ARIMA</code> 自動找趨勢參數。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">5. 不只分類：時間序列和分群</h2>



<h3 class="wp-block-heading">時間序列：ARIMA_PLUS</h3>



<p class="wp-block-paragraph">飲料店要預測每間分店未來 30 天的銷量，<a href="https://docs.cloud.google.com/bigquery/docs/arima-single-time-series-forecasting-tutorial">官方教學</a>的寫法：</p>



<pre class="wp-block-code"><code>CREATE OR REPLACE MODEL `drink.sales_forecast`
OPTIONS (
  model_type = 'ARIMA_PLUS',
  time_series_timestamp_col = 'sale_date',
  time_series_data_col = 'daily_sales',
  time_series_id_col = 'store_id',
  holiday_region = 'TW'
) AS
SELECT sale_date, daily_sales, store_id FROM `drink.daily_sales`;

SELECT * FROM ML.FORECAST(MODEL `drink.sales_forecast`,
  STRUCT(30 AS horizon, 0.8 AS confidence_level));</code></pre>


<ul class="wp-block-list">
<li><code>time_series_id_col</code>：一次幫 2,000 間分店各做一個模型</li>

<li><code>holiday_region</code>：把台灣的假日效應算進去（官方教學用美國假日舉例）</li>

<li><code>ML.FORECAST</code> 的 <code>horizon = 30</code> 是預測未來 30 天，<code>confidence_level = 0.8</code> 是給 80% 的預測區間（上下界）</li>

<li>官方簡介提到，ARIMA_PLUS 會<strong>自動處理異常值、季節性、假日</strong>；<code>ML.EXPLAIN_FORECAST</code> 可以把趨勢、季節性拆開看</li>
</ul>



<p class="wp-block-paragraph">不想管模型，官方簡介說可以用 <code>AI.FORECAST</code> 函數搭內建的 <strong>TimesFM</strong> 模型（預覽階段）直接預測。</p>



<h3 class="wp-block-heading">分群：K-means</h3>



<p class="wp-block-paragraph">不知道會員分幾種，想讓模型自己找（第 1 篇的非監督式學習）：<code>model_type = 'KMEANS'</code>，不用 <code>input_label_cols</code>，因為沒有答案。預測結果是每位會員屬於哪一群（<code>CENTROID_ID</code>），<code>ML.CENTROIDS</code> 看每一群的中心長什麼樣。</p>



<h3 class="wp-block-heading">推薦：矩陣分解</h3>



<p class="wp-block-paragraph">「猜你想點」：<code>model_type = 'MATRIX_FACTORIZATION'</code>，輸入是「誰買過什麼、評幾分」，<code>ML.RECOMMEND</code> 回傳每位會員對每種飲料的預測評分。官方定價頁註明矩陣分解只開放給 Editions 或有保留算力的客戶。</p>



<h3 class="wp-block-heading">要更強的模型</h3>



<p class="wp-block-paragraph"><code>BOOSTED_TREE_CLASSIFIER</code>（XGBoost）、<code>DNN_CLASSIFIER</code>、<code>AUTOML_CLASSIFIER</code> 這些寫法一樣是 SQL，但官方簡介說它們是「在 Agent Platform 訓練」：BigQuery 把工作送去 Agent Platform（原 Vertex AI）算完再拿回來。你感覺不到差別，只有費用算法不同（下一節）。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">6. 要花多少錢：算一次</h2>



<p class="wp-block-paragraph"><a href="https://docs.cloud.google.com/bigquery/pricing">官方定價頁</a>的 BigQuery ML 段落，重點是：</p>


<ul class="wp-block-list">
<li><strong>按量計費</strong>（on-demand）時，依「操作類型」收費：建模型、評估、檢查、預測各有價格</li>

<li><strong>評估、檢查、預測</strong>跟一般查詢<strong>同價</strong>，而且算在每月 1 TiB 的免費額度裡</li>

<li><strong>建模型（CREATE MODEL）</strong>是另一個價格，依輸入查詢處理的資料量計算</li>

<li><strong>超參數調校</strong>：每一組試驗都是一次建模型，費用是所有試驗的總和</li>

<li><strong>時間序列開 auto-ARIMA</strong>：會試很多候選模型，處理的位元組數要乘上候選模型數（<code>AUTO_ARIMA_MAX_ORDER</code> 設 5 時最多 42 個）</li>

<li>迭代式模型<strong>最多跑 50 輪</strong>就停</li>

<li>用 <strong>Editions</strong>（買算力）的話，BigQuery ML 包含在裡面；外部訓練的模型（DNN、提升樹、AutoML）要另外用 <code>ML_EXTERNAL</code> 類型的保留算力</li>
</ul>



<p class="wp-block-paragraph">官方頁面有一個計算範例，美國多區域的建模型價格是每 TiB 312.5 美元。套到飲料店（台灣區域價格請看定價頁，這裡用官方範例的數字）：</p>



<pre class="wp-block-code"><code>會員特徵表 2 GB
建模型費用 = 2 ÷ 1,024 TiB × 312.5 美元 ≈ 0.61 美元

超參數調校 20 組試驗
= 20 × 0.61 ≈ 12.2 美元

ARIMA_PLUS 開 auto-ARIMA、AUTO_ARIMA_MAX_ORDER = 5
銷售表 500 MB × 42 個候選模型 = 21 GB 的處理量
≈ 21 ÷ 1,024 × 312.5 ≈ 6.4 美元</code></pre>



<p class="wp-block-paragraph"><strong>數字怎麼看</strong>：</p>


<ul class="wp-block-list">
<li>一個 2 GB 的表建模型不到 1 美元，這就是「最快看到結果」的代價，很便宜</li>

<li>超參數調校和 auto-ARIMA 是<strong>倍數</strong>在長，試驗組數和候選模型數決定費用</li>

<li><code>ML.PREDICT</code> 對 50 萬列預測，就是掃一次表的查詢費，通常在免費額度內</li>

<li>內建模型可以先 <strong>dry run</strong>（試跑不執行）估處理量；外部訓練的模型不能</li>
</ul>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-03-cost.png" alt="BigQuery ML 費用算一次：建模型依處理資料量計價，2 GB 的表用官方範例價格約 0.61 美元；超參數調校 20 組就乘 20；評估與預測跟一般查詢同價，算在每月 1 TiB 免費額度" class="wp-image-12842" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-03-cost.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-03-cost-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-03-cost-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-03-cost-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<p class="wp-block-paragraph">站上有一篇 <a href="https://dongdonggcp.com/2026/03/27/bigquery-billing-guide/">BigQuery 計費方式</a>，按量和 Editions 的差別那篇講得更細。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">在 GCP 上怎麼做</h2>



<h3 class="wp-block-heading">1. 從哪裡下 SQL</h3>



<p class="wp-block-paragraph">官方簡介列的入口：Google Cloud 主控台的查詢編輯器、<code>bq</code> 命令列工具、REST API、BigQuery 裡的 Colab Enterprise 筆記本、外部工具（Jupyter、BI 平台）。會 Python 的人也可以用 <strong>BigQuery DataFrames</strong>（<code>bigframes</code>），官方教學每一步都有 SQL 和 DataFrames 兩種寫法。</p>



<h3 class="wp-block-heading">2. 資料先進 BigQuery</h3>



<p class="wp-block-paragraph">CSV、Cloud Storage、串流、其他資料庫都有辦法，站上有一篇<a href="https://dongdonggcp.com/2025/02/12/how-to-upload-data-to-bigquery/">把資料上傳到 BigQuery 的各種方法</a>。</p>



<h3 class="wp-block-heading">3. 要線上預測：註冊到 Model Registry</h3>



<p class="wp-block-paragraph"><code>ML.PREDICT</code> 是批次。要做「App 一打開就即時算流失機率」，<a href="https://docs.cloud.google.com/bigquery/docs/managing-models-vertex">官方文件</a>的做法是在 <code>CREATE MODEL</code> 加上：</p>



<pre class="wp-block-code"><code>OPTIONS (
  model_type = 'LOGISTIC_REG',
  input_label_cols = ['churned'],
  model_registry = 'VERTEX_AI',
  vertex_ai_model_id = 'churn_model'
)</code></pre>



<p class="wp-block-paragraph">模型會自動註冊到 Agent Platform 的 <strong>Model Registry</strong>，不用匯出、不用自己做服務容器，就能部署成端點做線上預測、管版本。需要 <code>roles/aiplatform.admin</code> 權限，而且要先開 Agent Platform API。部署的細節第 17 篇講。</p>



<h3 class="wp-block-heading">4. 改名對照</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>舊名稱</th><th>現在</th></tr></thead><tbody><tr><td>BQML、BigQuery ML</td><td>沒變</td></tr><tr><td>BQML.PREDICT（筆記寫法）</td><td><code>ML.PREDICT</code></td></tr><tr><td>Vertex AI Model Registry</td><td>Gemini Enterprise Agent Platform Model Registry（SQL 選項名稱仍是 <code>model_registry = 'VERTEX_AI'</code>）</td></tr><tr><td>「在 Vertex AI 訓練」的外部模型</td><td>在 Agent Platform 訓練，寫法不變</td></tr></tbody></table></figure>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">考試會怎麼考</h2>



<p class="wp-block-paragraph">Google Cloud <strong>Professional Machine Learning Engineer（PMLE，專業機器學習工程師）</strong> 證照，2026 年 6 月 1 日起的<a href="https://services.google.com/fh/files/misc/professional_machine_learning_engineer_exam_guide_english_new.pdf">官方考試指南</a>裡，這篇的內容對應到：</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>考試區塊</th><th>跟這篇有關的項目</th></tr></thead><tbody><tr><td>第 1 區：設計低程式碼 AI 方案（約 13%）</td><td>1.1 <strong>用 BigQuery ML 建模型</strong>（分類、迴歸、預測、分群）；<strong>用 BigQuery ML 做特徵工程或特徵選擇</strong>；<strong>用 BigQuery ML 產生預測</strong>；用 BigQuery 微調 Gemini</td></tr><tr><td>第 3 區：把原型放大成 ML 模型（約 21%）</td><td>3.1 選模型類型（ARIMA、DNN…）、選產品（BigQuery ML…）</td></tr><tr><td>第 5 區：自動化與編排 ML 管線（約 18%）</td><td>5.1 <strong>確保訓練和服務的前處理一致</strong>（TRANSFORM 子句就是這個）</td></tr></tbody></table></figure>



<figure class="wp-block-image aligncenter size-full"><img loading="lazy" decoding="async" width="1200" height="675" src="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-04-exam-keywords.png" alt="PMLE 考試關鍵字：只會 SQL 資料在 BigQuery 想到 BigQuery ML、類別不平衡想到 auto_class_weights、時間序列想到 ARIMA_PLUS 和 SEQ 切分、訓練和預測前處理要一致想到 TRANSFORM、每筆預測的原因想到 ML.EXPLAIN_PREDICT、線上預測想到 Model Registry" class="wp-image-12843" srcset="https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-04-exam-keywords.png 1200w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-04-exam-keywords-300x169.png 300w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-04-exam-keywords-1024x576.png 1024w, https://dongdonggcp.com/wp-content/uploads/2026/10/ml15-04-exam-keywords-768x432.png 768w" sizes="(max-width: 1200px) 100vw, 1200px" /></figure>



<h3 class="wp-block-heading">看到這些字，就想到這個</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>題目出現的關鍵字</th><th>想到</th></tr></thead><tbody><tr><td>「資料分析師」「只會 SQL」「資料在 BigQuery」「最快上線」</td><td><strong>BigQuery ML</strong></td></tr><tr><td>「是或不是」「會不會流失」</td><td><code>LOGISTIC_REG</code>（或 <code>BOOSTED_TREE_CLASSIFIER</code>）</td></tr><tr><td>「預測金額」「連續數值」</td><td><code>LINEAR_REG</code></td></tr><tr><td>「未來 N 天銷量」「季節性」「假日」</td><td><code>ARIMA_PLUS</code>＋<code>ML.FORECAST</code>；資料切分用 <code>SEQ</code></td></tr><tr><td>「會員分幾群」「沒有標籤」</td><td><code>KMEANS</code></td></tr><tr><td>「推薦商品」「誰買過什麼」</td><td><code>MATRIX_FACTORIZATION</code>＋<code>ML.RECOMMEND</code></td></tr><tr><td>「正例很少」「不平衡」</td><td><code>auto_class_weights = TRUE</code></td></tr><tr><td>「訓練和預測的前處理要一致」「避免 skew」</td><td><strong>TRANSFORM 子句</strong></td></tr><tr><td>「每一筆預測的原因」</td><td><code>ML.EXPLAIN_PREDICT</code>；整體重要性用 <code>ML.GLOBAL_EXPLAIN</code></td></tr><tr><td>「調整門檻」「寧可多抓」</td><td><code>ML.PREDICT</code> 或 <code>ML.EVALUATE</code> 的 <code>threshold</code> 參數</td></tr><tr><td>「自動找最佳正則化」</td><td><code>num_trials</code>＋<code>HPARAM_RANGE</code>／<code>HPARAM_CANDIDATES</code></td></tr><tr><td>「用 SQL 但要 AutoML 的效果」</td><td><code>AUTOML_CLASSIFIER</code>／<code>AUTOML_REGRESSOR</code></td></tr><tr><td>「即時預測」「線上端點」</td><td><code>model_registry = 'VERTEX_AI'</code> 註冊到 Model Registry，部署端點</td></tr><tr><td>「控制建模型的費用」</td><td>內建模型先 dry run；減少試驗組數；注意 auto-ARIMA 的候選數</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">六個常見陷阱</h3>


<ol class="wp-block-list">
<li><strong>把會員編號當特徵丟進去</strong>：模型會記答案，評估分數虛高、上線沒用</li>

<li><strong>時間序列用預設的 AUTO_SPLIT</strong>：預設是隨機切，未來的資料會混進訓練集（第 4、8 篇），要用 <code>SEQ</code></li>

<li><strong>訓練前自己在外面做標準化，預測時忘了做</strong>：訓練和上線不一致。放進 TRANSFORM 就不會忘</li>

<li><strong>不平衡資料忘了 <code>auto_class_weights</code></strong>：模型全猜「不流失」也有 95% 準確率，召回率卻是 0</li>

<li><strong>以為 ML.PREDICT 是即時的</strong>：它是批次，線上預測要走 Model Registry 部署端點</li>

<li><strong>超參數調校的費用當成一次</strong>：是試驗組數的倍數</li>
</ol>



<h3 class="wp-block-heading">練習情境（自己出的練習，不是真實考題）</h3>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">飲料店的分析師要用 BigQuery 裡的會員資料預測流失，流失會員只佔 5%。她希望寧可多抓一些可能流失的人，也不要漏掉。應該怎麼設定？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「BigQuery 裡」「分析師」→ <strong>BigQuery ML</strong>，<code>LOGISTIC_REG</code></li>

<li>「只佔 5%」→ <code>auto_class_weights = TRUE</code></li>

<li>「寧可多抓」→ 追<strong>召回率</strong>，<code>ML.PREDICT</code> 的 <code>threshold</code> 調低（例如 0.3），用 <code>ML.EVALUATE</code> 加同樣的 threshold 確認召回率</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">同一家店要預測每間分店未來兩週的日銷量，資料是過去三年的每日銷售表。分析師直接用預設設定訓練，發現評估分數好得不像真的。問題出在哪？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「好得不像真的」→ 懷疑<strong>資料洩漏</strong>（第 8 篇）</li>

<li>「時間序列」「預設設定」→ AUTO_SPLIT 是隨機切，未來的資料跑進訓練集</li>

<li>解法：用 <code>ARIMA_PLUS</code> 這類時間序列模型，或一般模型改 <code>data_split_method = 'SEQ'</code> 依時間切</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">模型上線後，工程師發現預測結果跟訓練時差很多。追查發現訓練前分析師用 Python 把客單價做了分桶，但上線時的 SQL 沒有分桶。怎麼避免？</p>
</blockquote>



<p class="wp-block-paragraph"><strong>判斷過程</strong>：</p>


<ul class="wp-block-list">
<li>「訓練和上線的前處理不一樣」→ <strong>訓練／服務偏差</strong>（第 20 篇）</li>

<li>解法：把分桶寫進 <code>CREATE MODEL</code> 的 <strong>TRANSFORM 子句</strong>（<code>ML.QUANTILE_BUCKETIZE</code>），<code>ML.PREDICT</code> 會自動用訓練時的切點</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">常見問答</h2>



<h3 class="wp-block-heading">BigQuery ML 怎麼入門？</h3>



<p class="wp-block-paragraph">三句 SQL：CREATE MODEL 指定模型類型和標籤欄、用 SELECT 給訓練資料；ML.EVALUATE 看精確率、召回率、AUC 這些分數；ML.PREDICT 對一張表批次預測，輸出多兩欄 predicted_標籤名 和機率。資料全程留在 BigQuery，不用寫 Python。官方的邏輯迴歸教學用美國人口普查資料走一遍，照著做一個下午就能完成。</p>



<h3 class="wp-block-heading">BigQuery ML 支援哪些模型？</h3>



<p class="wp-block-paragraph">內建的有線性迴歸、邏輯迴歸、K-means 分群、矩陣分解（推薦）、PCA、ARIMA_PLUS 時間序列、貢獻分析；透過 Agent Platform 訓練的有 DNN、Wide &amp; Deep、自動編碼器、提升樹（XGBoost）、隨機森林、AutoML；還能匯入 TensorFlow、ONNX、XGBoost 模型，或遠端呼叫 Gemini。寫法都是 CREATE MODEL 加 model_type。</p>



<h3 class="wp-block-heading">BigQuery ML 會自動做前處理嗎？</h3>



<p class="wp-block-paragraph">會。訓練時數字欄自動標準化（提升樹和隨機森林除外），文字、布林、日期欄自動 One-hot 編碼，時間戳記自動拆成年月星期等，NULL 數字補平均值、NULL 類別當成額外的類別。想自己控制就用 TRANSFORM 子句，裡面可以用 ML.STANDARD_SCALER、ML.BUCKETIZE、ML.FEATURE_CROSS、ML.IMPUTER 等函數，而且預測時會自動套用同樣的轉換。</p>



<h3 class="wp-block-heading">BigQuery ML 的資料怎麼切訓練集和評估集？</h3>



<p class="wp-block-paragraph">預設 AUTO_SPLIT：少於 500 列全部訓練；500 到 50,000 列隨機切 20% 評估；超過 50,000 列固定抽 10,000 列評估；有開超參數調校則 80% 訓練、10% 評估、10% 測試。時間序列資料要改用 SEQ 依順序切，否則未來的資料會混進訓練集。也可以用 CUSTOM 自己標，或 NO_SPLIT 另外準備評估資料。</p>



<h3 class="wp-block-heading">BigQuery ML 怎麼處理類別不平衡？</h3>



<p class="wp-block-paragraph">邏輯迴歸模型在 CREATE MODEL 加 auto_class_weights = TRUE，它會依每個類別出現頻率的反比加權，少數類別的每一筆都算比較重。另外在 ML.PREDICT 和 ML.EVALUATE 用 threshold 參數調門檻，流失預測這種寧可多抓的情境把門檻調低。</p>



<h3 class="wp-block-heading">ML.PREDICT 和 ML.EXPLAIN_PREDICT 差在哪？</h3>



<p class="wp-block-paragraph">ML.PREDICT 只給預測結果和機率；ML.EXPLAIN_PREDICT 是它的加強版，每一列多回傳貢獻最大的幾個特徵和貢獻值，top_k_features 預設 5 個。想看模型整體哪些特徵最重要，訓練時開 enable_global_explain，再用 ML.GLOBAL_EXPLAIN 查。筆記裡的 BQML.PREDICT、BQML.EXPLAIN_PREDICT 是舊寫法，正確名稱是 ML.PREDICT、ML.EXPLAIN_PREDICT。</p>



<h3 class="wp-block-heading">BigQuery ML 可以調超參數嗎？</h3>



<p class="wp-block-paragraph">可以。CREATE MODEL 設 num_trials 指定試幾組，超參數用 HPARAM_RANGE 給範圍或 HPARAM_CANDIDATES 給候選值，跑完用 ML.TRIAL_INFO 看每組分數。支援線性／邏輯迴歸、K-means、矩陣分解、自動編碼器、提升樹、隨機森林、DNN、Wide &amp; Deep。費用是每一組試驗的總和。</p>



<h3 class="wp-block-heading">BigQuery ML 能做時間序列預測嗎？</h3>



<p class="wp-block-paragraph">能。model_type 設 ARIMA_PLUS，指定時間欄和數值欄，用 time_series_id_col 可以一次對很多個序列（例如每間分店）各建一個模型，holiday_region 加入假日效應。預測用 ML.FORECAST 給 horizon（預測幾期）和 confidence_level（預測區間）。它會自動處理異常值、季節性、假日。不想管模型可以用 AI.FORECAST 搭內建的 TimesFM。</p>



<h3 class="wp-block-heading">BigQuery ML 要多少錢？</h3>



<p class="wp-block-paragraph">按量計費時，評估和預測跟一般查詢同價，算在每月 1 TiB 免費額度內；建模型另外計價，依輸入查詢處理的資料量算，官方範例美國多區域是每 TiB 312.5 美元，2 GB 的表約 0.61 美元。超參數調校是試驗組數的倍數，auto-ARIMA 是候選模型數的倍數。用 Editions 的話 BigQuery ML 包在裡面，外部訓練的模型要用 ML_EXTERNAL 保留算力。</p>



<h3 class="wp-block-heading">BigQuery ML 的預測是即時的嗎？</h3>



<p class="wp-block-paragraph">ML.PREDICT 是批次預測，一次對整張表算完。要做即時的線上預測，在 CREATE MODEL 加 model_registry = &#8216;VERTEX_AI&#8217; 把模型註冊到 Agent Platform 的 Model Registry，不用匯出、不用自己做服務容器，就能部署成端點。</p>



<h3 class="wp-block-heading">不會寫 SQL 能用 BigQuery ML 嗎？</h3>



<p class="wp-block-paragraph">官方簡介提到 Google Cloud 主控台有圖形介面可以操作模型（預覽階段），也可以用 BigQuery DataFrames 寫 Python。但 BigQuery ML 的設計初衷就是給會 SQL 的人，SQL 是它最完整的介面，建議至少學會 SELECT、WHERE、GROUP BY 這幾個基本句型。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">重點整理</h2>


<ul class="wp-block-list">
<li><strong>三句 SQL</strong>：<code>CREATE MODEL</code>（model_type＋input_label_cols＋AS SELECT）→ <code>ML.EVALUATE</code>（precision、recall、roc_auc…）→ <code>ML.PREDICT</code>（predicted_標籤名＋機率，threshold 可調）</li>

<li><strong>自動前處理</strong>：數字標準化、類別 One-hot、NULL 補平均值或當額外類別；要自己控制用 <strong>TRANSFORM</strong>，預測時自動套用同樣轉換，解決訓練／服務偏差</li>

<li><strong>資料切分</strong>：AUTO_SPLIT 預設 &lt; 500 全訓練、500～50,000 切 20%、&gt; 50,000 抽 10,000 列；<strong>時間序列用 SEQ</strong></li>

<li><strong>不平衡</strong>：<code>auto_class_weights = TRUE</code>；<strong>超參數</strong>：<code>num_trials</code>＋<code>HPARAM_RANGE</code>／<code>HPARAM_CANDIDATES</code></li>

<li><strong>其他模型</strong>：<code>ARIMA_PLUS</code>＋<code>ML.FORECAST</code>（時間序列）、<code>KMEANS</code>（分群）、<code>MATRIX_FACTORIZATION</code>（推薦）、<code>BOOSTED_TREE</code>／<code>DNN</code>／<code>AUTOML</code>（在 Agent Platform 訓練）</li>

<li><strong>費用</strong>：評估、預測同一般查詢價；建模型依處理量另計；調校和 auto-ARIMA 是倍數</li>

<li><strong>線上預測</strong>：<code>model_registry = 'VERTEX_AI'</code> 註冊到 Model Registry 再部署端點；函數名稱是 <code>ML.PREDICT</code> 不是 BQML.PREDICT</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">延伸閱讀</h2>



<p class="wp-block-paragraph"><strong>本系列</strong></p>


<ul class="wp-block-list">
<li>第 1 篇：<a href="https://dongdonggcp.com/2026/10/20/types-of-machine-learning-supervised-unsupervised-reinforcement/">機器學習有哪幾種？監督式、非監督式、強化學習一次看懂</a></li>

<li>第 2 篇：<a href="https://dongdonggcp.com/2026/10/20/classification-vs-regression-mae-rmse/">分類和迴歸差在哪？一個例子搞懂，附 MAE、RMSE 計算</a></li>

<li>第 3 篇：<a href="https://dongdonggcp.com/2026/10/20/features-labels-hyperparameters-machine-learning/">特徵、標籤、超參數是什麼？機器學習 5 個必懂名詞</a></li>

<li>第 4 篇：<a href="https://dongdonggcp.com/2026/10/21/train-validation-test-split-time-series/">訓練集、驗證集、測試集怎麼切？時間序列為什麼不能亂切</a></li>

<li>第 5 篇：<a href="https://dongdonggcp.com/2026/10/21/confusion-matrix-accuracy-precision-recall-f1/">混淆矩陣是什麼？用快篩搞懂準確率、精確率、召回率、F1</a></li>

<li>第 6 篇：<a href="https://dongdonggcp.com/2026/10/22/roc-curve-auc-threshold-auc-pr/">ROC 曲線和 AUC 怎麼看？門檻怎麼調、AUC-PR 差在哪</a></li>

<li>第 7 篇：<a href="https://dongdonggcp.com/2026/10/22/overfitting-regularization-dropout-early-stopping/">過度擬合是什麼？正則化、Dropout、提前停止 3 招解決</a></li>

<li>第 8 篇：<a href="https://dongdonggcp.com/2026/10/22/data-leakage-machine-learning/">資料洩漏是什麼？模型考試作弊的 3 種常見情況</a></li>

<li>第 9 篇：<a href="https://dongdonggcp.com/2026/10/22/class-imbalance-oversampling-downsampling-upweighting/">類別不平衡怎麼辦？過取樣、欠取樣與 Upweighting</a></li>

<li>第 10 篇：<a href="https://dongdonggcp.com/2026/10/22/data-preprocessing-normalization-missing-values-high-cardinality/">資料前處理怎麼做？標準化、遺失值、高基數類別</a></li>

<li>第 11 篇：<a href="https://dongdonggcp.com/2026/10/25/feature-engineering-feature-cross-embedding-data-augmentation/">特徵工程是什麼？特徵交叉、詞嵌入、資料增強一次看懂</a></li>

<li>第 12 篇：<a href="https://dongdonggcp.com/2026/10/25/machine-learning-data-privacy-dlp-federated-learning-vpc-service-controls/">機器學習的資料隱私怎麼保護？DLP、聯邦學習、VPC Service Controls</a></li>

<li>第 13 篇：<a href="https://dongdonggcp.com/2026/10/25/tfrecords-tf-data-prefetch-input-pipeline/">訓練資料讀太慢？TFRecords、tf.data 與 prefetch 加速</a></li>

<li>上一篇：第 14 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-automl-bigquery-ml-custom-training-how-to-choose/">Vertex AI AutoML、BigQuery ML、自訂訓練怎麼選？</a></li>

<li>下一篇：第 16 篇：<a href="https://dongdonggcp.com/2026/10/25/vertex-ai-custom-training-containers-distributed-gpu-tpu/">Vertex AI 自訂訓練：容器、分散式訓練、GPU 與 TPU</a></li>
</ul>



<p class="wp-block-paragraph"><strong>站上相關文章</strong></p>


<ul class="wp-block-list">
<li><a href="https://dongdonggcp.com/2024/11/23/what-is-bigquery-functions-advantages/">BigQuery 是什麼？功能、組成元件、特色和優勢完整介紹</a></li>

<li><a href="https://dongdonggcp.com/2025/07/04/is-bigquery-a-database-what-is-the-usage/">BigQuery 是資料庫嗎？跟資料庫差在哪</a></li>

<li><a href="https://dongdonggcp.com/2025/02/12/how-to-upload-data-to-bigquery/">把資料上傳到 BigQuery 的各種方法和步驟</a></li>

<li><a href="https://dongdonggcp.com/2026/03/27/bigquery-billing-guide/">BigQuery 計費方式完整介紹</a></li>

<li><a href="https://dongdonggcp.com/2026/03/19/bigquery-case-study-home-depot/">BigQuery 成功案例：Home Depot 導入 GCP 的案例解析</a></li>

<li><a href="https://dongdonggcp.com/2024/10/01/how-to-pass-gcp-data-engineer-certification-test/">GCP 證照 Data Engineer 怎麼考？</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="wp-block-paragraph">會 SQL 就能做機器學習，這是最低門檻的起點。如果你想有系統地從雲端基礎一路學到在 GCP 上動手做機器學習，可以看看<a href="https://dongdonggcp.com/">東東的 GCP 課程</a>，或<a href="https://line.me/R/ti/p/@754xlakm">加 LINE 聊聊</a>你現在的狀況，一起找出最適合你的學習順序。</p>



<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "BigQuery ML 怎麼入門？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "三句 SQL：CREATE MODEL 指定模型類型和標籤欄、用 SELECT 給訓練資料；ML.EVALUATE 看精確率、召回率、AUC 這些分數；ML.PREDICT 對一張表批次預測，輸出多兩欄 predicted_標籤名 和機率。資料全程留在 BigQuery，不用寫 Python。官方的邏輯迴歸教學用美國人口普查資料走一遍，照著做一個下午就能完成。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 支援哪些模型？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "內建的有線性迴歸、邏輯迴歸、K-means 分群、矩陣分解（推薦）、PCA、ARIMA_PLUS 時間序列、貢獻分析；透過 Agent Platform 訓練的有 DNN、Wide & Deep、自動編碼器、提升樹（XGBoost）、隨機森林、AutoML；還能匯入 TensorFlow、ONNX、XGBoost 模型，或遠端呼叫 Gemini。寫法都是 CREATE MODEL 加 model_type。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 會自動做前處理嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "會。訓練時數字欄自動標準化（提升樹和隨機森林除外），文字、布林、日期欄自動 One-hot 編碼，時間戳記自動拆成年月星期等，NULL 數字補平均值、NULL 類別當成額外的類別。想自己控制就用 TRANSFORM 子句，裡面可以用 ML.STANDARD_SCALER、ML.BUCKETIZE、ML.FEATURE_CROSS、ML.IMPUTER 等函數，而且預測時會自動套用同樣的轉換。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 的資料怎麼切訓練集和評估集？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "預設 AUTO_SPLIT：少於 500 列全部訓練；500 到 50,000 列隨機切 20% 評估；超過 50,000 列固定抽 10,000 列評估；有開超參數調校則 80% 訓練、10% 評估、10% 測試。時間序列資料要改用 SEQ 依順序切，否則未來的資料會混進訓練集。也可以用 CUSTOM 自己標，或 NO_SPLIT 另外準備評估資料。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 怎麼處理類別不平衡？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "邏輯迴歸模型在 CREATE MODEL 加 auto_class_weights = TRUE，它會依每個類別出現頻率的反比加權，少數類別的每一筆都算比較重。另外在 ML.PREDICT 和 ML.EVALUATE 用 threshold 參數調門檻，流失預測這種寧可多抓的情境把門檻調低。"
      }
    },
    {
      "@type": "Question",
      "name": "ML.PREDICT 和 ML.EXPLAIN_PREDICT 差在哪？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "ML.PREDICT 只給預測結果和機率；ML.EXPLAIN_PREDICT 是它的加強版，每一列多回傳貢獻最大的幾個特徵和貢獻值，top_k_features 預設 5 個。想看模型整體哪些特徵最重要，訓練時開 enable_global_explain，再用 ML.GLOBAL_EXPLAIN 查。筆記裡的 BQML.PREDICT、BQML.EXPLAIN_PREDICT 是舊寫法，正確名稱是 ML.PREDICT、ML.EXPLAIN_PREDICT。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 可以調超參數嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "可以。CREATE MODEL 設 num_trials 指定試幾組，超參數用 HPARAM_RANGE 給範圍或 HPARAM_CANDIDATES 給候選值，跑完用 ML.TRIAL_INFO 看每組分數。支援線性／邏輯迴歸、K-means、矩陣分解、自動編碼器、提升樹、隨機森林、DNN、Wide & Deep。費用是每一組試驗的總和。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 能做時間序列預測嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "能。model_type 設 ARIMA_PLUS，指定時間欄和數值欄，用 time_series_id_col 可以一次對很多個序列（例如每間分店）各建一個模型，holiday_region 加入假日效應。預測用 ML.FORECAST 給 horizon（預測幾期）和 confidence_level（預測區間）。它會自動處理異常值、季節性、假日。不想管模型可以用 AI.FORECAST 搭內建的 TimesFM。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 要多少錢？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "按量計費時，評估和預測跟一般查詢同價，算在每月 1 TiB 免費額度內；建模型另外計價，依輸入查詢處理的資料量算，官方範例美國多區域是每 TiB 312.5 美元，2 GB 的表約 0.61 美元。超參數調校是試驗組數的倍數，auto-ARIMA 是候選模型數的倍數。用 Editions 的話 BigQuery ML 包在裡面，外部訓練的模型要用 ML_EXTERNAL 保留算力。"
      }
    },
    {
      "@type": "Question",
      "name": "BigQuery ML 的預測是即時的嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "ML.PREDICT 是批次預測，一次對整張表算完。要做即時的線上預測，在 CREATE MODEL 加 model_registry = 'VERTEX_AI' 把模型註冊到 Agent Platform 的 Model Registry，不用匯出、不用自己做服務容器，就能部署成端點。"
      }
    },
    {
      "@type": "Question",
      "name": "不會寫 SQL 能用 BigQuery ML 嗎？",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "官方簡介提到 Google Cloud 主控台有圖形介面可以操作模型（預覽階段），也可以用 BigQuery DataFrames 寫 Python。但 BigQuery ML 的設計初衷就是給會 SQL 的人，SQL 是它最完整的介面，建議至少學會 SELECT、WHERE、GROUP BY 這幾個基本句型。"
      }
    }
  ]
}
</script><p>The post <a href="https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/">BigQuery ML 入門：只會 SQL 也能訓練模型</a> first appeared on <a href="https://dongdonggcp.com">東東 GCP 教學 - GCP 實戰講師</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://dongdonggcp.com/2026/10/25/bigquery-ml-tutorial-train-model-with-sql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
