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.
下一部影片見。