> 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.md).

# Gemma 4 - ローカルでの実行方法

E2B、E4B、26B A4B、31Bを含むGoogleの新しいGemma 4モデルをローカルで実行しましょう。

Gemma 4は、Google DeepMindの新しいオープンモデルファミリーです。以下のモデルが含まれます。 **12B**, **E2B**, **E4B**, **26B-A4B**、および **31B。** マルチモーダル対応のハイブリッド思考モデルで、140以上の言語と最大 **256Kのコンテキスト**に対応し、Dense版とMoE版があります。Gemma 4はApache-2.0ライセンスで提供され、ローカルデバイスで実行できます。

**Gemma-4-12B** は新モデルで、テキスト、画像、音声を統合的にサポートします。 **8GB** のRAM（4-bit）、または14GB（8-bit）で実行できます。 **Gemma-4-E2B** と **E4B** も画像と音声に対応しています。GGUF、MLX、またはNVFP4量子化を使って、 **5GBのRAM** （4-bit）、または15GB（フル16-bit）で実行できます。

<a href="https://unsloth.ai/docs/jp/moderu/gemma-4.md#run-gemma-4-tutorials" class="button primary">Gemma 4を実行</a><a href="https://unsloth.ai/docs/jp/moderu/gemma-4/train.md" class="button secondary">Gemma 4をファインチューニング</a><a href="https://unsloth.ai/docs/jp/moderu/gemma-4/qat.md" class="button primary">Gemma 4 QAT</a><a href="https://unsloth.ai/docs/jp/moderu/mtp.md#gemma-4-mtp" class="button secondary">Gemma 4 MTP</a>

