實際影片長度:12:44.000。原文、繁中、雙語可點擊句子跳轉影片。
0:00.000–0:12.160
Hi guys, welcome back. In this video,we'll be talking about how you can run aQwen in an AppleM4 Mac mini machine with just 24 GB of
0:12.160–0:22.320
unified memory. We know that Qwen 3.8 27billion parameter model will be of atleast 15 GB of size. And loading the
0:22.320–0:31.440
ntire model in the unified memory willnot only load the model, but also loadsthe KV cache, runtime, and the Mac
0:31.440–0:39.320
operating system all together. And whileyou load all of them in the VRAM, it isdefinitely going to hit the memory
0:39.320–0:46.960
ceiling for you, and it is going to begetting you the out of memory exception.So, how can we even handle the situation
0:46.960–0:49.800
of these kind of memory problem? And can
0:49.800–0:54.880
we even run a Qwen 3.8 27 billionparameter model in this machine? And is
0:54.880–1:02.680
it just the problem with the modelitself, or is it the problem with thequantization that we have? But what if
1:02.680–1:11.160
we have a quantization of the same exactmodel with just two-bit quantizationinstead of the four-bit quantization?
1:11.160–1:14.280
Can we run that at all? Well, welcome to
1:14.280–1:30.760
the Qwen model quantized to two-bitcalled as the Qwen 3.8 27 billion GSQRCO IQ2 QS model. And this model canload in the 24 GB of unified machine,
1:30.760–1:40.960
and it can support a full GPUoffloading, as well as it hasmulti-token prediction enabled as well.And this model can easily fit in an
1:40.960–1:50.800
Apple M4 machine of 24 GB of unifiedmemory, which includes the model, KVcache, runtime, and Mac operating system
1:50.800–1:57.520
without hitting the memory ceiling aswell. So, it can easily load everythingfor you within your Apple machine, which
1:57.520–2:03.400
is quite amazing. So, the memoryrequirement is going to be so much lessbecause of the two-bit quantization that
2:03.400–2:07.760
you have got in this particular model.So, how exactly is this possible? Will
2:07.760–2:15.680
the Qwen 3.8 right now will lose itsintelligence ability or the output willbe of less quality or how exactly is
2:15.680–2:17.920
this happening? What exactly is this new
2:17.920–2:20.280
model of a two-bit quantization? Well,
2:20.280–2:27.720
this particular Qwen model is a standardQwen model, but instead of applying thesame quantization everywhere, the
2:27.720–2:34.640
technique will determine which tensorsdeserves more precision and which cantolerate the aggressive compression.
2:34.640–2:39.760
That's exactly what this particulartechnique does. And what exactly is thistechnique that we're talking about? The
2:39.760–2:48.600
GSQ RCO or otherwise called as theGumbel Softmax quantization, whichintelligently optimizes the quantization
2:48.600–2:57.959
value while RCO intelligently decidewhere to allocate more or fewer bitsacross the model's uh tensors. So,
2:57.959–3:08.080
essentially, even if the model sizes isgoing to be reduced from the 16 BPW,which is a 16-bit original model, to a
3:08.080–3:16.160
two-bit quantization model, it is goingto be off almost 6.4 time of a sizelower, but still the model is going to
3:16.160–3:23.519
give you an amazing precision over here.That is the power of this particularmodel itself. And that's the reason why
3:23.519–3:31.000
even though the size of the model is somuch smaller, the quality of the outputis still going to be way more same like
3:31.000–3:37.239
how you can expect with theirquantization four model of the same Qwenmodel that you have got. That's exactly
3:37.239–3:45.080
what this particular model is, and weare going to see in this particularvideo how we can run the same exact Qwen
3:45.080–3:56.400
two-bit model in the Mac mini M4machine, and we're also going to see howfast it is going to be doing theinferencing for us and what it means
3:56.400–4:02.840
with different sizes of the KV cacheadjustment that I'm going to be doing inthis particular video. Now, I will show
4:02.840–4:12.120
you how it is going to be affecting thespeed as well as the number oftokens per second as well. So, in thisparticular video, we are going to see
4:12.120–4:20.359
which KV size or which KV cache is goingto be faster like 16-bit or 4-bit or8-bit quantization and which is going to
4:20.359–4:29.040
take more time and what is the totalnumber of tokens per second that you aregoing to be gettingwith different kinds of settings that
4:29.040–4:35.760
you are going to be doing in the LMStudio. And one more time, thisparticular model is actually notavailable in the MLX format. I
4:35.760–4:41.760
unfortunately have got only the GGMLformat and I'm going to be running thisparticular model in the LM Studio and I
4:41.760–4:48.880
will show you how the TPS is going to befor the different KV cache that we aregoing to be setting and running it. But,
4:48.880–4:50.720
you know what? This particular model is
4:50.720–4:57.720
not really going to hit the out ofmemory exception. Based on the differentKV cache setting, you can actually see
4:57.720–5:03.080
that this model is actually going to beperformant as well. And this is a goodnews for this particular model. Well, as
5:03.080–5:11.919
that said, let's start doing the testingof the model with a differentquantization. So, you can see that Ihave got my Mac mini M4 machine. The
5:11.919–5:20.600
total number of physical memory that youcan see over here is 24 gig and I'mgoing to be loading theQwen model in the LM Studio and I'm
5:20.600–5:30.200
going to set the context length overhere to at least like a 30 31 or 32,000over here. And you can see that this is
5:30.200–5:36.000
the maximum concurrent prediction.Instead of four, I'm going to be settingit to one cuz it's going to be reducing
5:36.000–5:45.080
the total number of compute as well. AndI'm also going to change the KV cachequantizationtype there. So, instead of using the
5:45.080–5:50.560
default, I'm going to be setting theFP16 this time. And I'm going to beloading this particular model. And the
5:50.560–5:57.760
moment I'm going to load this particularmodel, you can see that it is going tobe consuming around 20 gig or 21 gig of
5:57.760–6:08.680
the total memory in myRAM there. And now I'm going to berunning the the questions over there,inferencing it without the thinking
6:08.680–6:15.880
enabled. So the moment I'm going to run,let's say hi over here, I'm gettingaround 4.57 tokens per second. And now
6:15.880–6:23.400
if I'm going to say again like hi again,it is going to give me around 4.9 tokensper second. This is a dense model that
6:23.400–6:30.800
we're talking about, guys. Look at that.And now if I'm going to pass a longprompt to write a Selenium C# .NET code
6:30.800–6:36.880
for Google search operation with pageobject model and dependency injection.And if I'm going to run it, I'm going to
6:36.880–6:42.200
start the timer as well just in case.And if I'm going to show you the memoryspike there, you see that the memory
6:42.200–6:48.880
pressure is not increasing because it'sa two-bit quantization model. And at thesame time, you can see that I'm actually
6:48.880–6:55.000
getting the output over here. It is notas fast as you can imagine. It is notsuper fast like how you can expect with
6:55.000–7:03.480
a like a M5 Max machine. But you can seethat within 4 minutes, I got the outputwith a 5.67 tokens per second. This is
7:03.480–7:11.080
not bad to be honest. This is working.It's not really hitting that memoryceiling. And if you try to run afour-bit quantization, this is never
7:11.080–7:18.960
going to be running for you. And 4minutes is not that bad at all. Now I'mgoing to change the quantization toeight, which is a quantization eight
7:18.960–7:28.080
here for the KV cache alone. And I'mgoing to be loading this particularmodel. And I'm going to ask the samexact prompt there. Sending a hi
7:28.080–7:35.200
message. And going to say hi again. I'mgetting 5.47 token. And I'm going tosend the same exact Selenium code
7:35.200–7:42.080
prompt. And I'm going to start the timerover there. You can see that this timethe time is going to be a bit higher
7:42.080–7:52.520
than compared to the FP16 there. Thereason is because actually it's not thateven if you try to reduce thequantization, the things will be faster.
7:52.520–8:01.480
The inferencing will exactly be the samexact tokens per second because it alsoneed to dequantize and unpack the
8:01.480–8:10.000
quantization for you and then it isgoing to be doing some computeoperation. That's the reason whyactually the performance goes slower.
8:10.000–8:18.760
the the total number of time it takesfor the same exact prompt is going to behigher than compared to the FP16 for you
8:18.760–8:25.600
over there. See now, this is going to bethe FP4 that we have got. I'm going tobe asking the same exact question. The
8:25.600–8:30.919
total number of tokens per second is notchanging at all. And now if I'm going tobe running the same exact prompt, the
8:30.919–8:41.560
Selenium WebDriver question over therewith thequantization four there, instead of the4.04minutes which was taking in FP16, it is
8:41.560–8:48.520
4.46 as you can see here. So, based onthe quantization change, it is alsobviously going to change the time over
8:48.520–8:55.320
there. So, this proves the point thathe inferencing actually works even inLM Studio for us and you can see that
8:55.320–9:02.080
he output has got no compromise aswell. The output looks pretty muchexactly the same and I can see that itis still working. I mean there is a
9:02.080–9:07.960
change in the output of course in theWebDriver for the dependence injection.It's there over here. But in here, you
9:07.960–9:13.600
can see that the dependence injectionsetup has got a bit different with likedriver factory class there. That's the
9:13.600–9:20.280
only difference between both of them.But overall, I can actually see that itis working pretty much as expected. The
9:20.280–9:29.120
last test which I wanted to do with theFP16 of the same exact model is byconnecting to a pie coding agent. I want
9:29.120–9:39.040
o really see if this is going to workor not. So, I have set the FP16 overhere. I'm running it and I'm going to beopening the pie coding agent over here
9:39.040–9:45.840
and I'm going to choose the model. Asyou can see I'm going to be chasingchoosing that GSQRCO onslaught MTP model
9:45.840–9:54.200
there.And I'm going to be just saying hi overthere. Even for a high message it wastaking a long time. It's not very fast
9:54.200–10:02.440
as you can imagine.It was taking a long time and the outputyou can see that it is going to begiving you very very slow here. Which is
10:02.440–10:08.600
quite expected because this is a densemodel. And I now have told it to analyzethe code for me this particular
10:08.600–10:17.840
epository and that took me more than 27minutes just to analyze the code. I meanit went so deep to be honest like going
10:17.840–10:25.440
through each and every file even starto figure out what exactly is theproblem in the particular code. Butactually took 27 minutes to give me the
10:25.440–10:35.880
output which is what really happenedover here as you can see. So long storyshort, you can run a two-bitquantization Qwen 3.8 27 billion
10:35.880–10:46.080
parameter model in an Apple M4 Mac minimachine without hitting the memoryceiling. But what is the actualtechnique which makes the two-bit
10:46.080–10:53.120
quantization which helps you run in aMac mini M4 machine is actually the mostimportant part. That's the reason why I
10:53.120–10:58.560
actually wanted to show you what'sreally happening over here. And otherthing is you may ask what happens if you
10:58.560–11:05.000
try to run the same exact model in theApple M5 Max machine, right? So I'm
11:05.000–11:13.160
going to be loading the same exact modelas you can see over here and I'm goingto be doing an FP16 here as well. So
11:13.160–11:20.000
FP16 max current prediction is going tobe one as well. I'm going to loadingthis particular model and let's try to
11:20.000–11:26.000
ask the same exact question over hereand see how this is actually going towork in my Apple M5 Max machine. So this
11:26.000–11:32.880
a 128 gig machine. So you might bexpecting it to be running it faster andyou'll be expecting it to get at least a
11:32.880–11:39.600
100 tokens per second if you're thinkingthat way. But, if I'm going to berunning the same exact model in this
11:39.600–11:49.160
machine, you can see that it isresponding with 27 tokens per second. Itis not like 127 tokens per second. So,
11:49.160–11:57.440
it proves the point that it's not justabout the two-bit quantization modelwhich can run way more faster in an
11:57.440–12:04.800
Apple M5 Max machine because it's evenrunning in the M4 mini machine. But, thething is even though it is a two-bit
12:04.800–12:13.200
quantization, the quality of the outputstill remains, and that's the reason thetechnique of the GSQ RCU sits in.
12:13.200–12:21.800
So, it it safely chooses the best tensorwhich can be optimized to do a betterwork for better precision instead of
12:21.800–12:28.880
ocusing on the low precisionquantizations that is thereon the tensors there. So, [music] that'sit, guys. This is all I wanted to talk
12:28.880–12:36.640
to you about the Quant 3.8 27 billionparameter model with two-bitquantization. Once again, thank you somuch for watching this video. Catch you
12:36.640–12:39.160
in the next one.
0:00.000–0:12.160
嗨,大家好,歡迎回來。在這支影片裡,我們將討論如何僅使用 24 GB 的統一記憶體,在 Apple M4 Mac mini 機器上運行 Qwen。
0:12.160–0:22.320
我們知道 Qwen 3.8 270 億參數模型的體積至少為 15 GB。而載入
0:22.320–0:31.440
統一記憶體中的不僅僅是模型本身,還包括 KV 快取、執行階段以及 Mac
0:31.440–0:39.320
作業系統。當你把這些全部載入 VRAM 時,絕對會觸及記憶體
0:39.320–0:46.960
上限,並且會讓你遇到記憶體不足(out of memory)的例外錯誤。那麼,我們該如何處理這種
0:46.960–0:49.800
記憶體問題呢?並且我們真的能在這台機器上運行 Qwen 3.8 270 億參數模型嗎?而且
0:49.800–0:54.880
這只是模型本身的問題,還是我們所使用的量化方式有問題?但如果
0:54.880–1:02.680
我們對完全相同的模型採用兩比特量化,而不是四比特量化呢?
1:02.680–1:11.160
我們對相同模型進行量化,但採用兩比特量化而非四比特量化呢?
1:11.160–1:14.280
經過兩比特量化的 Qwen 模型,稱為 Qwen 3.8 270 億 GSQRCO IQ2 QS 模型。這個模型可以載入 24 GB 的統一記憶體中,
1:14.280–1:30.760
並且它支援完整的 GPU 卸載,同時也啟用了多令牌預測功能。這個模型可以輕鬆地放入
1:30.760–1:40.960
擁有 24 GB 統一記憶體的 Apple M4 機器中,這包括了模型、KV 快取、執行階段以及 Mac 作業系統
1:40.960–1:50.800
而不會觸及記憶體上限。因此,它可以輕鬆地為你在 Apple 機器中載入所有內容,這
1:50.800–1:57.520
同時不會觸及記憶體上限。因此,它可以在你的 Apple 機器中輕鬆載入所有內容,而
1:57.520–2:03.400
記憶體需求將大幅減少。那麼,這究竟是如何實現的呢?現在
2:03.400–2:07.760
的 Qwen 3.8 會失去其智能能力嗎?或者輸出的品質會變差嗎?這究竟是
2:07.760–2:15.680
Qwen 3.8 現在會失去其智能能力,還是輸出的品質會下降,或者具體來說會
2:15.680–2:17.920
兩比特量化模型究竟是什麼?好吧,
2:17.920–2:20.280
這個特定的 Qwen 模型是一個標準的 Qwen 模型,但與其在全體應用相同的量化,
2:20.280–2:27.720
該技術會決定哪些張量值得更高的精度,以及哪些可以容忍激進的壓縮。
2:27.720–2:34.640
這正是這個特定技術所做的。那麼,我們所討論的這個技術究竟是什麼呢?
2:34.640–2:39.760
GSQ RCO,也稱為 Gumbel Softmax 量化,它會智慧地優化量化
2:39.760–2:48.600
值,而 RCO 則會智慧地決定在模型的張量之間分配更多或更少的位元。因此,
2:48.600–2:57.959
基本上,即使模型體積會從 16 BPW(即 16 位元的原始模型)減少到
2:57.959–3:08.080
兩比特量化模型,其體積將減少約 6.4 倍,但模型仍然會
3:08.080–3:16.160
在這裡提供驚人的精度。這就是這個特定模型本身的威力。這也是為什麼
3:16.160–3:23.519
為你提供極高的精確度。這就是該特定模型本身的強大之處。這也是為什麼
3:23.519–3:31.000
你預期從相同 Qwen 模型的四比特量化中獲得的結果非常相似。這正是
3:31.000–3:37.239
這個特定模型的樣子,我們將在這支影片中看到我們如何運行完全相同的 Qwen
3:37.239–3:45.080
兩比特模型在 Mac mini M4 機器上,我們也將看到它進行推論的速度有多快,以及這意味著
3:45.080–3:56.400
在我這支影片中將要進行的不同 KV 快取調整下,不同大小的 KV 快取會如何影響
3:56.400–4:02.840
我會在本影片中調整不同大小的 KV 快取。現在,我將展示
4:02.840–4:12.120
它將如何影響速度以及每秒處理的 token 數量。因此,在本影片中,我們將看到
4:12.120–4:20.359
8 位元量化,以及哪個會花費更多時間,以及你在 LM Studio 中進行不同設定時
4:20.359–4:29.040
每秒會獲得多少令牌總數。還有一件事,這個特定模型實際上並沒有
4:29.040–4:35.760
你在 LM Studio 中進行的操作。還有一次,這個特定模型實際上並未提供 MLX 格式。我
4:35.760–4:41.760
不幸的是只有 GGML 格式,我將在本影片中於 LM Studio 中運行這個特定模型,並且我
4:41.760–4:48.880
向你展示對於我們將要設定和運行的不同 KV 快取,TPS(每秒令牌數)會是如何。但是,
4:48.880–4:50.720
你知道嗎?這個特定模型
4:50.720–4:57.720
實際上不會觸及記憶體不足(out of memory)的例外錯誤。根據不同的 KV 快取設定,你實際上可以看到
4:57.720–5:03.080
這個模型實際上也能發揮效能。這對這個特定模型來說是個好消息。那麼,
5:03.080–5:11.919
話雖如此,讓我們開始使用不同的量化方式來測試這個模型。你可以看到,我這裡有一台 Mac mini M4 機器。
5:11.919–5:20.600
你可以看到這裡的實體記憶體總量為 24 GB,我將在 LM Studio 中載入 Qwen 模型,並且
5:20.600–5:30.200
我會將這裡的上下文長度設定為至少 30,000、31,000 或 32,000。你可以看到這是
5:30.200–5:36.000
最大並行預測數。我將它從四設定為一,因為這樣也會減少
5:36.000–5:45.080
總計算量。同時,我也會更改那裡的 KV 快取量化類型。所以,與其使用
5:45.080–5:50.560
預設值,這次我將設定為 FP16。我將載入這個特定模型。而當我
5:50.560–5:57.760
載入這個特定模型的瞬間,你可以看到它將消耗大約 20 GB 或 21 GB 的
5:57.760–6:08.680
記憶體。現在我將在那裡執行問題,在不啟用思考的情況下進行推論。
6:08.680–6:15.880
所以,當我執行時,假設我在這裡輸入 hi,我每秒得到大約 4.57 個 token。然後現在
6:15.880–6:23.400
如果我再次輸入 hi,它將每秒給我大約 4.9 個 token。我們談論的是
6:23.400–6:30.800
一個密集模型,各位。看看那個。現在,如果我輸入一個長提示,要求撰寫用於 Google 搜尋操作的 Selenium C# .NET 程式碼
6:30.800–6:36.880
,包含頁面物件模型和依賴注入。如果我執行它,我也會啟動計時器以防萬一。如果我向你展示那裡的記憶體
6:36.880–6:42.200
我也啟動計時器,以防萬一。如果我向你展示記憶體尖峰那裡的情況,你會看到記憶體
6:42.200–6:48.880
壓力沒有增加,因為這是一個二比特量化模型。與此同時,你可以看到我實際上
6:48.880–6:55.000
在這裡得到了輸出。它沒有你想象中那麼快。它不像你預期在
6:55.000–7:03.480
像 M5 Max 機器上那樣超級快。但你可以看到,在 4 分鐘內,我得到了輸出,每秒 5.67 個 token。這
7:03.480–7:11.080
說實話還不錯。它在運作。它並沒有真正觸及記憶體上限。如果你嘗試執行
7:11.080–7:18.960
正在為你運行。而 4 分鐘根本不算差。現在我要將量化改為八位元,這裡僅針對 KV 快取採用八位元量化。我將載入這個特定模型,並在那裡發送完全相同的提示。發送 hi
7:18.960–7:28.080
與那裡的 FP16 相比。原因是實際上,即使你嘗試減少量化,速度也不會變快。
7:28.080–7:35.200
載入這個特定模型。我將詢問完全相同的提示。發送一個 hi
7:35.200–7:42.080
訊息。然後再次輸入 hi。我得到 5.47 個 token。我將發送完全相同的 Selenium 程式碼
7:42.080–7:52.520
量化為你,然後它將執行一些運算。這就是為什麼實際上效能變慢的原因。
7:52.520–8:01.480
與之前的 FP16 相比更高。原因是實際上,即使你嘗試減少
8:01.480–8:10.000
在那裡。現在你看,這就是我們得到的 FP4。我將提出完全相同的问题。
8:10.000–8:18.760
推論將完全以相同的每秒 token 數進行,因為它也需要解量化和解壓縮
8:18.760–8:25.600
在那邊。現在請看,這就是我們所使用的 FP4。我將提出完全相同的問題。
8:25.600–8:30.919
每秒的總 token 數量完全沒有變化。現在如果我運行完全相同的提示,
8:30.919–8:41.560
在那裡使用四比特量化的 Selenium WebDriver 問題,而不是 FP16 所需的 4.04 分鐘,它現在
8:41.560–8:48.520
之前的 FP16 更高。現在你看,這是我們擁有的 FP4。我將詢問完全相同的问题。
8:48.520–8:55.320
每秒 token 的總數完全沒有變化。現在,如果我執行完全相同的提示,
8:55.320–9:02.080
那裡的 Selenium WebDriver 問題,使用四比特量化,而不是 FP16 所需的 4.04 分鐘,它
9:02.080–9:07.960
當然,WebDriver 中的依賴注入輸出有所改變。它就在這裡。但在這裡,你
9:07.960–9:13.600
可以看到依賴注入的設定與這裡的驅動程式工廠類別有些不同。那就是
9:13.600–9:20.280
推論實際上在 LM Studio 中對我們有效,你可以看到
9:20.280–9:29.120
輸出也沒有妥協。輸出看起來幾乎完全相同,我可以看到它仍在運作。我的意思是,當然
9:29.120–9:39.040
WebDriver 的依賴注入輸出有所變化。它在那裡。但在這裡,你可以
9:39.040–9:45.840
看到依賴注入設定有些不同,例如那裡有 driver factory 類別。這就是
9:45.840–9:54.200
兩者之間唯一的區別。但總體而言,我實際上可以看到它大致按預期運作。
9:54.200–10:02.440
我最後想對相同模型的 FP16 進行的測試,是連接一個 pie coding agent。我想
10:02.440–10:08.600
相當預期,因為這是一個密集模型。現在我已經指示它為我分析這個特定
10:08.600–10:17.840
儲存庫的程式碼,光是分析程式碼就花了超過 27 分鐘。說實話,它深入的程度令人驚訝,
10:17.840–10:25.440
逐一檢查每個檔案,甚至開始釐清特定程式碼中究竟存在什麼問題。但實際上花了 27 分鐘才給出
10:25.440–10:35.880
輸出結果,這正是這裡發生的情況,如你所見。所以長話短說,你可以在 Apple M4 Mac mini 機器上運行兩比特量化 Qwen 3.8 270 億
10:35.880–10:46.080
在 Apple M4 Mac mini 機器上運行,而沒有觸及記憶體上限。但實際上是哪種
10:46.080–10:53.120
量化能在 Mac mini M4 機器上運行的技術,才是最關鍵的部分。這就是為什麼我
10:53.120–10:58.560
真的想向你展示這裡究竟發生了什麼。另一件事是,你可能會問,如果在
10:58.560–11:05.000
Apple M5 Max 機器上運行完全相同的模型會發生什麼情況,對吧?所以,我
11:05.000–11:13.160
會加載完全相同的模型,如你所見,這裡我也會進行 FP16 運算。因此,
11:13.160–11:20.000
FP16 的最大當前預測值也會是 1。我會加載這個特定模型,讓我們嘗試
11:20.000–11:26.000
在這裡問同樣的問題,看看這在我的 Apple M5 Max 機器上實際上會如何運作。所以,這
11:26.000–11:32.880
是一台 128 GB 記憶體機器。因此,你可能預期它會運行得更快,並且預期它至少能達到
11:32.880–11:39.600
每秒 100 個 token 的速度,如果你這樣想的話。但是,如果我在這台
11:39.600–11:49.160
機器上運行完全相同的模型,你可以看到它的回應速度是每秒 27 個 token。它並不是每秒 127 個 token。所以,
11:49.160–11:57.440
這證明了重點:這不僅僅是關於兩比特量化模型,因為它在
11:57.440–12:04.800
Apple M5 Max 機器上運行得比在 M4 mini 機器上還要快得多。但問題是,即使它是兩比特
12:04.800–12:13.200
量化,輸出的品質仍然保持不變,這就是 GSQ RCU 技術存在的理由。
12:13.200–12:21.800
因此,它安全地選擇最佳的張量,該張量可以進行最佳化,以提供更高的精確度,而不是
12:21.800–12:28.880
專注於張量上存在的低精度量化。所以,[音樂] 就是這些了,各位。這就是我想跟你們談論
12:28.880–12:36.640
關於具有兩比特量化的 Quant 3.8 270 億參數模型的所有內容。再次感謝大家觀看這部影片。我們
12:36.640–12:39.160
下一部影片見。
0:00.000–0:12.160
Hi guys, welcome back. In this video,we'll be talking about how you can run aQwen in an AppleM4 Mac mini machine with just 24 GB of
嗨,大家好,歡迎回來。在這支影片裡,我們將討論如何僅使用 24 GB 的統一記憶體,在 Apple M4 Mac mini 機器上運行 Qwen。
0:12.160–0:22.320
unified memory. We know that Qwen 3.8 27billion parameter model will be of atleast 15 GB of size. And loading the
我們知道 Qwen 3.8 270 億參數模型的體積至少為 15 GB。而載入
0:22.320–0:31.440
ntire model in the unified memory willnot only load the model, but also loadsthe KV cache, runtime, and the Mac
統一記憶體中的不僅僅是模型本身,還包括 KV 快取、執行階段以及 Mac
0:31.440–0:39.320
operating system all together. And whileyou load all of them in the VRAM, it isdefinitely going to hit the memory
作業系統。當你把這些全部載入 VRAM 時,絕對會觸及記憶體
0:39.320–0:46.960
ceiling for you, and it is going to begetting you the out of memory exception.So, how can we even handle the situation
上限,並且會讓你遇到記憶體不足(out of memory)的例外錯誤。那麼,我們該如何處理這種
0:46.960–0:49.800
of these kind of memory problem? And can
記憶體問題呢?並且我們真的能在這台機器上運行 Qwen 3.8 270 億參數模型嗎?而且
0:49.800–0:54.880
we even run a Qwen 3.8 27 billionparameter model in this machine? And is
這只是模型本身的問題,還是我們所使用的量化方式有問題?但如果
0:54.880–1:02.680
it just the problem with the modelitself, or is it the problem with thequantization that we have? But what if
我們對完全相同的模型採用兩比特量化,而不是四比特量化呢?
1:02.680–1:11.160
we have a quantization of the same exactmodel with just two-bit quantizationinstead of the four-bit quantization?
我們對相同模型進行量化,但採用兩比特量化而非四比特量化呢?
1:11.160–1:14.280
Can we run that at all? Well, welcome to
經過兩比特量化的 Qwen 模型,稱為 Qwen 3.8 270 億 GSQRCO IQ2 QS 模型。這個模型可以載入 24 GB 的統一記憶體中,
1:14.280–1:30.760
the Qwen model quantized to two-bitcalled as the Qwen 3.8 27 billion GSQRCO IQ2 QS model. And this model canload in the 24 GB of unified machine,
並且它支援完整的 GPU 卸載,同時也啟用了多令牌預測功能。這個模型可以輕鬆地放入
1:30.760–1:40.960
and it can support a full GPUoffloading, as well as it hasmulti-token prediction enabled as well.And this model can easily fit in an
擁有 24 GB 統一記憶體的 Apple M4 機器中,這包括了模型、KV 快取、執行階段以及 Mac 作業系統
1:40.960–1:50.800
Apple M4 machine of 24 GB of unifiedmemory, which includes the model, KVcache, runtime, and Mac operating system
而不會觸及記憶體上限。因此,它可以輕鬆地為你在 Apple 機器中載入所有內容,這
1:50.800–1:57.520
without hitting the memory ceiling aswell. So, it can easily load everythingfor you within your Apple machine, which
同時不會觸及記憶體上限。因此,它可以在你的 Apple 機器中輕鬆載入所有內容,而
1:57.520–2:03.400
is quite amazing. So, the memoryrequirement is going to be so much lessbecause of the two-bit quantization that
記憶體需求將大幅減少。那麼,這究竟是如何實現的呢?現在
2:03.400–2:07.760
you have got in this particular model.So, how exactly is this possible? Will
的 Qwen 3.8 會失去其智能能力嗎?或者輸出的品質會變差嗎?這究竟是
2:07.760–2:15.680
the Qwen 3.8 right now will lose itsintelligence ability or the output willbe of less quality or how exactly is
Qwen 3.8 現在會失去其智能能力,還是輸出的品質會下降,或者具體來說會
2:15.680–2:17.920
this happening? What exactly is this new
兩比特量化模型究竟是什麼?好吧,
2:17.920–2:20.280
model of a two-bit quantization? Well,
這個特定的 Qwen 模型是一個標準的 Qwen 模型,但與其在全體應用相同的量化,
2:20.280–2:27.720
this particular Qwen model is a standardQwen model, but instead of applying thesame quantization everywhere, the
該技術會決定哪些張量值得更高的精度,以及哪些可以容忍激進的壓縮。
2:27.720–2:34.640
technique will determine which tensorsdeserves more precision and which cantolerate the aggressive compression.
這正是這個特定技術所做的。那麼,我們所討論的這個技術究竟是什麼呢?
2:34.640–2:39.760
That's exactly what this particulartechnique does. And what exactly is thistechnique that we're talking about? The
GSQ RCO,也稱為 Gumbel Softmax 量化,它會智慧地優化量化
2:39.760–2:48.600
GSQ RCO or otherwise called as theGumbel Softmax quantization, whichintelligently optimizes the quantization
值,而 RCO 則會智慧地決定在模型的張量之間分配更多或更少的位元。因此,
2:48.600–2:57.959
value while RCO intelligently decidewhere to allocate more or fewer bitsacross the model's uh tensors. So,
基本上,即使模型體積會從 16 BPW(即 16 位元的原始模型)減少到
2:57.959–3:08.080
essentially, even if the model sizes isgoing to be reduced from the 16 BPW,which is a 16-bit original model, to a
兩比特量化模型,其體積將減少約 6.4 倍,但模型仍然會
3:08.080–3:16.160
two-bit quantization model, it is goingto be off almost 6.4 time of a sizelower, but still the model is going to
在這裡提供驚人的精度。這就是這個特定模型本身的威力。這也是為什麼
3:16.160–3:23.519
give you an amazing precision over here.That is the power of this particularmodel itself. And that's the reason why
為你提供極高的精確度。這就是該特定模型本身的強大之處。這也是為什麼
3:23.519–3:31.000
even though the size of the model is somuch smaller, the quality of the outputis still going to be way more same like
你預期從相同 Qwen 模型的四比特量化中獲得的結果非常相似。這正是
3:31.000–3:37.239
how you can expect with theirquantization four model of the same Qwenmodel that you have got. That's exactly
這個特定模型的樣子,我們將在這支影片中看到我們如何運行完全相同的 Qwen
3:37.239–3:45.080
what this particular model is, and weare going to see in this particularvideo how we can run the same exact Qwen
兩比特模型在 Mac mini M4 機器上,我們也將看到它進行推論的速度有多快,以及這意味著
3:45.080–3:56.400
two-bit model in the Mac mini M4machine, and we're also going to see howfast it is going to be doing theinferencing for us and what it means
在我這支影片中將要進行的不同 KV 快取調整下,不同大小的 KV 快取會如何影響
3:56.400–4:02.840
with different sizes of the KV cacheadjustment that I'm going to be doing inthis particular video. Now, I will show
我會在本影片中調整不同大小的 KV 快取。現在,我將展示
4:02.840–4:12.120
you how it is going to be affecting thespeed as well as the number oftokens per second as well. So, in thisparticular video, we are going to see
它將如何影響速度以及每秒處理的 token 數量。因此,在本影片中,我們將看到
4:12.120–4:20.359
which KV size or which KV cache is goingto be faster like 16-bit or 4-bit or8-bit quantization and which is going to
8 位元量化,以及哪個會花費更多時間,以及你在 LM Studio 中進行不同設定時
4:20.359–4:29.040
take more time and what is the totalnumber of tokens per second that you aregoing to be gettingwith different kinds of settings that
每秒會獲得多少令牌總數。還有一件事,這個特定模型實際上並沒有
4:29.040–4:35.760
you are going to be doing in the LMStudio. And one more time, thisparticular model is actually notavailable in the MLX format. I
你在 LM Studio 中進行的操作。還有一次,這個特定模型實際上並未提供 MLX 格式。我
4:35.760–4:41.760
unfortunately have got only the GGMLformat and I'm going to be running thisparticular model in the LM Studio and I
不幸的是只有 GGML 格式,我將在本影片中於 LM Studio 中運行這個特定模型,並且我
4:41.760–4:48.880
will show you how the TPS is going to befor the different KV cache that we aregoing to be setting and running it. But,
向你展示對於我們將要設定和運行的不同 KV 快取,TPS(每秒令牌數)會是如何。但是,
4:48.880–4:50.720
you know what? This particular model is
你知道嗎?這個特定模型
4:50.720–4:57.720
not really going to hit the out ofmemory exception. Based on the differentKV cache setting, you can actually see
實際上不會觸及記憶體不足(out of memory)的例外錯誤。根據不同的 KV 快取設定,你實際上可以看到
4:57.720–5:03.080
that this model is actually going to beperformant as well. And this is a goodnews for this particular model. Well, as
這個模型實際上也能發揮效能。這對這個特定模型來說是個好消息。那麼,
5:03.080–5:11.919
that said, let's start doing the testingof the model with a differentquantization. So, you can see that Ihave got my Mac mini M4 machine. The
話雖如此,讓我們開始使用不同的量化方式來測試這個模型。你可以看到,我這裡有一台 Mac mini M4 機器。
5:11.919–5:20.600
total number of physical memory that youcan see over here is 24 gig and I'mgoing to be loading theQwen model in the LM Studio and I'm
你可以看到這裡的實體記憶體總量為 24 GB,我將在 LM Studio 中載入 Qwen 模型,並且
5:20.600–5:30.200
going to set the context length overhere to at least like a 30 31 or 32,000over here. And you can see that this is
我會將這裡的上下文長度設定為至少 30,000、31,000 或 32,000。你可以看到這是
5:30.200–5:36.000
the maximum concurrent prediction.Instead of four, I'm going to be settingit to one cuz it's going to be reducing
最大並行預測數。我將它從四設定為一,因為這樣也會減少
5:36.000–5:45.080
the total number of compute as well. AndI'm also going to change the KV cachequantizationtype there. So, instead of using the
總計算量。同時,我也會更改那裡的 KV 快取量化類型。所以,與其使用
5:45.080–5:50.560
default, I'm going to be setting theFP16 this time. And I'm going to beloading this particular model. And the
預設值,這次我將設定為 FP16。我將載入這個特定模型。而當我
5:50.560–5:57.760
moment I'm going to load this particularmodel, you can see that it is going tobe consuming around 20 gig or 21 gig of
載入這個特定模型的瞬間,你可以看到它將消耗大約 20 GB 或 21 GB 的
5:57.760–6:08.680
the total memory in myRAM there. And now I'm going to berunning the the questions over there,inferencing it without the thinking
記憶體。現在我將在那裡執行問題,在不啟用思考的情況下進行推論。
6:08.680–6:15.880
enabled. So the moment I'm going to run,let's say hi over here, I'm gettingaround 4.57 tokens per second. And now
所以,當我執行時,假設我在這裡輸入 hi,我每秒得到大約 4.57 個 token。然後現在
6:15.880–6:23.400
if I'm going to say again like hi again,it is going to give me around 4.9 tokensper second. This is a dense model that
如果我再次輸入 hi,它將每秒給我大約 4.9 個 token。我們談論的是
6:23.400–6:30.800
we're talking about, guys. Look at that.And now if I'm going to pass a longprompt to write a Selenium C# .NET code
一個密集模型,各位。看看那個。現在,如果我輸入一個長提示,要求撰寫用於 Google 搜尋操作的 Selenium C# .NET 程式碼
6:30.800–6:36.880
for Google search operation with pageobject model and dependency injection.And if I'm going to run it, I'm going to
,包含頁面物件模型和依賴注入。如果我執行它,我也會啟動計時器以防萬一。如果我向你展示那裡的記憶體
6:36.880–6:42.200
start the timer as well just in case.And if I'm going to show you the memoryspike there, you see that the memory
我也啟動計時器,以防萬一。如果我向你展示記憶體尖峰那裡的情況,你會看到記憶體
6:42.200–6:48.880
pressure is not increasing because it'sa two-bit quantization model. And at thesame time, you can see that I'm actually
壓力沒有增加,因為這是一個二比特量化模型。與此同時,你可以看到我實際上
6:48.880–6:55.000
getting the output over here. It is notas fast as you can imagine. It is notsuper fast like how you can expect with
在這裡得到了輸出。它沒有你想象中那麼快。它不像你預期在
6:55.000–7:03.480
a like a M5 Max machine. But you can seethat within 4 minutes, I got the outputwith a 5.67 tokens per second. This is
像 M5 Max 機器上那樣超級快。但你可以看到,在 4 分鐘內,我得到了輸出,每秒 5.67 個 token。這
7:03.480–7:11.080
not bad to be honest. This is working.It's not really hitting that memoryceiling. And if you try to run afour-bit quantization, this is never
說實話還不錯。它在運作。它並沒有真正觸及記憶體上限。如果你嘗試執行
7:11.080–7:18.960
going to be running for you. And 4minutes is not that bad at all. Now I'mgoing to change the quantization toeight, which is a quantization eight
正在為你運行。而 4 分鐘根本不算差。現在我要將量化改為八位元,這裡僅針對 KV 快取採用八位元量化。我將載入這個特定模型,並在那裡發送完全相同的提示。發送 hi
7:18.960–7:28.080
here for the KV cache alone. And I'mgoing to be loading this particularmodel. And I'm going to ask the samexact prompt there. Sending a hi
與那裡的 FP16 相比。原因是實際上,即使你嘗試減少量化,速度也不會變快。
7:28.080–7:35.200
message. And going to say hi again. I'mgetting 5.47 token. And I'm going tosend the same exact Selenium code
載入這個特定模型。我將詢問完全相同的提示。發送一個 hi
7:35.200–7:42.080
prompt. And I'm going to start the timerover there. You can see that this timethe time is going to be a bit higher
訊息。然後再次輸入 hi。我得到 5.47 個 token。我將發送完全相同的 Selenium 程式碼
7:42.080–7:52.520
than compared to the FP16 there. Thereason is because actually it's not thateven if you try to reduce thequantization, the things will be faster.
量化為你,然後它將執行一些運算。這就是為什麼實際上效能變慢的原因。
7:52.520–8:01.480
The inferencing will exactly be the samexact tokens per second because it alsoneed to dequantize and unpack the
與之前的 FP16 相比更高。原因是實際上,即使你嘗試減少
8:01.480–8:10.000
quantization for you and then it isgoing to be doing some computeoperation. That's the reason whyactually the performance goes slower.
在那裡。現在你看,這就是我們得到的 FP4。我將提出完全相同的问题。
8:10.000–8:18.760
the the total number of time it takesfor the same exact prompt is going to behigher than compared to the FP16 for you
推論將完全以相同的每秒 token 數進行,因為它也需要解量化和解壓縮
8:18.760–8:25.600
over there. See now, this is going to bethe FP4 that we have got. I'm going tobe asking the same exact question. The
在那邊。現在請看,這就是我們所使用的 FP4。我將提出完全相同的問題。
8:25.600–8:30.919
total number of tokens per second is notchanging at all. And now if I'm going tobe running the same exact prompt, the
每秒的總 token 數量完全沒有變化。現在如果我運行完全相同的提示,
8:30.919–8:41.560
Selenium WebDriver question over therewith thequantization four there, instead of the4.04minutes which was taking in FP16, it is
在那裡使用四比特量化的 Selenium WebDriver 問題,而不是 FP16 所需的 4.04 分鐘,它現在
8:41.560–8:48.520
4.46 as you can see here. So, based onthe quantization change, it is alsobviously going to change the time over
之前的 FP16 更高。現在你看,這是我們擁有的 FP4。我將詢問完全相同的问题。
8:48.520–8:55.320
there. So, this proves the point thathe inferencing actually works even inLM Studio for us and you can see that
每秒 token 的總數完全沒有變化。現在,如果我執行完全相同的提示,
8:55.320–9:02.080
he output has got no compromise aswell. The output looks pretty muchexactly the same and I can see that itis still working. I mean there is a
那裡的 Selenium WebDriver 問題,使用四比特量化,而不是 FP16 所需的 4.04 分鐘,它
9:02.080–9:07.960
change in the output of course in theWebDriver for the dependence injection.It's there over here. But in here, you
當然,WebDriver 中的依賴注入輸出有所改變。它就在這裡。但在這裡,你
9:07.960–9:13.600
can see that the dependence injectionsetup has got a bit different with likedriver factory class there. That's the
可以看到依賴注入的設定與這裡的驅動程式工廠類別有些不同。那就是
9:13.600–9:20.280
only difference between both of them.But overall, I can actually see that itis working pretty much as expected. The
推論實際上在 LM Studio 中對我們有效,你可以看到
9:20.280–9:29.120
last test which I wanted to do with theFP16 of the same exact model is byconnecting to a pie coding agent. I want
輸出也沒有妥協。輸出看起來幾乎完全相同,我可以看到它仍在運作。我的意思是,當然
9:29.120–9:39.040
o really see if this is going to workor not. So, I have set the FP16 overhere. I'm running it and I'm going to beopening the pie coding agent over here
WebDriver 的依賴注入輸出有所變化。它在那裡。但在這裡,你可以
9:39.040–9:45.840
and I'm going to choose the model. Asyou can see I'm going to be chasingchoosing that GSQRCO onslaught MTP model
看到依賴注入設定有些不同,例如那裡有 driver factory 類別。這就是
9:45.840–9:54.200
there.And I'm going to be just saying hi overthere. Even for a high message it wastaking a long time. It's not very fast
兩者之間唯一的區別。但總體而言,我實際上可以看到它大致按預期運作。
9:54.200–10:02.440
as you can imagine.It was taking a long time and the outputyou can see that it is going to begiving you very very slow here. Which is
我最後想對相同模型的 FP16 進行的測試,是連接一個 pie coding agent。我想
10:02.440–10:08.600
quite expected because this is a densemodel. And I now have told it to analyzethe code for me this particular
相當預期,因為這是一個密集模型。現在我已經指示它為我分析這個特定
10:08.600–10:17.840
epository and that took me more than 27minutes just to analyze the code. I meanit went so deep to be honest like going
儲存庫的程式碼,光是分析程式碼就花了超過 27 分鐘。說實話,它深入的程度令人驚訝,
10:17.840–10:25.440
through each and every file even starto figure out what exactly is theproblem in the particular code. Butactually took 27 minutes to give me the
逐一檢查每個檔案,甚至開始釐清特定程式碼中究竟存在什麼問題。但實際上花了 27 分鐘才給出
10:25.440–10:35.880
output which is what really happenedover here as you can see. So long storyshort, you can run a two-bitquantization Qwen 3.8 27 billion
輸出結果,這正是這裡發生的情況,如你所見。所以長話短說,你可以在 Apple M4 Mac mini 機器上運行兩比特量化 Qwen 3.8 270 億
10:35.880–10:46.080
parameter model in an Apple M4 Mac minimachine without hitting the memoryceiling. But what is the actualtechnique which makes the two-bit
在 Apple M4 Mac mini 機器上運行,而沒有觸及記憶體上限。但實際上是哪種
10:46.080–10:53.120
quantization which helps you run in aMac mini M4 machine is actually the mostimportant part. That's the reason why I
量化能在 Mac mini M4 機器上運行的技術,才是最關鍵的部分。這就是為什麼我
10:53.120–10:58.560
actually wanted to show you what'sreally happening over here. And otherthing is you may ask what happens if you
真的想向你展示這裡究竟發生了什麼。另一件事是,你可能會問,如果在
10:58.560–11:05.000
try to run the same exact model in theApple M5 Max machine, right? So I'm
Apple M5 Max 機器上運行完全相同的模型會發生什麼情況,對吧?所以,我
11:05.000–11:13.160
going to be loading the same exact modelas you can see over here and I'm goingto be doing an FP16 here as well. So
會加載完全相同的模型,如你所見,這裡我也會進行 FP16 運算。因此,
11:13.160–11:20.000
FP16 max current prediction is going tobe one as well. I'm going to loadingthis particular model and let's try to
FP16 的最大當前預測值也會是 1。我會加載這個特定模型,讓我們嘗試
11:20.000–11:26.000
ask the same exact question over hereand see how this is actually going towork in my Apple M5 Max machine. So this
在這裡問同樣的問題,看看這在我的 Apple M5 Max 機器上實際上會如何運作。所以,這
11:26.000–11:32.880
a 128 gig machine. So you might bexpecting it to be running it faster andyou'll be expecting it to get at least a
是一台 128 GB 記憶體機器。因此,你可能預期它會運行得更快,並且預期它至少能達到
11:32.880–11:39.600
100 tokens per second if you're thinkingthat way. But, if I'm going to berunning the same exact model in this
每秒 100 個 token 的速度,如果你這樣想的話。但是,如果我在這台
11:39.600–11:49.160
machine, you can see that it isresponding with 27 tokens per second. Itis not like 127 tokens per second. So,
機器上運行完全相同的模型,你可以看到它的回應速度是每秒 27 個 token。它並不是每秒 127 個 token。所以,
11:49.160–11:57.440
it proves the point that it's not justabout the two-bit quantization modelwhich can run way more faster in an
這證明了重點:這不僅僅是關於兩比特量化模型,因為它在
11:57.440–12:04.800
Apple M5 Max machine because it's evenrunning in the M4 mini machine. But, thething is even though it is a two-bit
Apple M5 Max 機器上運行得比在 M4 mini 機器上還要快得多。但問題是,即使它是兩比特
12:04.800–12:13.200
quantization, the quality of the outputstill remains, and that's the reason thetechnique of the GSQ RCU sits in.
量化,輸出的品質仍然保持不變,這就是 GSQ RCU 技術存在的理由。
12:13.200–12:21.800
So, it it safely chooses the best tensorwhich can be optimized to do a betterwork for better precision instead of
因此,它安全地選擇最佳的張量,該張量可以進行最佳化,以提供更高的精確度,而不是
12:21.800–12:28.880
ocusing on the low precisionquantizations that is thereon the tensors there. So, [music] that'sit, guys. This is all I wanted to talk
專注於張量上存在的低精度量化。所以,[音樂] 就是這些了,各位。這就是我想跟你們談論
12:28.880–12:36.640
to you about the Quant 3.8 27 billionparameter model with two-bitquantization. Once again, thank you somuch for watching this video. Catch you
關於具有兩比特量化的 Quant 3.8 270 億參數模型的所有內容。再次感謝大家觀看這部影片。我們
12:36.640–12:39.160
in the next one.
下一部影片見。

