0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Qwen3-VL-2Bの量子化によるファイルサイズ・メモリー使用量と精度

Last updated at Posted at 2025-11-18

基盤モデルのサイズや計算負荷を大きく減らす目的で使われる量子化。
精度を保ちながらファイルサイズやメモリ使用量を軽量化でき、エッジデバイスやローカル環境での推論には不可欠です。

どのくらい量子化すると、何が起こるのかを調べたので残しておきます。

結論

精度は体感レベルになるが、LLM:Q4_K_M + mmproj:Q4_K_M の組み合わせが、高精度かつファイルサイズとメモリー使用量が小さくて、実行速度もバランスよくなる組み合わせと言えそう

CPU 負荷を多少あげて実行速度が遅くなっても、ファイルサイズとメモリー使用量を最小化するなら LLM:IQ4_XS + mmproj:Q4_K_M

詳細

  • LLM:Q2_K は、まったく使い物にならない
  • LLM:Q3_K_M は微妙な精度だが、用途によっては使えるかもしれない(わからない)
  • LLM は IQ4_XSFP16 に対する精度劣化は見られなかった。ファイルサイズは FP16 = 3.3GB → IQ4_XS = 970MB と、70% 削減となった
  • Vision Encoder (mmproj) は Q4_K_MFP16 に対する、精度劣化は見られなかった。ファイルサイズは FP16 = 782MB → Q4_K_M = 267MB で、66% 削減となった
  • ファイルサイズが小さくなると、使用するメモリーサイズも小さくなった。LLM:FP16 + mmorpj:FP16 = 4.9GB → LLM:IQ4_XS + mmproj:Q4_K_M = 2.0GB で、60% 削減となった
  • CPU への負荷は、FP16Q4_K_M ではほぼ同じだったが、IQ4_** では負荷が増え、実行速度も15%程度遅くなった
  • 量子化作業は、一般的な PC でも数分で終わる程度の負荷だった

LLM と Vision Encoder は、マルチモーダルモデル(VLMなど)を構成する個別の要素。Vision Encoder は画像から「物の形・色・位置といった要点」を抜き出し、LLM はその要点を読み取って言語的に理解するという役割分担です。二つ揃って VLM (Vision-Language Model; 視覚言語モデル) となります。

Qwen3-VL-2B

Qwen3-VL-2B: 画像とテキストを同時に扱える、いわゆるマルチモーダル基盤モデル。軽量ながら高い認識・推論能力があります。

Qwen3-VL-2B は、llama.cpp等で扱えるGGUF形式のファイルが公式から公開されています。この中には、量子化の起点となるベース精度「FP16」のGGUFファイルが公開されているので、これを使います。

量子化の環境構築 ― llama.cpp

量子化は llama.cpp の中の llama-quantize コマンドを使います。量子化は CPU だけで行われる処理なので、CPU Build で OK です。

【参考】Ubuntu 24.04 での llama.cpp 構築手順
sudo apt update && sudo apt upgrade -y
## sudo systemctl reboot
sudo apt install -y cmake build-essential python3-pip libcurl4-openssl-dev
git clone --depth 1 https://github.com/ggml-org/llama.cpp
cd llama.cpp/
cmake -B build
cmake --build build --config Release -j $(nproc)
ls build/bin/llama-quantize
#=> build/bin/llama-quantize

動作確認

mkdir models/
# 量子化形式 FP16 の LLM と Vision encoder(mmproj) のダウンロード
curl -L -O --output-dir models/ https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct-GGUF/resolve/main/Qwen3VL-2B-Instruct-F16.gguf
curl -L -O --output-dir models/ https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct-GGUF/resolve/main/mmproj-Qwen3VL-2B-Instruct-F16.gguf
ls models/
#=> Qwen3VL-2B-Instruct-F16.gguf  mmproj-Qwen3VL-2B-Instruct-F16.gguf

# 入力用画像のダウンロード
curl -L -o input.png 'https://docs.google.com/drawings/d/e/2PACX-1vTxGpI_rrhCG1_XTzo0M8bcJCBaY0pvuzxj6mJ9UW9VJWEMCwT8b52DsTYwmXJDJ_Xcl-AGJI66RiDu/pub?w=512&h=512'
ls *.png
#=> input.png

# マルチモーダルでの推論実行
llama.cpp/build/bin/llama-mtmd-cli \
  -m models/Qwen3VL-2B-Instruct-F16.gguf \
  --mmproj models/mmproj-Qwen3VL-2B-Instruct-F16.gguf \
  --threads $(($(nproc)-1)) --no-mmap -n 512 --temp 0.2 \
  --image input.png \
  -p "画像には何が映っていますか?一行で解説して、日本語で回答してください。"
#=> ぶわーっといろいろ表示されて...
#=> 富士山が雪を被った山頂と、その下に広がる緑の山々、そして前景に橋と車が見える。

