-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantization.html
More file actions
334 lines (306 loc) · 15.7 KB
/
Copy pathquantization.html
File metadata and controls
334 lines (306 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>量化:让大模型塞进小显卡</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@700;900&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root{
--paper:#EDEFE6;
--ink:#1B3B36;
--ink-soft:#4B6660;
--line:#B9C7B4;
--pin:#C33C54;
--sea:#3E7C8C;
--sun:#D9A227;
--serif:"Noto Serif SC","Songti SC","Source Han Serif SC","SimSun",serif;
--sans:"PingFang SC","Hiragino Sans GB","Microsoft YaHei",system-ui,-apple-system,sans-serif;
--mono:"IBM Plex Mono",ui-monospace,SFMono-Regular,Menlo,monospace;
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{
margin:0;background-color:var(--paper);
background-image:
linear-gradient(rgba(27,59,54,.045) 1px,transparent 1px),
linear-gradient(90deg,rgba(27,59,54,.045) 1px,transparent 1px);
background-size:44px 44px;
color:var(--ink);font-family:var(--sans);line-height:1.7;
}
.wrap{max-width:1040px;margin:0 auto;padding:0 24px}
.hero{padding:clamp(56px,12vw,120px) 0 clamp(30px,6vw,60px)}
.hero__tag{
font-family:var(--mono);font-size:12px;letter-spacing:.22em;color:var(--ink-soft);
margin:0 0 22px;display:flex;align-items:center;gap:12px;
}
.hero__tag::after{content:"";flex:1;height:1px;background:var(--line)}
.hero__title{
font-family:var(--serif);font-weight:900;
font-size:clamp(36px,8.4vw,80px);line-height:1.14;margin:0 0 18px;
}
.hero__title em{font-style:normal;color:var(--pin)}
.hero__sub{font-size:clamp(15px,2.6vw,19px);color:var(--ink-soft);margin:0;max-width:32em}
.plate{padding:clamp(52px,10vw,110px) 0;border-top:1px solid var(--line)}
.plate__eyebrow{font-family:var(--mono);font-size:12px;letter-spacing:.2em;color:var(--pin);margin:0 0 14px}
.plate__title{font-family:var(--serif);font-weight:700;font-size:clamp(27px,6vw,48px);line-height:1.25;margin:0 0 12px}
.plate__note{color:var(--ink-soft);margin:0;font-size:clamp(14px,2.4vw,17px)}
.figure{margin:clamp(28px,6vw,48px) 0 0}
.figure svg{width:100%;height:auto;display:block}
/* ---- 精度:数字被削短 ---- */
.digits{
font-family:var(--mono);font-weight:600;
font-size:clamp(26px,7vw,64px);letter-spacing:.02em;
background:#fff;border:2px solid var(--ink);border-radius:5px;
padding:clamp(16px,4vw,30px);box-shadow:6px 6px 0 rgba(27,59,54,.12);
overflow:hidden;white-space:nowrap;text-align:center;
}
.digits .keep{color:var(--ink)}
.digits .cut{color:var(--line);transition:color .35s ease}
.digits .gone{color:transparent}
/* ---- 控制台 ---- */
.rig{
background:#F5F6EF;border:2px solid var(--ink);border-radius:6px;
box-shadow:8px 8px 0 rgba(27,59,54,.1);
padding:clamp(18px,4vw,32px);margin-top:clamp(28px,6vw,44px);
}
.rig__grid{display:grid;grid-template-columns:1fr 1.05fr;gap:clamp(20px,4vw,44px);align-items:end}
@media(max-width:680px){.rig__grid{grid-template-columns:1fr;align-items:stretch}}
.tank{position:relative;height:320px;border-left:2px solid var(--ink);border-bottom:2px solid var(--ink)}
.tank__limit{
position:absolute;left:0;right:0;bottom:80px;
border-top:2px dashed var(--pin);
}
.tank__limit span{
position:absolute;right:0;top:-24px;font-family:var(--mono);
font-size:12px;color:var(--pin);letter-spacing:.08em;
}
.tank__bar{
position:absolute;left:22%;width:56%;bottom:0;
background:var(--sea);border:2px solid var(--ink);border-bottom:0;
transition:height .45s cubic-bezier(.4,1.3,.5,1),background .45s ease;
display:flex;align-items:flex-start;justify-content:center;
}
.tank__bar b{
font-family:var(--mono);font-size:clamp(13px,2.6vw,17px);color:#fff;
padding-top:8px;font-weight:500;
}
.tank__bar[data-fit="0"]{background:var(--pin)}
.readout{display:flex;flex-direction:column;gap:clamp(12px,2.4vw,18px)}
.row{display:flex;justify-content:space-between;align-items:baseline;border-bottom:1px solid var(--line);padding-bottom:10px}
.row i{font-style:normal;font-family:var(--mono);font-size:12px;letter-spacing:.14em;color:var(--ink-soft)}
.row strong{font-family:var(--serif);font-weight:700;font-size:clamp(20px,4.4vw,32px)}
.verdict{font-family:var(--serif);font-weight:700;font-size:clamp(18px,4vw,28px)}
.verdict[data-fit="1"]{color:var(--sea)}
.verdict[data-fit="0"]{color:var(--pin)}
.verdict[data-fit="2"]{color:var(--sun)}
.quality{margin-top:6px}
.quality__track{height:16px;background:#E3E8DC;border:1px solid var(--line);border-radius:9px;overflow:hidden}
.quality__fill{height:100%;background:var(--sun);transition:width .45s ease}
.slider{margin-top:clamp(24px,5vw,38px)}
.slider input{
-webkit-appearance:none;appearance:none;width:100%;height:6px;
background:var(--line);border-radius:3px;outline:none;margin:0;
}
.slider input::-webkit-slider-thumb{
-webkit-appearance:none;appearance:none;width:30px;height:30px;border-radius:50%;
background:var(--pin);border:3px solid var(--paper);cursor:pointer;
box-shadow:0 0 0 2px var(--ink);
}
.slider input::-moz-range-thumb{
width:24px;height:24px;border-radius:50%;background:var(--pin);
border:3px solid var(--paper);cursor:pointer;box-shadow:0 0 0 2px var(--ink);
}
.slider input:focus-visible{box-shadow:0 0 0 3px rgba(195,60,84,.35)}
.ticks{display:flex;justify-content:space-between;margin-top:12px;font-family:var(--mono);font-size:clamp(11px,2.4vw,14px);color:var(--ink-soft)}
.ticks span{cursor:pointer;padding:2px 4px}
.ticks span[data-on="1"]{color:var(--pin);font-weight:600}
/* ---- 名字卡 ---- */
.tags{display:flex;flex-wrap:wrap;gap:10px;margin-top:clamp(24px,5vw,40px)}
.tag{
font-family:var(--mono);font-size:clamp(12px,2.4vw,15px);
border:1px solid var(--line);background:#fff;border-radius:4px;padding:9px 14px;color:var(--ink-soft);
}
.tag b{color:var(--ink);font-weight:600}
.end{padding:clamp(60px,12vw,130px) 0;border-top:2px solid var(--ink);text-align:center}
.end__line{font-family:var(--serif);font-weight:900;font-size:clamp(23px,5.4vw,44px);line-height:1.45;margin:0}
.end__line em{font-style:normal;background:linear-gradient(transparent 62%,rgba(217,162,39,.55) 62%)}
.end__foot{font-family:var(--mono);font-size:12px;color:var(--ink-soft);letter-spacing:.2em;margin-top:26px}
.rise{opacity:0;transform:translateY(22px);transition:opacity .7s ease,transform .7s ease}
.rise.on{opacity:1;transform:none}
@media(prefers-reduced-motion:reduce){
.rise{opacity:1;transform:none;transition:none}
.tank__bar,.quality__fill{transition:none}
}
</style>
</head>
<body>
<header class="hero wrap">
<p class="hero__tag">量化 · QUANTIZATION</p>
<h1 class="hero__title">让大模型,<br>塞进<em>小显卡</em>。</h1>
<p class="hero__sub">办法不是让模型变聪明,是让它每个数字占的地方变小。</p>
</header>
<main>
<section class="plate wrap rise">
<p class="plate__eyebrow">01 / 模型是什么</p>
<h2 class="plate__title">一个模型 = 几十亿个数字。</h2>
<p class="plate__note">这些数字叫"权重"。跑模型,先要把它们全搬进显存。</p>
<div class="figure">
<svg viewBox="0 0 800 220" role="img" aria-label="模型由大量权重数字组成">
<g font-family="var(--mono)" font-size="17" fill="#3E7C8C">
<text x="0" y="30">0.0231</text><text x="130" y="30">-1.4420</text><text x="280" y="30">0.8817</text><text x="420" y="30">-0.0093</text><text x="560" y="30">0.3364</text><text x="690" y="30">1.0025</text>
<text x="0" y="80">-0.7710</text><text x="130" y="80">0.4508</text><text x="280" y="80">-0.1192</text><text x="420" y="80">0.9931</text><text x="560" y="80">-0.5507</text><text x="690" y="80">0.2140</text>
<text x="0" y="130" opacity=".7">0.6653</text><text x="130" y="130" opacity=".7">-0.3081</text><text x="280" y="130" opacity=".7">0.1274</text><text x="420" y="130" opacity=".7">-0.8846</text><text x="560" y="130" opacity=".7">0.7028</text><text x="690" y="130" opacity=".7">-0.0417</text>
<text x="0" y="180" opacity=".35">0.1590</text><text x="130" y="180" opacity=".35">0.9265</text><text x="280" y="180" opacity=".35">-0.3589</text><text x="420" y="180" opacity=".35">0.7932</text><text x="560" y="180" opacity=".35">-0.6264</text><text x="690" y="180" opacity=".35">0.3383</text>
</g>
<text x="400" y="214" text-anchor="middle" font-family="var(--serif)" font-weight="700" font-size="20" fill="#C33C54">…… 七十亿个 ……</text>
</svg>
</div>
</section>
<section class="plate wrap rise">
<p class="plate__eyebrow">02 / 量化做的事</p>
<h2 class="plate__title">把每个数字,记粗一点。</h2>
<p class="plate__note">3.14159265 记成 3.1 —— 差不多,但省一大截地方。</p>
<div class="figure">
<div class="digits" id="digits" aria-live="polite"></div>
</div>
</section>
<section class="plate wrap rise">
<p class="plate__eyebrow">03 / 拉一下试试</p>
<h2 class="plate__title">记得越粗,模型越小。</h2>
<p class="plate__note">以一个 70 亿参数的模型为例。虚线是一张普通显卡(8GB)。</p>
<div class="rig">
<div class="rig__grid">
<div class="tank" aria-hidden="true">
<div class="tank__limit"><span>普通显卡 8GB</span></div>
<div class="tank__bar" id="bar" data-fit="0"><b id="barLabel">28 GB</b></div>
</div>
<div class="readout">
<div class="row"><i>每个数字占</i><strong id="bits">32 位</strong></div>
<div class="row"><i>模型体积</i><strong id="size">28 GB</strong></div>
<div class="row"><i>普通显卡</i><span class="verdict" id="verdict" data-fit="0">装不下</span></div>
<div class="quality">
<div class="row" style="border:0;padding-bottom:6px"><i>回答质量</i><strong id="q">100%</strong></div>
<div class="quality__track"><div class="quality__fill" id="qfill" style="width:100%"></div></div>
</div>
</div>
</div>
<div class="slider">
<input type="range" id="range" min="0" max="3" step="1" value="0" aria-label="选择精度">
<div class="ticks" id="ticks">
<span data-i="0">FP32</span><span data-i="1">FP16</span><span data-i="2">INT8</span><span data-i="3">INT4</span>
</div>
</div>
</div>
</section>
<section class="plate wrap rise">
<p class="plate__eyebrow">04 / 代价</p>
<h2 class="plate__title">会笨一点点。</h2>
<p class="plate__note">像照片压缩:远看一样,凑近看有点糊。压太狠就明显了。</p>
<div class="figure">
<svg viewBox="0 0 800 260" role="img" aria-label="压缩越狠画面越糊的类比">
<g>
<rect x="10" y="20" width="180" height="180" fill="#3E7C8C"/>
<rect x="10" y="20" width="180" height="180" fill="none" stroke="#1B3B36" stroke-width="2"/>
<g fill="#EDEFE6"><circle cx="100" cy="90" r="34"/><path d="M40 180l45-58 36 40 26-28 43 46z"/></g>
</g>
<g>
<rect x="210" y="20" width="180" height="180" fill="#3E7C8C"/>
<rect x="210" y="20" width="180" height="180" fill="none" stroke="#1B3B36" stroke-width="2"/>
<g fill="#EDEFE6"><rect x="272" y="60" width="60" height="60"/><path d="M240 180l45-56 36 40 26-28 43 44z"/></g>
</g>
<g>
<rect x="410" y="20" width="180" height="180" fill="#3E7C8C"/>
<rect x="410" y="20" width="180" height="180" fill="none" stroke="#1B3B36" stroke-width="2"/>
<g fill="#EDEFE6"><rect x="470" y="60" width="60" height="60"/><rect x="440" y="140" width="120" height="40"/></g>
</g>
<g>
<rect x="610" y="20" width="180" height="180" fill="#3E7C8C"/>
<rect x="610" y="20" width="180" height="180" fill="none" stroke="#1B3B36" stroke-width="2"/>
<g fill="#EDEFE6"><rect x="640" y="50" width="120" height="120"/></g>
</g>
<g font-family="var(--mono)" font-size="14" fill="#4B6660" text-anchor="middle">
<text x="100" y="232">FP16</text><text x="300" y="232">INT8</text>
<text x="500" y="232">INT4</text><text x="700" y="232">再压就废了</text>
</g>
</svg>
</div>
</section>
<section class="plate wrap rise">
<p class="plate__eyebrow">05 / 你会看到的名字</p>
<h2 class="plate__title">下载模型时的那串后缀。</h2>
<p class="plate__note">看到 Q4、INT4、4bit,就是"压过的版本"。</p>
<div class="tags">
<span class="tag"><b>Q4_K_M</b> · 最常用,够小够稳</span>
<span class="tag"><b>Q8_0</b> · 几乎无损,但大一倍</span>
<span class="tag"><b>GGUF</b> · 文件格式,配 llama.cpp / Ollama</span>
<span class="tag"><b>GPTQ / AWQ</b> · 显卡上跑的压缩方案</span>
</div>
</section>
</main>
<footer class="end wrap">
<p class="end__line">量化,<br>用<em>一点点准确度</em>,换<em>跑得起来</em>。</p>
<p class="end__foot">END</p>
</footer>
<script>
(function(){
/* --- 02 数字被削短 --- */
var full = "3.14159265", box = document.getElementById("digits");
var keep = 4;
function paintDigits(k){
box.innerHTML = full.split("").map(function(c,i){
return i < k ? '<span class="keep">'+c+'</span>' : '<span class="cut">'+c+'</span>';
}).join("");
}
paintDigits(full.length);
var reduce = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
/* --- 03 控制台 --- */
var levels = [
{name:"FP32", bits:"32 位", gb:28, fit:0, q:100, keepDigits:10},
{name:"FP16", bits:"16 位", gb:14, fit:0, q:100, keepDigits:7},
{name:"INT8", bits:"8 位", gb:7, fit:2, q:99, keepDigits:4},
{name:"INT4", bits:"4 位", gb:3.8, fit:1, q:96, keepDigits:3}
];
var verdictText = {0:"装不下", 2:"刚好卡边", 1:"跑得动"};
var bar=document.getElementById("bar"), barLabel=document.getElementById("barLabel");
var bits=document.getElementById("bits"), size=document.getElementById("size");
var verdict=document.getElementById("verdict"), q=document.getElementById("q"), qfill=document.getElementById("qfill");
var range=document.getElementById("range"), ticks=document.getElementById("ticks");
var SCALE = 320/30; // 320px 高 = 30GB
function apply(i){
var L = levels[i];
bar.style.height = Math.max(L.gb*SCALE, 14) + "px";
bar.dataset.fit = (L.fit===0) ? "0" : "1";
barLabel.textContent = L.gb + " GB";
bits.textContent = L.bits;
size.textContent = L.gb + " GB";
verdict.textContent = verdictText[L.fit];
verdict.dataset.fit = L.fit;
q.textContent = L.q + "%";
qfill.style.width = ((L.q-90)/10*100) + "%";
paintDigits(L.keepDigits);
Array.prototype.forEach.call(ticks.children, function(s,k){
s.dataset.on = (k===i) ? "1" : "0";
});
}
range.addEventListener("input", function(){ apply(+range.value); });
Array.prototype.forEach.call(ticks.children, function(s){
s.addEventListener("click", function(){ range.value = s.dataset.i; apply(+s.dataset.i); });
});
apply(0);
/* --- reveal --- */
var items = document.querySelectorAll(".rise");
if(!("IntersectionObserver" in window) || reduce){
items.forEach(function(el){ el.classList.add("on"); });
} else {
var io = new IntersectionObserver(function(en){
en.forEach(function(e){ if(e.isIntersecting){ e.target.classList.add("on"); io.unobserve(e.target); } });
},{threshold:.15});
items.forEach(function(el){ io.observe(el); });
}
})();
</script>
</body>
</html>