{% hint style="success" %}
**新着：** [**Gemma 4 MTPが登場**](https://unsloth.ai/docs/jp/moderu/mtp.md)**！MTPを使うと、精度を損なわずに推論を1.4～2.2倍高速化できます。MTPは** [**Unsloth Studio**](https://unsloth.ai/docs/jp/moderu/mtp.md#unsloth-studio-mtp-guide)**.**
{% endhint %}

{% columns %}
{% column %}
**Gemma-4-26B-A4B** は、 **18GB** （4-bit）、または28GB（8-bit）で実行できます。 **Gemma-4-31B** には **20GBのRAM** （4-bit）、または34GB（8-bit）が必要です。

すべてのGGUFと [MLX](#mlx-dynamic-quants) を実行できるようになり、Gemma 4のファインチューニングも [Unsloth Studio](#unsloth-studio-guide) で行えます（右図参照）。

[**QAT** 版](https://unsloth.ai/docs/jp/moderu/gemma-4/qat.md) のGemma 4は、モデルの品質を保ちながら、メモリ要件を約3分の1に削減します。
{% 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%2FstfdTMsoBMmsbQsgQ1Ma%2Flandscape%20clip%20gemma.gif?alt=media&amp;token=eec5f2f7-b97a-4c1c-ad01-5a041c3e4013" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% hint style="success" %}
**6月9日：** [Gemma 4 MTP](https://unsloth.ai/docs/jp/moderu/mtp.md) が登場。

**6月5日：** [Gemma 4 QAT](https://unsloth.ai/docs/jp/moderu/gemma-4/qat.md) をリリース。

**6月2日:** Gemma 4 12B Unifiedがリリースされました。

**4月20日:** 実施しました： [Gemma 4 GGUFベンチマーク](#unsloth-gguf-benchmarks) 最適な量子化を選ぶためにご活用ください。
{% endhint %}

### 使い方ガイド

Gemma 4は、推論、コーディング、ツールの使用、長いコンテキストやエージェント型のワークフロー、マルチモーダルタスクに優れています。小型のE2BおよびE4BはスマートフォンやノートPC向けに設計されており、大型モデルはNVIDIA RTX GPU搭載PCなど、中〜高性能のCPU／VRAMシステムを対象としています。

| Gemma 4のバリアント   | 詳細                                                | 最適な用途                           |
| --------------- | ------------------------------------------------- | ------------------------------- |
| **E2B**         | <p>Dense + PLE（コンテキスト長128K）<br>対応: テキスト、画像、音声</p> | スマートフォン／エッジ推論、ASR、音声翻訳向け        |
| **E4B**         | <p>Dense + PLE（コンテキスト長128K）<br>対応: テキスト、画像、音声</p> | ノートPCや高速なローカルマルチモーダル処理に適した小型モデル |
| **12B Unified** | <p>Dense（コンテキスト長256K）<br>対応: テキスト、画像、音声</p>       | ノートPCやローカルマルチモーダル処理向けの中型モデル     |
| **26B-A4B**     | <p>MoE（コンテキスト長256K）<br>対応: テキスト、画像</p>            | コンピューター操作における速度と品質の最適なバランス      |
| **31B**         | <p>Dense（コンテキスト長256K）<br>対応: テキスト、画像</p>          | 推論速度は遅めですが、最高の性能を発揮             |

**Gemma 4の詳細:** [**性能ベンチマーク**](#official-gemma-benchmarks) **および** [**GGUFベンチマーク**](#unsloth-gguf-benchmarks)**.**

**26B-A4Bと31Bのどちらを選ぶべきですか？**

* **26B-A4B** は速度と精度のバランスに優れています。MoE設計により、アクティブパラメーターは4Bで、31Bより高速です。RAMに制約があり、速度を優先して多少の品質低下を許容できる場合に選びましょう。
* **31B** は、現時点で最も高性能なGemma 4モデルです。十分なメモリがあり、多少速度が遅くても最大限の品質を求める場合に選びましょう。

### ハードウェア要件

**表: Gemma 4推論に推奨されるGGUFのハードウェア要件** （単位は総メモリ容量: RAM + VRAM、またはユニファイドメモリ）。Gemma 4はmacOS、NVIDIA RTX GPUなどで使用できます。

| Gemma 4のバリアント   |     4ビット |     8ビット | BF16 / FP16 |
| --------------- | -------: | -------: | ----------: |
| **E2B**         |     4 GB |   5～8 GB |       10 GB |
| **E4B**         | 5.5～6 GB |  9～12 GB |       16 GB |
| **12B Unified** |   7～8 GB | 13～14 GB |       25 GB |
| **26B A4B**     | 16～18 GB | 28～30 GB |       52 GB |
| **31B**         | 17～20 GB | 34～38 GB |       62 GB |

{% hint style="info" %}
目安として、利用可能なメモリの合計は、ダウンロードする量子化モデルのサイズを少なくとも上回っている必要があります。満たない場合でも、llama.cpp はRAMの一部を使用したり、ディスクにオフロードしたりして実行できますが、生成速度は遅くなります。また、使用するコンテキストウィンドウによっては、より多くの計算リソースが必要になります。
{% endhint %}

### 推奨設定

Googleが推奨するデフォルトのGemma 4パラメータを使用することをおすすめします。

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

{% hint style="info" %}
Gemma 4の最大コンテキスト長は **128K** です（ **E2B** / **E4B** および `262,144` です（ **12B** / **26B A4B** / **31B**.
{% endhint %}

#### のモデル）。

以前のGemmaチャットテンプレートと異なり、Gemma 4では標準の **`system`**, **`assistant`**、および **`user`** ロールを使用し、思考を明示的に制御する機能が追加されています。

**思考を有効にする方法：**

トークン **`<|think|>`** をシステムプロンプトの **先頭に**.

{% columns %}
{% column %}
**思考を有効にする**

```
<|think|>
あなたは慎重なコーディングアシスタントです。回答を明確に説明してください。
```

{% endcolumn %}

{% column %}
**思考を無効にする**

```
あなたは慎重なコーディングアシスタントです。回答を明確に説明してください。
```

{% endcolumn %}
{% endcolumns %}

**出力の動作：**

{% columns %}
{% column %}
思考が有効な場合、モデルは最終回答の前に内部推論チャネルを出力します。

```
<|channel>thought
[内部推論]
<channel|>
[最終回答]
```

{% endcolumn %}

{% column %}
思考が無効な場合でも、大きなモデルは最終回答の前に **空の思考ブロック** を出力することがあります。

```
<|channel>thought
<channel|>
[最終回答]
```

{% endcolumn %}
{% endcolumns %}

**たとえば、「**&#x30D5;ランスの首都はどこですか？」を使う場合：

{% code overflow="wrap" %}

```
<bos><|turn>system\n<|think|><turn|>\n<|turn>user\nWhat is the capital of France?<turn|>\n<|turn>model\n
```

{% endcode %}

**その後、次のように出力されます：**

{% code overflow="wrap" %}

```
<|channel>thought\nThe user is asking for the capital of France.\nThe capital of France is Paris.<channel|>The capital of France is Paris.<turn|>
```

{% endcode %}

**複数ターンのチャットに関するルール：**

複数ターンの会話では、 **チャット履歴には、ユーザーに表示する最終回答のみを残してください**。次のようにしないでください **しない** 前の思考ブロックを次のターンに再入力しないでください。

{% code overflow="wrap" %}

```
<bos><|turn>user\nWhat is 1+1?<turn|>\n<|turn>model\n2<turn|>\n<|turn>user\nWhat is 1+1?<turn|>\n<|turn>model\n2<turn|>\n<|turn>user\nWhat is 1+1?<turn|>\n<|turn>model\n2<turn|>\n<|turn>user\nWhat is 1+1?<turn|>\n<|turn>model\n2<turn|>\n
```

{% endcode %}

**思考を無効にする方法：**

注 `llama-cli` 安定して動作しない場合があるため、推論を無効にするには `llama-server` を使用してください：

{% 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 %}

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

Gemma 4のGGUFは複数のサイズがあるため、小型モデルでは8ビット、大型モデルでは次の形式から始めることをおすすめします。 [**Dynamic**](https://unsloth.ai/docs/jp/ji-chu/dynamic-3.0-ggufs.md) **4ビット**. [Gemma 4 GGUF](https://huggingface.co/collections/unsloth/gemma-4) または [MLX](#mlx-dynamic-quants) または [NVFP4](#nvfp4-guide):

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

<a href="https://unsloth.ai/docs/jp/moderu/gemma-4.md#unsloth-studio-guide" class="button primary">🦥 Unsloth Desktop ガイド</a><a href="https://unsloth.ai/pages/693bc7a2f22dcaf0c6bc0818f2076196fe331fa7#llama.cpp-guide" class="button primary">🦙 Llama.cppガイド</a><a href="https://unsloth.ai/docs/jp/moderu/gemma-4.md#nvfp4-guide" class="button primary">NVFP4 ガイド</a>

{% columns %}
{% column %}
**無料でGemma 4を実行・学習できるUIを、** [**Unsloth Studio**](https://unsloth.ai/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 ガイド

Gemma 4を、ローカルAI向けの新しいオープンソースデスクトップUIである [Unsloth Desktop](https://unsloth.ai/docs/jp/shii/studio.md)で実行し、ファインチューニングできるようになりました。Unsloth Studioを使うと、モデルをローカルで以下の環境上で実行できます。 **MacOS、Windows**、Linux：

{% columns %}
{% column %}

* 検索、ダウンロード、 [GGUF の実行](https://unsloth.ai/docs/jp/shii/studio.md#run-models-locally) および safetensors モデルの実行
* [**自己修復機能付き** ツール呼び出し](https://unsloth.ai/docs/jp/shii/studio.md#execute-code--heal-tool-calling) + **ウェブ検索**
* [**コード実行**](https://unsloth.ai/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 の学習](https://unsloth.ai/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%2FpAGvwjGD0iVMZKBoyu7m%2Fgreeennn.png?alt=media&amp;token=d17a5528-8375-444c-9aff-f9e9f7903bcd" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}

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

最も簡単に始めるには、 [Unsloth Desktop アプリ](https://unsloth.ai/docs/jp/desktop.md)をダウンロードしてください。対応環境： [macOS](https://unsloth.ai/docs/jp/meru/install/mac.md), [Windows](https://unsloth.ai/docs/jp/meru/install/windows-installation.md)、 [Linux](https://unsloth.ai/docs/jp/meru/install/linux.md).

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">Unslothをダウンロード</a>

* <i class="fa-apple">:apple:</i> [macOS版をダウンロード](https://unsloth.ai/download/mac)
* <i class="fa-windows">:windows:</i> [Windows版をダウンロード](https://unsloth.ai/download/windows)
* <i class="fa-linux">:linux:</i> [Linux版をダウンロード](https://unsloth.ai/download/linux)

または、手動でインストールする場合：

**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を開きます。

**HTTPS と Cloudflare を使って Unsloth を安全に起動する**

**新機能！** Unsloth では、無料の Cloudflare トンネルを介して HTTPS で安全に起動できるようになりました。以下のコマンドを使用してください（Windows、Mac、Linux で動作します）：

```bash
unsloth studio --secure
```

{% endstep %}

{% step %}

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

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

次に、 [Unsloth Chat](https://unsloth.ai/docs/jp/shii/studio/chat.md) タブを開き、検索バーでGemma 4を検索して、必要なモデルと量子化形式をダウンロードします。Unslothは最新のGemma-4-12B Unifiedモデルに対応しています。

<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%2FpYoNILI8NFMl8QaQlc7V%2FScreenshot%202026-04-02%20at%2010.37.32%E2%80%AFPM.png?alt=media&amp;token=18d5918e-4f71-4e0e-b8c9-464097389835" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### Gemma 4を実行

Unsloth Studioを使用する場合、推論パラメータは自動的に設定されますが、手動で変更することもできます。コンテキスト長、チャットテンプレート、その他の設定も編集できます。GGUFファイルとMLXファイルを実行できます。

詳しくは、 [Unsloth Studioの推論ガイド](https://unsloth.ai/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ガイド

このガイドでは、12B、26B-A4B、31BにはDynamic 4-bitを、E2BとE4Bには8-bitを使用します。詳細： [Gemma 4 GGUFコレクション](https://huggingface.co/collections/unsloth/gemma-4)

これらのチュートリアルでは、 [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` を使用します。llama.cpp は必要な分だけを自動的に正確に使用するため、コンテキスト長を設定する必要はありません。

{% 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 %}

**12B:**

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

**26B-A4B:**

```bash
export LLAMA_CACHE="unsloth/gemma-4-26B-A4B-it-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-26B-A4B-it-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-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-31B-it-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-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/gemma-4-E4B-it-GGUF:Q8_0 \
    --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-GGUF:Q8_0 \
    --temp 1.0 \
    --top-p 0.95 \
    --top-k 64
```

{% endstep %}

{% step %}
次のコードを使ってモデルを手動でダウンロードすることもできます（ `pip install huggingface_hub`をインストールした後）。 `UD-Q4_K_XL` または `Q8_0` など、ほかの量子化バージョンを選択できます。ダウンロードが停止する場合は、こちらをご覧ください。 [Hugging Face Hub、XET のデバッグ](https://unsloth.ai/docs/jp/ji-chu/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
hf download unsloth/gemma-4-26B-A4B-it-GGUF \
    --local-dir unsloth/gemma-4-26B-A4B-it-GGUF \
    --include "*mmproj-BF16*" \
    --include "*UD-Q4_K_XL*" # 動的2ビット量子化には "*UD-Q2_K_XL*" を使用
```

{% endstep %}

{% step %}
次に、会話モードでモデルを実行します（ビジョン機能では `mmproj-F16`):

{% code overflow="wrap" %}

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

{% endstep %}
{% endstepper %}

### MLX Dynamic Quants

MacOSデバイス向けの初回トライアルとして、Dynamic 4bitおよび8bit量子化モデルもアップロードしました。MLX量子化モデルは **ビジョンに対応しています。**

{% hint style="success" %}
すべてのMLX量子化モデルが[ Unsloth Studio](#unsloth-studio-guide)!
{% endhint %}

| Gemma 4 | 4-bit MLX                                                            | 8-bit MLX                                                         |
| ------- | -------------------------------------------------------------------- | ----------------------------------------------------------------- |
| 31B     | [リンク](https://huggingface.co/unsloth/gemma-4-31b-it-UD-MLX-4bit)     | [リンク](https://huggingface.co/unsloth/gemma-4-31b-it-MLX-8bit)     |
| 26B-A4B | [リンク](https://huggingface.co/unsloth/gemma-4-26b-a4b-it-UD-MLX-4bit) | [リンク](https://huggingface.co/unsloth/gemma-4-26b-a4b-it-MLX-8bit) |
| E4B     | [リンク](https://huggingface.co/unsloth/gemma-4-E4B-it-UD-MLX-4bit)     | [リンク](https://huggingface.co/unsloth/gemma-4-E4B-it-MLX-8bit)     |
| E2B     | [リンク](https://huggingface.co/unsloth/gemma-4-E2B-it-UD-MLX-4bit)     | [リンク](https://huggingface.co/unsloth/gemma-4-E2B-it-MLX-8bit)     |

試すには、次のコマンドを実行します：

{% code overflow="wrap" %}

```bash
curl -fsSL https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/scripts/install_gemma4_mlx.sh | sh
source ~/.unsloth/unsloth_gemma4_mlx/bin/activate
python -m mlx_vlm.chat --model unsloth/gemma-4-26b-a4b-it-UD-MLX-4bit
```

{% endcode %}

### **NVFP4 ガイド**

以下をアップロードしました： [Dynamic NVFP4](https://unsloth.ai/docs/jp/ji-chu/nvfp4.md) NVIDIA Blackwell GPUで4-bit推論を高速化するGemma 4用Dynamic NVFP4量子化モデルです。Gemma 4を含む各モデルのハードウェア要件は以下のとおりです。また、全体的な速度向上もご確認ください。

| Gemma 4のバリアント                                                      | 必要なVRAM | BF16より高速 |
| ------------------------------------------------------------------ | ------: | -------: |
| [E2B](https://huggingface.co/unsloth/gemma-4-E2B-it-NVFP4)         |    7 GB |  1.12倍高速 |
| [E4B](https://huggingface.co/unsloth/gemma-4-E4B-it-NVFP4)         |    9 GB |  1.22倍高速 |
| [12B Unified](https://huggingface.co/unsloth/gemma-4-12b-it-NVFP4) |   11 GB |  1.26倍高速 |
| [26B A4B](https://huggingface.co/unsloth/gemma-4-26B-A4B-it-NVFP4) |   26 GB |  1.41倍高速 |
| [31B](https://huggingface.co/unsloth/gemma-4-31B-it-NVFP4)         |   32 GB |  1.45倍高速 |

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FZw91MhTauyOZGP5HT7bl%2Fimage.png?alt=media&amp;token=ae0051a9-af39-4ef7-8ed2-9f8c1fff33fc" alt="" width="563"><figcaption></figcaption></figure>

#### **vLLMチュートリアル：**

NVFP4量子化モデルを実行するには、以下のコマンドでGemma-4-26B-A4Bを [vLLM](https://unsloth.ai/docs/jp/ji-chu/inference-and-deployment/vllm-guide.md) または [SGLang](https://unsloth.ai/docs/jp/ji-chu/inference-and-deployment/sglang-guide.md) で実行できます（モデル名は `gemma-4-31B-it-NVFP4` などに変更できます）。また、MoEバックエンドは選択しないでください。vLLMに選択させます。たとえば、Marlinは2.5倍遅くなります。詳しくは [#marlin-vs-flashinfer-vs-cutlass-vs-cute-dsl](#marlin-vs-flashinfer-vs-cutlass-vs-cute-dsl "mention")DGX Sparkをお使いの場合は、こちらをご覧ください： [#dgx-spark-serving](#dgx-spark-serving "mention") 次を使用する必要があります： `--moe-backend flashinfer_b12x` 使用しないと、推論が大幅に遅くなります。

vLLMを別のvenvにインストールするには、次のようにします。

{% code overflow="wrap" expandable="true" %}

```bash
uv venv unsloth-nvfp4-env --python 3.13
source unsloth-nvfp4-env/bin/activate
uv pip install "vllm>=0.25.0" "flashinfer-python>=0.6.13" "nvidia-cutlass-dsl>=4.5.2" \
    --torch-backend=auto
```

{% endcode %}

次に、26B MoEバリアントをサービングするには：

```shell
vllm serve unsloth/gemma-4-26B-A4B-it-NVFP4
```

以下を `unsloth/gemma-4-26B-A4B-it-NVFP4` 任意の [利用可能なNVFP4](https://unsloth.ai/docs/jp/ji-chu/nvfp4.md#overview) 量子化モデル名に変更してください。

MTP（投機的デコード）を有効にするには、次のようにします（デコードは高速になりますが、スループットは多少低下します）。

```bash
vllm serve unsloth/gemma-4-26B-A4B-it-NVFP4
    --speculative-config '{"method": "mtp", "num_speculative_tokens": 2}'
```

Torchcodec関連の問題が発生した場合は、以下を実行してからvLLMを再起動してください。

{% code overflow="wrap" expandable="true" %}

```bash
sudo apt-get update
sudo apt-get install -y ffmpeg
```

{% endcode %}

#### **NVFP4量子化モデルを使ったDGX Spark**

DGX Sparkで正しいカーネルが使われるようにするには（そうしないと、推論が **2倍遅く**なります）、まず次の点を確認してください。

{% code overflow="wrap" expandable="true" %}

```bash
python -c "
import torch; from vllm.utils.flashinfer import has_flashinfer_b12x_gemm as g, has_flashinfer_b12x_moe as m
cap = torch.cuda.get_device_capability(); print('cap', cap, '| b12x gemm', g(), '| b12x moe', m()); assert cap[0] == 12 and g() and m(), 'b12x unavailable: serving would degrade to marlin W4A16'"
```

{% endcode %}

エラーが発生しないはずです。エラーが発生した場合は、vLLMを更新するか、次の方法で再インストールしてください。

{% code overflow="wrap" expandable="true" %}

```bash
uv venv unsloth-nvfp4-env --python 3.13
source unsloth-nvfp4-env/bin/activate
uv pip install "vllm>=0.25.0" "flashinfer-python>=0.6.13" "nvidia-cutlass-dsl>=4.5.2" \
    --torch-backend=auto
```

{% endcode %}

次に、DGX SparkでvLLMを使ってサービングするには、以下を実行します。

{% code overflow="wrap" expandable="true" %}

```shellscript
export CUTE_DSL_ARCH=sm_121a
vllm serve unsloth/gemma-4-26B-A4B-it-NVFP4 --moe-backend flashinfer_b12x
```

{% endcode %}

Torchcodec関連の問題が発生した場合は、以下を実行してからvLLMを再起動してください。

{% code overflow="wrap" expandable="true" %}

```bash
sudo apt-get update
sudo apt-get install -y ffmpeg
```

{% endcode %}

#### **SGLangチュートリアル：**

```bash
python -m sglang.launch_server --model-path unsloth/gemma-4-31B-it-NVFP4 --speculative-algorithm NEXTN \
     --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4
```

### Ollamaガイド

OllamaはUnsloth GGUFを適切にサポートするようになりました。次を使用してください： `curl -fsSL https://ollama.com/install.sh | sh` を使って Linux に Ollama をインストールするか、 `irm https://ollama.com/install.ps1 | iex` を使って Windows にインストールします。\
\
単一の量子化ファイル（50 GB 未満）を使うには、次のコマンドを実行します。

{% code overflow="wrap" %}

```bash
ollama run hf.co/unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL
```

{% endcode %}

大きな BF16 シャードのように複数のシャードがある場合は、次のようにします。

{% code overflow="wrap" %}

```bash
pip install -U huggingface_hub

# mmproj と BF16 を2回の呼び出しでダウンロード
hf download unsloth/gemma-4-26B-A4B-it-GGUF --include "BF16/*" \
    --local-dir gemma4
hf download unsloth/gemma-4-26B-A4B-it-GGUF --include "mmproj-BF16.gguf" \
    --local-dir gemma4

mv gemma4/mmproj-BF16.gguf gemma4/BF16/
echo "FROM ./gemma4/BF16" > Modelfile

ollama create unsloth-gemma4 -f Modelfile
ollama run unsloth-gemma4
```

{% endcode %}

<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%2FjflAyMZg9ZaSmeUL7LlQ%2Fimage.png?alt=media&amp;token=ddda55e7-0526-4fe0-99bc-d0cb4d05f7fa" alt="" width="563"><figcaption></figcaption></figure></div>

{% hint style="info" %}
次のエラーが表示される場合は `Error: 500 Internal Server Error: unable to load model` 次のコマンドで Ollama を更新するか、 `curl -fsSL https://ollama.com/install.sh | sh` PowerShell 用のコマンドを使用してください。
{% endhint %}

## Gemma 4 のベストプラクティス

### プロンプトの例

#### シンプルな推論プロンプト

```
システム:
<|think|>
あなたは、正確な推論を行うアシスタントです。

ユーザー:
列車が午前8時15分に出発し、午前11時47分に到着しました。所要時間はどれくらいですか？
```

#### OCR／ドキュメント用プロンプト

OCR では、 **視覚トークンの予算を大きく** するために、たとえば **560** を使用するか、 **1120**.

```
[最初に画像]
この領収書からすべてのテキストを抽出してください。明細、合計金額、店舗名、日付を JSON で返してください。
```

#### マルチモーダル比較プロンプト

```
[画像1]
[画像2]
この2つのスクリーンショットを比較し、新規ユーザーが混乱しやすいのはどちらか教えてください。
```

#### 音声ASR用プロンプト

```
次の音声セグメントを {LANGUAGE} で文字起こしし、{LANGUAGE} のテキストにしてください。

回答の形式について、次の指示に従ってください。
* 文字起こしのみを出力し、改行は入れないでください。
* 数字を文字起こしするときは、数字で表記してください。たとえば、one point seven ではなく 1.7、three ではなく 3 と記述してください。
```

#### 音声翻訳用プロンプト

```
次の音声セグメントを {SOURCE_LANGUAGE} で文字起こししてから、{TARGET_LANGUAGE} に翻訳してください。回答は、まず {SOURCE_LANGUAGE} の文字起こしを出力し、次に改行を1つ入れ、その後に文字列 '{TARGET_LANGUAGE}: ' を出力し、最後に {TARGET_LANGUAGE} の翻訳を出力してください。
```

### マルチモーダル設定

マルチモーダルプロンプトで最良の結果を得るには、マルチモーダルコンテンツを先頭に配置してください。

* 画像や音声を **テキストより前に配置してください。**.
* 動画の場合は、まずフレームのシーケンスを渡し、その後に指示を渡してください。

#### 音声と動画の制限

* **音声** で利用できます **12B**, **E2B** および **E4B** のみ。
* 音声は最大 **30秒**.
* 動画は最大 **60秒** 処理が **1秒あたり1フレーム** の場合。

#### 音声プロンプトテンプレート

**ASRプロンプト**

```
次の音声セグメントを {LANGUAGE} で文字起こしし、{LANGUAGE} のテキストにしてください。

回答の形式について、次の指示に従ってください。
* 文字起こしのみを出力し、改行は入れないでください。
* 数字を文字起こしするときは、数字で表記してください。たとえば、one point seven ではなく 1.7、three ではなく 3 と記述してください。
```

**音声翻訳プロンプト**

```
次の音声セグメントを{SOURCE_LANGUAGE}で書き起こし、その後{TARGET_LANGUAGE}に翻訳してください。
回答は、まず{SOURCE_LANGUAGE}での書き起こしを出力し、次に改行を1つ入れ、続けて「{TARGET_LANGUAGE}: 」という文字列を出力してから、{TARGET_LANGUAGE}で翻訳を出力してください。
```

## 📊 ベンチマーク

### Unsloth GGUFのベンチマーク

最適な量子化を選べるよう、プロバイダーごとにGemma 4 GGUFの平均KLダイバージェンスをベンチマークしました（値が小さいほど優れています）。

* UnslothのすべてのGGUFがKLダイバージェンスでSOTAパレートフロンティアに位置
* KLDは、量子化モデルが元のBF16の出力分布にどれだけ近いかを示し、精度がどの程度維持されているかを表します。

<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%2F8y2cQ4VFqGEJLBS8PKZV%2Fgemma%20426b%20bench.lossless.webp?alt=media" alt=""><figcaption><p>26B A4B - KLDベンチマーク（値が小さいほど優れています）</p></figcaption></figure></div>

### Gemma公式ベンチマーク

**テキスト／コードのベンチマーク**

| ベンチマーク              | Gemma 4 31B | Gemma 4 26B A4B | Gemma 4 12B Unified | Gemma 4 E4B | Gemma 4 E2B | Gemma 3 27B（思考なし） |
| ------------------- | ----------- | --------------- | ------------------- | ----------- | ----------- | ----------------- |
| MMLU Pro            | 85.2%       | 82.6%           | 77.2%               | 69.4%       | 60.0%       | 67.6%             |
| AIME 2026（ツールなし）    | 89.2%       | 88.3%           | 77.5%               | 42.5%       | 37.5%       | 20.8%             |
| LiveCodeBench v6    | 80.0%       | 77.1%           | 72.0%               | 52.0%       | 44.0%       | 29.1%             |
| Codeforces ELO      | 2150        | 1718            | 1659                | 940         | 633         | 110               |
| GPQA Diamond        | 84.3%       | 82.3%           | 78.8%               | 58.6%       | 43.4%       | 42.4%             |
| Tau2                | 76.9%       | 68.2%           | 69.0%               | 42.2%       | 24.5%       | 16.2%             |
| HLE（ツールなし）          | 19.5%       | 8.7%            | 5.2%                | -           | -           | -                 |
| HLE（検索あり）           | 26.5%       | 17.2%           | -                   | -           | -           | -                 |
| BigBench Extra Hard | 74.4%       | 64.8%           | 53.0%               | 33.1%       | 21.9%       | 19.3%             |
| MMMLU               | 88.4%       | 86.3%           | 83.4%               | 76.6%       | 67.4%       | 70.7%             |

**ビジョンベンチマーク**

| MMMU Pro                        | 76.9% | 73.8% | 69.1% | 52.6% | 44.2% | 49.7% |
| ------------------------------- | ----- | ----- | ----- | ----- | ----- | ----- |
| OmniDocBench 1.5（値が小さいほど優れています） | 0.131 | 0.149 | 0.164 | 0.181 | 0.290 | 0.365 |
| MATH-Vision                     | 85.6% | 82.4% | 79.7% | 59.5% | 52.4% | 46.0% |
| MedXPertQA MM                   | 61.3% | 58.1% | 48.7% | 28.7% | 23.5% | -     |

**音声ベンチマーク**

| CoVoST                    | -     | -     | 38.5<sup>\*</sup>  | 35.54 | 33.47 | -     |
| ------------------------- | ----- | ----- | ------------------ | ----- | ----- | ----- |
| FLEURS（値が小さいほど優れています）     | -     | -     | 0.069<sup>\*</sup> | 0.08  | 0.09  | -     |
| **長文コンテキスト**              |       |       |                    |       |       |       |
| MRCR v2 8 needle 128k（平均） | 66.4% | 44.1% | 43.4%              | 25.4% | 19.1% | 13.5% |

<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%2FfKaFMy7LHQYNKpfsf7Zy%2Fgemma%204%20banner.png?alt=media&amp;token=8bd8d0e0-ccb6-4ded-b99b-2c8a18370ae5" alt=""><figcaption></figcaption></figure></div>


---

# 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.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.
