[{"data":1,"prerenderedAt":6318},["ShallowReactive",2],{"site-info":3,"post-kmeans-fewer-epochs":99,"related-zh-TW-kmeans-fewer-epochs":4837},{"id":4,"company":5,"extension":16,"meta":17,"services":18,"social":96,"stem":97,"__hash__":98},"site\u002Fsite.yml",{"name":6,"nameEn":7,"email":8,"address":9,"addressEn":10,"lineUrl":11,"lineId":12,"duns":13,"youtube":14,"youtubeId":15},"銡策數位有限公司","Jecision Digital Co., Ltd.","contact@jecision.com","231 新北市新店區北新路二段 262 號 3 樓之 3","3F.-3, No. 262, Sec. 2, Beixin Rd., Xindian Dist., New Taipei City 231, Taiwan","https:\u002F\u002Fline.me\u002FR\u002Fti\u002Fp\u002F@374qnumi","@374qnumi","963905705","https:\u002F\u002Fwww.youtube.com\u002Fshorts\u002F6UE0WTmyjsg","6UE0WTmyjsg","yml",{},[19,43,69],{"key":20,"zh":21,"en":32},"audit",{"title":22,"tagline":23,"summary":24,"points":25,"deliverable":29,"detail":30,"duration":31},"企業 AI 導入健檢","先看清楚，再花錢","60 分鐘線上訪談，盤點最耗時、最依賴人力的營運環節；我們會告訴你哪些工作現在就能交給 AI、哪些還不成熟。",[26,27,28],"現況盤點：梳理日常營運中最耗時、最依賴人力的環節","痛點診斷：判斷哪些工作現在就能交給 AI，哪些建議先保留人力","可行性評估：依你的業務特性與預算，篩選適合的模型與工具","《企業 AI 導入建議報告書》（PDF）","含 1–2 個「開發成本最低、成效最明顯」的優先項目、技術棧建議、預期節省的人力時間與下一步","訪談 60 分鐘，報告書 3 個工作天內交付",{"title":33,"tagline":34,"summary":35,"points":36,"deliverable":40,"detail":41,"duration":42},"AI Readiness Audit","Look before you spend","A 60-minute remote audit of the workflows that eat the most time and people-power — and an honest answer on what AI can take over today, and what it cannot.",[37,38,39],"Audit the daily workflows that consume the most time and headcount","Triage which tasks AI can own today, and which should stay human","Shortlist the models and tools that fit your budget and constraints","AI Adoption Recommendation Report (PDF)","One or two highest-ROI entry points, a recommended tech stack, expected hours saved, and the concrete next step","60-minute call, report delivered within 3 business days",{"key":44,"zh":45,"en":56},"prompt",{"title":46,"tagline":47,"summary":48,"points":49,"deliverable":53,"detail":54,"duration":55},"提示詞工程","讓 AI 穩定產出，而不是碰運氣","針對你的實際任務設計提示詞與多步驟工作流，並做極限測試，確保換了資料、換了人操作也不會走鐘。",[50,51,52],"客製提示詞：ChatGPT、Claude、Gemini、Midjourney 等主流工具的專屬模板","除錯與優化：修掉幻覺、格式跑掉、時好時壞的問題","工作流建置：把複雜任務拆成多步驟提示詞與可重複的 SOP","提示詞文件或設定檔","附使用說明與範例，並提供 1 對 1 教學，確保你與團隊能自己維護","依任務複雜度報價，通常 3–7 個工作天",{"title":57,"tagline":58,"summary":59,"points":60,"deliverable":66,"detail":67,"duration":68},"Prompt Engineering","Make AI produce reliably, not by luck","Prompt sets and multi-step workflows designed for your actual tasks, stress-tested so they keep working when the data or the operator changes.",[61,62,64],"Custom prompts for ChatGPT, Claude, Gemini, Midjourney and friends",{"Debugging and tuning":63},"kill hallucinations, broken formats and flaky output",{"Workflow design":65},"break complex work into repeatable multi-step SOPs","Prompt library or exportable config","Ships with usage notes and examples, plus a 1:1 walkthrough so your team can maintain it","Quoted by complexity, typically 3–7 business days",{"key":70,"zh":71,"en":82},"poc",{"title":72,"tagline":73,"summary":74,"points":75,"deliverable":79,"detail":80,"duration":81},"極速 PoC","五天，看到能跑的東西","不談架構藍圖，直接做一個能動的雛形。五個工作天內交付線上可操作的智能體，用你真實的資料驗證。",[76,77,78],"Day 1：15 分鐘對焦，鎖定單一痛點與資料盤點","Day 2–4：模型串接、邏輯設計與雛形開發","Day 5：Demo 展示與 AI 擴展建議書","可線上操作的智能體雛形","交付範圍為概念驗證與展示，不含後續維運或大規模伺服器部署；要進階成完整系統會另行報價","5 個工作天",{"title":83,"tagline":84,"summary":85,"points":86,"deliverable":93,"detail":94,"duration":95},"Rapid PoC","Five days to something that runs","No architecture decks — a working prototype built in five business days, validated against your real data.",[87,89,91],{"Day 1":88},"15-minute scoping call, one pain point, data inventory",{"Day 2–4":90},"model integration, logic design, prototype build",{"Day 5":92},"live demo plus an AI expansion recommendation","A runnable online agent prototype","Proof of concept and demo scope only; ongoing operations and large-scale deployment are quoted separately","5 business days",[],"site","XTwARfVAOcrXNiKehsM6V6cdkd2HXy4d5yZVrSWrI3Q",{"zh":100,"en":2592},{"id":101,"title":102,"author":103,"body":104,"cover":2572,"coverAlt":2573,"date":2574,"description":2575,"draft":2576,"extension":2577,"featured":2576,"lang":2578,"meta":2579,"navigation":255,"ogImage":2580,"path":2581,"seo":2582,"slug":2583,"stem":2584,"tags":2585,"translationKey":2583,"updated":2590,"__hash__":2591},"blog\u002Fblog\u002Fzh-TW\u002Fkmeans-fewer-epochs.md","k-means 的 25 遍，可以只讀 2 遍","Jecision",{"type":105,"value":106,"toc":2562},"minimark",[107,134,138,141,144,147,150,153,156,234,241,244,261,264,268,271,274,277,1159,1175,1178,1181,1242,1246,1249,1252,1257,1979,1989,1996,2002,2008,2080,2083,2089,2092,2095,2098,2101,2108,2111,2114,2117,2128,2131,2135,2138,2144,2147,2234,2237,2244,2251,2254,2257,2274,2308,2311,2314,2317,2324,2327,2381,2384,2387,2390,2393,2399,2475,2481,2521,2527,2530,2533,2558],[108,109,110],"blockquote",{},[111,112,113,114,121,122,127,128,133],"p",{},"數字來自 ",[115,116,120],"a",{"href":117,"rel":118},"https:\u002F\u002Farxiv.org\u002Fabs\u002F2611.09501",[119],"nofollow","arXiv 2611.09501v1","（2026-11-06，FAIR at Meta）、",[115,123,126],{"href":124,"rel":125},"https:\u002F\u002Fe-means.github.io",[119],"官方專案頁","與 ",[115,129,132],{"href":130,"rel":131},"https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Ffaiss\u002Fblob\u002Fmain\u002Ffaiss\u002FClustering.h",[119],"faiss 原始碼","。我們沒有獨立重跑論文實驗；文中那個 120 點的小模擬是我們自己跑的，設定寫在圖 2 前面。",[135,136,137],"h2",{"id":137},"先確認這筆錢你付過了",[111,139,140],{},"你在做 RAG，或做資料去重。文件進來、切成 chunk、算成向量，然後某一支排程把它們聚成叢集、寫成索引檔。",[111,142,143],{},"重建一次索引，最慢的往往就是這一步。它用的還是 1957 年的演算法，預設要你把資料掃 25 遍。這篇要講的是，同樣的損失，有沒有機會只掃 2 遍。",[111,145,146],{},"有，但只在某些條件下成立。FAIR 的 e-means 用 1.4–2.6 輪追平同樣的損失，也已經進了 faiss 正式版。它加速的是建置、不是查詢，而且有規模門檻。這篇會把條件畫清楚。",[111,148,149],{},"讀完你會多一個問題可以問：「那你們重建索引要多久？」",[135,151,152],{"id":152},"它藏在建置流程的中間",[111,154,155],{},"k-means 不是冷門演算法，它是這一堆東西的底層：",[157,158,159,175],"table",{},[160,161,162],"thead",{},[163,164,165,169,172],"tr",{},[166,167,168],"th",{},"應用",[166,170,171],{},"k-means 在哪",[166,173,174],{},"你什麼時候付這筆錢",[176,177,178,190,201,212,223],"tbody",{},[163,179,180,184,187],{},[181,182,183],"td",{},"IVF 向量索引",[181,185,186],{},"粗量化：先分成大類，查詢時只進對應的桶",[181,188,189],{},"建索引、換模型、補資料",[163,191,192,195,198],{},[181,193,194],{},"乘積量化（PQ）",[181,196,197],{},"把向量切段，每一段各自分群一次",[181,199,200],{},"同上",[163,202,203,206,209],{},[181,204,205],{},"VQ-VAE、神經音訊編碼",[181,207,208],{},"碼簿學習（每個叢集配一個代表向量）",[181,210,211],{},"訓練、換資料集",[163,213,214,217,220],{},[181,215,216],{},"資料去重、異常偵測",[181,218,219],{},"聚類找重複與離群",[181,221,222],{},"匯入、清洗",[163,224,225,228,231],{},[181,226,227],{},"客戶分群、影像分群",[181,229,230],{},"就是它本身",[181,232,233],{},"每次分析",[111,235,236,237],{},"共同的形狀是：",[238,239,240],"strong",{},"它在離線，不在查詢路徑上。",[111,242,243],{},"如圖 1，一支索引的壽命裡，左半是建置、右半是查詢。查詢只讀一次索引；建置要把向量掃過很多遍。你每天感覺到的延遲在右半，真正吃掉時間的在左半。",[245,246,249,250,249,257],"figure",{"className":247},[248],"article-figure","\n  ",[251,252],"video",{"src":253,"poster":254,"autoPlay":255,"loop":255,"muted":255,"playsInline":255,"ariaLabel":256},"\u002Fimages\u002Fblog\u002Fkmeans-fewer-epochs\u002Fpipeline.mp4","\u002Fimages\u002Fblog\u002Fkmeans-fewer-epochs\u002Fpipeline-poster.jpg",true,"索引建置管線：原始資料、嵌入、k-means、索引檔，最後才是查詢；k-means 那格標著 25 遍掃描",[258,259,260],"figcaption",{},"圖 1：左半是建置、右半是查詢；k-means 那格標著 25 遍掃描。",[111,262,263],{},"粗算一下：以 100 萬筆、768 維、k = 4,096 為例（fp32），一趟掃描大約 3.1 GB。Faiss 的 k-means 預設跑 25 輪，就是 77 GB 上下的讀取，還不含距離計算與寫入。這個數字會隨維度、資料型別變動，但量級就是這樣。",[135,265,267],{"id":266},"它還是-1957-年那支-lloyd","它還是 1957 年那支 Lloyd",[111,269,270],{},"Lloyd 的 k-means 只有兩步：把每個點分給最近的質心；把每個質心移到它那群點的平均位置。重複到不再變動。",[111,272,273],{},"它保證收斂——收到局部最小值，不是全域。這個保證從 1957 年貝爾實驗室的技術備忘錄一路用到現在，正式發表是 1982 年。",[111,275,276],{},"要最小化的東西長這樣：",[278,279,282],"span",{"className":280},[281],"katex-display",[278,283,286,465],{"className":284},[285],"katex",[278,287,290],{"className":288},[289],"katex-mathml",[291,292,295],"math",{"xmlns":293,"display":294},"http:\u002F\u002Fwww.w3.org\u002F1998\u002FMath\u002FMathML","block",[296,297,298,460],"semantics",{},[299,300,301,314,319,322,326,329,332,335,345,362,401,403,407,409,411,413,415,417,420,423,436],"mrow",{},[299,302,303,308,311],{},[304,305,307],"mi",{"mathvariant":306},"normal","M",[304,309,310],{"mathvariant":306},"S",[304,312,313],{"mathvariant":306},"E",[315,316,318],"mo",{"stretchy":317},"false","(",[304,320,321],{},"X",[315,323,325],{"separator":324},"true",",",[304,327,328],{},"C",[315,330,331],{"stretchy":317},")",[315,333,334],{},"=",[336,337,338,342],"mfrac",{},[339,340,341],"mn",{},"1",[304,343,344],{},"n",[346,347,348,351,360],"munderover",{},[315,349,350],{},"∑",[299,352,353,356,358],{},[304,354,355],{},"i",[315,357,334],{},[339,359,341],{},[304,361,344],{},[363,364,365,398],"msup",{},[299,366,367,370,378,381,396],{},[315,368,369],{"fence":324},"∥",[371,372,373,376],"msub",{},[304,374,375],{},"x",[304,377,355],{},[315,379,380],{},"−",[371,382,383,386],{},[304,384,385],{},"c",[299,387,388,390,392,394],{},[304,389,115],{},[315,391,318],{"stretchy":317},[304,393,355],{},[315,395,331],{"stretchy":317},[315,397,369],{"fence":324},[339,399,400],{},"2",[315,402,325],{"separator":324},[404,405],"mspace",{"width":406},"2em",[304,408,115],{},[315,410,318],{"stretchy":317},[304,412,355],{},[315,414,331],{"stretchy":317},[315,416,334],{},[304,418,419],{},"arg",[315,421,422],{},"⁡",[424,425,426,433],"munder",{},[299,427,428,431],{},[304,429,430],{},"min",[315,432,422],{},[304,434,435],{},"j",[363,437,438,458],{},[299,439,440,442,448,450,456],{},[315,441,369],{"fence":324},[371,443,444,446],{},[304,445,375],{},[304,447,355],{},[315,449,380],{},[371,451,452,454],{},[304,453,385],{},[304,455,435],{},[315,457,369],{"fence":324},[339,459,400],{},[461,462,464],"annotation",{"encoding":463},"application\u002Fx-tex","\\mathrm{MSE}(X, C) = \\frac{1}{n} \\sum_{i=1}^{n} \\left\\| x_i - c_{a(i)} \\right\\|^2,\n\\qquad a(i) = \\arg\\min_j \\left\\| x_i - c_j \\right\\|^2",[278,466,469,523,960],{"className":467,"ariaHidden":324},[468],"katex-html",[278,470,473,478,487,491,496,500,504,508,512,516,520],{"className":471},[472],"base",[278,474],{"className":475,"style":477},[476],"strut","height:1em;vertical-align:-0.25em;",[278,479,482],{"className":480},[481],"mord",[278,483,486],{"className":484},[481,485],"mathrm","MSE",[278,488,318],{"className":489},[490],"mopen",[278,492,321],{"className":493,"style":495},[481,494],"mathnormal","margin-right:0.0785em;",[278,497,325],{"className":498},[499],"mpunct",[278,501],{"className":502,"style":503},[404],"margin-right:0.1667em;",[278,505,328],{"className":506,"style":507},[481,494],"margin-right:0.0715em;",[278,509,331],{"className":510},[511],"mclose",[278,513],{"className":514,"style":515},[404],"margin-right:0.2778em;",[278,517,334],{"className":518},[519],"mrel",[278,521],{"className":522,"style":515},[404],[278,524,526,530,608,611,692,695,926,929,932,936,939,942,945,948,951,954,957],{"className":525},[472],[278,527],{"className":528,"style":529},[476],"height:2.9291em;vertical-align:-1.2777em;",[278,531,533,537,605],{"className":532},[481],[278,534],{"className":535},[490,536],"nulldelimiter",[278,538,540],{"className":539},[336],[278,541,545,596],{"className":542},[543,544],"vlist-t","vlist-t2",[278,546,549,591],{"className":547},[548],"vlist-r",[278,550,554,568,579],{"className":551,"style":553},[552],"vlist","height:1.3214em;",[278,555,557,562],{"style":556},"top:-2.314em;",[278,558],{"className":559,"style":561},[560],"pstrut","height:3em;",[278,563,565],{"className":564},[481],[278,566,344],{"className":567},[481,494],[278,569,571,574],{"style":570},"top:-3.23em;",[278,572],{"className":573,"style":561},[560],[278,575],{"className":576,"style":578},[577],"frac-line","border-bottom-width:0.04em;",[278,580,582,585],{"style":581},"top:-3.677em;",[278,583],{"className":584,"style":561},[560],[278,586,588],{"className":587},[481],[278,589,341],{"className":590},[481],[278,592,595],{"className":593},[594],"vlist-s","​",[278,597,599],{"className":598},[548],[278,600,603],{"className":601,"style":602},[552],"height:0.686em;",[278,604],{},[278,606],{"className":607},[511,536],[278,609],{"className":610,"style":503},[404],[278,612,616],{"className":613},[614,615],"mop","op-limits",[278,617,619,683],{"className":618},[543,544],[278,620,622,680],{"className":621},[548],[278,623,626,652,665],{"className":624,"style":625},[552],"height:1.6514em;",[278,627,629,633],{"style":628},"top:-1.8723em;margin-left:0em;",[278,630],{"className":631,"style":632},[560],"height:3.05em;",[278,634,640],{"className":635},[636,637,638,639],"sizing","reset-size6","size3","mtight",[278,641,643,646,649],{"className":642},[481,639],[278,644,355],{"className":645},[481,494,639],[278,647,334],{"className":648},[519,639],[278,650,341],{"className":651},[481,639],[278,653,655,658],{"style":654},"top:-3.05em;",[278,656],{"className":657,"style":632},[560],[278,659,660],{},[278,661,350],{"className":662},[614,663,664],"op-symbol","large-op",[278,666,668,671],{"style":667},"top:-4.3em;margin-left:0em;",[278,669],{"className":670,"style":632},[560],[278,672,674],{"className":673},[636,637,638,639],[278,675,677],{"className":676},[481,639],[278,678,344],{"className":679},[481,494,639],[278,681,595],{"className":682},[594],[278,684,686],{"className":685},[548],[278,687,690],{"className":688,"style":689},[552],"height:1.2777em;",[278,691],{},[278,693],{"className":694,"style":503},[404],[278,696,699,901],{"className":697},[698],"minner",[278,700,702,753,798,802,806,809,864],{"className":701},[698],[278,703,705],{"className":704},[490],[278,706,710],{"className":707},[708,709],"delimsizing","mult",[278,711,713,744],{"className":712},[543,544],[278,714,716,741],{"className":715},[548],[278,717,720],{"className":718,"style":719},[552],"height:0.85em;",[278,721,723,727],{"style":722},"top:-2.85em;",[278,724],{"className":725,"style":726},[560],"height:3.2em;",[278,728,730],{"style":729},"width:0.556em;height:1.2em;",[731,732,737],"svg",{"xmlns":733,"width":734,"height":735,"viewBox":736},"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","0.556em","1.2em","0 0 556 1200",[738,739],"path",{"d":740},"M145 15 v585 v0 v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v0 v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M188 15 H145 v585 v0 v585 h43z\nM367 15 v585 v0 v585 c2.667,10,9.667,15,21,15\nc10,0,16.667,-5,20,-15 v-585 v0 v-585 c-2.667,-10,-9.667,-15,-21,-15\nc-10,0,-16.667,5,-20,15z M410 15 H367 v585 v0 v585 h43z",[278,742,595],{"className":743},[594],[278,745,747],{"className":746},[548],[278,748,751],{"className":749,"style":750},[552],"height:0.35em;",[278,752],{},[278,754,756,759],{"className":755},[481],[278,757,375],{"className":758},[481,494],[278,760,763],{"className":761},[762],"msupsub",[278,764,766,789],{"className":765},[543,544],[278,767,769,786],{"className":768},[548],[278,770,773],{"className":771,"style":772},[552],"height:0.3117em;",[278,774,776,780],{"style":775},"top:-2.55em;margin-left:0em;margin-right:0.05em;",[278,777],{"className":778,"style":779},[560],"height:2.7em;",[278,781,783],{"className":782},[636,637,638,639],[278,784,355],{"className":785},[481,494,639],[278,787,595],{"className":788},[594],[278,790,792],{"className":791},[548],[278,793,796],{"className":794,"style":795},[552],"height:0.15em;",[278,797],{},[278,799],{"className":800,"style":801},[404],"margin-right:0.2222em;",[278,803,380],{"className":804},[805],"mbin",[278,807],{"className":808,"style":801},[404],[278,810,812,815],{"className":811},[481],[278,813,385],{"className":814},[481,494],[278,816,818],{"className":817},[762],[278,819,821,855],{"className":820},[543,544],[278,822,824,852],{"className":823},[548],[278,825,828],{"className":826,"style":827},[552],"height:0.3448em;",[278,829,831,834],{"style":830},"top:-2.5198em;margin-left:0em;margin-right:0.05em;",[278,832],{"className":833,"style":779},[560],[278,835,837],{"className":836},[636,637,638,639],[278,838,840,843,846,849],{"className":839},[481,639],[278,841,115],{"className":842},[481,494,639],[278,844,318],{"className":845},[490,639],[278,847,355],{"className":848},[481,494,639],[278,850,331],{"className":851},[511,639],[278,853,595],{"className":854},[594],[278,856,858],{"className":857},[548],[278,859,862],{"className":860,"style":861},[552],"height:0.3552em;",[278,863],{},[278,865,867],{"className":866},[511],[278,868,870],{"className":869},[708,709],[278,871,873,893],{"className":872},[543,544],[278,874,876,890],{"className":875},[548],[278,877,879],{"className":878,"style":719},[552],[278,880,881,884],{"style":722},[278,882],{"className":883,"style":726},[560],[278,885,886],{"style":729},[731,887,888],{"xmlns":733,"width":734,"height":735,"viewBox":736},[738,889],{"d":740},[278,891,595],{"className":892},[594],[278,894,896],{"className":895},[548],[278,897,899],{"className":898,"style":750},[552],[278,900],{},[278,902,904],{"className":903},[762],[278,905,907],{"className":906},[543],[278,908,910],{"className":909},[548],[278,911,914],{"className":912,"style":913},[552],"height:1.054em;",[278,915,917,920],{"style":916},"top:-3.3029em;margin-right:0.05em;",[278,918],{"className":919,"style":779},[560],[278,921,923],{"className":922},[636,637,638,639],[278,924,400],{"className":925},[481,639],[278,927],{"className":928,"style":503},[404],[278,930,325],{"className":931},[499],[278,933],{"className":934,"style":935},[404],"margin-right:2em;",[278,937],{"className":938,"style":503},[404],[278,940,115],{"className":941},[481,494],[278,943,318],{"className":944},[490],[278,946,355],{"className":947},[481,494],[278,949,331],{"className":950},[511],[278,952],{"className":953,"style":515},[404],[278,955,334],{"className":956},[519],[278,958],{"className":959,"style":515},[404],[278,961,963,967,975,978,1027,1030],{"className":962},[472],[278,964],{"className":965,"style":966},[476],"height:1.8178em;vertical-align:-0.8638em;",[278,968,970,971],{"className":969},[614],"ar",[278,972,974],{"style":973},"margin-right:0.0139em;","g",[278,976],{"className":977,"style":503},[404],[278,979,981],{"className":980},[614,615],[278,982,984,1018],{"className":983},[543,544],[278,985,987,1015],{"className":986},[548],[278,988,991,1004],{"className":989,"style":990},[552],"height:0.6679em;",[278,992,994,997],{"style":993},"top:-2.3723em;margin-left:0em;",[278,995],{"className":996,"style":561},[560],[278,998,1000],{"className":999},[636,637,638,639],[278,1001,435],{"className":1002,"style":1003},[481,494,639],"margin-right:0.0572em;",[278,1005,1007,1010],{"style":1006},"top:-3em;",[278,1008],{"className":1009,"style":561},[560],[278,1011,1012],{},[278,1013,430],{"className":1014},[614],[278,1016,595],{"className":1017},[594],[278,1019,1021],{"className":1020},[548],[278,1022,1025],{"className":1023,"style":1024},[552],"height:0.8638em;",[278,1026],{},[278,1028],{"className":1029,"style":503},[404],[278,1031,1033,1134],{"className":1032},[698],[278,1034,1036,1041,1081,1084,1087,1090,1131],{"className":1035},[698],[278,1037,369],{"className":1038,"style":1040},[490,1039],"delimcenter","top:0em;",[278,1042,1044,1047],{"className":1043},[481],[278,1045,375],{"className":1046},[481,494],[278,1048,1050],{"className":1049},[762],[278,1051,1053,1073],{"className":1052},[543,544],[278,1054,1056,1070],{"className":1055},[548],[278,1057,1059],{"className":1058,"style":772},[552],[278,1060,1061,1064],{"style":775},[278,1062],{"className":1063,"style":779},[560],[278,1065,1067],{"className":1066},[636,637,638,639],[278,1068,355],{"className":1069},[481,494,639],[278,1071,595],{"className":1072},[594],[278,1074,1076],{"className":1075},[548],[278,1077,1079],{"className":1078,"style":795},[552],[278,1080],{},[278,1082],{"className":1083,"style":801},[404],[278,1085,380],{"className":1086},[805],[278,1088],{"className":1089,"style":801},[404],[278,1091,1093,1096],{"className":1092},[481],[278,1094,385],{"className":1095},[481,494],[278,1097,1099],{"className":1098},[762],[278,1100,1102,1122],{"className":1101},[543,544],[278,1103,1105,1119],{"className":1104},[548],[278,1106,1108],{"className":1107,"style":772},[552],[278,1109,1110,1113],{"style":775},[278,1111],{"className":1112,"style":779},[560],[278,1114,1116],{"className":1115},[636,637,638,639],[278,1117,435],{"className":1118,"style":1003},[481,494,639],[278,1120,595],{"className":1121},[594],[278,1123,1125],{"className":1124},[548],[278,1126,1129],{"className":1127,"style":1128},[552],"height:0.2861em;",[278,1130],{},[278,1132,369],{"className":1133,"style":1040},[511,1039],[278,1135,1137],{"className":1136},[762],[278,1138,1140],{"className":1139},[543],[278,1141,1143],{"className":1142},[548],[278,1144,1147],{"className":1145,"style":1146},[552],"height:0.954em;",[278,1148,1150,1153],{"style":1149},"top:-3.2029em;margin-right:0.05em;",[278,1151],{"className":1152,"style":779},[560],[278,1154,1156],{"className":1155},[636,637,638,639],[278,1157,400],{"className":1158},[481,639],[111,1160,1161,1162,1166,1167,1170,1171,1174],{},"Faiss 的 ",[1163,1164,1165],"code",{},"Kmeans"," 預設 ",[1163,1168,1169],{},"niter = 25","，每一輪都是一次完整分配。原始碼裡還有一個常被忽略的角落：",[1163,1172,1173],{},"max_points_per_centroid = 256","。當 n 遠大於 k 時，Faiss 會先抽樣到每個叢集最多 256 點。前面那個例子（100 萬點配 4,096 個叢集）剛好還在門檻內（256 × 4,096 ≈ 105 萬）。所以你掃的就是全部。",[111,1176,1177],{},"每一輪的成本是 O(n · k · d)，而且是隨機讀取。這是記憶體頻寬在吃時間，不是浮點運算。25 輪不是幻覺，是真的把資料從頭到尾走了 25 次。這裡的「輪」就是 epoch：資料完整跑過一遍。",[111,1179,1180],{},"那為什麼沒被換掉？小批次版本 1967 年就有（MacQueen）。2010 年 Sculley 的 web-scale 版本也在跑。它們每輪只讀一小批、快得多，代價是誤差偏高，而且你得自己調批次大小與學習率。對大部分場景，「慢，但不用想」是一個很合理的預設。",[157,1182,1183,1199],{},[160,1184,1185],{},[163,1186,1187,1190,1193,1196],{},[166,1188,1189],{},"做法",[166,1191,1192],{},"每輪讀多少",[166,1194,1195],{},"統計量怎麼更新",[166,1197,1198],{},"代價",[176,1200,1201,1215,1229],{},[163,1202,1203,1206,1209,1212],{},[181,1204,1205],{},"Lloyd（全量，Faiss 預設）",[181,1207,1208],{},"全部 n 點",[181,1210,1211],{},"每輪重算精確均值",[181,1213,1214],{},"慢；預設 25 輪",[163,1216,1217,1220,1223,1226],{},[181,1218,1219],{},"MacQueen、Sculley（小批次）",[181,1221,1222],{},"一小批",[181,1224,1225],{},"累加，從不忘記",[181,1227,1228],{},"快，但早期錯誤的分配會一直投票",[163,1230,1231,1234,1236,1239],{},[181,1232,1233],{},"e-means",[181,1235,1222],{},[181,1237,1238],{},"指數移動平均，舊分配衰減",[181,1240,1241],{},"快；參數由標度律算",[135,1243,1245],{"id":1244},"e-means-換掉的四件事","e-means 換掉的四件事",[111,1247,1248],{},"論文的做法叫 e-means，來自 Meta FAIR。論文標題直接寫著「one-tenth the epochs」。作者名單裡有 Matthijs Douze 與 Hervé Jégou，兩人是 Faiss 的作者；再加上 Hugo Touvron。這是同一個團隊在挑戰自己的預設值。",[111,1250,1251],{},"它沒有發明新的損失函數——目標還是上面那條 MSE，改的是「質心怎麼更新」。",[111,1253,1254],{},[238,1255,1256],{},"第一件事，統計量改成指數移動平均。",[278,1258,1260],{"className":1259},[281],[278,1261,1263,1384],{"className":1262},[285],[278,1264,1266],{"className":1265},[289],[291,1267,1268],{"xmlns":293,"display":294},[296,1269,1270,1381],{},[299,1271,1272,1279,1282,1284,1286,1288,1291,1293,1299,1302,1304,1308,1314,1316,1318,1324,1326,1328,1330,1332,1334,1336,1342,1344,1346,1348,1355,1357,1359,1365,1367],{},[371,1273,1274,1277],{},[304,1275,1276],{},"N",[304,1278,435],{},[315,1280,1281],{},"←",[315,1283,318],{"stretchy":317},[339,1285,341],{},[315,1287,380],{},[304,1289,1290],{},"α",[315,1292,331],{"stretchy":317},[371,1294,1295,1297],{},[304,1296,1276],{},[304,1298,435],{},[315,1300,1301],{},"+",[304,1303,1290],{},[1305,1306,1307],"mtext",{}," ",[371,1309,1310,1312],{},[304,1311,344],{},[304,1313,435],{},[315,1315,325],{"separator":324},[404,1317],{"width":406},[371,1319,1320,1322],{},[304,1321,310],{},[304,1323,435],{},[315,1325,1281],{},[315,1327,318],{"stretchy":317},[339,1329,341],{},[315,1331,380],{},[304,1333,1290],{},[315,1335,331],{"stretchy":317},[371,1337,1338,1340],{},[304,1339,310],{},[304,1341,435],{},[315,1343,1301],{},[304,1345,1290],{},[1305,1347,1307],{},[371,1349,1350,1353],{},[304,1351,1352],{},"s",[304,1354,435],{},[315,1356,325],{"separator":324},[404,1358],{"width":406},[371,1360,1361,1363],{},[304,1362,385],{},[304,1364,435],{},[315,1366,334],{},[336,1368,1369,1375],{},[371,1370,1371,1373],{},[304,1372,310],{},[304,1374,435],{},[371,1376,1377,1379],{},[304,1378,1276],{},[304,1380,435],{},[461,1382,1383],{"encoding":463},"N_j \\leftarrow (1-\\alpha) N_j + \\alpha\\, n_j, \\qquad\nS_j \\leftarrow (1-\\alpha) S_j + \\alpha\\, s_j, \\qquad\nc_j = \\frac{S_j}{N_j}",[278,1385,1387,1445,1466,1529,1641,1662,1723,1834],{"className":1386,"ariaHidden":324},[468],[278,1388,1390,1394,1436,1439,1442],{"className":1389},[472],[278,1391],{"className":1392,"style":1393},[476],"height:0.9694em;vertical-align:-0.2861em;",[278,1395,1397,1401],{"className":1396},[481],[278,1398,1276],{"className":1399,"style":1400},[481,494],"margin-right:0.109em;",[278,1402,1404],{"className":1403},[762],[278,1405,1407,1428],{"className":1406},[543,544],[278,1408,1410,1425],{"className":1409},[548],[278,1411,1413],{"className":1412,"style":772},[552],[278,1414,1416,1419],{"style":1415},"top:-2.55em;margin-left:-0.109em;margin-right:0.05em;",[278,1417],{"className":1418,"style":779},[560],[278,1420,1422],{"className":1421},[636,637,638,639],[278,1423,435],{"className":1424,"style":1003},[481,494,639],[278,1426,595],{"className":1427},[594],[278,1429,1431],{"className":1430},[548],[278,1432,1434],{"className":1433,"style":1128},[552],[278,1435],{},[278,1437],{"className":1438,"style":515},[404],[278,1440,1281],{"className":1441},[519],[278,1443],{"className":1444,"style":515},[404],[278,1446,1448,1451,1454,1457,1460,1463],{"className":1447},[472],[278,1449],{"className":1450,"style":477},[476],[278,1452,318],{"className":1453},[490],[278,1455,341],{"className":1456},[481],[278,1458],{"className":1459,"style":801},[404],[278,1461,380],{"className":1462},[805],[278,1464],{"className":1465,"style":801},[404],[278,1467,1469,1473,1477,1480,1520,1523,1526],{"className":1468},[472],[278,1470],{"className":1471,"style":1472},[476],"height:1.0361em;vertical-align:-0.2861em;",[278,1474,1290],{"className":1475,"style":1476},[481,494],"margin-right:0.0037em;",[278,1478,331],{"className":1479},[511],[278,1481,1483,1486],{"className":1482},[481],[278,1484,1276],{"className":1485,"style":1400},[481,494],[278,1487,1489],{"className":1488},[762],[278,1490,1492,1512],{"className":1491},[543,544],[278,1493,1495,1509],{"className":1494},[548],[278,1496,1498],{"className":1497,"style":772},[552],[278,1499,1500,1503],{"style":1415},[278,1501],{"className":1502,"style":779},[560],[278,1504,1506],{"className":1505},[636,637,638,639],[278,1507,435],{"className":1508,"style":1003},[481,494,639],[278,1510,595],{"className":1511},[594],[278,1513,1515],{"className":1514},[548],[278,1516,1518],{"className":1517,"style":1128},[552],[278,1519],{},[278,1521],{"className":1522,"style":801},[404],[278,1524,1301],{"className":1525},[805],[278,1527],{"className":1528,"style":801},[404],[278,1530,1532,1535,1538,1541,1581,1584,1587,1590,1632,1635,1638],{"className":1531},[472],[278,1533],{"className":1534,"style":1393},[476],[278,1536,1290],{"className":1537,"style":1476},[481,494],[278,1539],{"className":1540,"style":503},[404],[278,1542,1544,1547],{"className":1543},[481],[278,1545,344],{"className":1546},[481,494],[278,1548,1550],{"className":1549},[762],[278,1551,1553,1573],{"className":1552},[543,544],[278,1554,1556,1570],{"className":1555},[548],[278,1557,1559],{"className":1558,"style":772},[552],[278,1560,1561,1564],{"style":775},[278,1562],{"className":1563,"style":779},[560],[278,1565,1567],{"className":1566},[636,637,638,639],[278,1568,435],{"className":1569,"style":1003},[481,494,639],[278,1571,595],{"className":1572},[594],[278,1574,1576],{"className":1575},[548],[278,1577,1579],{"className":1578,"style":1128},[552],[278,1580],{},[278,1582,325],{"className":1583},[499],[278,1585],{"className":1586,"style":935},[404],[278,1588],{"className":1589,"style":503},[404],[278,1591,1593,1597],{"className":1592},[481],[278,1594,310],{"className":1595,"style":1596},[481,494],"margin-right:0.0576em;",[278,1598,1600],{"className":1599},[762],[278,1601,1603,1624],{"className":1602},[543,544],[278,1604,1606,1621],{"className":1605},[548],[278,1607,1609],{"className":1608,"style":772},[552],[278,1610,1612,1615],{"style":1611},"top:-2.55em;margin-left:-0.0576em;margin-right:0.05em;",[278,1613],{"className":1614,"style":779},[560],[278,1616,1618],{"className":1617},[636,637,638,639],[278,1619,435],{"className":1620,"style":1003},[481,494,639],[278,1622,595],{"className":1623},[594],[278,1625,1627],{"className":1626},[548],[278,1628,1630],{"className":1629,"style":1128},[552],[278,1631],{},[278,1633],{"className":1634,"style":515},[404],[278,1636,1281],{"className":1637},[519],[278,1639],{"className":1640,"style":515},[404],[278,1642,1644,1647,1650,1653,1656,1659],{"className":1643},[472],[278,1645],{"className":1646,"style":477},[476],[278,1648,318],{"className":1649},[490],[278,1651,341],{"className":1652},[481],[278,1654],{"className":1655,"style":801},[404],[278,1657,380],{"className":1658},[805],[278,1660],{"className":1661,"style":801},[404],[278,1663,1665,1668,1671,1674,1714,1717,1720],{"className":1664},[472],[278,1666],{"className":1667,"style":1472},[476],[278,1669,1290],{"className":1670,"style":1476},[481,494],[278,1672,331],{"className":1673},[511],[278,1675,1677,1680],{"className":1676},[481],[278,1678,310],{"className":1679,"style":1596},[481,494],[278,1681,1683],{"className":1682},[762],[278,1684,1686,1706],{"className":1685},[543,544],[278,1687,1689,1703],{"className":1688},[548],[278,1690,1692],{"className":1691,"style":772},[552],[278,1693,1694,1697],{"style":1611},[278,1695],{"className":1696,"style":779},[560],[278,1698,1700],{"className":1699},[636,637,638,639],[278,1701,435],{"className":1702,"style":1003},[481,494,639],[278,1704,595],{"className":1705},[594],[278,1707,1709],{"className":1708},[548],[278,1710,1712],{"className":1711,"style":1128},[552],[278,1713],{},[278,1715],{"className":1716,"style":801},[404],[278,1718,1301],{"className":1719},[805],[278,1721],{"className":1722,"style":801},[404],[278,1724,1726,1730,1733,1736,1776,1779,1782,1785,1825,1828,1831],{"className":1725},[472],[278,1727],{"className":1728,"style":1729},[476],"height:0.7167em;vertical-align:-0.2861em;",[278,1731,1290],{"className":1732,"style":1476},[481,494],[278,1734],{"className":1735,"style":503},[404],[278,1737,1739,1742],{"className":1738},[481],[278,1740,1352],{"className":1741},[481,494],[278,1743,1745],{"className":1744},[762],[278,1746,1748,1768],{"className":1747},[543,544],[278,1749,1751,1765],{"className":1750},[548],[278,1752,1754],{"className":1753,"style":772},[552],[278,1755,1756,1759],{"style":775},[278,1757],{"className":1758,"style":779},[560],[278,1760,1762],{"className":1761},[636,637,638,639],[278,1763,435],{"className":1764,"style":1003},[481,494,639],[278,1766,595],{"className":1767},[594],[278,1769,1771],{"className":1770},[548],[278,1772,1774],{"className":1773,"style":1128},[552],[278,1775],{},[278,1777,325],{"className":1778},[499],[278,1780],{"className":1781,"style":935},[404],[278,1783],{"className":1784,"style":503},[404],[278,1786,1788,1791],{"className":1787},[481],[278,1789,385],{"className":1790},[481,494],[278,1792,1794],{"className":1793},[762],[278,1795,1797,1817],{"className":1796},[543,544],[278,1798,1800,1814],{"className":1799},[548],[278,1801,1803],{"className":1802,"style":772},[552],[278,1804,1805,1808],{"style":775},[278,1806],{"className":1807,"style":779},[560],[278,1809,1811],{"className":1810},[636,637,638,639],[278,1812,435],{"className":1813,"style":1003},[481,494,639],[278,1815,595],{"className":1816},[594],[278,1818,1820],{"className":1819},[548],[278,1821,1823],{"className":1822,"style":1128},[552],[278,1824],{},[278,1826],{"className":1827,"style":515},[404],[278,1829,334],{"className":1830},[519],[278,1832],{"className":1833,"style":515},[404],[278,1835,1837,1841],{"className":1836},[472],[278,1838],{"className":1839,"style":1840},[476],"height:2.3324em;vertical-align:-0.9721em;",[278,1842,1844,1847,1976],{"className":1843},[481],[278,1845],{"className":1846},[490,536],[278,1848,1850],{"className":1849},[336],[278,1851,1853,1967],{"className":1852},[543,544],[278,1854,1856,1964],{"className":1855},[548],[278,1857,1860,1908,1916],{"className":1858,"style":1859},[552],"height:1.3603em;",[278,1861,1862,1865],{"style":556},[278,1863],{"className":1864,"style":561},[560],[278,1866,1868],{"className":1867},[481],[278,1869,1871,1874],{"className":1870},[481],[278,1872,1276],{"className":1873,"style":1400},[481,494],[278,1875,1877],{"className":1876},[762],[278,1878,1880,1900],{"className":1879},[543,544],[278,1881,1883,1897],{"className":1882},[548],[278,1884,1886],{"className":1885,"style":772},[552],[278,1887,1888,1891],{"style":1415},[278,1889],{"className":1890,"style":779},[560],[278,1892,1894],{"className":1893},[636,637,638,639],[278,1895,435],{"className":1896,"style":1003},[481,494,639],[278,1898,595],{"className":1899},[594],[278,1901,1903],{"className":1902},[548],[278,1904,1906],{"className":1905,"style":1128},[552],[278,1907],{},[278,1909,1910,1913],{"style":570},[278,1911],{"className":1912,"style":561},[560],[278,1914],{"className":1915,"style":578},[577],[278,1917,1918,1921],{"style":581},[278,1919],{"className":1920,"style":561},[560],[278,1922,1924],{"className":1923},[481],[278,1925,1927,1930],{"className":1926},[481],[278,1928,310],{"className":1929,"style":1596},[481,494],[278,1931,1933],{"className":1932},[762],[278,1934,1936,1956],{"className":1935},[543,544],[278,1937,1939,1953],{"className":1938},[548],[278,1940,1942],{"className":1941,"style":772},[552],[278,1943,1944,1947],{"style":1611},[278,1945],{"className":1946,"style":779},[560],[278,1948,1950],{"className":1949},[636,637,638,639],[278,1951,435],{"className":1952,"style":1003},[481,494,639],[278,1954,595],{"className":1955},[594],[278,1957,1959],{"className":1958},[548],[278,1960,1962],{"className":1961,"style":1128},[552],[278,1963],{},[278,1965,595],{"className":1966},[594],[278,1968,1970],{"className":1969},[548],[278,1971,1974],{"className":1972,"style":1973},[552],"height:0.9721em;",[278,1975],{},[278,1977],{"className":1978},[511,536],[111,1980,1981,1984,1985,1988],{},[1163,1982,1983],{},"n_j","、",[1163,1986,1987],{},"s_j"," 是這一小批點裡分到第 j 叢集的數量與總和。α 決定「忘得多快」：α 大，最近幾批說話；α 小，歷史平均。舊的分配不是被刪掉，是被打折。",[111,1990,1991,1992,1995],{},"MacQueen 的更新是 ",[1163,1993,1994],{},"S ← S + s","，永不忘記。訓練早期質心位置很差，那時候分出來的標籤多半是錯的；但它們在後面每一輪都還有完整的一票，會把質心拖住。e-means 給它們一個衰減係數，等於「慢慢忘掉早期的錯誤判斷」。",[111,1997,1998,2001],{},[238,1999,2000],{},"第二件事，α 不是常數。"," 它從較大的值開始，沿著 cosine 曲線降到初始值的十分之一。先降快、後降慢，像一條降溫曲線，後期就越來越穩。",[111,2003,2004,2007],{},[238,2005,2006],{},"第三件事，死叢集要救。"," 小批次更新很容易出現「沒有任何點分給它」的質心。叢集數看起來是 k，實際能用的不到 k。e-means 每五批檢查一次。把低於平均計數 10% 的叢集重新指派：挑一顆大的，拆成兩顆，補上那個空位。Faiss 本來就有這個做法。影響有多大？論文自己的 ablation（一次關掉一個元件，看損失掉多少）拆得很細：",[157,2009,2010,2029],{},[160,2011,2012],{},[163,2013,2014,2017,2020,2023,2026],{},[166,2015,2016],{},"資料集",[166,2018,2019],{},"復活策略",[166,2021,2022],{},"死叢集",[166,2024,2025],{},"佔碼簿",[166,2027,2028],{},"測試 MSE",[176,2030,2031,2048,2064],{},[163,2032,2033,2036,2039,2042,2045],{},[181,2034,2035],{},"DEEP",[181,2037,2038],{},"按大小分裂",[181,2040,2041],{},"47",[181,2043,2044],{},"0.3%",[181,2046,2047],{},"0.3876",[163,2049,2050,2052,2055,2058,2061],{},[181,2051,2035],{},[181,2053,2054],{},"從批次隨機抽點",[181,2056,2057],{},"2,343",[181,2059,2060],{},"14.3%",[181,2062,2063],{},"0.3912",[163,2065,2066,2068,2071,2074,2077],{},[181,2067,2035],{},[181,2069,2070],{},"不救",[181,2072,2073],{},"4,313",[181,2075,2076],{},"26.3%",[181,2078,2079],{},"0.3945",[111,2081,2082],{},"100 萬個向量、k = 16,384、5 個 epoch、5 個種子平均；SIFT 上的差距類似。關掉復活，四分之一的叢集是空的。其他幾個元件（初始化、cosine、finalization）只差零點幾個百分點。四件事不是平權的，影響最大的是這一件。",[111,2084,2085,2088],{},[238,2086,2087],{},"第四件事，參數不要你猜。"," 批次大小與初始步長由 (n, k, T) 的標度律（用問題規模反推參數的經驗公式）算出來。論文量到的超參 regret 約 0.07%，你不用掃。",[111,2090,2091],{},"這裡要小心一個字面陷阱：「不用調參」指的是相對於 Lloyd 沒有多出新的旋鈕。k 還是你選的，epoch 數也是（預設 5），只是那兩個原本最難調的內部參數被公式接走了。",[111,2093,2094],{},"還有一個設計選擇值得講：他們不用梯度下降。專案頁的說法是，學習率一大，梯度更新會衝過頭。EMA 則保證質心一定落在「曾經被分配到這個叢集的點」的凸包裡面——不是當前那一批，是歷史。",[111,2096,2097],{},"而且 Lloyd 其實是 e-means 的特例。批次設成全部 n、α 設成 1，一次 e-means 更新就等於一次 Lloyd。所以兩者不是兩個世界，是同一條公式的兩端——論文發現，那一端剛好是最差的參數組合。",[111,2099,2100],{},"還有一個實務上的小設計。訓練結束時，最後一批的分配可以拿來重算一次精確均值（last-epoch-mean）。這會讓訓練集損失再降一點。如果你在意的是新資料上的表現，就用另一組慢速 EMA 收尾。兩者成本都可忽略，等於一次訓練能產兩組質心，看你拿質心去服務誰。",[111,2102,2103,2104,2107],{},"最後是這篇最反直覺的地方——",[238,2105,2106],{},"雜訊有用","。",[111,2109,2110],{},"Lloyd 每輪的損失只會下降，所以它一旦走進一個局部最小值，就沒有動力出來。小批次更新每次只看一小部分，梯度有雜訊。論文自己的解釋是：正是這個雜訊，會把質心推離那些「看起來收斂了、其實分錯了」的配置。他們用 200 個種子在玩具資料上重跑，e-means 掉進病態配置的機率明顯較低。",[111,2112,2113],{},"如圖 2，這是我們自己跑的小型模擬，不是論文原圖。設定是三個高斯團、每團 40 點、固定亂數種子、k = 3、同一組初始中心（刻意放壞）。e-means 用批次 12、初始 α = 0.35 加 cosine 衰減、2.5 個 epoch；Lloyd 則是每輪全量。",[111,2115,2116],{},"左邊的 Lloyd 第 8 輪就幾乎不動，再跑到 33 輪仍停在 MSE 5.39。兩顆質心擠在同一團，另一顆落在兩團中間。右邊的 e-means 用 25 次更新收到 1.28，一顆對一團。",[245,2118,249,2120,249,2125],{"className":2119},[248],[251,2121],{"src":2122,"poster":2123,"autoPlay":255,"loop":255,"muted":255,"playsInline":255,"ariaLabel":2124},"\u002Fimages\u002Fblog\u002Fkmeans-fewer-epochs\u002Fcentroids.mp4","\u002Fimages\u002Fblog\u002Fkmeans-fewer-epochs\u002Fcentroids-poster.jpg","同一組資料、同一組初始中心：左邊 Lloyd 的兩顆質心擠在同一團，右邊 e-means 的三顆各對到一團",[258,2126,2127],{},"圖 2：同一組資料、同一組初始中心。左邊的兩顆擠在同一團，右邊的三顆各對到一團（我們自己的模擬）。",[111,2129,2130],{},"這個例子只說明「同一組初始值下，兩種更新方式會走到不同的地方」，不是保證。論文的結論是機率，不是每次都能逃出來。",[135,2132,2134],{"id":2133},"快-10-倍是在比什麼","「快 10 倍」是在比什麼",[111,2136,2137],{},"先講對照條件，這是全文最容易被誤讀的地方：",[111,2139,2140,2143],{},[238,2141,2142],{},"基準是「e-means 跑 1.4–2.6 輪」對「Lloyd 跑 25 輪」的損失。"," 不是「Lloyd 跑到完全收斂」。",[111,2145,2146],{},"換句話說，基準是「大家平常就跑 25 輪」的那個點。Lloyd 再跑下去損失還會降一點，差距會縮小。",[157,2148,2149,2162],{},[160,2150,2151],{},[163,2152,2153,2156,2159],{},[166,2154,2155],{},"項目",[166,2157,2158],{},"數字",[166,2160,2161],{},"條件與出處",[176,2163,2164,2179,2193,2207,2218],{},[163,2165,2166,2169,2172],{},[181,2167,2168],{},"追平 Lloyd 跑 25 輪所需輪數",[181,2170,2171],{},"1.4–2.6",[181,2173,2174,2178],{},[115,2175,2177],{"href":117,"rel":2176},[119],"論文摘要","；多個嵌入資料集",[163,2180,2181,2184,2187],{},[181,2182,2183],{},"GPU 加速",[181,2185,2186],{},"10–45×",[181,2188,2189,2190],{},"對 Flash-KMeans、H100；",[115,2191,2177],{"href":117,"rel":2192},[119],[163,2194,2195,2198,2201],{},[181,2196,2197],{},"CPU 加速",[181,2199,2200],{},"8–15×",[181,2202,2203,2204],{},"對 Faiss；",[115,2205,126],{"href":124,"rel":2206},[119],[163,2208,2209,2212,2215],{},[181,2210,2211],{},"最大規模",[181,2213,2214],{},"100 億點、1,600 萬叢集，2.5 輪",[181,2216,2217],{},"DINO10B：論文的 100 億筆 DINO 特徵資料集",[163,2219,2220,2223,2226],{},[181,2221,2222],{},"社群量到的 Lloyd 迭代次數",[181,2224,2225],{},"19–229 輪",[181,2227,2228,2233],{},[115,2229,2232],{"href":2230,"rel":2231},"https:\u002F\u002Fgithub.com\u002Fscikit-learn\u002Fscikit-learn\u002Fissues\u002F35383",[119],"scikit-learn issue #35383","；社群實測，不是論文",[111,2235,2236],{},"最後一列不是在說「25 輪不夠」。它是在說，Lloyd 的收斂輪數本來就浮動——社群那邊量到 19 到 229 輪。所以重點不是 25 這個數字，是「每一輪都是一次全量掃描」。25 只是預設值，不是物理常數。",[111,2238,2239,2240,2243],{},"還有一個陷阱：",[238,2241,2242],{},"輪數不等於時間。"," 如果只算資料掃過幾遍，2.5 輪對 25 輪大約是 10 倍。實際的 wall-clock 卻是 10–45 倍。我的理解是，差距有一部分來自小批次更容易吃滿 GPU；論文沒有把 10–45 倍拆到「哪一段省下來」這一層。",[111,2245,2246,2247,2250],{},"保守的講法：",[238,2248,2249],{},"大約 10 倍","。45 倍是特定設定、特定 GPU、對特定的對照實作。任何寫成「k-means 快 45 倍」的句子，都要帶著這三個條件。",[111,2252,2253],{},"順帶說明一個容易混掉的細節。摘要寫的是 GPU 10–45 倍（對 Flash-KMeans）。專案頁另外寫 CPU 8–15 倍（對 Faiss）。兩個數字量的對象不同，不要互換、也不要相加。",[111,2255,2256],{},"我認為 GPU 的倍數比 CPU 大，是因為差距有一部分來自「小批次能不能吃滿硬體」。GPU 核心多、記憶體頻寬高，同樣的批次更容易被排滿。CPU 那組（8–15 倍）反而對一般讀者更有參考價值——多數人手上沒有 H100。",[111,2258,2259,2260,2265,2266,2269,2270,2273],{},"它進正式版了嗎？進了。faiss ",[115,2261,2264],{"href":2262,"rel":2263},"https:\u002F\u002Fgithub.com\u002Ffacebookresearch\u002Ffaiss\u002Freleases\u002Ftag\u002Fv1.16.0",[119],"1.16.0","（2026-11-10 發布）包含 ",[1163,2267,2268],{},"faiss.contrib.e_means","；PyPI 的 ",[1163,2271,2272],{},"faiss-cpu"," 也已經是 1.16.0。用法五行：",[2275,2276,2281],"pre",{"className":2277,"code":2278,"language":2279,"meta":2280,"style":2280},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","from faiss.contrib.e_means import Emeans\n\nem = Emeans(d, k, nepochs=5)\ncentroids, labels = em.train(x)   # x 是 PyTorch tensor (n, d)\n","python","",[1163,2282,2283,2290,2296,2302],{"__ignoreMap":2280},[278,2284,2287],{"class":2285,"line":2286},"line",1,[278,2288,2289],{},"from faiss.contrib.e_means import Emeans\n",[278,2291,2293],{"class":2285,"line":2292},2,[278,2294,2295],{"emptyLinePlaceholder":255},"\n",[278,2297,2299],{"class":2285,"line":2298},3,[278,2300,2301],{},"em = Emeans(d, k, nepochs=5)\n",[278,2303,2305],{"class":2285,"line":2304},4,[278,2306,2307],{},"centroids, labels = em.train(x)   # x 是 PyTorch tensor (n, d)\n",[111,2309,2310],{},"還沒有的東西：獨立複現。論文很新（11 月 6 日），有釋出複現腳本與基準資料，但目前只有作者自己的數字。",[111,2312,2313],{},"另外它終究是隨機演算法：同一個資料集、不同的種子，收斂到的解會不一樣。論文的數字是多個資料集、多個設定的結果，不是每一次執行都會剛好落在 1.4 輪。",[135,2315,2316],{"id":2316},"所以你的索引會變快嗎",[111,2318,2319,2320,2323],{},"先說結論：",[238,2321,2322],{},"它加速的是索引建置，不是查詢。"," 如果你的問題是「檢索太慢」，這篇幫不上忙。那個要換 HNSW（一種不用先分群的圖索引）、量化，或換一顆更小的模型。",[111,2325,2326],{},"有感的條件大概長這樣：",[157,2328,2329,2339],{},[160,2330,2331],{},[163,2332,2333,2336],{},[166,2334,2335],{},"你的情況",[166,2337,2338],{},"建議",[176,2340,2341,2349,2357,2365,2373],{},[163,2342,2343,2346],{},[181,2344,2345],{},"幾千份文件的 RAG，重建只要幾秒",[181,2347,2348],{},"先別動，快 10 倍對你沒差",[163,2350,2351,2354],{},[181,2352,2353],{},"10 萬點以上、k 上千、每次重建要等",[181,2355,2356],{},"值得做一次 A\u002FB",[163,2358,2359,2362],{},[181,2360,2361],{},"重建頻繁（每天或每次換模型）",[181,2363,2364],{},"值得換，先看 CPU 路徑",[163,2366,2367,2370],{},[181,2368,2369],{},"用 HNSW、不需要粗量化",[181,2371,2372],{},"這一步不存在，跳過",[163,2374,2375,2378],{},[181,2376,2377],{},"想加速的是推論",[181,2379,2380],{},"換錯題目了",[111,2382,2383],{},"還有一個常被忽略的前提：GPU 那條路要 H100 或 H200 等級的卡。還要對應的 GPU 核心函式庫（CuTe 或 Triton 後端），以及對得上版本的 CUTLASS、QuACK。CPU 那條路只要 faiss 本身，反而是多數人實際能跑的。專案頁的 8–15 倍就是 CPU 對 Faiss。",[111,2385,2386],{},"代價也要寫清楚：新 API 要驗，換初始化之後 recall 要重測。近似解本來就不保證全域最優（Lloyd 也不保證）。快 10 倍換到的是重建時間，不是免費的品質。",[111,2388,2389],{},"要驗的話，準備一份查詢集，跟暴力搜尋（Flat）的 top-10 對答案算 recall@10。只看 MSE 會漏掉檢索品質這一塊。",[135,2391,2392],{"id":2392},"明天可以做的三件事",[111,2394,2395,2398],{},[238,2396,2397],{},"第一，量一次重建。"," 記五個數字：n、k、niter、wall-clock、最終 MSE。沒有這五個，任何「要不要換」都是猜的。",[2275,2400,2402],{"className":2277,"code":2401,"language":2279,"meta":2280,"style":2280},"import numpy as np, faiss, time\n\nx = np.ascontiguousarray(x, dtype='float32')\nflat = faiss.IndexFlatL2(x.shape[1])   # 只用來算最終損失\n\nt0 = time.perf_counter()\nkm = faiss.Kmeans(x.shape[1], k, niter=25)\nkm.train(x)\nsecs = time.perf_counter() - t0\n\nflat.add(km.centroids)\nD, _ = flat.search(x, 1)\nprint(f\"{secs:.1f}s  MSE={D.mean():.3f}\")\n",[1163,2403,2404,2409,2413,2418,2423,2428,2434,2440,2446,2452,2457,2463,2469],{"__ignoreMap":2280},[278,2405,2406],{"class":2285,"line":2286},[278,2407,2408],{},"import numpy as np, faiss, time\n",[278,2410,2411],{"class":2285,"line":2292},[278,2412,2295],{"emptyLinePlaceholder":255},[278,2414,2415],{"class":2285,"line":2298},[278,2416,2417],{},"x = np.ascontiguousarray(x, dtype='float32')\n",[278,2419,2420],{"class":2285,"line":2304},[278,2421,2422],{},"flat = faiss.IndexFlatL2(x.shape[1])   # 只用來算最終損失\n",[278,2424,2426],{"class":2285,"line":2425},5,[278,2427,2295],{"emptyLinePlaceholder":255},[278,2429,2431],{"class":2285,"line":2430},6,[278,2432,2433],{},"t0 = time.perf_counter()\n",[278,2435,2437],{"class":2285,"line":2436},7,[278,2438,2439],{},"km = faiss.Kmeans(x.shape[1], k, niter=25)\n",[278,2441,2443],{"class":2285,"line":2442},8,[278,2444,2445],{},"km.train(x)\n",[278,2447,2449],{"class":2285,"line":2448},9,[278,2450,2451],{},"secs = time.perf_counter() - t0\n",[278,2453,2455],{"class":2285,"line":2454},10,[278,2456,2295],{"emptyLinePlaceholder":255},[278,2458,2460],{"class":2285,"line":2459},11,[278,2461,2462],{},"flat.add(km.centroids)\n",[278,2464,2466],{"class":2285,"line":2465},12,[278,2467,2468],{},"D, _ = flat.search(x, 1)\n",[278,2470,2472],{"class":2285,"line":2471},13,[278,2473,2474],{},"print(f\"{secs:.1f}s  MSE={D.mean():.3f}\")\n",[111,2476,2477,2480],{},[238,2478,2479],{},"第二，把 niter 降下來看看。"," 這是最便宜的實驗：同一份資料，niter 跑 25、10、5，看 MSE 差多少。如果 10 輪的損失只差一點，你的預設值就多付了 1.5 倍的掃描。",[2275,2482,2484],{"className":2277,"code":2483,"language":2279,"meta":2280,"style":2280},"for niter in (25, 10, 5):\n    km = faiss.Kmeans(x.shape[1], k, niter=niter)\n    km.train(x)\n    flat.reset()\n    flat.add(km.centroids)\n    D, _ = flat.search(x, 1)\n    print(niter, f\"{D.mean():.3f}\")\n",[1163,2485,2486,2491,2496,2501,2506,2511,2516],{"__ignoreMap":2280},[278,2487,2488],{"class":2285,"line":2286},[278,2489,2490],{},"for niter in (25, 10, 5):\n",[278,2492,2493],{"class":2285,"line":2292},[278,2494,2495],{},"    km = faiss.Kmeans(x.shape[1], k, niter=niter)\n",[278,2497,2498],{"class":2285,"line":2298},[278,2499,2500],{},"    km.train(x)\n",[278,2502,2503],{"class":2285,"line":2304},[278,2504,2505],{},"    flat.reset()\n",[278,2507,2508],{"class":2285,"line":2425},[278,2509,2510],{},"    flat.add(km.centroids)\n",[278,2512,2513],{"class":2285,"line":2430},[278,2514,2515],{},"    D, _ = flat.search(x, 1)\n",[278,2517,2518],{"class":2285,"line":2436},[278,2519,2520],{},"    print(niter, f\"{D.mean():.3f}\")\n",[111,2522,2523,2526],{},[238,2524,2525],{},"第三，規模夠大才換 e-means。"," 用同一份資料、同一組初始化，比 wall-clock 與最終 MSE；有索引的話再比 recall@10。CPU 那條路不用 GPU，適合先做。",[111,2528,2529],{},"最後回到那個 25。它不是物理常數，是一個預設值。這篇的重點不是叫你換掉 k-means，而是提醒你：那個 25 可以量、可以調，也可以被換掉。而提案換掉它的，是 Faiss 自己的作者。",[135,2531,2532],{"id":2532},"延伸閱讀",[2534,2535,2536,2544,2551],"ul",{},[2537,2538,2539,2543],"li",{},[115,2540,2542],{"href":2541},"\u002Fblog\u002Frunning-is-not-done","跑得起來跟真的幹完活是四件事","：同一種拆法，拆的是「模型可用」的四層",[2537,2545,2546,2550],{},[115,2547,2549],{"href":2548},"\u002Fblog\u002Fquantization-kernel-dispatch","量化會不會加速，取決於你怎麼寫 kernel","：同一類「實作方式吃掉十倍差距」",[2537,2552,2553,2557],{},[115,2554,2556],{"href":2555},"\u002Fblog\u002Fstrata-125b-on-12gb","125B 模型跑在 12GB 顯卡","：地端部署的記憶體取捨",[2559,2560,2561],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":2280,"searchDepth":2292,"depth":2292,"links":2563},[2564,2565,2566,2567,2568,2569,2570,2571],{"id":137,"depth":2292,"text":137},{"id":152,"depth":2292,"text":152},{"id":266,"depth":2292,"text":267},{"id":1244,"depth":2292,"text":1245},{"id":2133,"depth":2292,"text":2134},{"id":2316,"depth":2292,"text":2316},{"id":2392,"depth":2292,"text":2392},{"id":2532,"depth":2292,"text":2532},"\u002Fimages\u002Fblog\u002Fkmeans-fewer-epochs.svg","標題「k-means 的 25 遍，可以只讀 2 遍」的技術筆記封面","2026-11-14","Faiss 的 k-means 預設跑 25 輪、每輪把訓練向量完整掃一遍；Meta FAIR 的 e-means 改用指數移動平均加小批次更新，1.4–2.6 輪就追平同樣的損失。這篇講它換掉了哪幾件事、10 到 45 倍是在比什麼，以及你的索引什麼時候才真的會有感。",false,"md","zh-TW",{},"\u002Fimages\u002Fblog\u002Fkmeans-fewer-epochs.jpg","\u002Fblog\u002Fzh-tw\u002Fkmeans-fewer-epochs",{"title":102,"description":2575},"kmeans-fewer-epochs","blog\u002Fzh-TW\u002Fkmeans-fewer-epochs",[2586,2587,2588,2589],"clustering","faiss","vector-search","performance",null,"om7iB4cAehVtmN9CyzhnlvaE9_LZBmcSxRJuFmeOjmM",{"id":2593,"title":2594,"author":103,"body":2595,"cover":4826,"coverAlt":4827,"date":2574,"description":4828,"draft":2576,"extension":2577,"featured":2576,"lang":4829,"meta":4830,"navigation":255,"ogImage":4831,"path":4832,"seo":4833,"slug":2583,"stem":4834,"tags":4835,"translationKey":2583,"updated":2590,"__hash__":4836},"blog\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs.md","k-means Reads Your Data 25 Times. Two Would Do.",{"type":105,"value":2596,"toc":4816},[2597,2627,2631,2634,2637,2640,2644,2647,2719,2725,2728,2739,2742,2746,2749,2752,2755,3502,3514,3517,3520,3580,3584,3592,3595,3600,4303,4311,4317,4323,4329,4391,4394,4405,4408,4411,4414,4420,4428,4431,4434,4445,4448,4452,4455,4461,4543,4546,4553,4560,4563,4576,4598,4601,4604,4608,4615,4618,4672,4675,4678,4681,4685,4691,4749,4755,4787,4793,4796,4800,4814],[108,2598,2599],{},[111,2600,2601,2602,2606,2607,2611,2612,2616,2617,2621,2622,2626],{},"Four kinds of source. The ",[115,2603,2605],{"href":117,"rel":2604},[119],"paper"," (arXiv 2611.09501, Nov 6, 2026; FAIR at Meta) supplies the headline numbers; the ",[115,2608,2610],{"href":124,"rel":2609},[119],"project page"," supplies the CPU range and the ablation; the ",[115,2613,2615],{"href":130,"rel":2614},[119],"faiss source"," and its ",[115,2618,2620],{"href":2262,"rel":2619},[119],"1.16.0 release"," supply the defaults and the shipping status; one ",[115,2623,2625],{"href":2230,"rel":2624},[119],"GitHub issue"," supplies the 19–229 iteration range, and it is community data, not the paper. The 3.1 GB \u002F 77 GB arithmetic and the Figure 2 simulation are ours. We did not rerun the paper's experiments.",[135,2628,2630],{"id":2629},"the-bill-you-already-paid","The bill you already paid",[111,2632,2633],{},"You are deduplicating a corpus, or building RAG (retrieval-augmented generation: search your own documents, then put the hits in the prompt). Files arrive, get chunked, get embedded. Then a scheduled job clusters the vectors and writes an index; only after that can queries run.",[111,2635,2636],{},"That last step is usually the slowest part of a rebuild, and it still runs the 1957 algorithm: by default, 25 passes over your data. Meta FAIR's e-means matches the same loss in about two, and it ships in faiss.",[111,2638,2639],{},"It speeds up the build, not the query, and it has a size threshold. This essay draws those lines, and ends with three things you can measure tomorrow.",[135,2641,2643],{"id":2642},"it-hides-inside-the-build","It hides inside the build",[111,2645,2646],{},"k-means is not exotic. It is the layer under all of this:",[157,2648,2649,2662],{},[160,2650,2651],{},[163,2652,2653,2656,2659],{},[166,2654,2655],{},"Where",[166,2657,2658],{},"What k-means does",[166,2660,2661],{},"When you pay",[176,2663,2664,2675,2686,2697,2708],{},[163,2665,2666,2669,2672],{},[181,2667,2668],{},"IVF indexes",[181,2670,2671],{},"coarse quantizer: assign each vector to one of k buckets",[181,2673,2674],{},"build, re-embed, new data",[163,2676,2677,2680,2683],{},[181,2678,2679],{},"Product quantization",[181,2681,2682],{},"one clustering per sub-space, after splitting the vector",[181,2684,2685],{},"same",[163,2687,2688,2691,2694],{},[181,2689,2690],{},"VQ-VAE, neural audio codecs",[181,2692,2693],{},"codebook learning (one reference vector per cluster)",[181,2695,2696],{},"training, dataset change",[163,2698,2699,2702,2705],{},[181,2700,2701],{},"Dedup, anomaly detection",[181,2703,2704],{},"cluster to find duplicates and outliers",[181,2706,2707],{},"ingest, cleanup",[163,2709,2710,2713,2716],{},[181,2711,2712],{},"Customer or image segmentation",[181,2714,2715],{},"the algorithm itself",[181,2717,2718],{},"every analysis",[111,2720,2721,2722],{},"The common shape: ",[238,2723,2724],{},"it runs offline, off the query path.",[111,2726,2727],{},"Figure 1 shows the life of an index. The left half is the build; the right half is the query. A query reads the index once. The build sweeps the vectors many times. The latency you feel every day is on the right; the time that actually disappears is on the left.",[245,2729,249,2731,249,2736],{"className":2730},[248],[251,2732],{"src":2733,"poster":2734,"autoPlay":255,"loop":255,"muted":255,"playsInline":255,"ariaLabel":2735},"\u002Fimages\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs\u002Fpipeline.mp4","\u002Fimages\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs\u002Fpipeline-poster.jpg","Index build pipeline: raw data, embeddings, k-means, index; only then a query. The k-means box is tagged 25 passes.",[258,2737,2738],{},"Figure 1: build on the left, query on the right; the k-means box carries 25 passes.",[111,2740,2741],{},"Some arithmetic. Take 1M vectors, 768 dimensions, fp32, k = 4,096: one pass is about 3.1 GB. Faiss's default 25 passes is roughly 77 GB of reads, before distance arithmetic and index writes. The numbers move with dimension, dtype and nredo (Faiss can rerun clustering and keep the best run), but the order of magnitude does not.",[135,2743,2745],{"id":2744},"still-lloyds-1957-algorithm","Still Lloyd's 1957 algorithm",[111,2747,2748],{},"Lloyd's loop is two steps: assign each point to its nearest centroid; move each centroid to the mean of its points. Repeat until nothing moves.",[111,2750,2751],{},"It converges, to a local minimum rather than a global one. That guarantee comes from a 1957 Bell Labs memo, formally published in 1982.",[111,2753,2754],{},"The objective:",[278,2756,2758],{"className":2757},[281],[278,2759,2761,2897],{"className":2760},[285],[278,2762,2764],{"className":2763},[289],[291,2765,2766],{"xmlns":293,"display":294},[296,2767,2768,2894],{},[299,2769,2770,2778,2780,2782,2784,2786,2788,2790,2796,2810,2842,2844,2846,2848,2850,2852,2854,2856,2858,2860,2870],{},[299,2771,2772,2774,2776],{},[304,2773,307],{"mathvariant":306},[304,2775,310],{"mathvariant":306},[304,2777,313],{"mathvariant":306},[315,2779,318],{"stretchy":317},[304,2781,321],{},[315,2783,325],{"separator":324},[304,2785,328],{},[315,2787,331],{"stretchy":317},[315,2789,334],{},[336,2791,2792,2794],{},[339,2793,341],{},[304,2795,344],{},[346,2797,2798,2800,2808],{},[315,2799,350],{},[299,2801,2802,2804,2806],{},[304,2803,355],{},[315,2805,334],{},[339,2807,341],{},[304,2809,344],{},[363,2811,2812,2840],{},[299,2813,2814,2816,2822,2824,2838],{},[315,2815,369],{"fence":324},[371,2817,2818,2820],{},[304,2819,375],{},[304,2821,355],{},[315,2823,380],{},[371,2825,2826,2828],{},[304,2827,385],{},[299,2829,2830,2832,2834,2836],{},[304,2831,115],{},[315,2833,318],{"stretchy":317},[304,2835,355],{},[315,2837,331],{"stretchy":317},[315,2839,369],{"fence":324},[339,2841,400],{},[315,2843,325],{"separator":324},[404,2845],{"width":406},[304,2847,115],{},[315,2849,318],{"stretchy":317},[304,2851,355],{},[315,2853,331],{"stretchy":317},[315,2855,334],{},[304,2857,419],{},[315,2859,422],{},[424,2861,2862,2868],{},[299,2863,2864,2866],{},[304,2865,430],{},[315,2867,422],{},[304,2869,435],{},[363,2871,2872,2892],{},[299,2873,2874,2876,2882,2884,2890],{},[315,2875,369],{"fence":324},[371,2877,2878,2880],{},[304,2879,375],{},[304,2881,355],{},[315,2883,380],{},[371,2885,2886,2888],{},[304,2887,385],{},[304,2889,435],{},[315,2891,369],{"fence":324},[339,2893,400],{},[461,2895,2896],{"encoding":463},"\\mathrm{MSE}(X, C) = \\frac{1}{n}\\sum_{i=1}^{n}\\left\\| x_i - c_{a(i)} \\right\\|^2,\n\\qquad a(i) = \\arg\\min_j \\left\\| x_i - c_j \\right\\|^2",[278,2898,2900,2939,3317],{"className":2899,"ariaHidden":324},[468],[278,2901,2903,2906,2912,2915,2918,2921,2924,2927,2930,2933,2936],{"className":2902},[472],[278,2904],{"className":2905,"style":477},[476],[278,2907,2909],{"className":2908},[481],[278,2910,486],{"className":2911},[481,485],[278,2913,318],{"className":2914},[490],[278,2916,321],{"className":2917,"style":495},[481,494],[278,2919,325],{"className":2920},[499],[278,2922],{"className":2923,"style":503},[404],[278,2925,328],{"className":2926,"style":507},[481,494],[278,2928,331],{"className":2929},[511],[278,2931],{"className":2932,"style":515},[404],[278,2934,334],{"className":2935},[519],[278,2937],{"className":2938,"style":515},[404],[278,2940,2942,2945,3007,3010,3077,3080,3284,3287,3290,3293,3296,3299,3302,3305,3308,3311,3314],{"className":2941},[472],[278,2943],{"className":2944,"style":529},[476],[278,2946,2948,2951,3004],{"className":2947},[481],[278,2949],{"className":2950},[490,536],[278,2952,2954],{"className":2953},[336],[278,2955,2957,2996],{"className":2956},[543,544],[278,2958,2960,2993],{"className":2959},[548],[278,2961,2963,2974,2982],{"className":2962,"style":553},[552],[278,2964,2965,2968],{"style":556},[278,2966],{"className":2967,"style":561},[560],[278,2969,2971],{"className":2970},[481],[278,2972,344],{"className":2973},[481,494],[278,2975,2976,2979],{"style":570},[278,2977],{"className":2978,"style":561},[560],[278,2980],{"className":2981,"style":578},[577],[278,2983,2984,2987],{"style":581},[278,2985],{"className":2986,"style":561},[560],[278,2988,2990],{"className":2989},[481],[278,2991,341],{"className":2992},[481],[278,2994,595],{"className":2995},[594],[278,2997,2999],{"className":2998},[548],[278,3000,3002],{"className":3001,"style":602},[552],[278,3003],{},[278,3005],{"className":3006},[511,536],[278,3008],{"className":3009,"style":503},[404],[278,3011,3013],{"className":3012},[614,615],[278,3014,3016,3069],{"className":3015},[543,544],[278,3017,3019,3066],{"className":3018},[548],[278,3020,3022,3042,3052],{"className":3021,"style":625},[552],[278,3023,3024,3027],{"style":628},[278,3025],{"className":3026,"style":632},[560],[278,3028,3030],{"className":3029},[636,637,638,639],[278,3031,3033,3036,3039],{"className":3032},[481,639],[278,3034,355],{"className":3035},[481,494,639],[278,3037,334],{"className":3038},[519,639],[278,3040,341],{"className":3041},[481,639],[278,3043,3044,3047],{"style":654},[278,3045],{"className":3046,"style":632},[560],[278,3048,3049],{},[278,3050,350],{"className":3051},[614,663,664],[278,3053,3054,3057],{"style":667},[278,3055],{"className":3056,"style":632},[560],[278,3058,3060],{"className":3059},[636,637,638,639],[278,3061,3063],{"className":3062},[481,639],[278,3064,344],{"className":3065},[481,494,639],[278,3067,595],{"className":3068},[594],[278,3070,3072],{"className":3071},[548],[278,3073,3075],{"className":3074,"style":689},[552],[278,3076],{},[278,3078],{"className":3079,"style":503},[404],[278,3081,3083,3261],{"className":3082},[698],[278,3084,3086,3123,3163,3166,3169,3172,3224],{"className":3085},[698],[278,3087,3089],{"className":3088},[490],[278,3090,3092],{"className":3091},[708,709],[278,3093,3095,3115],{"className":3094},[543,544],[278,3096,3098,3112],{"className":3097},[548],[278,3099,3101],{"className":3100,"style":719},[552],[278,3102,3103,3106],{"style":722},[278,3104],{"className":3105,"style":726},[560],[278,3107,3108],{"style":729},[731,3109,3110],{"xmlns":733,"width":734,"height":735,"viewBox":736},[738,3111],{"d":740},[278,3113,595],{"className":3114},[594],[278,3116,3118],{"className":3117},[548],[278,3119,3121],{"className":3120,"style":750},[552],[278,3122],{},[278,3124,3126,3129],{"className":3125},[481],[278,3127,375],{"className":3128},[481,494],[278,3130,3132],{"className":3131},[762],[278,3133,3135,3155],{"className":3134},[543,544],[278,3136,3138,3152],{"className":3137},[548],[278,3139,3141],{"className":3140,"style":772},[552],[278,3142,3143,3146],{"style":775},[278,3144],{"className":3145,"style":779},[560],[278,3147,3149],{"className":3148},[636,637,638,639],[278,3150,355],{"className":3151},[481,494,639],[278,3153,595],{"className":3154},[594],[278,3156,3158],{"className":3157},[548],[278,3159,3161],{"className":3160,"style":795},[552],[278,3162],{},[278,3164],{"className":3165,"style":801},[404],[278,3167,380],{"className":3168},[805],[278,3170],{"className":3171,"style":801},[404],[278,3173,3175,3178],{"className":3174},[481],[278,3176,385],{"className":3177},[481,494],[278,3179,3181],{"className":3180},[762],[278,3182,3184,3216],{"className":3183},[543,544],[278,3185,3187,3213],{"className":3186},[548],[278,3188,3190],{"className":3189,"style":827},[552],[278,3191,3192,3195],{"style":830},[278,3193],{"className":3194,"style":779},[560],[278,3196,3198],{"className":3197},[636,637,638,639],[278,3199,3201,3204,3207,3210],{"className":3200},[481,639],[278,3202,115],{"className":3203},[481,494,639],[278,3205,318],{"className":3206},[490,639],[278,3208,355],{"className":3209},[481,494,639],[278,3211,331],{"className":3212},[511,639],[278,3214,595],{"className":3215},[594],[278,3217,3219],{"className":3218},[548],[278,3220,3222],{"className":3221,"style":861},[552],[278,3223],{},[278,3225,3227],{"className":3226},[511],[278,3228,3230],{"className":3229},[708,709],[278,3231,3233,3253],{"className":3232},[543,544],[278,3234,3236,3250],{"className":3235},[548],[278,3237,3239],{"className":3238,"style":719},[552],[278,3240,3241,3244],{"style":722},[278,3242],{"className":3243,"style":726},[560],[278,3245,3246],{"style":729},[731,3247,3248],{"xmlns":733,"width":734,"height":735,"viewBox":736},[738,3249],{"d":740},[278,3251,595],{"className":3252},[594],[278,3254,3256],{"className":3255},[548],[278,3257,3259],{"className":3258,"style":750},[552],[278,3260],{},[278,3262,3264],{"className":3263},[762],[278,3265,3267],{"className":3266},[543],[278,3268,3270],{"className":3269},[548],[278,3271,3273],{"className":3272,"style":913},[552],[278,3274,3275,3278],{"style":916},[278,3276],{"className":3277,"style":779},[560],[278,3279,3281],{"className":3280},[636,637,638,639],[278,3282,400],{"className":3283},[481,639],[278,3285],{"className":3286,"style":503},[404],[278,3288,325],{"className":3289},[499],[278,3291],{"className":3292,"style":935},[404],[278,3294],{"className":3295,"style":503},[404],[278,3297,115],{"className":3298},[481,494],[278,3300,318],{"className":3301},[490],[278,3303,355],{"className":3304},[481,494],[278,3306,331],{"className":3307},[511],[278,3309],{"className":3310,"style":515},[404],[278,3312,334],{"className":3313},[519],[278,3315],{"className":3316,"style":515},[404],[278,3318,3320,3323,3328,3331,3375,3378],{"className":3319},[472],[278,3321],{"className":3322,"style":966},[476],[278,3324,970,3326],{"className":3325},[614],[278,3327,974],{"style":973},[278,3329],{"className":3330,"style":503},[404],[278,3332,3334],{"className":3333},[614,615],[278,3335,3337,3367],{"className":3336},[543,544],[278,3338,3340,3364],{"className":3339},[548],[278,3341,3343,3354],{"className":3342,"style":990},[552],[278,3344,3345,3348],{"style":993},[278,3346],{"className":3347,"style":561},[560],[278,3349,3351],{"className":3350},[636,637,638,639],[278,3352,435],{"className":3353,"style":1003},[481,494,639],[278,3355,3356,3359],{"style":1006},[278,3357],{"className":3358,"style":561},[560],[278,3360,3361],{},[278,3362,430],{"className":3363},[614],[278,3365,595],{"className":3366},[594],[278,3368,3370],{"className":3369},[548],[278,3371,3373],{"className":3372,"style":1024},[552],[278,3374],{},[278,3376],{"className":3377,"style":503},[404],[278,3379,3381,3479],{"className":3380},[698],[278,3382,3384,3387,3427,3430,3433,3436,3476],{"className":3383},[698],[278,3385,369],{"className":3386,"style":1040},[490,1039],[278,3388,3390,3393],{"className":3389},[481],[278,3391,375],{"className":3392},[481,494],[278,3394,3396],{"className":3395},[762],[278,3397,3399,3419],{"className":3398},[543,544],[278,3400,3402,3416],{"className":3401},[548],[278,3403,3405],{"className":3404,"style":772},[552],[278,3406,3407,3410],{"style":775},[278,3408],{"className":3409,"style":779},[560],[278,3411,3413],{"className":3412},[636,637,638,639],[278,3414,355],{"className":3415},[481,494,639],[278,3417,595],{"className":3418},[594],[278,3420,3422],{"className":3421},[548],[278,3423,3425],{"className":3424,"style":795},[552],[278,3426],{},[278,3428],{"className":3429,"style":801},[404],[278,3431,380],{"className":3432},[805],[278,3434],{"className":3435,"style":801},[404],[278,3437,3439,3442],{"className":3438},[481],[278,3440,385],{"className":3441},[481,494],[278,3443,3445],{"className":3444},[762],[278,3446,3448,3468],{"className":3447},[543,544],[278,3449,3451,3465],{"className":3450},[548],[278,3452,3454],{"className":3453,"style":772},[552],[278,3455,3456,3459],{"style":775},[278,3457],{"className":3458,"style":779},[560],[278,3460,3462],{"className":3461},[636,637,638,639],[278,3463,435],{"className":3464,"style":1003},[481,494,639],[278,3466,595],{"className":3467},[594],[278,3469,3471],{"className":3470},[548],[278,3472,3474],{"className":3473,"style":1128},[552],[278,3475],{},[278,3477,369],{"className":3478,"style":1040},[511,1039],[278,3480,3482],{"className":3481},[762],[278,3483,3485],{"className":3484},[543],[278,3486,3488],{"className":3487},[548],[278,3489,3491],{"className":3490,"style":1146},[552],[278,3492,3493,3496],{"style":1149},[278,3494],{"className":3495,"style":779},[560],[278,3497,3499],{"className":3498},[636,637,638,639],[278,3500,400],{"className":3501},[481,639],[111,3503,3504,3505,3507,3508,3510,3511,3513],{},"Faiss's ",[1163,3506,1165],{}," defaults to ",[1163,3509,1169],{},", and each iteration is a full assignment pass — one epoch in the usual sense: the data is seen once. This essay uses pass and epoch interchangeably. One more default gets less attention: ",[1163,3512,1173],{},". When n is much larger than k, Faiss subsamples to at most 256 points per centroid. The 1M-point, 4,096-centroid example sits just inside that threshold (256 × 4,096 ≈ 1.05M), so all of it is scanned.",[111,3515,3516],{},"Each pass costs O(n · k · d) and is memory-bound, random-access. Twenty-five passes are not a metaphor; they are 25 full sweeps of the array.",[111,3518,3519],{},"Why has it survived? Mini-batch versions date back to 1967 (MacQueen), and Sculley's web-scale version has been around since 2010. They read one batch per update, which is much faster, at the cost of a higher error and two knobs you must tune. For most teams, \"slow but no decisions\" is a reasonable default.",[157,3521,3522,3538],{},[160,3523,3524],{},[163,3525,3526,3529,3532,3535],{},[166,3527,3528],{},"Variant",[166,3530,3531],{},"Data per update",[166,3533,3534],{},"Statistics",[166,3536,3537],{},"Cost",[176,3539,3540,3554,3568],{},[163,3541,3542,3545,3548,3551],{},[181,3543,3544],{},"Lloyd (Faiss default)",[181,3546,3547],{},"all n points",[181,3549,3550],{},"exact mean, recomputed",[181,3552,3553],{},"slow; 25 passes",[163,3555,3556,3559,3562,3565],{},[181,3557,3558],{},"MacQueen \u002F Sculley",[181,3560,3561],{},"one mini-batch",[181,3563,3564],{},"cumulative, never forgotten",[181,3566,3567],{},"fast; early mistakes keep voting",[163,3569,3570,3572,3574,3577],{},[181,3571,1233],{},[181,3573,3561],{},[181,3575,3576],{},"exponential moving average",[181,3578,3579],{},"fast; parameters from a scaling law",[135,3581,3583],{"id":3582},"what-e-means-changed","What e-means changed",[111,3585,3586,3587,3591],{},"The paper's algorithm is e-means, from Meta FAIR. The title says it outright: ",[115,3588,3590],{"href":117,"rel":3589},[119],"\"one-tenth the epochs\"",". The author list includes Matthijs Douze and Hervé Jégou, the authors of faiss; Hugo Touvron is on it too. This is a team arguing against its own default.",[111,3593,3594],{},"It does not invent a new loss. The objective is the MSE above; what changes is how a centroid moves.",[111,3596,3597],{},[238,3598,3599],{},"One: the statistics become an exponential moving average.",[278,3601,3603],{"className":3602},[281],[278,3604,3606,3719],{"className":3605},[285],[278,3607,3609],{"className":3608},[289],[291,3610,3611],{"xmlns":293,"display":294},[296,3612,3613,3717],{},[299,3614,3615,3621,3623,3625,3627,3629,3631,3633,3639,3641,3643,3645,3651,3653,3655,3661,3663,3665,3667,3669,3671,3673,3679,3681,3683,3685,3691,3693,3695,3701,3703],{},[371,3616,3617,3619],{},[304,3618,1276],{},[304,3620,435],{},[315,3622,1281],{},[315,3624,318],{"stretchy":317},[339,3626,341],{},[315,3628,380],{},[304,3630,1290],{},[315,3632,331],{"stretchy":317},[371,3634,3635,3637],{},[304,3636,1276],{},[304,3638,435],{},[315,3640,1301],{},[304,3642,1290],{},[1305,3644,1307],{},[371,3646,3647,3649],{},[304,3648,344],{},[304,3650,435],{},[315,3652,325],{"separator":324},[404,3654],{"width":406},[371,3656,3657,3659],{},[304,3658,310],{},[304,3660,435],{},[315,3662,1281],{},[315,3664,318],{"stretchy":317},[339,3666,341],{},[315,3668,380],{},[304,3670,1290],{},[315,3672,331],{"stretchy":317},[371,3674,3675,3677],{},[304,3676,310],{},[304,3678,435],{},[315,3680,1301],{},[304,3682,1290],{},[1305,3684,1307],{},[371,3686,3687,3689],{},[304,3688,1352],{},[304,3690,435],{},[315,3692,325],{"separator":324},[404,3694],{"width":406},[371,3696,3697,3699],{},[304,3698,385],{},[304,3700,435],{},[315,3702,334],{},[336,3704,3705,3711],{},[371,3706,3707,3709],{},[304,3708,310],{},[304,3710,435],{},[371,3712,3713,3715],{},[304,3714,1276],{},[304,3716,435],{},[461,3718,1383],{"encoding":463},[278,3720,3722,3777,3798,3859,3969,3990,4051,4161],{"className":3721,"ariaHidden":324},[468],[278,3723,3725,3728,3768,3771,3774],{"className":3724},[472],[278,3726],{"className":3727,"style":1393},[476],[278,3729,3731,3734],{"className":3730},[481],[278,3732,1276],{"className":3733,"style":1400},[481,494],[278,3735,3737],{"className":3736},[762],[278,3738,3740,3760],{"className":3739},[543,544],[278,3741,3743,3757],{"className":3742},[548],[278,3744,3746],{"className":3745,"style":772},[552],[278,3747,3748,3751],{"style":1415},[278,3749],{"className":3750,"style":779},[560],[278,3752,3754],{"className":3753},[636,637,638,639],[278,3755,435],{"className":3756,"style":1003},[481,494,639],[278,3758,595],{"className":3759},[594],[278,3761,3763],{"className":3762},[548],[278,3764,3766],{"className":3765,"style":1128},[552],[278,3767],{},[278,3769],{"className":3770,"style":515},[404],[278,3772,1281],{"className":3773},[519],[278,3775],{"className":3776,"style":515},[404],[278,3778,3780,3783,3786,3789,3792,3795],{"className":3779},[472],[278,3781],{"className":3782,"style":477},[476],[278,3784,318],{"className":3785},[490],[278,3787,341],{"className":3788},[481],[278,3790],{"className":3791,"style":801},[404],[278,3793,380],{"className":3794},[805],[278,3796],{"className":3797,"style":801},[404],[278,3799,3801,3804,3807,3810,3850,3853,3856],{"className":3800},[472],[278,3802],{"className":3803,"style":1472},[476],[278,3805,1290],{"className":3806,"style":1476},[481,494],[278,3808,331],{"className":3809},[511],[278,3811,3813,3816],{"className":3812},[481],[278,3814,1276],{"className":3815,"style":1400},[481,494],[278,3817,3819],{"className":3818},[762],[278,3820,3822,3842],{"className":3821},[543,544],[278,3823,3825,3839],{"className":3824},[548],[278,3826,3828],{"className":3827,"style":772},[552],[278,3829,3830,3833],{"style":1415},[278,3831],{"className":3832,"style":779},[560],[278,3834,3836],{"className":3835},[636,637,638,639],[278,3837,435],{"className":3838,"style":1003},[481,494,639],[278,3840,595],{"className":3841},[594],[278,3843,3845],{"className":3844},[548],[278,3846,3848],{"className":3847,"style":1128},[552],[278,3849],{},[278,3851],{"className":3852,"style":801},[404],[278,3854,1301],{"className":3855},[805],[278,3857],{"className":3858,"style":801},[404],[278,3860,3862,3865,3868,3871,3911,3914,3917,3920,3960,3963,3966],{"className":3861},[472],[278,3863],{"className":3864,"style":1393},[476],[278,3866,1290],{"className":3867,"style":1476},[481,494],[278,3869],{"className":3870,"style":503},[404],[278,3872,3874,3877],{"className":3873},[481],[278,3875,344],{"className":3876},[481,494],[278,3878,3880],{"className":3879},[762],[278,3881,3883,3903],{"className":3882},[543,544],[278,3884,3886,3900],{"className":3885},[548],[278,3887,3889],{"className":3888,"style":772},[552],[278,3890,3891,3894],{"style":775},[278,3892],{"className":3893,"style":779},[560],[278,3895,3897],{"className":3896},[636,637,638,639],[278,3898,435],{"className":3899,"style":1003},[481,494,639],[278,3901,595],{"className":3902},[594],[278,3904,3906],{"className":3905},[548],[278,3907,3909],{"className":3908,"style":1128},[552],[278,3910],{},[278,3912,325],{"className":3913},[499],[278,3915],{"className":3916,"style":935},[404],[278,3918],{"className":3919,"style":503},[404],[278,3921,3923,3926],{"className":3922},[481],[278,3924,310],{"className":3925,"style":1596},[481,494],[278,3927,3929],{"className":3928},[762],[278,3930,3932,3952],{"className":3931},[543,544],[278,3933,3935,3949],{"className":3934},[548],[278,3936,3938],{"className":3937,"style":772},[552],[278,3939,3940,3943],{"style":1611},[278,3941],{"className":3942,"style":779},[560],[278,3944,3946],{"className":3945},[636,637,638,639],[278,3947,435],{"className":3948,"style":1003},[481,494,639],[278,3950,595],{"className":3951},[594],[278,3953,3955],{"className":3954},[548],[278,3956,3958],{"className":3957,"style":1128},[552],[278,3959],{},[278,3961],{"className":3962,"style":515},[404],[278,3964,1281],{"className":3965},[519],[278,3967],{"className":3968,"style":515},[404],[278,3970,3972,3975,3978,3981,3984,3987],{"className":3971},[472],[278,3973],{"className":3974,"style":477},[476],[278,3976,318],{"className":3977},[490],[278,3979,341],{"className":3980},[481],[278,3982],{"className":3983,"style":801},[404],[278,3985,380],{"className":3986},[805],[278,3988],{"className":3989,"style":801},[404],[278,3991,3993,3996,3999,4002,4042,4045,4048],{"className":3992},[472],[278,3994],{"className":3995,"style":1472},[476],[278,3997,1290],{"className":3998,"style":1476},[481,494],[278,4000,331],{"className":4001},[511],[278,4003,4005,4008],{"className":4004},[481],[278,4006,310],{"className":4007,"style":1596},[481,494],[278,4009,4011],{"className":4010},[762],[278,4012,4014,4034],{"className":4013},[543,544],[278,4015,4017,4031],{"className":4016},[548],[278,4018,4020],{"className":4019,"style":772},[552],[278,4021,4022,4025],{"style":1611},[278,4023],{"className":4024,"style":779},[560],[278,4026,4028],{"className":4027},[636,637,638,639],[278,4029,435],{"className":4030,"style":1003},[481,494,639],[278,4032,595],{"className":4033},[594],[278,4035,4037],{"className":4036},[548],[278,4038,4040],{"className":4039,"style":1128},[552],[278,4041],{},[278,4043],{"className":4044,"style":801},[404],[278,4046,1301],{"className":4047},[805],[278,4049],{"className":4050,"style":801},[404],[278,4052,4054,4057,4060,4063,4103,4106,4109,4112,4152,4155,4158],{"className":4053},[472],[278,4055],{"className":4056,"style":1729},[476],[278,4058,1290],{"className":4059,"style":1476},[481,494],[278,4061],{"className":4062,"style":503},[404],[278,4064,4066,4069],{"className":4065},[481],[278,4067,1352],{"className":4068},[481,494],[278,4070,4072],{"className":4071},[762],[278,4073,4075,4095],{"className":4074},[543,544],[278,4076,4078,4092],{"className":4077},[548],[278,4079,4081],{"className":4080,"style":772},[552],[278,4082,4083,4086],{"style":775},[278,4084],{"className":4085,"style":779},[560],[278,4087,4089],{"className":4088},[636,637,638,639],[278,4090,435],{"className":4091,"style":1003},[481,494,639],[278,4093,595],{"className":4094},[594],[278,4096,4098],{"className":4097},[548],[278,4099,4101],{"className":4100,"style":1128},[552],[278,4102],{},[278,4104,325],{"className":4105},[499],[278,4107],{"className":4108,"style":935},[404],[278,4110],{"className":4111,"style":503},[404],[278,4113,4115,4118],{"className":4114},[481],[278,4116,385],{"className":4117},[481,494],[278,4119,4121],{"className":4120},[762],[278,4122,4124,4144],{"className":4123},[543,544],[278,4125,4127,4141],{"className":4126},[548],[278,4128,4130],{"className":4129,"style":772},[552],[278,4131,4132,4135],{"style":775},[278,4133],{"className":4134,"style":779},[560],[278,4136,4138],{"className":4137},[636,637,638,639],[278,4139,435],{"className":4140,"style":1003},[481,494,639],[278,4142,595],{"className":4143},[594],[278,4145,4147],{"className":4146},[548],[278,4148,4150],{"className":4149,"style":1128},[552],[278,4151],{},[278,4153],{"className":4154,"style":515},[404],[278,4156,334],{"className":4157},[519],[278,4159],{"className":4160,"style":515},[404],[278,4162,4164,4167],{"className":4163},[472],[278,4165],{"className":4166,"style":1840},[476],[278,4168,4170,4173,4300],{"className":4169},[481],[278,4171],{"className":4172},[490,536],[278,4174,4176],{"className":4175},[336],[278,4177,4179,4292],{"className":4178},[543,544],[278,4180,4182,4289],{"className":4181},[548],[278,4183,4185,4233,4241],{"className":4184,"style":1859},[552],[278,4186,4187,4190],{"style":556},[278,4188],{"className":4189,"style":561},[560],[278,4191,4193],{"className":4192},[481],[278,4194,4196,4199],{"className":4195},[481],[278,4197,1276],{"className":4198,"style":1400},[481,494],[278,4200,4202],{"className":4201},[762],[278,4203,4205,4225],{"className":4204},[543,544],[278,4206,4208,4222],{"className":4207},[548],[278,4209,4211],{"className":4210,"style":772},[552],[278,4212,4213,4216],{"style":1415},[278,4214],{"className":4215,"style":779},[560],[278,4217,4219],{"className":4218},[636,637,638,639],[278,4220,435],{"className":4221,"style":1003},[481,494,639],[278,4223,595],{"className":4224},[594],[278,4226,4228],{"className":4227},[548],[278,4229,4231],{"className":4230,"style":1128},[552],[278,4232],{},[278,4234,4235,4238],{"style":570},[278,4236],{"className":4237,"style":561},[560],[278,4239],{"className":4240,"style":578},[577],[278,4242,4243,4246],{"style":581},[278,4244],{"className":4245,"style":561},[560],[278,4247,4249],{"className":4248},[481],[278,4250,4252,4255],{"className":4251},[481],[278,4253,310],{"className":4254,"style":1596},[481,494],[278,4256,4258],{"className":4257},[762],[278,4259,4261,4281],{"className":4260},[543,544],[278,4262,4264,4278],{"className":4263},[548],[278,4265,4267],{"className":4266,"style":772},[552],[278,4268,4269,4272],{"style":1611},[278,4270],{"className":4271,"style":779},[560],[278,4273,4275],{"className":4274},[636,637,638,639],[278,4276,435],{"className":4277,"style":1003},[481,494,639],[278,4279,595],{"className":4280},[594],[278,4282,4284],{"className":4283},[548],[278,4285,4287],{"className":4286,"style":1128},[552],[278,4288],{},[278,4290,595],{"className":4291},[594],[278,4293,4295],{"className":4294},[548],[278,4296,4298],{"className":4297,"style":1973},[552],[278,4299],{},[278,4301],{"className":4302},[511,536],[111,4304,4305,4307,4308,4310],{},[1163,4306,1983],{}," and ",[1163,4309,1987],{}," are the count and sum the current batch contributes to cluster j. α sets how fast to forget: a large α listens to recent batches, a small one averages history. Old assignments are not deleted; they are discounted.",[111,4312,4313,4314,4316],{},"MacQueen's rule is ",[1163,4315,1994],{},", and it never forgets. Early in training the centroids are bad, so the labels are mostly wrong, and those wrong labels keep a full vote forever, dragging the centroid. e-means gives them a decay factor: slowly forget the early mistakes.",[111,4318,4319,4322],{},[238,4320,4321],{},"Two: α is not constant."," It starts larger and follows a cosine schedule down to a tenth of its initial value. Fast at first, slow at the end.",[111,4324,4325,4328],{},[238,4326,4327],{},"Three: dead clusters must be revived."," Mini-batch updates easily produce centroids with no points assigned. The cluster count says k; the usable count is lower. Every five batches, e-means reassigns clusters below 10% of the mean count by splitting a large donor cluster in two. Faiss already had this trick. The paper's ablation (turn one component off, see what the loss does) is unusually clean:",[157,4330,4331,4350],{},[160,4332,4333],{},[163,4334,4335,4338,4341,4344,4347],{},[166,4336,4337],{},"Dataset",[166,4339,4340],{},"Revival",[166,4342,4343],{},"Dead clusters",[166,4345,4346],{},"Of codebook",[166,4348,4349],{},"Test MSE",[176,4351,4352,4365,4378],{},[163,4353,4354,4356,4359,4361,4363],{},[181,4355,2035],{},[181,4357,4358],{},"split by size",[181,4360,2041],{},[181,4362,2044],{},[181,4364,2047],{},[163,4366,4367,4369,4372,4374,4376],{},[181,4368,2035],{},[181,4370,4371],{},"resample from batch",[181,4373,2057],{},[181,4375,2060],{},[181,4377,2063],{},[163,4379,4380,4382,4385,4387,4389],{},[181,4381,2035],{},[181,4383,4384],{},"off",[181,4386,2073],{},[181,4388,2076],{},[181,4390,2079],{},[111,4392,4393],{},"1M vectors, k = 16,384, 5 epochs, averaged over 5 seeds; SIFT behaves the same way. With revival off, a quarter of the codebook is empty. The other components (initialization, cosine, finalization) move the loss by a fraction of a percent. The four changes are not equal; this is the one that matters.",[111,4395,4396,4399,4400,4404],{},[238,4397,4398],{},"Four: you do not tune the parameters."," Batch size and initial step come from scaling laws fitted on (n, k, T); the reported regret is about ",[115,4401,4403],{"href":124,"rel":4402},[119],"0.07%",". There is a trap in \"no hyperparameters\": it means no new knobs relative to Lloyd. You still pick k and the number of epochs T (5 by default). The two hardest internal parameters are handled by a formula.",[111,4406,4407],{},"A design note: they do not use gradient descent. The project page says large learning rates make gradient updates overshoot. EMA keeps the centroid inside the convex hull of the points ever assigned to that cluster — not the current batch, the history.",[111,4409,4410],{},"Lloyd is a special case of e-means: set the batch to all n and α to 1, and one e-means update equals one Lloyd update. The two are ends of one formula, and the paper finds that end is the worst parameter setting.",[111,4412,4413],{},"One practical detail: at the end of training, the last batch's assignments can be used to recompute an exact mean (last-epoch-mean), lowering the train loss a little more. If what you care about is unseen data, finish with a second, slower EMA. Both cost little, so one run can produce two sets of centroids.",[111,4415,4416,4417],{},"Then the counterintuitive part: ",[238,4418,4419],{},"noise helps.",[111,4421,4422,4423,4427],{},"Lloyd's loss only decreases, so once it settles into a local minimum it has no reason to leave. A mini-batch sees a slice at a time, so its updates carry noise. The paper's explanation is that this noise pushes centroids out of configurations that look converged but are mispartitioned. Across ",[115,4424,4426],{"href":124,"rel":4425},[119],"200 seeds"," on toy data, e-means lands in pathological configurations far less often.",[111,4429,4430],{},"Figure 2 is our own small simulation, not the paper's figure: three Gaussian blobs of 40 points each, fixed seed, k = 3, and the same deliberately bad initial centroids. e-means uses batch 12, an initial α of 0.35 with cosine decay, and 2.5 epochs; Lloyd is full-batch.",[111,4432,4433],{},"Lloyd stops moving by pass 8 and is still at MSE 5.39 after 33 passes: two centroids in one blob, one between the other two. e-means reaches 1.28 in 25 updates, one centroid per blob.",[245,4435,249,4437,249,4442],{"className":4436},[248],[251,4438],{"src":4439,"poster":4440,"autoPlay":255,"loop":255,"muted":255,"playsInline":255,"ariaLabel":4441},"\u002Fimages\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs\u002Fcentroids.mp4","\u002Fimages\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs\u002Fcentroids-poster.jpg","Same data, same initial centroids: on the left, two Lloyd centroids share a blob; on the right, three e-means centroids each take one.",[258,4443,4444],{},"Figure 2: our simulation, settings above. Left: two centroids share a blob. Right: one each.",[111,4446,4447],{},"This example shows only that, from one initialization, two update rules end up in different places. It is not a guarantee. The paper's claim is probabilistic: not every run escapes.",[135,4449,4451],{"id":4450},"what-the-10-compares","What the \"10×\" compares",[111,4453,4454],{},"The comparison is the easiest thing to misread:",[111,4456,4457,4460],{},[238,4458,4459],{},"It is e-means at 1.4–2.6 epochs against Lloyd at 25 epochs. It is not Lloyd run to convergence."," Lloyd would keep improving a little; the gap would narrow.",[157,4462,4463,4476],{},[160,4464,4465],{},[163,4466,4467,4470,4473],{},[166,4468,4469],{},"Item",[166,4471,4472],{},"Number",[166,4474,4475],{},"Condition and source",[176,4477,4478,4492,4505,4518,4529],{},[163,4479,4480,4483,4485],{},[181,4481,4482],{},"Epochs to match Lloyd at 25",[181,4484,2171],{},[181,4486,4487,4491],{},[115,4488,4490],{"href":117,"rel":4489},[119],"abstract","; several embedding datasets",[163,4493,4494,4497,4499],{},[181,4495,4496],{},"GPU speedup",[181,4498,2186],{},[181,4500,4501,4502],{},"against Flash-KMeans, an alternative GPU k-means implementation, on H100; ",[115,4503,4490],{"href":117,"rel":4504},[119],[163,4506,4507,4510,4512],{},[181,4508,4509],{},"CPU speedup",[181,4511,2200],{},[181,4513,4514,4515],{},"against Faiss; ",[115,4516,2610],{"href":124,"rel":4517},[119],[163,4519,4520,4523,4526],{},[181,4521,4522],{},"Largest run",[181,4524,4525],{},"10B points, 16M clusters, 2.5 epochs",[181,4527,4528],{},"DINO10B, the paper's 10B DINO-feature dataset",[163,4530,4531,4534,4537],{},[181,4532,4533],{},"Lloyd iterations in the wild",[181,4535,4536],{},"19–229",[181,4538,4539,4542],{},[115,4540,2232],{"href":2230,"rel":4541},[119],"; community, not the paper",[111,4544,4545],{},"The last row is not an argument that 25 is too few. It says Lloyd's iteration count varies with the data. The point is not the number 25; it is that every pass is a full sweep. 25 is a default, not a law.",[111,4547,4548,4549,4552],{},"Another trap: ",[238,4550,4551],{},"epochs are not time."," Counting data sweeps alone, 2.5 against 25 is about 10×. The measured wall-clock is 10–45×. My reading is that part of the gap is mini-batches saturating a GPU better; the paper does not break the 10–45× down to that level.",[111,4554,4555,4556,4559],{},"The conservative statement: ",[238,4557,4558],{},"about 10×."," The 45× end is a specific setting, a specific GPU, against a specific reference implementation.",[111,4561,4562],{},"One detail worth separating: the abstract says 10–45× on GPU against Flash-KMeans. The project page reports 8–15× on CPU against Faiss. Different baselines; do not swap or add them.",[111,4564,4565,4566,4569,4570,4572,4573,4575],{},"It shipped: faiss ",[115,4567,2264],{"href":2262,"rel":4568},[119]," (Nov 10, 2026) includes ",[1163,4571,2268],{},", and ",[1163,4574,2272],{}," on PyPI is 1.16.0. Four lines:",[2275,4577,4579],{"className":2277,"code":4578,"language":2279,"meta":2280,"style":2280},"from faiss.contrib.e_means import Emeans\n\nem = Emeans(d, k, nepochs=5)\ncentroids, labels = em.train(x)   # x is a PyTorch tensor (n, d)\n",[1163,4580,4581,4585,4589,4593],{"__ignoreMap":2280},[278,4582,4583],{"class":2285,"line":2286},[278,4584,2289],{},[278,4586,4587],{"class":2285,"line":2292},[278,4588,2295],{"emptyLinePlaceholder":255},[278,4590,4591],{"class":2285,"line":2298},[278,4592,2301],{},[278,4594,4595],{"class":2285,"line":2304},[278,4596,4597],{},"centroids, labels = em.train(x)   # x is a PyTorch tensor (n, d)\n",[111,4599,4600],{},"What it does not have yet: independent replication. The paper is days old, with reproduction scripts and benchmark data, but only the authors' numbers.",[111,4602,4603],{},"It is also stochastic: different seeds land on different solutions. The reported numbers come from many datasets and settings, not a guarantee that every run finishes in 1.4 epochs.",[135,4605,4607],{"id":4606},"will-your-index-get-faster","Will your index get faster?",[111,4609,4610,4611,4614],{},"The headline: ",[238,4612,4613],{},"it speeds up index construction, not queries."," If your problem is \"search is slow,\" this is the wrong essay. That is HNSW (a graph index without clustering), quantization, or a smaller model.",[111,4616,4617],{},"Where it pays:",[157,4619,4620,4630],{},[160,4621,4622],{},[163,4623,4624,4627],{},[166,4625,4626],{},"Your situation",[166,4628,4629],{},"Advice",[176,4631,4632,4640,4648,4656,4664],{},[163,4633,4634,4637],{},[181,4635,4636],{},"A few thousand documents; rebuilds take seconds",[181,4638,4639],{},"leave it; 10× is invisible",[163,4641,4642,4645],{},[181,4643,4644],{},"100k+ vectors, k in the thousands, rebuilds hurt",[181,4646,4647],{},"worth an A\u002FB",[163,4649,4650,4653],{},[181,4651,4652],{},"Frequent rebuilds (daily, or every model swap)",[181,4654,4655],{},"worth switching; start with the CPU path",[163,4657,4658,4661],{},[181,4659,4660],{},"HNSW, no coarse quantizer",[181,4662,4663],{},"this step does not exist; skip",[163,4665,4666,4669],{},[181,4667,4668],{},"You want inference faster",[181,4670,4671],{},"wrong problem",[111,4673,4674],{},"One prerequisite is easy to miss: the GPU path wants an H100 or H200 and matching CUDA and kernel builds; the CPU path is the one most readers can actually run. The CPU path needs only faiss itself, and the 8–15× number is exactly that path.",[111,4676,4677],{},"The costs: a new API to validate, recall to re-measure after changing initialization. An approximate solution does not guarantee a global optimum (Lloyd does not either). The 10× buys build time, not free quality.",[111,4679,4680],{},"To check it: keep a query set and compare recall@10 — the share of queries whose top 10 contain a true nearest neighbour — against exact (Flat) search. MSE alone will miss retrieval quality.",[135,4682,4684],{"id":4683},"three-things-to-do-tomorrow","Three things to do tomorrow",[111,4686,4687,4690],{},[238,4688,4689],{},"First, measure one rebuild."," Record five numbers: n, k, niter, wall-clock, final MSE. Without them, \"switch or not\" is a guess.",[2275,4692,4694],{"className":2277,"code":4693,"language":2279,"meta":2280,"style":2280},"import numpy as np, faiss, time\n\nx = np.ascontiguousarray(x, dtype='float32')\nflat = faiss.IndexFlatL2(x.shape[1])   # only to score the final loss\n\nt0 = time.perf_counter()\nkm = faiss.Kmeans(x.shape[1], k, niter=25)\nkm.train(x)\nsecs = time.perf_counter() - t0\n\nflat.add(km.centroids)\nD, _ = flat.search(x, 1)\nprint(f\"{secs:.1f}s  MSE={D.mean():.3f}\")\n",[1163,4695,4696,4700,4704,4708,4713,4717,4721,4725,4729,4733,4737,4741,4745],{"__ignoreMap":2280},[278,4697,4698],{"class":2285,"line":2286},[278,4699,2408],{},[278,4701,4702],{"class":2285,"line":2292},[278,4703,2295],{"emptyLinePlaceholder":255},[278,4705,4706],{"class":2285,"line":2298},[278,4707,2417],{},[278,4709,4710],{"class":2285,"line":2304},[278,4711,4712],{},"flat = faiss.IndexFlatL2(x.shape[1])   # only to score the final loss\n",[278,4714,4715],{"class":2285,"line":2425},[278,4716,2295],{"emptyLinePlaceholder":255},[278,4718,4719],{"class":2285,"line":2430},[278,4720,2433],{},[278,4722,4723],{"class":2285,"line":2436},[278,4724,2439],{},[278,4726,4727],{"class":2285,"line":2442},[278,4728,2445],{},[278,4730,4731],{"class":2285,"line":2448},[278,4732,2451],{},[278,4734,4735],{"class":2285,"line":2454},[278,4736,2295],{"emptyLinePlaceholder":255},[278,4738,4739],{"class":2285,"line":2459},[278,4740,2462],{},[278,4742,4743],{"class":2285,"line":2465},[278,4744,2468],{},[278,4746,4747],{"class":2285,"line":2471},[278,4748,2474],{},[111,4750,4751,4754],{},[238,4752,4753],{},"Second, lower niter and look."," The cheapest experiment: the same data at niter 25, 10 and 5. If 10 is close enough, your default was paying 1.5× the scans for nothing.",[2275,4756,4757],{"className":2277,"code":2483,"language":2279,"meta":2280,"style":2280},[1163,4758,4759,4763,4767,4771,4775,4779,4783],{"__ignoreMap":2280},[278,4760,4761],{"class":2285,"line":2286},[278,4762,2490],{},[278,4764,4765],{"class":2285,"line":2292},[278,4766,2495],{},[278,4768,4769],{"class":2285,"line":2298},[278,4770,2500],{},[278,4772,4773],{"class":2285,"line":2304},[278,4774,2505],{},[278,4776,4777],{"class":2285,"line":2425},[278,4778,2510],{},[278,4780,4781],{"class":2285,"line":2430},[278,4782,2515],{},[278,4784,4785],{"class":2285,"line":2436},[278,4786,2520],{},[111,4788,4789,4792],{},[238,4790,4791],{},"Third, switch only at scale."," Use the same data and the same initialization; compare wall-clock, final MSE, and recall@10 if you have an index. The CPU path needs no GPU, so it is the right place to start.",[111,4794,4795],{},"The number 25 is not a physical constant. It is a default. The point is not to replace k-means; it is that 25 can be measured, tuned, or replaced -- and the people proposing to replace it are the authors of faiss.",[135,4797,4799],{"id":4798},"further-reading","Further reading",[2534,4801,4802,4808],{},[2537,4803,4804,4807],{},[115,4805,4806],{"href":2541},"A running model is not a finished job",": the same kind of teardown, applied to \"the model works\"",[2537,4809,4810,4813],{},[115,4811,4812],{"href":2548},"Quantization speed is often a kernel problem",": another case where implementation choices decide a 10× gap",[2559,4815,2561],{},{"title":2280,"searchDepth":2292,"depth":2292,"links":4817},[4818,4819,4820,4821,4822,4823,4824,4825],{"id":2629,"depth":2292,"text":2630},{"id":2642,"depth":2292,"text":2643},{"id":2744,"depth":2292,"text":2745},{"id":3582,"depth":2292,"text":3583},{"id":4450,"depth":2292,"text":4451},{"id":4606,"depth":2292,"text":4607},{"id":4683,"depth":2292,"text":4684},{"id":4798,"depth":2292,"text":4799},"\u002Fimages\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs.svg","Cover for the English essay, k-means Reads Your Data 25 Times","Faiss's k-means defaults to 25 full passes over the training set; Meta FAIR's e-means matches that loss in 1.4–2.6 with EMA updates and dead-cluster revival. What the 10× really compares.","en",{},"\u002Fimages\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs.jpg","\u002Fblog\u002Fen\u002Fkmeans-fewer-epochs",{"title":2594,"description":4828},"blog\u002Fen\u002Fkmeans-fewer-epochs",[2586,2587,2588,2589],"p0-rCBuSmcTSAtS0HEnwAqCdgrJz-0Ah0cXj_OTmTvA",[4838,5658],{"id":4839,"title":4840,"author":103,"body":4841,"cover":5642,"coverAlt":5643,"date":5644,"description":5645,"draft":2576,"extension":2577,"featured":2576,"lang":2578,"meta":5646,"navigation":255,"ogImage":5647,"path":5648,"seo":5649,"slug":5650,"stem":5651,"tags":5652,"translationKey":5650,"updated":2590,"__hash__":5657},"blog\u002Fblog\u002Fzh-TW\u002Fweight-edit-loop-repair.md","它沒有變聰明，只是不再打轉",{"type":105,"value":4842,"toc":5631},[4843,4848,4851,4854,4860,4869,4872,4887,4890,4893,4984,4987,4990,4993,4996,4999,5005,5008,5012,5015,5018,5021,5031,5034,5051,5054,5057,5065,5068,5075,5086,5090,5093,5096,5143,5154,5160,5163,5166,5169,5172,5176,5179,5182,5185,5188,5191,5196,5202,5205,5213,5216,5220,5223,5232,5235,5238,5378,5381,5384,5387,5390,5393,5398,5404,5407,5410,5413,5416,5419,5422,5431,5434,5437,5476,5482,5485,5496,5499,5503,5506,5517,5520,5523,5529,5536,5543,5549,5552,5560,5563],[108,4844,4845],{},[111,4846,4847],{},"這篇的數字來自原文（部落格貼文，不是同儕審查論文）與公開 logs、Qwen 的 model card、Hugging Face 上的重建版重跑，以及硅星人Pro 按 logs 做的逐題重算。逐題配對那一段是二手重算，我會標出來。我們沒有在自己的機器上重跑那 50 次前向。",[135,4849,4850],{"id":4850},"先講一個畫面",[111,4852,4853],{},"你在筆電上跑一顆 0.8B 的小模型，給它一題國中數學。它想了三分鐘，輸出到上限被切斷；回頭看，整段在重複同兩句話。",[111,4855,4856,4857],{},"你的結論大概是：模型太小。這篇要給你的是一個更準的分界——",[238,4858,4859],{},"分數變好，是模型變聰明，還是它終於講得完？",[111,4861,4862,4863,4868],{},"十一月二日，四位 MIT CSAIL 的研究者公開",[115,4864,4867],{"href":4865,"rel":4866},"https:\u002F\u002Frikiyat.github.io\u002Fblog\u002Fweight-space-programming\u002F",[119],"一組實驗","。他們讓 GPT-6 Astra 直接修改 Qwen3.5-0.8B 的權重，只動了 0.016%。",[111,4870,4871],{},"同一顆模型，MATH-500 從 7.9% 變成 48.1%。",[111,4873,4874,4875,4880,4881,4886],{},"那則貼文在 ",[115,4876,4879],{"href":4877,"rel":4878},"https:\u002F\u002Fnews.ycombinator.com\u002Fitem?id=50341174",[119],"Hacker News"," 拿到將近 3,000 分、900 則留言。中文媒體的標題則是「爆改 Qwen 大腦」這一路（",[115,4882,4885],{"href":4883,"rel":4884},"https:\u002F\u002F36kr.com\u002Fp\u002F4056494372181124",[119],"例","）。",[111,4888,4889],{},"拆開來看，那個六倍買到的不是數學能力，是「把話講完」。而這兩件事在 benchmark 表上長得一樣，除非你多記一欄。",[135,4891,4892],{"id":4892},"先讀最後一欄",[157,4894,4895,4914],{},[160,4896,4897],{},[163,4898,4899,4902,4905,4908,4911],{},[166,4900,4901],{},"Qwen3.5-0.8B",[166,4903,4904],{},"MATH-500",[166,4906,4907],{},"GSM8K",[166,4909,4910],{},"IFEval",[166,4912,4913],{},"撞 32,768 token 上限",[176,4915,4916,4933,4950,4967],{},[163,4917,4918,4921,4924,4927,4930],{},[181,4919,4920],{},"原始",[181,4922,4923],{},"7.9%",[181,4925,4926],{},"13.8%",[181,4928,4929],{},"21.0%",[181,4931,4932],{},"93.0%",[163,4934,4935,4938,4941,4944,4947],{},[181,4936,4937],{},"改，10 次前向",[181,4939,4940],{},"12.3%",[181,4942,4943],{},"25.7%",[181,4945,4946],{},"49.0%",[181,4948,4949],{},"87.2%",[163,4951,4952,4955,4958,4961,4964],{},[181,4953,4954],{},"改，25 次前向",[181,4956,4957],{},"14.1%",[181,4959,4960],{},"25.1%",[181,4962,4963],{},"39.9%",[181,4965,4966],{},"86.4%",[163,4968,4969,4972,4975,4978,4981],{},[181,4970,4971],{},"改，50 次前向",[181,4973,4974],{},"48.1%",[181,4976,4977],{},"67.1%",[181,4979,4980],{},"62.3%",[181,4982,4983],{},"33.1%",[111,4985,4986],{},"前向（forward pass）就是讓模型真的回答一批題目，看它輸出什麼。不是訓練，也不給梯度。",[111,4988,4989],{},"四列用的是同一個方法，但三次交出的是三份不同的補丁，不是同一招多給預算。差別在於 Astra 被允許跑幾次前向。",[111,4991,4992],{},"10 次：12.3。25 次：14.1。50 次：48.1。",[111,4994,4995],{},"看前三列，你會說「預算不夠」。但最後一欄講的是另一件事。",[111,4997,4998],{},"10 次和 25 次時，撞上上限的數學題還有 87% 和 86%。到 50 次，掉到 33.1%。",[111,5000,5001,5004],{},[238,5002,5003],{},"分數是跟著截斷率走的。"," 前兩次沒有把迴圈修掉，分數就留在原地；把撞上限的比例壓下來，分數才動。",[111,5006,5007],{},"有一條線不聽這個解釋：IFEval 在 10 次前向就從 21.0 跳到 49.0，那時截斷率還有 87.2%。IFEval 的答案短，截斷對它的影響小。單次執行的結果，我不會拿它下結論。",[135,5009,5011],{"id":5010},"它改的是什麼兩層一個方向十三萬個權重","它改的是什麼：兩層、一個方向、十三萬個權重",[111,5013,5014],{},"Astra 做的事可以拆成三步。",[111,5016,5017],{},"第一步，看 96 道練習題的回答。其中 85 道撞到 32,768 上限，撞上去的內容幾乎都在重複。",[111,5019,5020],{},"第二步，把這個重複追到第 15 層與第 19 層的 MLP。MLP 是每個 transformer 區塊裡的前饋層，這兩層的輸出一直在同一個方向上推。",[111,5022,5023,5024,5027,5028,5030],{},"第三步，從這兩層的 ",[1163,5025,5026],{},"down_proj"," 各挑 64 個輸出欄位，把那個方向減掉。",[1163,5029,5026],{}," 是前饋層最後把結果投影回模型寬度的那個矩陣。",[111,5032,5033],{},"2 × 64 × 1,024 = 131,072 個權重，約占 8 億的 0.016%。",[111,5035,5036,5037,5042,5043,5046,5047,5050],{},"Hugging Face 上有人照公開的 diff ",[115,5038,5041],{"href":5039,"rel":5040},"https:\u002F\u002Fhuggingface.co\u002FRikiyaT\u002FQwen3.5-0.8B-weight-space-programming",[119],"重建了檢查點","。公開 logs 裡的腳本逐個 tensor 對 sha256：只有 ",[1163,5044,5045],{},"layers.15.mlp.down_proj"," 與 ",[1163,5048,5049],{},"layers.19.mlp.down_proj"," 兩個張量不同。",[111,5052,5053],{},"我認為這是最乾淨的一種驗證。不是「他們說改了兩個張量」，是「重建出來的檔案只有兩個張量不同」。",[111,5055,5056],{},"比喻的話：模型不是不會算，它是在某個地方一直被推回原點，繞著同樣兩三句話轉。那個「推回去的力」，在權重裡是一個方向。減掉它，模型就能把已經想到的答案寫完（圖 1）。",[111,5058,5059,5060,5064],{},"Astra 還自己做了一個對照。取一個與目標方向正交、改動量相同的隨機方向減掉，成績只動 1.5 個百分點（",[115,5061,5063],{"href":4883,"rel":5062},[119],"覆盤","）。所以動的是方向，不是「隨便改一點權重都會變好」。",[111,5066,5067],{},"這不是全新的技術路線。把「拒絕回答」定位到單一方向的研究、ROME 與 MEMIT 那種「找到一組權重、改掉一件事」的做法，都在同一個家族裡。",[111,5069,5070,5071,5074],{},"新的部分是",[238,5072,5073],{},"誰來找那個方向。"," 這次是一個通用模型自己找，而且會把理由寫出來。",[245,5076,249,5078,249,5083],{"className":5077},[248],[251,5079],{"src":5080,"poster":5081,"autoPlay":255,"loop":255,"muted":255,"playsInline":255,"ariaLabel":5082},"\u002Fimages\u002Fblog\u002Fweight-edit-loop-repair\u002Floop-repair.mp4","\u002Fimages\u002Fblog\u002Fweight-edit-loop-repair\u002Floop-repair-poster.jpg","左邊是原始模型反覆輸出、撞上 32,768 上限；右邊是減掉一個方向之後，答案在預算內寫完",[258,5084,5085],{},"圖 1：同一顆模型。左邊一直被推回原點，93% 的數學題撞上上限；右邊減掉兩層 MLP 裡的方向，撞上限的比例掉到 33%。",[135,5087,5089],{"id":5088},"_579-題裡576-題原本只是講不完","579 題裡，576 題原本只是講不完",[111,5091,5092],{},"這是最關鍵、也最容易被誤讀的一段。",[111,5094,5095],{},"硅星人Pro 把公開 logs 的逐題紀錄重算一次。他們挑的 1,152 道題，是練習題裡保留起來、沒有拿去挑補丁的那批。",[157,5097,5098,5114],{},[160,5099,5100],{},[163,5101,5102,5105,5108,5111],{},[166,5103,5104],{},"原本的狀態",[166,5106,5107],{},"題數",[166,5109,5110],{},"改之前答對",[166,5112,5113],{},"改之後答對",[176,5115,5116,5129],{},[163,5117,5118,5121,5124,5127],{},[181,5119,5120],{},"有正常結束",[181,5122,5123],{},"114",[181,5125,5126],{},"93.9%",[181,5128,5126],{},[163,5130,5131,5134,5137,5140],{},[181,5132,5133],{},"被上限截斷",[181,5135,5136],{},"1,038",[181,5138,5139],{},"1.4%",[181,5141,5142],{},"56.7%",[2534,5144,5145,5148,5151],{},[2537,5146,5147],{},"從錯變對 579 題，其中 576 題原本是被截斷的",[2537,5149,5150],{},"從對變錯 5 題",[2537,5152,5153],{},"平均回答長度從 30,868 token 降到 22,037",[111,5155,5156,5159],{},[238,5157,5158],{},"已經答完的 114 題，正確率一位小數都沒動。"," 114 題裡 3 題從錯變對、3 題從對變錯，剛好打平。",[111,5161,5162],{},"579 個救援裡，576 個來自那 1,038 道本來沒講完的。真正的進步在那裡。",[111,5164,5165],{},"這件事不是誰抓到破綻。原文的表格最後一欄就是 93% 到 33.1%，Astra 自己的最終報告也寫了 576／579。",[111,5167,5168],{},"作者沒有隱瞞：logs、檢查點、失敗的實驗都公開了。他們只是沒有把「已經答完的題目有沒有變」算成一行。",[111,5170,5171],{},"補一句：這張表是依 logs 重算出來的，不是原文的表格。我們沒有自己重算。",[135,5173,5175],{"id":5174},"不會打轉的模型它修不動","不會打轉的模型，它修不動",[111,5177,5178],{},"同樣的方法，換到 Gemma 3 270M 就失效了。",[111,5180,5181],{},"這顆模型很少打轉：只有 8.5% 的回答撞到上限。Qwen 那顆是 93%。",[111,5183,5184],{},"Astra 讀它的失敗，找到的是普通的算錯與代數步驟錯。沒有一個可以關掉的零件。",[111,5186,5187],{},"改完之後，MATH-500 落在 7.0% 到 7.7% 之間，改之前是 6.8%。Astra 自己的報告把這個幅度標成「未達確立」。",[111,5189,5190],{},"原文那句話，是整篇最重要的：",[108,5192,5193],{},[111,5194,5195],{},"Editing weights could remove an obstacle that hid an ability, but it could not add an ability the model lacked.",[111,5197,5198,5199],{},"翻成白話：",[238,5200,5201],{},"改權重可以移除擋住能力的障礙，但不能加進模型本來沒有的能力。",[111,5203,5204],{},"這句話對你有直接用途。你的模型表現差，先問是哪一種差。",[2534,5206,5207,5210],{},[2537,5208,5209],{},"它會算，但講不完（一直重複、撞上限）→ 移除障礙有效",[2537,5211,5212],{},"它算錯 → 移除障礙無效，換模型或換任務",[111,5214,5215],{},"第一種，可以先從設定下手，不必換模型。第二種，別在權重上花時間。",[135,5217,5219],{"id":5218},"被批的不是結果是包裝","被批的不是結果，是包裝",[111,5221,5222],{},"這篇被罵得很兇。但先把話講清楚：被批的是包裝，不是結果。",[111,5224,5225,5226,5231],{},"spaCy 的作者 Matthew Honnibal 寫了一篇",[115,5227,5230],{"href":5228,"rel":5229},"https:\u002F\u002Fhonnibal.dev\u002Fblog\u002Fastra-read-write-misleading",[119],"質疑","，用魔術師比喻。",[111,5233,5234],{},"同一場戲，第一次用特殊道具，第二次改用藏東西，第三次用強迫選擇。觀眾以為只有一種手法，於是每看一次都像推翻了上一個假設。",[111,5236,5237],{},"他的證據是一張表，把八個實驗按「Astra 實際拿到什麼」排開：",[157,5239,5240,5259],{},[160,5241,5242],{},[163,5243,5244,5247,5250,5253,5256],{},[166,5245,5246],{},"實驗",[166,5248,5249],{},"對象",[166,5251,5252],{},"只看原始權重",[166,5254,5255],{},"用 Python",[166,5257,5258],{},"跑過模型",[176,5260,5261,5277,5291,5305,5319,5333,5348,5363],{},[163,5262,5263,5266,5269,5272,5275],{},[181,5264,5265],{},"1 猜遊戲",[181,5267,5268],{},"1.7 萬",[181,5270,5271],{},"✓",[181,5273,5274],{},"—",[181,5276,5274],{},[163,5278,5279,5282,5285,5287,5289],{},[181,5280,5281],{},"2 猜形狀",[181,5283,5284],{},"2.4 萬",[181,5286,5271],{},[181,5288,5274],{},[181,5290,5274],{},[163,5292,5293,5296,5299,5301,5303],{},[181,5294,5295],{},"3 猜語言與複製頭",[181,5297,5298],{},"716 萬",[181,5300,5274],{},[181,5302,5271],{},[181,5304,5274],{},[163,5306,5307,5310,5313,5315,5317],{},[181,5308,5309],{},"4 修卡住的車",[181,5311,5312],{},"17 萬",[181,5314,5271],{},[181,5316,5274],{},[181,5318,5274],{},[163,5320,5321,5324,5327,5329,5331],{},[181,5322,5323],{},"5 從零寫 MinAtar",[181,5325,5326],{},"2 萬",[181,5328,5274],{},[181,5330,5274],{},[181,5332,5274],{},[163,5334,5335,5338,5341,5343,5345],{},[181,5336,5337],{},"6 從零寫圍棋",[181,5339,5340],{},"148 萬",[181,5342,5274],{},[181,5344,5271],{},[181,5346,5347],{},"✓（0–50 次）",[163,5349,5350,5353,5356,5358,5360],{},[181,5351,5352],{},"7 找出阿諛模型",[181,5354,5355],{},"2.7 億",[181,5357,5274],{},[181,5359,5271],{},[181,5361,5362],{},"✓（只看 attention）",[163,5364,5365,5368,5371,5373,5375],{},[181,5366,5367],{},"8 修 Qwen 數學",[181,5369,5370],{},"約 8 億",[181,5372,5274],{},[181,5374,5271],{},[181,5376,5377],{},"✓（50 次前向）",[111,5379,5380],{},"（表依 Honnibal 的整理改寫，數字用他的級距。實驗 4 另外拿到一段失敗錄影。實驗 5 的權重從 0 開始，沒有東西可讀。實驗 7 只看權重時四次全錯，加上 attention 工具才三對三。）",[111,5382,5383],{},"真正「只看原始權重、不給工具、不跑模型」的，只有實驗 1、2、4。對象是 1.7 萬到 17 萬個權重的小網路。",[111,5385,5386],{},"所有碰到真語言模型的實驗都用 Python。Qwen 那組還被允許跑 50 次前向。",[111,5388,5389],{},"摘要卻把三種能力寫成一句話：「只看原始權重，就能理解並修改另一個模型。」讀者自然會以為是同一招。",[111,5391,5392],{},"還有一件事更硬。那次數學實驗的提示詞裡，作者直接寫了：",[108,5394,5395],{},[111,5396,5397],{},"if the model often fails because it repeats itself and never finishes, finding and fixing what drives that repetition counts",[111,5399,5400,5401],{},"也就是說，",[238,5402,5403],{},"「重複」被當成有效修改的例子，寫在任務說明裡。",[111,5405,5406],{},"他們也做了一個拿掉這個提示的版本（v4）。10 次前向時不再交出修改，25 次只到 14.1%，而且沒有跑 50 次的版本。",[111,5408,5409],{},"所以「沒有提示時能不能到 48.1」，公開資料回答不了。",[111,5411,5412],{},"（v4 除了拿掉失敗範例，還改了練習題與驗證題的分法和流程。這個對照不乾淨，但方向值得記住。）",[111,5414,5415],{},"也該給作者記一筆。貼文公開後不久，他們改了摘要：把「遠超過人類或傳統演算法」拿掉，換成比較保留的說法。",[111,5417,5418],{},"負面實驗照登，logs 全部公開，檢查點也放出來。",[111,5420,5421],{},"我的判斷：能力是真的。代價與包裝被放大，但證據鏈沒有斷。",[111,5423,5424,5425,5430],{},"Hugging Face 上的",[115,5426,5429],{"href":5427,"rel":5428},"https:\u002F\u002Fhuggingface.co\u002FprithivMLmods\u002FQwen3.5-0.8B-weight-space-programming-GGUF",[119],"重建版","重跑 500 題，編輯後拿到 51.0%，撞上限 31.6%。換一個人、換一張卡，結論沒變。",[135,5432,5433],{"id":5433},"你明天可以做的四件事",[111,5435,5436],{},"不用等下一篇論文。任何一次「改完之後分數變好」，都可以用這四步驗。",[5438,5439,5440,5453,5459,5470],"ol",{},[2537,5441,5442,5448,5449,5452],{},[238,5443,5444,5445,2107],{},"加一欄 ",[1163,5446,5447],{},"finish_reason"," 那是 API 回傳的結束原因，等於 ",[1163,5450,5451],{},"length"," 就是被上限截斷。這個比例超過 10%，就不要直接比總分。",[2537,5454,5455,5458],{},[238,5456,5457],{},"看截斷回應的尾巴。"," 8-gram 重複率，就是連續八個 token 一模一樣的比例。太高，表示它在繞圈，不是題目太難。",[2537,5460,5461,5464,5465,5469],{},[238,5462,5463],{},"核設定。"," 思考模式開關、temperature、token 上限，跟 model card 對一次。這篇的基準是強制開思考、temperature 0.6、presence penalty 1.5、上限 32,768；",[115,5466,4901],{"href":5467,"rel":5468},"https:\u002F\u002Fhuggingface.co\u002FQwen\u002FQwen3.5-0.8B",[119]," 的預設是非思考模式。",[2537,5471,5472,5475],{},[238,5473,5474],{},"加一個不會打轉的對照模型。"," 它沒進步，你看到的就不是能力提升。",[111,5477,5478,5479,2107],{},"四個步驟都不需要幾十小時的模型對話，只需要一個 ",[1163,5480,5481],{},"if",[111,5483,5484],{},"那什麼時候真的值得改權重？三種情況。",[2534,5486,5487,5490,5493],{},[2537,5488,5489],{},"病理已經被寫進 model card，像這顆模型的迴圈，Qwen 自己警告過",[2537,5491,5492],{},"你沒有資料或算力做微調",[2537,5494,5495],{},"你接受它現在是研究階段：一次成功的編輯花了 80 次程式執行、158 輪對話，接近一整天",[111,5497,5498],{},"作者自己也說，還沒證明比微調便宜。",[135,5500,5502],{"id":5501},"三個問題加上一句提醒","三個問題，加上一句提醒",[111,5504,5505],{},"下次看到「某個方法讓模型變強六倍」，先問三題。",[2534,5507,5508,5511,5514],{},[2537,5509,5510],{},"分母是什麼？（基準是在哪個設定下量的）",[2537,5512,5513],{},"上限是多少？（有多少題根本沒講完）",[2537,5515,5516],{},"有沒有對照組？（換一顆不會打轉的模型，還成立嗎）",[111,5518,5519],{},"這三題擋不掉所有誤讀，但能擋掉大部分新聞。",[111,5521,5522],{},"如果你正在選地端模型，或評估一個「調完之後變很好」的內部結果，我們做過類似的事。",[111,5524,5525,5526,4886],{},"把能跑、能回答、能通過驗收拆成四層（",[115,5527,5528],{"href":2541},"「跑得起來」跟「真的幹完活」是四件事",[111,5530,5531,5532,4886],{},"同一個道理換到量化模型，是「檔案本身可能是壞的」（",[115,5533,5535],{"href":5534},"\u002Fblog\u002Fbroken-on-arrival-quantized-models","你下載的量化模型可能是壞的",[111,5537,5538,5539,4886],{},"而「把移除障礙寫成能力進化」這個模式，我們也寫過一次（",[115,5540,5542],{"href":5541},"\u002Fblog\u002Feth-refuted-not-p-np","「推翻 ETH」不是「攻破 P=NP」",[111,5544,5545,5546],{},"這三篇講的是同一件事：",[238,5547,5548],{},"分數變好，跟模型變強，是兩個不同的句子。",[111,5550,5551],{},"要把它們分開，只需要一欄資料。而那一欄，你今天的 pipeline 其實就有了。",[111,5553,5554,5555,5559],{},"想把這件事變成團隊的例行檢查？我們做",[115,5556,5558],{"href":5557},"\u002Fservices","地端 AI 導入","時，第一件事就是這個：先量，再決定要不要換模型。",[135,5561,5562],{"id":5562},"資料來源",[2534,5564,5565,5573,5582,5594,5602,5611,5624],{},[2537,5566,5567,5568,5572],{},"原始貼文：",[115,5569,5571],{"href":4865,"rel":5570},[119],"Sparks of Weight-Space Programming","（Rikiya Takehi、Jayden Teoh、Alex Zhang、Omar Khattab，2026-11-02；未同儕審查）",[2537,5574,5575,5576,5581],{},"完整 logs：",[115,5577,5580],{"href":5578,"rel":5579},"https:\u002F\u002Fgithub.com\u002FRikiyaT\u002Flm_understand-logs",[119],"RikiyaT\u002Flm_understand-logs","，1,125 次模型調用",[2537,5583,5584,5585,5589,5590],{},"檢查點：",[115,5586,5588],{"href":5039,"rel":5587},[119],"RikiyaT\u002FQwen3.5-0.8B-weight-space-programming","；重建版重跑數據見 ",[115,5591,5593],{"href":5427,"rel":5592},[119],"GGUF 卡",[2537,5595,5596,5597,5601],{},"逐題重算（1,152 題配對、579／576、隨機方向對照）：硅星人Pro〈",[115,5598,5600],{"href":4883,"rel":5599},[119],"刷屏的「Astra 改造 Qwen 大腦」跟我們想要的 RSI 沒多大關係","〉，2026-11-05",[2537,5603,5604,5605,5610],{},"另一份獨立整理：",[115,5606,5609],{"href":5607,"rel":5608},"https:\u002F\u002Ftraictory.com\u002Fnews\u002F2026-11-04-mit-weight-space-programming",[119],"traictory","，2026-11-04",[2537,5612,5613,5614,5618,5619],{},"批評：",[115,5615,5617],{"href":5228,"rel":5616},[119],"Honnibal","，2026-11-03；",[115,5620,5623],{"href":5621,"rel":5622},"https:\u002F\u002Fsimonwillison.net\u002F2026\u002FNov\u002F3\u002Fqwen-can-interpret-model-weights\u002F",[119],"Simon Willison 的整理",[2537,5625,5626,5627],{},"採樣設定與預設模式：",[115,5628,5630],{"href":5467,"rel":5629},[119],"Qwen3.5-0.8B model card",{"title":2280,"searchDepth":2292,"depth":2292,"links":5632},[5633,5634,5635,5636,5637,5638,5639,5640,5641],{"id":4850,"depth":2292,"text":4850},{"id":4892,"depth":2292,"text":4892},{"id":5010,"depth":2292,"text":5011},{"id":5088,"depth":2292,"text":5089},{"id":5174,"depth":2292,"text":5175},{"id":5218,"depth":2292,"text":5219},{"id":5433,"depth":2292,"text":5433},{"id":5501,"depth":2292,"text":5502},{"id":5562,"depth":2292,"text":5562},"\u002Fimages\u002Fblog\u002Fweight-edit-loop-repair.svg","標題「它沒有變聰明，只是不再打轉」的技術筆記封面","2026-11-08","一個 0.8B 小模型改掉 0.016% 的權重，MATH-500 從 7.9% 跳到 48.1%。但逐題比對後，救回來的 579 題裡有 576 題原本是被 32,768 token 上限截斷的；已經答完的 114 題，正確率完全沒變。這篇把六倍拆開，給你四步檢查——下次看到分數暴漲時，先看截斷率，再看對照組。",{},"\u002Fimages\u002Fblog\u002Fweight-edit-loop-repair.jpg","\u002Fblog\u002Fzh-tw\u002Fweight-edit-loop-repair",{"title":4840,"description":5645},"weight-edit-loop-repair","blog\u002Fzh-TW\u002Fweight-edit-loop-repair",[5653,5654,5655,5656],"local-llm","reasoning-models","evaluation","interpretability","WA7IcJhsMEwChZwPlmimkW-vQze8P_jzZWU7jGg1Yxw",{"id":5659,"title":2549,"author":103,"body":5660,"cover":6302,"coverAlt":6303,"date":6304,"description":6305,"draft":2576,"extension":2577,"featured":2576,"lang":2578,"meta":6306,"navigation":255,"ogImage":6307,"path":6308,"seo":6309,"slug":6310,"stem":6311,"tags":6312,"translationKey":6310,"updated":2590,"__hash__":6317},"blog\u002Fblog\u002Fzh-TW\u002Fquantization-kernel-dispatch.md",{"type":105,"value":5661,"toc":6292},[5662,5667,5669,5672,5675,5678,5681,5684,5688,5691,5694,5697,5700,5703,5706,5709,5714,5717,5728,5732,5735,5738,5800,5803,5806,5809,5812,5818,5824,5830,5833,5929,5932,5935,5938,5942,5945,5948,6018,6021,6024,6027,6030,6037,6040,6044,6047,6050,6098,6101,6104,6107,6110,6114,6117,6123,6129,6135,6141,6202,6205,6225,6229,6232,6235,6249,6252,6258,6273,6276],[108,5663,5664],{},[111,5665,5666],{},"數字全部來自 arXiv 2605.05699v1（2026-05-07）。作者是 Illumina 的 Mohamed Amine Bergach；這是單人預印本，未同儕審查。我們沒有在 Apple M1 上獨立重跑；「我認為」的地方會標出來。",[135,5668,4850],{"id":4850},[111,5670,5671],{},"你在筆電上跑 1B 模型，context 從 256 拉到 4K，解碼變慢、KV cache（解碼時累積的 K\u002FV 快取）越長越吃記憶體。這篇要幫你看懂兩組數字：那個「慢 17%」跟「快 8%」分別在比什麼。還有下次看 benchmark 要問哪四件事，以及什麼時候該留 fp16 退路。",[111,5673,5674],{},"上網查，答案通常是「量化」。但下一句總是「會變慢」。",[111,5676,5677],{},"有一篇論文把這句話拆開了。同一份 int4（4-bit 整數）KV cache 量化，eager 版要四次 kernel 啟動（dispatch）。在 360M 模型上，這讓延遲比 SRHT（用 Hadamard 做隨機旋轉的對照法）高 17%。把四步融成兩顆 kernel 後，SmolLM 的同一組對照變成低 1%，1.7B 低 5%；Qwen 仍慢 1%。端到端對 fp16，Gemma-3 1B 在 256 前綴低 8.2%。",[111,5679,5680],{},"但先別高興。換到 Qwen2.5-1.5B 的 2K 前綴，它只吐兩個 token 就 EOS（提前結束）。這 8% 有平台、前綴、架構的前提，後面會把邊界畫出來。",[111,5682,5683],{},"這篇要把兩個常被混在一起的問題拆開。一個是實作稅：同一個演算法，eager 版四次 dispatch、融合版兩顆 kernel。另一個是部署帳：int4 cache 對 fp16，端到端到底快多少、什麼時候會壞。",[135,5685,5687],{"id":5686},"先看那個慢-17","先看那個「慢 17%」",[111,5689,5690],{},"論文的方法叫 rotate-then-quantize。KV cache 裡的每個 K\u002FV 向量，先做一個隨機旋轉，再壓成 int4；attention 讀取時，再解量化、反旋轉回來。",[111,5692,5693],{},"這裡的旋轉是 SRFT（sign-randomized FFT）：先乘上一組固定的隨機正負號，再做 FFT。目的是打散離群值。模型的 K\u002FV 向量裡，少數很大的值會把量化尺度撐大，其他值就被壓成 0；先旋轉，讓每個座標看起來接近高斯分布，均勻量化才不會被少數大值拖垮。",[111,5695,5696],{},"問題在「四步」怎麼寫。eager 版把旋轉、量化、解量化、反旋轉拆成四個 PyTorch\u002FMPS 呼叫；每一層、每一個解碼步，就是四次 kernel dispatch。",[111,5698,5699],{},"dispatch 是什麼？就是 GPU 每啟動一顆 kernel 的排隊與搬資料成本。計算本身可能只有幾微秒，但四次啟動、四次把資料搬進搬出，加起來就變成主成本。",[111,5701,5702],{},"論文量到的代價是：SmolLM2-360M 延遲高 17%、1.7B 高 16%、Qwen2.5-1.5B 高 12%。基準是 SRHT（sign-randomized Hadamard transform），另一種隨機旋轉，不是 fp16。",[111,5704,5705],{},"為什麼拿 SRHT 當基準？因為 SRFT 和 SRHT 的量化品質在誤差內，差別只在「旋轉用 FFT 還是 Hadamard」。拿它對照，才能把「旋轉本身的成本」和「四步拆開的實作稅」分開。",[111,5707,5708],{},"論文有一句話是整段的骨架，我照原意翻：",[108,5710,5711],{},[111,5712,5713],{},"成本在 dispatch，不在計算。底層的 rfft 和 irfft 各只要個位數微秒，但四步分開呼叫，把這個開銷乘了上去。",[111,5715,5716],{},"這就是為什麼同樣的演算法，換一個寫法會從 +17% 變成 −1%。不是量化變好了，是四次排隊變成兩次（如圖 1）。",[245,5718,249,5720,249,5725],{"className":5719},[248],[251,5721],{"src":5722,"poster":5723,"autoPlay":255,"loop":255,"muted":255,"playsInline":255,"ariaLabel":5724},"\u002Fimages\u002Fblog\u002Fquantization-kernel-dispatch\u002Fkernel-fusion.mp4","\u002Fimages\u002Fblog\u002Fquantization-kernel-dispatch\u002Fkernel-fusion-poster.jpg","左邊是 eager 版四次 kernel dispatch，右邊是融合成 forward 與 inverse 兩顆 kernel",[258,5726,5727],{},"圖 1：同一份量化，eager 版每層每步四次 dispatch；融合版把前兩步與後兩步各收成一顆 kernel。",[135,5729,5731],{"id":5730},"把四步融成兩顆還不夠","把四步融成兩顆，還不夠",[111,5733,5734],{},"融合的做法，是把前兩步和後兩步各自塞進一顆 Metal kernel（Apple 的 GPU 程式）：forward 做旋轉加量化，inverse 做解量化加反旋轉。資料在中間不用回 device memory，留在 GPU 內部的快速記憶體。",[111,5736,5737],{},"同一組對照，SmolLM 反轉，Qwen 仍慢 1%：",[157,5739,5740,5756],{},[160,5741,5742],{},[163,5743,5744,5747,5750,5753],{},[166,5745,5746],{},"模型",[166,5748,5749],{},"SRHT 基準",[166,5751,5752],{},"eager Δ",[166,5754,5755],{},"融合 SRFT（Δ）",[176,5757,5758,5772,5786],{},[163,5759,5760,5763,5766,5769],{},[181,5761,5762],{},"SmolLM2-360M",[181,5764,5765],{},"37.4 ms\u002Ftok",[181,5767,5768],{},"+17%",[181,5770,5771],{},"37.0 ms\u002Ftok（−1%）",[163,5773,5774,5777,5780,5783],{},[181,5775,5776],{},"SmolLM2-1.7B",[181,5778,5779],{},"222.2 ms\u002Ftok",[181,5781,5782],{},"+16%",[181,5784,5785],{},"211.9 ms\u002Ftok（−5%）",[163,5787,5788,5791,5794,5797],{},[181,5789,5790],{},"Qwen2.5-1.5B",[181,5792,5793],{},"84.9 ms\u002Ftok",[181,5795,5796],{},"+12%",[181,5798,5799],{},"85.7 ms\u002Ftok（+1%）",[111,5801,5802],{},"（Δ 相對 SRHT，百分比取整；256 token 前綴加 128 token 生成；Apple M1。不是對 fp16。）",[111,5804,5805],{},"1.7B 的差距比 360M 大。eager 的罰則在兩個模型上差不多（+17% 對 +16%）。差別在融合後：1.7B 每層的 KV 維度是 2048，360M 只有 320。融合 kernel 的固定啟動成本被更多工作攤薄，所以它從 −1% 變成 −5%。",[111,5807,5808],{},"到這裡，故事看起來很乾淨：四步變兩顆，慢 17% 變快 1%（360M）。但如果你看到這裡就下結論「量化一定快」，會漏掉下一段。",[111,5810,5811],{},"端到端對 fp16 的 −8.2%，不是只有融合。它還需要三個條件。",[111,5813,5814,5817],{},[238,5815,5816],{},"第一，量化配方。"," 4-bit 如果只用 per-token（每個 token 一個尺度），Qwen 的 ΔPPL 會炸到 +7975。作者改成 per-channel λ 加 per-group abs-max（每個 channel 一個縮放係數，每 32 個值一組取絕對值最大），把同一個數字壓到 +638.6。這個配方是在同一顆融合 kernel 裡做的。",[111,5819,5820,5823],{},[238,5821,5822],{},"第二，dequant-prefix cache。"," 解量化過的前綴先存起來，不要每一步重算；最近 16 個 token 保留 fp16，只有這個視窗滿了才失效。沒有它，Qwen 在 1024 前綴是 +2.4% 慢；有了它，才變成 −1.6% 快（表內回算；論文文字寫 −0.7%）。",[111,5825,5826,5829],{},[238,5827,5828],{},"第三，模型架構。"," Gemma-3 1B 有 sliding-window 層：大部分層只看固定視窗、用 fp16，只有少數 full-attention 層（看完整前綴）要付 dequant 成本。所以它的優勢可以撐到 4096；Qwen 是 28 層 full-attention，成本隨前綴線性成長。",[111,5831,5832],{},"把這三件事放回去，端到端的表長這樣：",[157,5834,5835,5850],{},[160,5836,5837],{},[163,5838,5839,5841,5844,5847],{},[166,5840,5746],{},[166,5842,5843],{},"前綴",[166,5845,5846],{},"fp16 → int4（ms\u002Ftok）",[166,5848,5849],{},"延遲差",[176,5851,5852,5866,5879,5892,5905,5917],{},[163,5853,5854,5857,5860,5863],{},[181,5855,5856],{},"Gemma-3 1B",[181,5858,5859],{},"256",[181,5861,5862],{},"71.2 → 65.4",[181,5864,5865],{},"−8.2%",[163,5867,5868,5870,5873,5876],{},[181,5869,5856],{},[181,5871,5872],{},"1024",[181,5874,5875],{},"83.3 → 82.5",[181,5877,5878],{},"−0.9%",[163,5880,5881,5883,5886,5889],{},[181,5882,5856],{},[181,5884,5885],{},"2048",[181,5887,5888],{},"129.5 → 121.3",[181,5890,5891],{},"−6.3%",[163,5893,5894,5896,5899,5902],{},[181,5895,5856],{},[181,5897,5898],{},"4096",[181,5900,5901],{},"188.5 → 182.4",[181,5903,5904],{},"−3.2%",[163,5906,5907,5909,5911,5914],{},[181,5908,5790],{},[181,5910,5859],{},[181,5912,5913],{},"90.7 → 88.3",[181,5915,5916],{},"−2.6%",[163,5918,5919,5921,5923,5926],{},[181,5920,5790],{},[181,5922,5872],{},[181,5924,5925],{},"137.1 → 134.9",[181,5927,5928],{},"−1.6%",[111,5930,5931],{},"（Δ 相對 fp16；Apple M1；256 token 前綴加 128 token 生成。Qwen 2048 不在表裡，原因見下一節。Qwen 1024 的 −1.6% 是用表內 137.1 → 134.9 回算；論文文字寫 −0.7%，我們以表內數字為準。）",[111,5933,5934],{},"記憶體方面，Qwen 是 3.0–3.1×；Gemma 的 19.5× 不是同層比較（full-attention 層內約 3.2×），不能直接跟 Qwen 比。",[111,5936,5937],{},"−8.2% 是 256 前綴的最佳情況。同一個模型拉到 4096，只剩 −3.2%。Qwen 拉到 1024，只剩 −1.6%。「量化快 8%」不是一個常數，是一條會隨前綴長度變化的曲線。",[135,5939,5941],{"id":5940},"快之前先看它掉了多少","快之前，先看它掉了多少",[111,5943,5944],{},"速度之外，還有一本帳：品質。量化對品質的影響，通常看困惑度（perplexity，PPL）的變化；ΔPPL 是量化後減 fp16 的差。",[111,5946,5947],{},"4-bit per-token 的 ΔPPL 如下（Cosmopedia，8192 個 held-out token）：",[157,5949,5950,5968],{},[160,5951,5952],{},[163,5953,5954,5956,5959,5962,5965],{},[166,5955,5746],{},[166,5957,5958],{},"FP16 PPL",[166,5960,5961],{},"不旋轉（identity）",[166,5963,5964],{},"SRHT",[166,5966,5967],{},"SRFT",[176,5969,5970,5987,6003],{},[163,5971,5972,5975,5978,5981,5984],{},[181,5973,5974],{},"SmolLM2-135M",[181,5976,5977],{},"6.61",[181,5979,5980],{},"+1.96 ± 0.15",[181,5982,5983],{},"+0.34 ± 0.01",[181,5985,5986],{},"+0.38 ± 0.06",[163,5988,5989,5991,5994,5997,6000],{},[181,5990,5762],{},[181,5992,5993],{},"4.87",[181,5995,5996],{},"+0.97 ± 0.08",[181,5998,5999],{},"+0.20 ± 0.03",[181,6001,6002],{},"+0.21 ± 0.02",[163,6004,6005,6007,6010,6013,6016],{},[181,6006,5776],{},[181,6008,6009],{},"3.77",[181,6011,6012],{},"+1.04",[181,6014,6015],{},"+0.16",[181,6017,6015],{},[111,6019,6020],{},"（前兩列是 3 個 seed 的平均 ± 1σ；1.7B 因為計算成本只跑 1 個 seed。6-bit 與 8-bit 在這組測試裡無損。）",[111,6022,6023],{},"旋轉不是可選項。135M 不旋轉是 +1.96，旋轉後是 +0.38；差了大約 5 倍。這也解釋了為什麼「量化會壞」和「量化只是變慢」常常是同一件事的兩面：如果你的旋轉沒做對，4-bit 的誤差會直接反映在 PPL 上。",[111,6025,6026],{},"6-bit 和 8-bit 無損，4-bit 才是取捨點。3-bit 的絕對誤差更大，但這篇沒有把 3-bit 當賣點，我也不建議讀者從 3-bit 開始。",[111,6028,6029],{},"Qwen 的 4-bit 是另一個故事。Python reference 的 per-token 是 +7975.3，Metal 的 per-token 是 +7727.9；加上 per-channel λ 加 per-group g32 之後，融合版是 +638.6。這是 12.5 倍的改善，跟 Python reference 的 +654.6 同級。",[111,6031,6032,6033,6036],{},"但 +638.6 仍然是 +638.6。",[238,6034,6035],{},"12.5 倍的改善，不等於可以上線。"," 論文把這個叫做「關掉災難」；我認為，它比較像是把火從整棟房子縮到一個房間，離安全還很遠。如果你要在 Qwen 上開 4-bit，請用任務指標驗收，不要只看 PPL 的相對改善。",[111,6038,6039],{},"Gemma 的結果比較好：per-token +18.7，融合後 +3.6。Python reference 是 −5.2，差距 +8.8 來自 kernel 的 fp32 reduction 與 rounding ordering，不是演算法。這一點作者自己做了兩個 ablation 排除。",[135,6041,6043],{"id":6042},"它真的會壞qwen-2k-只吐兩個-token","它真的會壞：Qwen 2K 只吐兩個 token",[111,6045,6046],{},"現在回到那個「先別高興」。",[111,6048,6049],{},"Qwen2.5-1.5B 在 2048 前綴，int4 只生成 2 個 token 就 EOS；fp16 是 64 個。",[157,6051,6052,6064],{},[160,6053,6054],{},[163,6055,6056,6058,6061],{},[166,6057,2155],{},[166,6059,6060],{},"fp16",[166,6062,6063],{},"int4",[176,6065,6066,6077,6088],{},[163,6067,6068,6071,6074],{},[181,6069,6070],{},"生成 token 數（2048 前綴）",[181,6072,6073],{},"64",[181,6075,6076],{},"2（EOS）",[163,6078,6079,6082,6085],{},[181,6080,6081],{},"峰值記憶體",[181,6083,6084],{},"4447 MB",[181,6086,6087],{},"5527 MB",[163,6089,6090,6093,6095],{},[181,6091,6092],{},"作者退路",[181,6094,5274],{},[181,6096,6097],{},"約 1.5K 以上退回 fp16",[111,6099,6100],{},"原因不只一個。dequant-prefix cache 加上 int4 storage，讓峰值記憶體從 4447 拉到 5527 MB（+24%）；再加上 28 層 full-attention 的量化噪聲累積，logits 被推去提前 EOS。",[111,6102,6103],{},"我認為，讓 1024 變快的那個設計，也是讓 2048 變壞的設計之一。prefix cache 把解量化成本從「前綴越長越慢」攤成固定成本，但它同時佔記憶體；在 Qwen 這種全注意力堆疊上，兩件事一起發生，就爆了。",[111,6105,6106],{},"Gemma 為什麼沒事？它的 sliding-window 層用 fp16，只有少數 full-attention 層付 dequant 成本；所以前綴拉長，成本成長得比較慢。架構不同，同一份量化 cache 的結果就不同。",[111,6108,6109],{},"如果你要在自己的模型上開這個 cache，先測 2K。不是測「能不能生成」，是測「生成出來的東西對不對、會不會提前停」。作者給的退路很明確：超過約 1.5K，就退回 fp16。",[135,6111,6113],{"id":6112},"看-benchmark-要問的四件事","看 benchmark 要問的四件事",[111,6115,6116],{},"這篇論文最有用的地方，不是「Apple Silicon 比較快」，是它把一張 benchmark 拆成幾個要問的問題。",[111,6118,6119,6122],{},[238,6120,6121],{},"第一，平台。"," 這是 unified memory（CPU 與 GPU 共用記憶體）還是獨立 HBM（顯示卡自己的記憶體）？論文說：在獨立 HBM、dispatch 開銷高的 GPU 上，慣常的取捨會回復。也就是說，同樣的 kernel 搬過去，不一定還快。看到「量化加速」先問跑在哪。",[111,6124,6125,6128],{},[238,6126,6127],{},"第二，kernel。"," 這是 fused 還是四步分開？如果 benchmark 沒寫，數字可能被 dispatch 稅主導。你可以直接問：一層一步幾次 dispatch？",[111,6130,6131,6134],{},[238,6132,6133],{},"第三，前綴與架構。"," 256 前綴的 −8% 不是 4K 的 −3.2%；full-attention 堆疊和 sliding-window 的曲線也不一樣。要求對方給 256、1K、2K 三組數字，不要只看一張最好的圖。",[111,6136,6137,6140],{},[238,6138,6139],{},"第四，品質。"," ΔPPL 的 baseline 與配方是什麼？+638.6 比 +7975 好，但仍然是 +638.6。per-token 和 per-channel+group 是兩種不同的東西，不能拿來互相比。",[157,6142,6143,6156],{},[160,6144,6145],{},[163,6146,6147,6150,6153],{},[166,6148,6149],{},"問題",[166,6151,6152],{},"為什麼要問",[166,6154,6155],{},"怎麼查",[176,6157,6158,6169,6180,6191],{},[163,6159,6160,6163,6166],{},[181,6161,6162],{},"平台是 unified memory 還是獨立 HBM？",[181,6164,6165],{},"取捨是否反轉的邊界",[181,6167,6168],{},"看硬體規格；要求分平台數字",[163,6170,6171,6174,6177],{},[181,6172,6173],{},"Kernel 是 fused 還是四步分開？",[181,6175,6176],{},"相對 SRHT 可能慢 12–17%",[181,6178,6179],{},"看 benchmark 是否寫「4 dispatches」或「fused」",[163,6181,6182,6185,6188],{},[181,6183,6184],{},"前綴多長、模型是 full-attention 還是 sliding-window？",[181,6186,6187],{},"長 context 可能失效",[181,6189,6190],{},"要求 256／1K／2K 三組；看架構",[163,6192,6193,6196,6199],{},[181,6194,6195],{},"ΔPPL 的 baseline 與量化配方是什麼？",[181,6197,6198],{},"+638.6 比 +7975 好，但仍是 +638.6",[181,6200,6201],{},"看 baseline、per-token 或 per-channel+group",[135,6203,6204],{"id":6204},"別過度解讀",[2534,6206,6207,6210,6213,6216,6219,6222],{},[2537,6208,6209],{},"單一平台：只有 Apple M1；獨立 HBM 的 GPU 沒測。",[2537,6211,6212],{},"模型都是小模型（135M–1.7B），沒有 7B 以上。",[2537,6214,6215],{},"單人預印本，未同儕審查；我們沒有獨立複現。",[2537,6217,6218],{},"Gemma 的 19.5× 不是同層比較；full-attention 層內約 3.2×。",[2537,6220,6221],{},"Qwen 2K 會壞；作者自己寫了 1.5K 的退路。",[2537,6223,6224],{},"這篇不是說「融合是唯一解」；它只處理四步拆開這一種成本。",[135,6226,6228],{"id":6227},"結論問題不是量化快不快","結論：問題不是「量化快不快」",[111,6230,6231],{},"量化不是一個開關，是一條工程鏈：平台、kernel、量化配方、前綴長度、模型架構，任何一個換了，答案就換了。",[111,6233,6234],{},"這篇的兩本帳，可以這樣記：",[2534,6236,6237,6243],{},[2537,6238,6239,6242],{},[238,6240,6241],{},"實作稅"," 是同一份方法，eager 四步對融合兩顆，差距 11–21 個百分點。",[2537,6244,6245,6248],{},[238,6246,6247],{},"部署帳"," 是 int4 cache 對 fp16，短前綴最多 −8.2%，長前綴會縮到個位數百分比（Qwen 1024 是 −1.6%，Gemma 4096 是 −3.2%），而且可能提前 EOS。",[111,6250,6251],{},"明天可以先做一件事：用你的模型跑 256、1K、2K 三個前綴，記錄 ms\u002Ftok 和輸出品質；如果模型是 full-attention 堆疊，1.5K 以上先留 fp16 退路；2K 是測試點。",[111,6253,6254,6255,6257],{},"如果你要的是有人陪你把自己的模型跑過這三個前綴，我們的",[115,6256,22],{"href":5557},"做的就是這件事。先判斷哪些工作現在就能交給 AI，哪些還不成熟。",[111,6259,6260,6261,6266,6267,6272],{},"量化系列走到這裡，三篇的弧線是：",[115,6262,6263],{"href":2555},[1163,6264,6265],{},"strata"," 講取捨，",[115,6268,6269],{"href":5534},[1163,6270,6271],{},"broken-on-arrival"," 講配方，這篇講實作。同一個問題，從「要不要量化」走到「怎麼寫那個 kernel」。",[6274,6275],"hr",{},[111,6277,6278],{},[6279,6280,6281,6282,6287,6288,1984,6290,2107],"em",{},"論文：",[115,6283,6286],{"href":6284,"rel":6285},"https:\u002F\u002Farxiv.org\u002Fabs\u002F2605.05699",[119],"arXiv 2605.05699v1","（Mohamed Amine Bergach, Illumina）。前作：",[115,6289,2556],{"href":2555},[115,6291,5535],{"href":5534},{"title":2280,"searchDepth":2292,"depth":2292,"links":6293},[6294,6295,6296,6297,6298,6299,6300,6301],{"id":4850,"depth":2292,"text":4850},{"id":5686,"depth":2292,"text":5687},{"id":5730,"depth":2292,"text":5731},{"id":5940,"depth":2292,"text":5941},{"id":6042,"depth":2292,"text":6043},{"id":6112,"depth":2292,"text":6113},{"id":6204,"depth":2292,"text":6204},{"id":6227,"depth":2292,"text":6228},"\u002Fimages\u002Fblog\u002Fquantization-kernel-dispatch.svg","標題「量化會不會加速，取決於你怎麼寫 kernel」的技術筆記封面","2026-11-05","同一份 int4 KV cache 量化，eager 版相對 SRHT 慢 12–17%，把四步融成兩顆 Metal kernel 後追平；端到端對 fp16，Gemma 短前綴快 8.2%，但 Qwen 2K 前綴只吐兩個 token。差別在四步拆開呼叫，還是融成兩顆——以及平台、前綴與架構的前提。",{},"\u002Fimages\u002Fblog\u002Fquantization-kernel-dispatch.jpg","\u002Fblog\u002Fzh-tw\u002Fquantization-kernel-dispatch",{"title":2549,"description":6305},"quantization-kernel-dispatch","blog\u002Fzh-TW\u002Fquantization-kernel-dispatch",[6313,6314,6315,6316],"quantization","kv-cache","apple-silicon","inference","nxxvpD8Ugm7w7mX3s1VM_GxUtkB58VVj0Hd2cm51owY",1794643891174]