> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/moderu/gemma-4/qat.md).

# Gemma 4 QAT

E2B、E4B、12B、26B-A4B、31Bを含むGoogle Gemma 4 QATモデルをローカルで実行します。

Gemma 4 QATは、Google DeepMindの新しい [Gemma 4](/docs/jp/moderu/gemma-4.md) 〜するように設計されたバリアント **メモリ要件を削減しつつ、モデル品質を維持**。これにより、次のようなより大きなモデルを実行できるようになります **Gemma 4 26B-A4B**を、ローカルでコンシューマー向けGPU上にわずか **16GBのRAM**.

Gemma 4 QATは量子化を念頭に置いて学習されており、4ビット形式でも約**72%のメモリ使用量削減** を **ほぼ元の性能**。E2BとE4B向けの2つの特別なモバイル量子化も提供されており、量子化幅の混合を使用しています。

次のように変換すると `Q4_0` QATから素朴に変換すると、26B-A4BでTop-1精度はわずか70.2%しか得られません。 [私たちはUnsloth Dynamic手法を適用し](#qat-analysis) それを **85.6%（+15.6%）に引き上げ、さらに** [**200MB小さく**](#usage-guide)!

Gemma 4 QATには以下が含まれます： **E2B**, **E4B**, **12B、26B-A4B**と **31B。** これらは、140以上の言語と最大 **256Kのコンテキストをサポートする、マルチモーダルなハイブリッド思考モデルです。**

{% columns %}
{% column %} <a href="/docs/jp/moderu/gemma-4/qat.md#run-gemma-4-qat-tutorials" class="button primary">Gemma 4 QATを実行する</a><a href="/docs/jp/moderu/gemma-4/qat.md#qat-analysis" class="button secondary">QAT分析</a>

**Gemma-4-E2B** QATは3GB RAMで動作し、 **E4B** 5GB&#x3067;**、12B** 7GB&#x3067;**、26-A4B** 15GBで **31B** 18GB&#x3067;**.**

私たちはGemma 4 QAT GGUFを次のように名付けています `UD-Q4_K_XL` q4\_0はサイズが大きいにもかかわらず精度を低下させることが分かったためです。私たちの [Gemma 4 QAT GGUF](https://huggingface.co/collections/unsloth/gemma-4-qat).

比較するには `int4` 量子化については、元のサイズとQAT後のサイズの差を以下でご覧ください。QATはメモリを約72%削減しつつ、元の精度をほぼすべて保持します：
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FGLHNSIo3qe4ByThVZDzm%2Fgemma%204%20qat.png?alt=media&amp;token=ae72b8e1-def7-447c-bafc-67514354df7d" alt="" width="563"><figcaption><p>Gemma 4 Mobile QATの仕組みの可視化。</p></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

| Gemma 4     | QAT（int4）GGUF |  元のBF16 |    変化率 |
| ----------- | ------------: | ------: | -----: |
| **E2B**     |       2.62 GB | 9.31 GB | 71.86% |
| **E4B**     |       4.22 GB | 15.1 GB | 72.05% |
| **12B**     |       6.72 GB | 23.8 GB | 71.76% |
| **26B A4B** |       14.2 GB | 50.5 GB | 71.88% |
| **31B**     |       17.3 GB | 61.4 GB | 71.82% |

### 使用ガイド

Gemma 4のE2BおよびE4B向けQATバリアントはスマートフォンやノートPC向けに設計されており、より大きな26B-A4Bと31B QAT モデルは、強力な家庭用GPUだけでなくノートPCでも動作するようになりました。

あります **GGUFファイルは1つだけ** 各Gemma 4モデルについて。これは、アップロードされた `UD-Q4_K_XL` バージョンより高い精度は改善ではなく精度低下を招くことが分かったためです。元の非QATのQ4\_0量子化を使用してください [ここ](https://huggingface.co/collections/unsloth/gemma-4).

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FrTygbMBlZcUER9GUMzKg%2Fimage.png?alt=media&amp;token=85c3c44b-0f42-477a-9ce2-30b085e21b5c" alt="" width="563"><figcaption></figcaption></figure>

### ハードウェア要件

**表：Gemma 4 QAT推論GGUFの推奨ハードウェア要件** （単位 = 総メモリ: RAM + VRAM、またはユニファイドメモリ）。

| Gemma 4 QAT     |    要件 |
| --------------- | ----: |
| **E2B** QAT     |  3 GB |
| **E4B** QAT     |  5 GB |
| **12B** QAT     |  7 GB |
| **26B A4B** QAT | 15 GB |
| **31B** QAT     | 18 GB |

{% hint style="info" %}
この表は約8Kトークンのコンテキストを前提としています。llama.cppの26B A4B向けデフォルト256Kコンテキストは、KVキャッシュを約5 GB追加します。メモリ制約のあるCPU専用マシンでは、 `-c 8192` または `-c 16384`; `--fit` は現在、CPUで再パックされた重みを無視します。
{% endhint %}

### 推奨設定

QATチェックポイントは、同じ推奨Gemma 4設定を使用しています：

* `temperature = 1.0`
* `top_p = 0.95`
* `top_k = 64`

{% hint style="info" %}
Gemma 4の最大コンテキストは **128K** を **E2B**, **E4B** そして **256K** を **12B**, **26B A4B**, **31B**.
{% endhint %}

## QAT分析

QAT Q4\_0チェックポイントをllama.cpp側でQ4\_0に素朴に変換すると、実際には精度が低下し、Q4\_0用のBF16 QAT格子とも実際には整合していないことが分かりました。私たちはUnsloth Dynamic手法を適用して、llama.cpp互換のQ4\_0形式と真のBF16 QAT Q4\_0形式の間の一致をより良く強制し、量子化をより小さく（埋め込みにはQ6\_Kが不要でした）、さらにより高精度にすることに成功しました！

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FcBHRs9twWiAnjgtm4EKf%2Fimage.png?alt=media&amp;token=023d7771-dba1-4a1e-a8c4-da6ac98921f7" alt=""><figcaption></figcaption></figure>

以下はKLD、Top 1%精度、ディスク容量の表です。私たちのバージョンが99.9% KLDと平均KLDを劇的に改善していることが分かります。 **例えばE2Bでは、素朴なQ4\_0量子化の平均KLDは0.00173に対して0.05109（相対的に29倍改善）であり、しかも私たちのものはさらに22%小さいです！**

主な問題は、QAT BF16からllama.cppのQ4\_0形式への変換が非可逆でないことです。llama.cppはF16スケールを使用しますが、QAT BF16はBF16スケールを使用し、llama.cpp側ではスケールが最適に決定されません。

素朴な変換ではBF16 QATに対してバイト一致率24.77%ですが、私たちはいくつかのハックで99.96%まで引き上げられることを発見しました！

<table><thead><tr><th width="100">モデル</th><th>メソッド</th><th>ディスク（GB）</th><th>99.9% KLD</th><th>平均KLD</th><th width="77.5999755859375">Top-1 %</th></tr></thead><tbody><tr><td>E2B</td><td>Unsloth</td><td><strong>2.62</strong></td><td>0.0557</td><td>0.00173</td><td><strong>98.16</strong></td></tr><tr><td>E2B</td><td>Q4_0</td><td>3.35</td><td>1.0513</td><td>0.05109</td><td>89.29</td></tr><tr><td>E4B</td><td>Unsloth</td><td><strong>4.22</strong></td><td>0.0536</td><td>0.00121</td><td><strong>98.54</strong></td></tr><tr><td>E4B</td><td>Q4_0</td><td>5.15</td><td>0.6722</td><td>0.03778</td><td>90.94</td></tr><tr><td>26B</td><td>Unsloth</td><td><strong>14.25</strong></td><td>2.7087</td><td>0.09788</td><td><strong>85.63</strong></td></tr><tr><td>26B</td><td>Q4_0</td><td>14.44</td><td>4.5420</td><td>0.36094</td><td>70.20</td></tr><tr><td>31B</td><td>Unsloth</td><td><strong>17.29</strong></td><td>1.3659</td><td>0.01403</td><td><strong>96.67</strong></td></tr><tr><td>31B</td><td>Q4_0</td><td>17.65</td><td>3.0030</td><td>0.09349</td><td>87.91</td></tr><tr><td>12B</td><td>Unsloth</td><td><strong>6.72</strong></td><td>9.2740</td><td>0.13288</td><td><strong>88.76</strong></td></tr><tr><td>12B</td><td>Q4_0</td><td>6.98</td><td>14.7323</td><td>0.50702</td><td>74.08</td></tr></tbody></table>

## モバイル混合QAT

Gemma-4チームは、Gemma-4-E2B-itとGemma-4-E4B-itの特別なモバイル混合QAT版もリリースしました。私たちはそれらをllama.cpp互換形式に忠実に変換し、ほぼすべての精度も回復しました。2ビット層にはTQ2\_0を使用し、負のスケーラーを使いました。

E2BとE4Bの両方にUD-Q2\_K\_XL量子化を作成しました。

|                  | E2Bモバイル      | E4Bモバイル   |
| ---------------- | ------------ | --------- |
| サイズ              | 2.19 GB      | 3.22 GB   |
| 2ビット（TQ2\_0）テンソル | 61（深いMLPを含む） | 2（埋め込みのみ） |
| BF16との平均KLD      | 0.00409      | 0.00102   |
| Top-1 %          | 97.82%       | 98.76%    |
| ベースPPL           | \~103        | 42.4      |

こちらを参照 [gemma-4-E2B-it-qat-GGUF](https://huggingface.co/unsloth/gemma-4-E2B-it-qat-GGUF) そして [gemma-4-E4B-it-qat-GGUF](https://huggingface.co/unsloth/gemma-4-E4B-it-qat-GGUF) を `UD-Q2_K_XL`.

## Gemma 4 QATチュートリアルを実行する

Gemma 4 GGUFは複数のサイズで提供されるため、小さいモデルの推奨開始点は8ビットで、大きいモデルは **ダイナミック4ビット**. [Gemma 4 GGUF](https://huggingface.co/collections/unsloth/gemma-4-qat):

| [E2B](https://huggingface.co/unsloth/gemma-4-E2B-it-qat-GGUF) | [E4B](https://huggingface.co/unsloth/gemma-4-E4B-it-qat-GGUF) | [12b](https://huggingface.co/unsloth/gemma-4-12b-it-qat-GGUF) | [26B-A4B](https://huggingface.co/unsloth/gemma-4-26B-A4B-it-qat-GGUF) | [31B](https://huggingface.co/unsloth/gemma-4-31B-it-qat-GGUF) |
| ------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------- |

<a href="/docs/jp/moderu/gemma-4/qat.md#unsloth-studio-guide" class="button primary">🦥 Unsloth Studio ガイド</a><a href="/pages/136e446d64d842f3384bec65ba2ec312454e6e91#llama.cpp-guide" class="button primary">🦙 Llama.cppガイド</a>

{% columns %}
{% column %}
**UI付きでGemma 4 QATを無料で実行・学習できます。** [**Unsloth Studio**](/docs/jp/shii/studio.md)✨ **ノートブック：**
{% endcolumn %}

{% column %}
{% embed url="<https://colab.research.google.com/github/unslothai/unsloth/blob/main/studio/Unsloth_Studio_Colab.ipynb>" %}
{% endcolumn %}
{% endcolumns %}

### 🦥 Unsloth Studio ガイド

Gemma 4 QATは、現在 [Unsloth Studio](/docs/jp/shii/studio.md)、ローカルAI向けの新しいオープンソースWeb UIです。Unsloth Studioでは、モデルをローカルで実行できます **MacOS、Windows**、Linux、そして:

{% columns %}
{% column %}

* 検索、ダウンロード、 [GGUFを実行](/docs/jp/shii/studio.md#run-models-locally) およびsafetensorモデル
* [**自己修復** ツール呼び出し](/docs/jp/shii/studio.md#execute-code--heal-tool-calling) + **web search**
* [**コード実行**](/docs/jp/shii/studio.md#run-models-locally) （Python、Bash）
* [自動推論](https://unsloth.ai/docs/desktop#feature-deep-dive) パラメータ調整（temp、top-pなど）
* llama.cppによる高速CPU + GPU推論
* [LLMを学習](/docs/jp/shii/studio.md#no-code-training) VRAMを70%削減して2倍高速
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FVrLgXwplAMcvkU4owjPk%2F26b%20gif.gif?alt=media&amp;token=8a569952-c152-435f-b815-c9f295619587" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}

#### Unslothをインストール

ターミナルで次を実行してください:

**MacOS、Linux、WSL:**

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

**Windows PowerShell:**

```bash
irm https://unsloth.ai/install.ps1 | iex
```

{% endstep %}

{% step %}

#### Unsloth を起動

**MacOS、Linux、WSL、Windows:**

```bash
unsloth studio -H 0.0.0.0 -p 8888
```

その後、 `http://127.0.0.1:8888` （またはお使いのURL）をブラウザで開いてください。
{% endstep %}

{% step %}

#### Gemma 4 QATを検索してダウンロード

初回起動時には、アカウントを保護するためのパスワードを作成し、再度サインインする必要があります。

それから [Unsloth Chat](/docs/jp/shii/studio/chat.md) タブへ行き、検索バーでGemma 4を検索して、必要なモデルと量子化をダウンロードしてください。
{% endstep %}

{% step %}

#### Gemma 4 QATを実行する

Unsloth Studio を使用すると推論パラメータは自動設定されるはずですが、手動で変更することもできます。コンテキスト長、チャットテンプレート、その他の設定も編集できます。

詳細については、次を参照してください。 [Unsloth Studio 推論ガイド](/docs/jp/shii/studio/chat.md).

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FVrLgXwplAMcvkU4owjPk%2F26b%20gif.gif?alt=media&amp;token=8a569952-c152-435f-b815-c9f295619587" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### 🦙 Llama.cppガイド

このガイドでは量子化タイプを選択する必要はありません。というのも、1つしかないからです： `UD-Q4_K_XL`。参照： [Gemma 4 QATコレクション](https://huggingface.co/collections/unsloth/gemma-4-qat)。これらのチュートリアルでは、私たちは [llama.cpp](llama.cpphttps://github.com/ggml-org/llama.cpp) 高速なローカル推論のために、特にCPUをお持ちの場合に

{% stepper %}
{% step %}
最新の `llama.cpp` **を** [**GitHubこちら**](https://github.com/ggml-org/llama.cpp)。以下のビルド手順に従うこともできます。変更してください `-DGGML_CUDA=ON` を `-DGGML_CUDA=OFF` GPUがない場合、またはCPU推論のみを使いたい場合は。 **Apple Mac / Metalデバイスの場合**、次を設定します `-DGGML_CUDA=OFF` その後は通常どおり続けてください。Metalサポートはデフォルトで有効です。

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggml-org/llama.cpp
cmake llama.cpp -B llama.cpp/build \
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endstep %}

{% step %}
を使いたい場合は `llama.cpp` 、モデルを直接読み込んで使用するには、各モデルに応じて以下のコマンドに従ってください。 `UD-Q4_K_XL` は唯一の量子化タイプです。Hugging Face経由でもダウンロードできます（ステップ3）。これは次と同様です `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` 特定の場所に保存するには、

**26B-A4B：**

```bash
export LLAMA_CACHE="unsloth/gemma-4-26B-A4B-it-qat-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-26B-A4B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

**31B：**

```bash
export LLAMA_CACHE="unsloth/gemma-4-31B-it-qat-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-31B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

**E4B：**

```bash
export LLAMA_CACHE="unsloth/gemma-4-E4B-it-qat-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-E4B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

**E2B：**

```bash
export LLAMA_CACHE="unsloth/gemma-4-E2B-it-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-E2B-it-qat-GGUF:UD-Q4_K_XL \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

{% endstep %}

{% step %}
以下をインストールした後、( `pip install huggingface_hub hf_transfer` をインストール後）。 `UD-Q4_K_XL` を選ぶこともできますし、 `Q8_0` のような他の量子化バージョンも選べます。ダウンロードが止まる場合は、以下を参照してください: [Hugging Face Hub、XET のデバッグ](/docs/jp/ji-chu/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
hf download unsloth/gemma-4-26B-A4B-it-qat-GGUF \\
    --local-dir unsloth/gemma-4-26B-A4B-it-qat-GGUF \\
    --include "*mmproj-BF16*" \
    --include "*UD-Q4_K_XL*" # Dynamic 2bitの場合は "*UD-Q2_K_XL*" を使用
```

{% endstep %}

{% step %}
その後、会話モードでモデルを実行します（ビジョン `mmproj-F16`):

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/gemma-4-26B-A4B-it-qat-GGUF/gemma-4-26B-A4B-it-qat-UD-Q4_K_XL.gguf \\
    --mmproj unsloth/gemma-4-26B-A4B-it-qat-GGUF/mmproj-BF16.gguf \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64
```

{% endcode %}
{% endstep %}

{% step %}

### Llama-serverデプロイ

llama-serverでGemma-4をデプロイするには、次を使用してください:

```bash
./llama.cpp/llama-server \
    --model unsloth/gemma-4-26B-A4B-it-qat-GGUF/gemma-4-26B-A4B-it-qat-UD-Q4_K_XL.gguf \\
    --mmproj unsloth/gemma-4-26B-A4B-it-qat-GGUF/mmproj-BF16.gguf \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 64 \
    --alias "unsloth/gemma-4-26B-A4B-it-qat-GGUF" \\
    --port 8001 \\
    --chat-template-kwargs '{"enable_thinking":true}'
```

{% hint style="warning" %}
に [思考 / 推論を無効化する](#how-to-enable-or-disable-reasoning-and-thinking)には、 `--chat-template-kwargs '{"enable_thinking":false}'`

もしあなたが **Windows** PowerShellなら、次を使用します： `--chat-template-kwargs "{\"enable_thinking\":false}"`

'true'と'false'は同じように使用してください。
{% endhint %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/jp/moderu/gemma-4/qat.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