影片筆記:How I Ran Qwen3.8-27B GSQ-RCO on a 24GB Mac Mini !

<!-- VIDEONOTE_PUBLICATION_WARNINGS_BEGIN -->

⚠️ 可先使用,仍有待修正項目

本筆記已完成可閱讀的逐字稿與時間跳轉;下列為待處理問題,建議播放原片確認。

  • 待修正:逐字稿全文快速校讀未完成(已保留自動字幕/原始逐字稿並繼續生成筆記。;未完成的全文速讀項目可在精進模式回聽確認。)

<!-- VIDEONOTE_PUBLICATION_WARNINGS_END -->

一句話總結

影片演示如何在配備 24GB 統一記憶體的 Apple M4 Mac mini 上,透過使用兩比特量化技術(GSQ RCO)將 Qwen 3.8 27B 模型壓縮,成功在記憶體限制內運行並進行推理,同時對比了不同 KV cache 量化設定下的效能與品質。

核心重點

  1. 記憶體突破:標準 Qwen 3.8 27B 模型(約 15GB)加上 KV cache、運行時及 macOS 系統會超過 24GB 統一記憶體極限。透過將模型量化至兩比特(2-bit),可完整載入記憶體而不觸發 Out of Memory 錯誤。
  2. GSQ RCO 技術:採用 Gumbel Softmax Quantization (GSQ RCO) 技術,智能分配位元數,將 16-bit 模型縮減約 6.4 倍體積,同時保持高精度與輸出品質。
  3. 效能與品質平衡:
  • 兩比特模型體積大幅縮小,支援完整 GPU offloading 及多令牌預測(MTP)。
  • 在 M4 Mac mini 上,KV cache 設為 FP16 時,簡單問候 TPS 約 4.57-4.9,長提示詞約 5.67 TPS。
  • KV cache 設為 8-bit 或 4-bit 時,因需進行去量化(dequantize)和解壓縮(unpack)計算,導致推理速度變慢,甚至比 FP16 更慢。
  • 輸出品質與四比特模型相近,僅在特定程式碼設定(如 Dependency Injection)上有微小差異。
  1. 硬體瓶頸驗證:在 Apple M5 Max (128GB) 上測試,實際 TPS 僅約 27,未達預期的高速度。結論指出兩比特模型的推理速度受限於模型密度與去量化計算,而非單純由硬體規格決定。