入力用の画像はこれです(私が撮影した写真です)推論結果は環境で違うかもしれませんが、そういうもんです

ちなみに "ぶわーっといろいろ表示される内容" を抑制したければ 2>/dev/null してください。抑制オプションが見当たりませんでした。

量子化

量子化は llama-quantize を使います。実行後はファイルサイズと実行時間が出ます
ちなみに量子化には GPU は使いません。CPU 性能が重要です

量子化前のファイルサイズ - FP16

-rw-r--r-- 1 ma2shita ma2shita 3.3G Nov 18 18:44 Qwen3VL-2B-Instruct-F16.gguf
-rw-r--r-- 1 ma2shita ma2shita 782M Nov 18 23:23 mmproj-Qwen3VL-2B-Instruct-F16.gguf

試験対象の量子化フォーマット

LLM と Vision Encoder (mmproj) はそれぞれ量子化が行えます。よく見るものは以下の通りです。

  • FP16 16bit浮動小数点で重みを保持し、精度をほぼ損なわない標準的な高精度形式
  • Q4_K_M 4bitのブロック量子化で、軽量化と再現性のバランスが良い実用的な4bit形式
  • IQ4_XS 極小スケールで圧縮を強め、サイズ最小化を優先する軽量特化の4bit形式

他には Q4_K_S とか IQ4_NL 等がありますが、これはモデルのファイル名についています。これで量子化フォーマットの内容を判別するのが通例のようです。

今回は4bit量子化から、さらにファイルサイズを削減して代償に精度を捨てることになる3ビット量子化(Q3_K_M)や2ビット量子化(Q2_K)も試してみました。

量子化コマンドラインと実行速度

私の llama-quantize の実行環境は 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz、メモリーは 16GB です

【参考】/proc/cpuinfo
$ cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 1
cpu cores       : 4
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 1
cpu cores       : 4
apicid          : 3
initial apicid  : 3
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 4
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 2
cpu cores       : 4
apicid          : 4
initial apicid  : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 5
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 2
cpu cores       : 4
apicid          : 5
initial apicid  : 5
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 6
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 3
cpu cores       : 4
apicid          : 6
initial apicid  : 6
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor       : 7
vendor_id       : GenuineIntel
cpu family      : 6
model           : 140
model name      : 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
stepping        : 1
microcode       : 0xffffffff
cpu MHz         : 2803.209
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 3
cpu cores       : 4
apicid          : 7
initial apicid  : 7
fpu             : yes
fpu_exception   : yes
cpuid level     : 27
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves vnmi avx512vbmi umip avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear flush_l1d arch_capabilities
vmx flags       : vnmi invvpid ept_x_only ept_ad ept_1gb tsc_offset vtpr ept vpid unrestricted_guest ept_mode_based_exec tsc_scaling
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb bhi
bogomips        : 5606.41
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:
【参考】/proc/meminfo
$ cat /proc/meminfo
MemTotal:       16193760 kB
MemFree:         9502436 kB
MemAvailable:   15522256 kB
Buffers:           19504 kB
Cached:          6065536 kB
SwapCached:            0 kB
Active:          4045900 kB
Inactive:        2157896 kB
Active(anon):       2552 kB
Inactive(anon):   119956 kB
Active(file):    4043348 kB
Inactive(file):  2037940 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       4194304 kB
SwapFree:        4194304 kB
Dirty:                56 kB
Writeback:             0 kB
AnonPages:        118532 kB
Mapped:           144972 kB
Shmem:              3752 kB
KReclaimable:     186284 kB
Slab:             257376 kB
SReclaimable:     186284 kB
SUnreclaim:        71092 kB
KernelStack:        3492 kB
PageTables:         2860 kB
SecPageTables:         0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    12291184 kB
Committed_AS:     596912 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       28804 kB
VmallocChunk:          0 kB
Percpu:             3296 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
Unaccepted:            0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:       76800 kB
DirectMap2M:     7075840 kB
DirectMap1G:    17825792 kB

Q** は短時間、 IQ4_** は時間がかかります

LLM を FP16 → Q4_K_M
$ llama.cpp/build/bin/llama-quantize models/Qwen3VL-2B-Instruct-F16.gguf models/Qwen3VL-2B-Instruct-Q4_K_M.gguf Q4_K_M
...
llama_model_quantize_impl: model size  =  3281.97 MiB
llama_model_quantize_impl: quant size  =  1050.43 MiB

main: quantize time = 32541.66 ms
main:    total time = 32541.66 ms
LLM を FP16 → IQ4_XS
$ llama.cpp/build/bin/llama-quantize models/Qwen3VL-2B-Instruct-F16.gguf models/Qwen3VL-2B-Instruct-IQ4_XS.gguf IQ4_XS
...
llama_model_quantize_impl: model size  =  3281.97 MiB
llama_model_quantize_impl: quant size  =   963.53 MiB

