> 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 - ローカルでの実行方法

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ビット）または14GB（8ビット）が必要です。 **Gemma-4-E2B** および **E4B** は画像と音声もサポートします。動作には **5GB RAM** （4ビット）または15GB（フル16ビット）。GGUF、MLX、またはNVFP4の量子化で利用できます。

<a href="/pages/693bc7a2f22dcaf0c6bc0818f2076196fe331fa7#run-gemma-4-tutorials" class="button primary">Gemma 4 を実行する</a><a href="/pages/4a6e7bbec569d341f876db55593564610de4d0a8" class="button secondary">Gemma 4 をファインチューニングする</a><a href="/pages/136e446d64d842f3384bec65ba2ec312454e6e91" class="button primary">Gemma 4 QAT</a><a href="/pages/dd5bb70bca754ea9bde116b50d92614a5ee10c37#gemma-4-mtp" class="button secondary">Gemma 4 MTP</a>

{% hint style="success" %}
**新登場:** [**Gemma 4 MTP が登場しました**](/docs/jp/moderu/mtp.md)**! MTP により、精度を落とさずに 1.4～2.2 倍高速な推論が可能になります。MTP を直接実行できます。** [**Unsloth Studio**](/docs/jp/moderu/mtp.md#unsloth-studio-mtp-guide)**.**
{% endhint %}

{% columns %}
{% column %}
**Gemma-4-26B-A4B** 動作には **18GB** （4ビット）または28GB（8ビット）が必要です。 **Gemma-4-31B** 必要です **20GB RAM** （4ビット）または34GB（8ビット）が必要です。

これで、すべての GGUF を実行でき、 [MLX](#mlx-dynamic-quants) および Gemma 4 をファインチューニングできます。 [Unsloth Studio](#unsloth-studio-guide) （右を参照）。

[**QAT** 各バリアント](/docs/jp/moderu/gemma-4/qat.md) の Gemma 4 は、モデル品質を保ちながらメモリ要件を約3分の1に削減します。
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/52ac81606e9a31b3f691aabcec5c0ad84f45aee2" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

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

**6月5日:** [Gemma 4 QAT](/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>            | PC利用で速度と品質のバランスが最良                 |
| **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\nフランスの首都はどこですか？<turn|>\n<|turn>model\n
```

{% endcode %}

**すると次のように出力されます:**

{% code overflow="wrap" %}

```
<|channel>thought\nユーザーはフランスの首都を尋ねています。\nフランスの首都はパリです。<channel|>フランスの首都はパリです。<turn|>
```

{% endcode %}

**マルチターン会話のルール:**

マルチターン会話では、 **チャット履歴には最終的に表示された回答のみを残します**。 **しない** 前の思考ブロックを次のターンに戻さないでください。

{% code overflow="wrap" %}

```
<bos><|turn>user\n1+1は何ですか？<turn|>\n<|turn>model\n2<turn|>\n<|turn>user\n1+1は何ですか？<turn|>\n<|turn>model\n2<turn|>\n<|turn>user\n1+1は何ですか？<turn|>\n<|turn>model\n2<turn|>\n<|turn>user\n1+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**](/docs/jp/ji-ben/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="/pages/693bc7a2f22dcaf0c6bc0818f2076196fe331fa7#unsloth-studio-guide" class="button primary">🦥 Unsloth Desktop ガイド</a><a href="/pages/693bc7a2f22dcaf0c6bc0818f2076196fe331fa7#llama.cpp-guide" class="button primary">🦙 Llama.cpp ガイド</a><a href="/pages/693bc7a2f22dcaf0c6bc0818f2076196fe331fa7#nvfp4-guide" class="button primary">NVFP4 ガイド</a>

{% columns %}
{% column %}
**Gemma 4 は、UI 付きで無料で実行・学習できます。** [**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 ガイド

Gemma 4 は現在、以下で実行およびファインチューニングできます: [Unsloth Desktop](/docs/jp/shii/studio.md)は、ローカルAI向けの新しいオープンソースデスクトップ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) + **ウェブ検索**
* [**コード実行**](/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="/files/e80de67ed3ea23603ff90d3a5750d20c31d2e56d" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}

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

始める最も簡単な方法は、以下をダウンロードすることです: [Unsloth Desktop アプリ](/docs/jp/desktop.md)。対応: [macOS](/docs/jp/meru/install/mac.md), [Windows](/docs/jp/meru/install/windows-installation.md)、および [Linux](/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](/docs/jp/shii/studio/chat.md) タブへ移動し、検索バーで Gemma 4 を検索して、希望するモデルと量子化をダウンロードしてください。Unsloth は最新の Gemma-4-12B Unified モデルをサポートしています。

<div data-with-frame="true"><figure><img src="/files/5ce0cbbf8496663435148cc3eb0a7f192d13179d" alt="" width="375"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### Gemma 4 を実行する

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

詳細については、以下をご覧ください: [Unsloth Studio 推論ガイド](/docs/jp/shii/studio/chat.md).

<div data-with-frame="true"><figure><img src="/files/15781d66f25558946794c4025a5ece324f0db186" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### 🦙 Llama.cpp ガイド

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

これらのチュートリアルでは、 [llama.cpp](llama.cpphttps://github.com/ggml-org/llama.cpp) 高速なローカル推論に 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デバッグ](/docs/jp/ji-ben/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*" # 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-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 動的量子化

MacOS デバイス向けの最初の試みとして、動的 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 ガイド**

アップロードしました [動的 NVFP4](/docs/jp/ji-ben/nvfp4.md) NVIDIA Blackwell GPU でより高速な 4-bit 推論を行うための Gemma 4 量子化版です。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="/files/4be465fbffe804dae8002ce19bdbfa30382add76" alt="" width="563"><figcaption></figcaption></figure>

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

NVFP4 量子化版を実行するには、以下の Gemma-4-26B-A4B の実行コマンドを参照してください [vLLM](/docs/jp/ji-ben/inference-and-deployment/vllm-guide.md) および [SGLang](/docs/jp/ji-ben/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` さもないと、推論がかなり遅くなります。

別の venv に 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 %}

次に 26B MoE 版を提供するには:

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

変更してください `unsloth/gemma-4-26B-A4B-it-NVFP4` 任意の [利用可能な NVFP4](/docs/jp/ji-ben/nvfp4.md#overview) 量子化名に！

MTP / speculative decoding（より高速なデコードですが、スループットはやや低下）を有効にするには、次を使用してください:

```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 の場合です。\
\
1つの量子化ファイル（50GB 未満）を使うには:

{% 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="/files/0761a140fbaca6784e4d35032c20a60ea20bd865" 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**.

```
[image first]
このレシートからすべてのテキストを抽出してください。明細、合計、店舗名、日付を JSON で返してください。
```

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

```
[image 1]
[image 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 ダイバージェンスのベンチマークを実施しました（低いほど良い）。

* KL ダイバージェンスは、量子化モデルが元の BF16 出力分布にどれだけ一致しているかを示し、保持された精度を表します。
* KLD は、量子化モデルが元の BF16 出力分布にどれだけ一致しているかを示し、保持された精度を示します。

<div data-with-frame="true"><figure><img src="/files/d265501d0f0774cfc0fc76a1d11f9ff5179a6a94" 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（think なし） |
| ------------------- | ----------- | --------------- | ------------------- | ----------- | ----------- | --------------------- |
| 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="/files/2f05e915ec04ec487a14a8f018a782370af74f57" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