詳細大綱

A. 問題背景與解決方案

  • 記憶體瓶頸:標準 Qwen 3.8 27B 模型大小至少 15GB。加上 KV cache、運行時及 macOS 系統,會超過 24GB 統一記憶體的極限,導致 Out of Memory 異常。
  • 解決方案:引入 Qwen 3.8 27B GSQRCO IQ2 QS 模型(兩比特量化版本)。
  • 核心優勢:
  • 體積大幅縮小,可完整載入 24GB 記憶體。
  • 支援完整 GPU offloading。
  • 啟用多令牌預測(Multi-token prediction, MTP)。

B. GSQ RCO 技術原理

  • 技術名稱:GSQ RCO 或 Gumbel Softmax quantization。
  • 運作機制:
  • 並非對所有張量(tensors)應用相同的量化標準。
  • 智能決定哪些張量需要更高精度,哪些可容忍激進壓縮。
  • RCO 部分智能決定在模型的張量間分配多或少位元。
  • 效果:將 16-bit 原模型縮減至兩比特,體積降低約 6.4 倍,但保持高精度與輸出品質。

C. LM Studio 實測環境與設定

  • 硬體:Apple M4 Mac mini,24GB 統一記憶體。
  • 軟體:LM Studio。
  • 模型格式:僅提供 GGML 格式(非 MLX 格式)。
  • 測試參數:
  • Context length:設為 30,000 - 32,000。
  • Max concurrent prediction:設為 1(減少計算量,原預設為 4)。
  • KV cache quantization:分別測試 FP16、8-bit、4-bit。