main: quantize time = 96935.31 ms
main:    total time = 96935.31 ms
mmproj を FP16 → Q4_K_M
$ llama.cpp/build/bin/llama-quantize models/mmproj-Qwen3VL-2B-Instruct-F16.gguf models/mmproj-Qwen3VL-2B-Instruct-Q4_K_M.gguf Q4_K_M
...
llama_model_quantize_impl: model size  =   781.42 MiB
llama_model_quantize_impl: quant size  =   263.17 MiB
llama_model_quantize_impl: WARNING: 1 of 105 tensor(s) required fallback quantization

main: quantize time =  8657.55 ms
main:    total time =  8657.55 ms

推論結果

CPU(%) と メモリー使用量は /usr/bin/time -v の以下から得ています

  • CPU 使用率 = Percent of CPU this job got の値
  • メモリー使用量 = Maximum resident set size の値
  • 実行時間 = llama_perf_context_print: total time の値
LLM mmproj 精度(FP16比較) ファイルサイズ(LLM + mmproj = TTL) CPU 使用率 メモリー使用量 実行時間
FP16 FP16 (基準) 3.3 GB + 782 MB = 4.1 GB 533 % 4,878,768 KB 14,794 ms
Q4_K_M FP16 同等 1.1 GB + 782 MB = 1.9 GB 581 % 2,595,800 KB 10,831 ms
Q3_K_M FP16 少し劣化 897 MB + 782 MB = 1.7 GB 648 % 2,431,916 KB 13,169 ms
Q2_K FP16 ひどい 724 MB + 782 MB = 1.5 GB 661 % 2,276,912 KB 14,760 ms
IQ4_NL FP16 同等 1.0 GB + 782 MB = 1.8 GB 564 % 2,548,644 KB 12,295 ms
IQ4_XS FP16 同等 970 MB + 782 MB = 1.7 GB 618 % 2,504,548 KB 14,489 ms
Q4_K_M Q8_0 同等 1.1 GB + 425 MB = 1.5 GB 549 % 2,220,856 KB 11,019 ms
IQ4_XS Q8_0 同等 970 MB + 425 MB = 1.4 GB 657 % 2,129,508 KB 15,353 ms
Q4_K_M Q4_K_M 同等 1.1 GB + 264 MB = 1.3 GB 557 % 2,058,652 KB 11,801 ms
IQ4_XS Q4_K_M 同等 970 MB + 264 MB = 1.2 GB 609 % 1,967,592 KB 16,173 ms
Q3_K_M Q4_K_M 少し劣化 897 MB + 264 MB = 1.1 GB 631 % 1,894,704 KB 13,520 ms

各量子化フォーマットでの実際の出力内容

共通コマンドライン

$ llama.cpp/build/bin/llama-mtmd-cli \
  -m models/Qwen3VL-2B-Instruct-**.gguf \
  --mmproj models/mmproj-Qwen3VL-2B-Instruct-**.gguf \
  --threads $(($(nproc)-1)) --no-mmap -n 512 --temp 0.2 \
  --image input.png \
  -p "画像には何が映っていますか?一行で解説して、日本語で回答してください。"
LLM:FP16 + mmproj:FP16

富士山が雪を被った姿を、橋と木々の風景が見えるように写っています。

LLM:Q4_K_M + mmproj:FP16

富士山とその周囲の山々、そして橋と車が映っています。

LLM:Q3_K_M + mmproj:FP16

空に雲が広がり、雪をかぶった山の姿がそびえています。

LLM:Q2_K + mmproj:FP16

日本語で回答します。
山の上に雪がみっくり、
山の上に雪がみっくり、
山の上に雪がみっくり、
山の上に雪がみっくり、
山の上に雪がみっくり、
山の上に雪がみっくり、
^C (強制終了)

LLM:IQ4_NL + mmproj:FP16

富士山が、雲に覆われた空の下、緑の山々の上にそびえています。前景には、橋と車が見えます。

LLM:IQ4_XS + mmproj:FP16

雪を被った富士山が、曇りの空の下、緑の山々の上にそびえています。

LLM:Q4_K_M + mmproj:Q8_0

富士山が雪を被った山頂と、その下の緑豊かな山々、そして前景に橋と車が見える風景です。

LLM:IQ4_XS + mmproj:Q8_0

富士山が、雲の下にそびえ立つ姿を、鉄道橋の上から捉えられています。

LLM:Q4_K_M + mmproj:Q4_K_M

富士山が雪を被った山頂が、雲に覆われた空の下にそびえ立っています。

LLM:IQ4_XS + mmproj:Q4_K_M

富士山が、雲の下にそびえ立つ姿を、遠くの山の麓から捉えています。

LLM:Q3_K_M + mmproj:Q4_K_M

山の上に雪をかぶった山の姿が見えます。

あとがき

Q2_K は、もはや壊れてますね。
明日はがんばります。

EoT

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?