D. 性能測試結果(M4 Mac mini)

  • 測試提示詞:
  1. 簡單問候(Hi)。
  2. 長提示詞:撰寫 Selenium C# .NET 代碼(Google 搜尋操作、Page Object Model、Dependency Injection)。
  • KV Cache FP16 設定:
  • 記憶體佔用:約 20-21GB。
  • 簡單問候 TPS:約 4.57 - 4.9 tokens/sec。
  • 長提示詞耗時:約 4 分鐘,TPS 約 5.67 tokens/sec。
  • 結果:未觸發記憶體上限,輸出正常。
  • KV Cache 8-bit 設定:
  • 簡單問候 TPS:約 5.47 tokens/sec。
  • 長提示詞耗時:比 FP16 更長。
  • 原因:需進行去量化(dequantize)和解壓縮(unpack)計算,導致效能變慢。
  • KV Cache 4-bit (FP4) 設定:
  • TPS 與 FP16 相近。
  • 長提示詞耗時:約 4.46 分鐘(比 FP16 的 4 分鐘稍慢)。
  • Pie Coding Agent 測試:
  • 連接 AI 程式碼代理進行代碼分析。
  • 耗時超過 27 分鐘,因需深入分析每個檔案。
  • 輸出品質:與四比特模型相比,僅在 Dependency Injection 設定(如 driver factory class)上有微小差異,整體運作符合預期。

E. Apple M5 Max (128GB) 對比測試

  • 硬體:Apple M5 Max,128GB 記憶體。
  • 預期 vs 實際:
  • 預期:可能達到 100+ tokens/sec。
  • 實際:約 27 tokens/sec。
  • 結論:兩比特模型在 M5 Max 上並未顯著快於 M4 Mac mini,證明速度受限於模型密度與去量化計算,而非僅取決於硬體規格。

工具 / 模型 / 名詞整理

  • 硬體設備:
  • Apple M4 Mac mini
  • Apple M5 Max (Mac)
  • 模型名稱:
  • Qwen 3.8 27 billion parameter model
  • Qwen 3.8 27 billion GSQRCO IQ2 QS model (兩比特量化版本)
  • GSQ RCO / Gumbel Softmax quantization (量化技術)
  • 軟體與平台:
  • LM Studio
  • Pie coding agent (AI 程式碼代理工具)
  • 技術格式與參數:
  • GGML format
  • MLX format (影片指出該模型目前無此格式)
  • Unified Memory (統一記憶體)
  • KV cache (Key-Value cache)
  • Quantization levels: 2-bit, 4-bit (FP4), 8-bit, 16-bit (16 BPW), FP16
  • Multi-token prediction (MTP)
  • Tokens Per Second (TPS)
  • 程式開發相關:
  • Selenium C# .NET
  • Page Object Model
  • Dependency Injection
  • WebDriver

操作流程整理

  1. 準備環境:使用 Apple M4 Mac mini (24GB RAM) 與 LM Studio。
  2. 載入模型:下載並載入 Qwen 3.8 27B GSQRCO IQ2 QS 模型(GGML 格式)。
  3. 設定參數:
  • 設定 Context length 為 30,000 - 32,000。
  • 將 Max concurrent prediction 設為 1。
  • 選擇 KV cache quantization 設定(FP16, 8-bit, 或 4-bit)。
  1. 執行測試:
  • 發送簡單問候(Hi)測試基礎 TPS。
  • 發送長提示詞(撰寫 Selenium C# .NET 代碼)測試長上下文處理能力。
  • 連接 Pie coding agent 進行程式碼分析測試。
  1. 觀察結果:記錄不同 KV cache 設定下的 TPS、耗時、記憶體佔用及輸出品質。
  2. 對比測試:在 Apple M5 Max (128GB) 上重複測試,比較硬體升級帶來的效能變化。

值得注意的限制或風險

  1. 量化帶來的效能損耗:雖然兩比特模型體積小,但在 M4 Mac mini 上,KV cache 設為 8-bit 或 4-bit 時,因需進行去量化和解壓縮計算,導致推理速度變慢,甚至不如 FP16 設定。
  2. 硬體規格非唯一決定因素:在 M5 Max (128GB) 上,兩比特模型的 TPS 僅約 27,未達預期的高速度,顯示速度受限於模型密度與去量化計算,而非僅取決於硬體規格。
  3. 記憶體極限:標準模型無法在 24GB 記憶體上運行,必須使用特定量化版本。
  4. 輸出品質微小差異:與四比特模型相比,兩比特模型在特定程式碼設定(如 Dependency Injection)上可能有微小差異,需評估是否影響實際應用。

逐字稿辨識疑點

  • Qwen 3.8:逐字稿中多次提及「Qwen 3.8」,通常 Qwen 版本號為 1, 2, 2.5, 3 等,「3.8」可能為口誤或特定內部版本號,需查證。
  • GSQRCO / GSQ RCO:逐字稿中交替使用「GSQRCO」與「GSQ RCO」,並解釋為「Gumbel Softmax quantization」。此縮寫組合較不常見,需查證是否為特定論文或技術的準確拼寫。
  • M5 Max:逐字稿中提到測試硬體為「Apple M5 Max machine」。截至目前公開資訊,Apple 尚未發布 M5 系列晶片,此處可能為口誤(應為 M4 Max 或其他型號)或未來預測,需查證。
  • IQ2 QS:模型名稱中出現「IQ2 QS」,此為 GGUF 量化格式的一種,拼寫正確,但需確認是否與 GSQRCO 技術完全對應。
  • Pie coding agent:逐字稿中明確提到「pie coding agent」,此名稱較不常見,可能是特定內部工具、口誤(如「Py coding」或「AI coding agent」)或特定產品名稱,需查證。
  • 127 tokens per second:在 M5 Max 測試段落,講者提到「not like 127 tokens per second」,此數字可能是為了對比而舉例,或為口誤(如 12.7 或 100+),需查證。

可延伸追問

  1. GSQ RCO 技術的具體論文或官方文件為何?其與傳統量化方法(如 AWQ, GPTQ)的差異為何?
  2. 為何在 M5 Max 上 TPS 僅約 27?是否有其他優化空間或設定建議?
  3. 「Pie coding agent」的具體功能與適用場景為何?是否為開源工具?
  4. Qwen 3.8 是否為官方正式發布版本?若非,其與 Qwen 2.5 或 Qwen 3 的關係為何?
  5. 在實際生產環境中,兩比特模型的輸出品質差異是否可接受?是否有自動評估指標?

生字列表

生字讀音類型中文
unified memory/ˌjuːnɪfaɪd ˈmeməri/統一記憶體
parameter/pəˈræmɪtər/noun參數
KV cache/ˌkeɪ ˈviː kæʃ/nounKV 快取
out of memory exception/aʊt əv ˈmeməri ɪkˈsɛpʃən/noun phrase記憶體不足例外
quantization/ˌkwɒntaɪˈzeɪʃən/noun量化
two-bit/ˈtuː ˈbɪt/adjective兩比特
offloading/ˌɒfˈləʊdɪŋ/noun卸載
multi-token prediction/ˈmʌlti ˈtəʊkən prɪˈdɪkʃən/noun phrase多令牌預測
memory ceiling/ˈmeməri ˈsiːlɪŋ/noun phrase記憶體上限
precision/prɪˈsɪʒən/noun精度
tensors/ˈtɛnzərz/noun張量
aggressive/əˈɡrɛsɪv/adjective激進的
allocate/ˈæləkeɪt/verb分配
inferencing/ˈɪnfərɛnsɪŋ/noun推論
prompt/prɒmpt/noun提示
dense model/dɛns ˈmɒdəl/noun phrase密集模型
TPS/ˌtiː piː ˈɛs/noun每秒令牌數
compromise/ˈkɒmprəmaɪz/noun妥協

生字解說

unified memory /ˌjuːnɪfaɪd ˈmeməri/

· C1

意思:統一記憶體

解說:Apple Silicon 架構特有的記憶體設計,CPU 與 GPU 共享同一塊記憶體池,無需複製數據即可互相訪問,提升效率。

影片原句
In this video, we'll be talking about how you can run a Qwen in an Apple M4 Mac mini machine with just 24 GB of unified memory.
在這支影片裡,我們將討論如何僅使用 24 GB 的統一記憶體,在 Apple M4 Mac mini 機器上運行 Qwen。
延伸例句
The M4 chip's unified memory architecture allows seamless data sharing between the processor and graphics unit.
M4 晶片的統一記憶體架構允許處理器和圖形單元之間無縫共享數據。

parameter /pəˈræmɪtər/

noun · C1

意思:參數

解說:在機器學習模型中,指模型在訓練過程中學習到的內部變量,決定了模型的規模和容量。

影片原句
We know that Qwen 3.8 27 billion parameter model will be of at least 15 GB of size.
我們知道 Qwen 3.8 270 億參數模型的體積至少為 15 GB。
延伸例句
Large language models with hundreds of billions of parameters can understand complex nuances in language.
擁有數千億參數的大型語言模型可以理解語言中複雜的細微差別。

KV cache /ˌkeɪ ˈviː kæʃ/

noun · C1

意思:KV 快取

解說:鍵值快取,用於儲存注意力機制中計算過的鍵和值,以加速長文本生成的過程,避免重複計算。

影片原句
Loading the entire model in the unified memory will not only load the model, but also loads the KV cache, runtime, and the Mac operating system all together.
統一記憶體中的不僅僅是模型本身,還包括 KV 快取、執行階段以及 Mac 作業系統。
延伸例句
Increasing the KV cache size can significantly improve generation speed for long conversations.
增加 KV 快取的大小可以顯著提高長對話的生成速度。

out of memory exception /aʊt əv ˈmeməri ɪkˈsɛpʃən/

noun phrase · C1

意思:記憶體不足例外

解說:程式執行時因記憶體耗盡而拋出的錯誤,導致程序無法繼續運行或崩潰。

影片原句
It is definitely going to hit the memory ceiling for you, and it is going to be getting you the out of memory exception.
絕對會觸及記憶體上限,並且會讓你遇到記憶體不足(out of memory)的例外錯誤。
延伸例句
The application crashed with an out of memory exception when processing large datasets.
處理大型數據集時,應用程式因記憶體不足例外而崩潰。

quantization /ˌkwɒntaɪˈzeɪʃən/

noun · C1

意思:量化

解說:將高精度數據(如浮點數)轉換為低精度數據(如整數)的過程,旨在減少模型體積和計算資源需求。

影片原句
Is it just the problem with the model itself, or is it the problem with the quantization that we have?
這只是模型本身的問題,還是我們所使用的量化方式有問題?
延伸例句
Post-training quantization is a common technique to optimize neural networks for deployment.
訓練後量化是優化神經網絡以進行部署的常見技術。

two-bit /ˈtuː ˈbɪt/

adjective · C1

意思:兩比特

解說:指數據精度為 2 位元,相比 4 位元或 8 位元,能極大壓縮模型體積,但可能影響精度。

影片原句
What if we have a quantization of the same exact model with just two-bit quantization instead of the four-bit quantization?
我們對完全相同的模型採用兩比特量化,而不是四比特量化呢?
延伸例句
Two-bit quantization reduces the model size by a factor of eight compared to 8-bit.
與 8 位元相比,兩比特量化將模型體積減少了八倍。

offloading /ˌɒfˈləʊdɪŋ/

noun · C1

意思:卸載

解說:將計算任務從 CPU 轉移至 GPU 或其他專用硬體以加速處理的過程。

影片原句
And this model can support a full GPU offloading, as well as it has multi-token prediction enabled as well.
並且它支援完整的 GPU 卸載,同時也啟用了多令牌預測功能。
延伸例句
GPU offloading is essential for training deep learning models efficiently.
GPU 卸載對於高效訓練深度學習模型至關重要。

multi-token prediction /ˈmʌlti ˈtəʊkən prɪˈdɪkʃən/

noun phrase · C1

意思:多令牌預測

解說:一種推理優化技術,允許模型在一次迭代中預測多個輸出令牌,從而提高生成速度。

影片原句
And this model can support a full GPU offloading, as well as it has multi-token prediction enabled as well.
並且它支援完整的 GPU 卸載,同時也啟用了多令牌預測功能。
延伸例句
Enabling multi-token prediction can double the inference speed on supported hardware.
在支援的硬體上啟用多令牌預測可以將推理速度加倍。

memory ceiling /ˈmeməri ˈsiːlɪŋ/

noun phrase · C1

意思:記憶體上限

解說:硬體所能提供的最大記憶體容量,超過此限制將導致無法載入更大模型。

影片原句
And while you load all of them in the VRAM, it is definitely going to hit the memory ceiling for you.
當你把這些全部載入 VRAM 時,絕對會觸及記憶體上限。
延伸例句
The 16GB memory ceiling limits the size of models that can be run locally.
16GB 的記憶體上限限制了可以在本地運行的模型大小。

precision /prɪˈsɪʒən/

noun · C1

意思:精度

解說:數據表示的準確程度,高精度意味著更少的捨入誤差和更準確的計算結果。

影片原句
The technique will determine which tensors deserves more precision and which can tolerate the aggressive compression.
該技術會決定哪些張量值得更高的精度,以及哪些可以容忍激進的壓縮。
延伸例句
FP16 precision offers a good balance between speed and accuracy for most AI tasks.
對於大多數 AI 任務,FP16 精度在速度和準確性之間提供了良好的平衡。

tensors /ˈtɛnzərz/

noun · C1

意思:張量

解說:多維陣列,是神經網絡中數據的基本表示形式,包含權重和激活值。

影片原句
The technique will determine which tensors deserves more precision and which can tolerate the aggressive compression.
該技術會決定哪些張量值得更高的精度,以及哪些可以容忍激進的壓縮。
延伸例句
Neural networks process data by manipulating tensors through various layers.
神經網絡通過在各層中操作張量來處理數據。

aggressive /əˈɡrɛsɪv/

adjective · B2

意思:激進的

解說:在此語境下指極度壓縮或大幅削減資源,通常伴隨較大的精度損失風險。

影片原句
The technique will determine which tensors deserves more precision and which can tolerate the aggressive compression.
該技術會決定哪些張量值得更高的精度,以及哪些可以容忍激進的壓縮。
延伸例句
Aggressive pruning can reduce model size but may hurt performance.
激進的剪枝可以減少模型體積,但可能會損害性能。

allocate /ˈæləkeɪt/

verb · C1

意思:分配

解說:指將資源(如位元)指定給特定用途或組件。

影片原句
RCO intelligently decides where to allocate more or fewer bits across the model's uh tensors.
RCO 則會智慧地決定在模型的張量之間分配更多或更少的位元。
延伸例句
The system dynamically allocates memory based on current workload.
系統根據當前工作負載動態分配記憶體。

inferencing /ˈɪnfərɛnsɪŋ/

noun · C1

意思:推論

解說:指使用訓練好的模型對新數據進行預測或生成的過程,與訓練過程相對。

影片原句
We're also going to see how fast it is going to be doing the inferencing for us.
我們也將看到它進行推論的速度有多快。
延伸例句
Optimizing inferencing latency is crucial for real-time applications.
優化推論延遲對於即時應用至關重要。

prompt /prɒmpt/

noun · B2

意思:提示

解說:輸入給語言模型的文本指令,用於引導模型生成特定的回應。

影片原句
If I'm going to pass a long prompt to write a Selenium C# .NET code.
如果我輸入一個長提示,要求撰寫用於 Google 搜尋操作的 Selenium C# .NET 程式碼。
延伸例句
Crafting a clear and detailed prompt is key to getting accurate results from AI.
編寫清晰詳細的提示是從 AI 獲得準確結果的關鍵。

dense model /dɛns ˈmɒdəl/

noun phrase · C1

意思:密集模型

解說:指所有參數在每次推理時都參與計算的模型,與稀疏模型相對,通常計算量更大。

影片原句
This is a dense model that we're talking about, guys.
我們談論的是密集模型,各位。
延伸例句
Dense models generally offer higher accuracy but require more computational resources.
密集模型通常提供更高的準確性,但需要更多的計算資源。

TPS /ˌtiː piː ˈɛs/

noun · C1

意思:每秒令牌數

解說:Tokens Per Second 的縮寫,衡量語言模型生成速度的指標。

影片原句
I will show you how the TPS is going to be for the different KV cache that we are going to be setting.
向你展示對於我們將要設定和運行的不同 KV 快取,TPS(每秒令牌數)會是如何。
延伸例句
A higher TPS indicates a faster response time for the language model.
較高的 TPS 表示語言模型的回應時間更快。

compromise /ˈkɒmprəmaɪz/

noun · B2

意思:妥協

解說:在此語境下指品質或性能的損失或降低。

影片原句
The output has got no compromise as well.
輸出也沒有妥協。
延伸例句
There should be no compromise on safety standards in manufacturing.
在製造業中,安全標準不應有任何妥協。

句型解說(含實例)

how you can [verb] ... with just [resource]

意思:如何僅使用 [資源] 來 [動作] ...

接續:how + subject + can + verb + object + with just + noun phrase

解說:用於介紹在資源受限的情況下實現某種目標的方法,強調資源的高效利用。

影片原句
In this video, we'll be talking about how you can run a Qwen in an Apple M4 Mac mini machine with just 24 GB of unified memory.
在這支影片裡,我們將討論如何僅使用 24 GB 的統一記憶體,在 Apple M4 Mac mini 機器上運行 Qwen。
實例
  1. Let me show you how you can deploy a server with just one command.
    讓我展示你如何僅用一條命令來部署伺服器。
  2. This tutorial explains how you can train a model with just a laptop.
    本教程解釋了你如何僅用筆記型電腦來訓練模型。

not only [verb] ..., but also [verb] ...

意思:不僅 [動作1] ...,還 [動作2] ...

接續:not only + verb phrase + but also + verb phrase

解說:用於強調動作或狀態的多重性,表示除了主要情況外,還有額外的情況。

影片原句
Loading the entire model in the unified memory will not only load the model, but also loads the KV cache, runtime, and the Mac operating system all together.
統一記憶體中的不僅僅是模型本身,還包括 KV 快取、執行階段以及 Mac 作業系統。
實例
  1. The new software not only improves speed but also enhances security.
    新軟體不僅提高了速度,還增強了安全性。
  2. She not only passed the exam but also got the highest score.
    她不僅通過了考試,還得了最高分。

it is going to [verb] ... for you

意思:它將會為你 [動作] ...

接續:it + is going to + verb + object + for + pronoun

解說:用於預測某事對特定對象產生的影響或結果,常帶有負面或強調意味。

影片原句
And while you load all of them in the VRAM, it is definitely going to hit the memory ceiling for you.
當你把這些全部載入 VRAM 時,絕對會觸及記憶體上限。
實例
  1. Ignoring the warning will definitely cause errors for you.
    忽略警告絕對會為你導致錯誤。
  2. Using the wrong library is going to break your code for you.
    使用錯誤的庫將會破壞你的程式碼。

what if [clause] ...

意思:如果 [情況] 會怎樣 ...

接續:what if + subject + verb + object/complement

解說:用於提出假設性問題,探討某種情況發生後的後果或可能性。

影片原句
What if we have a quantization of the same exact model with just two-bit quantization instead of the four-bit quantization?
我們對完全相同的模型採用兩比特量化,而不是四比特量化呢?
實例
  1. What if we switch to a different framework?
    如果我們切換到不同的框架會怎樣?
  2. What if the server goes down during the update?
    如果更新期間伺服器宕機會怎樣?

instead of [noun/gerund]

意思:代替 [名詞/動名詞]

接續:instead of + noun phrase / gerund

解說:用於表示選擇另一種方案或事物,取代原本的计划或選項。

影片原句
What if we have a quantization of the same exact model with just two-bit quantization instead of the four-bit quantization?
我們對完全相同的模型採用兩比特量化,而不是四比特量化呢?
實例
  1. We should use open-source tools instead of buying expensive licenses.
    我們應該使用開源工具,而不是購買昂貴的授權。
  2. He decided to walk instead of driving to work.
    他決定走路去上班,而不是開車。

which includes [list]

意思:其中包括 [列表]

接續:which + includes + noun phrase(s)

解說:用於補充說明前文提到的事物所包含的具體內容或組成部分。

影片原句
And this model can easily fit in an Apple M4 machine of 24 GB of unified memory, which includes the model, KV cache, runtime, and Mac operating system.
這個模型可以輕鬆地放入擁有 24 GB 統一記憶體的 Apple M4 機器中,這包括了模型、KV 快取、執行階段以及 Mac 作業系統。
實例
  1. The package includes training, testing, and deployment phases.
    該套件包括訓練、測試和部署階段。
  2. The budget covers hardware, software, and maintenance costs.
    預算涵蓋硬體、軟體和維護成本。

without hitting [noun]

意思:在不觸及 [名詞] 的情況下

接續:without + gerund + object

解說:用於描述在避免某種負面結果或限制的情況下進行某項操作。

影片原句
And this model can easily fit in an Apple M4 machine of 24 GB of unified memory, which includes the model, KV cache, runtime, and Mac operating system without hitting the memory ceiling as well.
並且它支援完整的 GPU 卸載,同時也啟用了多令牌預測功能。這個模型可以輕鬆地放入擁有 24 GB 統一記憶體的 Apple M4 機器中,這包括了模型、KV 快取、執行階段以及 Mac 作業系統而不會觸及記憶體上限。
實例
  1. You can optimize the code without hitting the performance bottleneck.
    你可以在不觸及效能瓶頸的情況下優化程式碼。
  2. The system runs smoothly without hitting the error threshold.
    系統平穩運行,未觸及錯誤閾值。

that's exactly what [clause]

意思:那正是 [情況]

接續:that's + exactly + what + subject + verb

解說:用於強調前文所述內容與後文解釋的一致性,表示「這就是...的真諦/情況」。

影片原句
That's exactly what this particular technique does.
這正是這個特定技術所做的。
實例
  1. That's exactly what I meant when I said it was risky.
    當我說這有風險時,那正是我的意思。
  2. That's exactly what the documentation says about this feature.
    文件上關於這個功能的說明正是如此。