> 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/tutorials/glm-4.6-how-to-run-locally.md).

# GLM-4.6: ローカル実行ガイド

Z.aiのGLM-4.6およびGLM-4.6V-Flashモデルを自分のローカルデバイスで実行する方法のガイド！

GLM-4.6 と **GLM-4.6V-Flash** 最新の推論モデルです **Z.ai**、コーディングおよびエージェントのベンチマークでSOTA性能を達成しつつ、より改善された会話チャットも提供します。 [**GLM-4.6V-Flash**](#glm-4.6v-flash) **より小さい9Bモデルは2025年12月に公開され、今すぐ実行することもできます。**

フル版の355Bパラメータモデルには **400GB** のディスク容量が必要ですが、Unsloth Dynamic 2-bit GGUF ではサイズが **135GB** (-**75%)**. [**GLM-4.6-GGUF**](https://huggingface.co/unsloth/GLM-4.6-GGUF)

{% hint style="success" %}
最高の性能のために、利用可能な総メモリ（VRAM + システム RAM）が、ダウンロードする量子化済みモデルファイルのサイズを上回っていることを確認してください。そうでなくても、llama.cpp は SSD/HDD オフロード経由で実行できますが、推論は遅くなります。
{% endhint %}

すべてのアップロードは Unsloth の [Dynamic 2.0](/docs/jp/ji-chu/dynamic-3.0-ggufs.md) を使用して、SOTAの5-shot MMLU と Aider の性能を実現しています。つまり、精度の損失を最小限に抑えたまま、量子化された GLM LLM を実行・ファインチューニングできます。

**チュートリアルナビゲーション:**

<a href="#glm-4.6v-flash" class="button secondary">GLM-4.6V-Flash を実行</a><a href="#glm-4.6" class="button secondary">GLM-4.6 を実行</a>

### :bug:Unslothのチャットテンプレートとバグ修正

私たちが行った重要な修正の1つは、GGUF のプロンプト処理に関する問題への対処です。ここでは2回目のプロンプトが動作しないことがありました。この問題は修正しましたが、私たちの修正がない GGUF では依然としてこの問題が残っています。たとえば、Unsloth 版ではない GLM-4.6 GGUF を使うと、1回目の会話は問題なく動きますが、2回目は壊れます。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-f1a25a7b2dbbabd5d04d079ae4dcf352bc326964%2Ftool-calling-on-glm-4-6-with-unsloths-ggufs-v0-oys0k2088nuf1.webp?alt=media" alt="" width="563"><figcaption></figcaption></figure>

これはチャットテンプレートで解決したため、私たちの版を使うと、2回目以降（3回目、4回目など）の会話もエラーなく動作します。ツール呼び出しにはまだいくつか問題があり、帯域の制限のため、まだ十分に調査できていません。これらの残りの問題については、すでに GLM チームに伝えています。

### :mag\_right:GLM 4.6V Flash の癖と修正

{% hint style="info" %}
GLM-4.6V-Flash は、中国語で推論し、中国語で出力する場合があります。これは私たちの量子化版に特有のものではなく、モデル側の癖です。推論と出力を英語に強制するには、システムプロンプトに「英語で応答し、英語で推論してください」と指定してください！
{% endhint %}

他の量子化プロバイダの BF16 および Q8\_0 の量子化版もテストしましたが、どれも中国語で推論しているようです。たとえば、seed 3407 の2つの別々の量子化版で、同じプロンプト「PythonでFlappy Birdゲームを作成して」を与えると、中国語での推論が表示されます：

{% columns %}
{% column %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FiQxOQlwJSuun6suWO5KR%2Fimage.png?alt=media&amp;token=f9228737-46ae-4077-825e-cff965003b20" alt=""><figcaption></figcaption></figure>
{% endcolumn %}

{% column %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FhhQ4dOjfqBHtSOkL4Ldg%2Fimage.png?alt=media&amp;token=a6cd50fe-179a-44c2-a31d-987e78901985" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

「英語で推論する」というシステムプロンプトを使うことで、 `--system-prompt "英語で応答してください"` llama.cpp では、たとえば次のように:

```bash
./llama.cpp/llama-cli -hf unsloth/GLM-4.6V-Flash-GGUF:BF16 \
    --jinja --temp 0.8 --top-p 0.6 --top-k 2 --repeat-penalty 1.1 --min-p 0.0 --seed 3407 \
    --prompt "PythonでFlappy Birdゲームを作成して" --system-prompt "英語で応答してください"
```

推論は中国語ですが、出力は英語です。さらに続けて「1+1 はいくつ？」と尋ねると、英語のみが返ってきます：

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FIhIYFR5tIDa3Dc3FyURO%2Fimage.png?alt=media&amp;token=d79b38d0-a1c8-4c29-bd5a-116a39d9e85a" alt="" width="375"><figcaption></figcaption></figure>

そして最後に、「英語で応答し、英語で推論する」というシステムプロンプトを使うことで、 `--system-prompt "英語で応答し、英語で推論してください"` llama.cpp では、たとえば次のように:

```bash
./llama.cpp/llama-cli -hf unsloth/GLM-4.6V-Flash-GGUF:BF16 \
    --jinja --temp 0.8 --top-p 0.6 --top-k 2 --repeat-penalty 1.1 --min-p 0.0 --seed 3407 \
    --prompt "PythonでFlappy Birdゲームを作成して" \
    --system-prompt "英語で応答し、英語で推論してください"
```

推論は英語で行われ、出力も英語です！ さらに続けて「1+1 はいくつ？」と尋ねると、英語のみが返ってきます：

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F55ykzBc3su8TzIePlh3t%2Fimage.png?alt=media&amp;token=07b9f59a-7879-4831-86a0-4ed234c4ba99" alt=""><figcaption></figcaption></figure>

## :gear: 使用ガイド

2-bit 動的量子化 UD-Q2\_K\_XL は 135GB のディスク容量を使用します。これは **1x24GB カードと 128GB の RAM** での MoE オフロードと相性が良いです。1-bit の UD-TQ1 GGUF も **Ollama 上でネイティブに動作します**!

{% hint style="info" %}
使用する必要があります `--jinja` を llama.cpp の量子化版で使用してください。これは私たちの [固定チャットテンプレート](#chat-template-bug-fixes) を使用し、正しいテンプレートを有効にします！ `--jinja`
{% endhint %}

4-bit の量子化版は 1x 40GB GPU に収まります（MoE 層は RAM にオフロード）。この構成に加えて 165GB の追加 RAM があれば、約 5 token/s が期待できます。4-bit を実行するには少なくとも 205GB の RAM を推奨します。最適な性能には、少なくとも 205GB のユニファイドメモリ、または 5+ token/s のために 205GB の RAM+VRAM 合計が必要です。生成速度を上げ、より長いコンテキストに対応する方法を学ぶには、 [こちらを読む](#improving-generation-speed).

{% hint style="success" %}
必須ではありませんが、最良の性能のためには、VRAM + RAM の合計をダウンロードする量子化版のサイズと同じにしてください。そうでない場合でも、ハードドライブ/SSD へのオフロードは llama.cpp で動作しますが、推論は遅くなります。
{% endhint %}

### 推奨設定

Z.ai によると、GLM-4.6V-Flash と GLM-4.6 の推論には異なる設定があります：

| GLM-4.6V-Flash                                                     | GLM-4.6                                                                    |
| ------------------------------------------------------------------ | -------------------------------------------------------------------------- |
| <mark style="background-color:green;">**temperature = 0.8**</mark> | <mark style="background-color:green;">**temperature = 1.0**</mark>         |
| <mark style="background-color:green;">**top\_p = 0.6**</mark> （推奨） | <mark style="background-color:green;">**top\_p = 0.95**</mark> （コーディングに推奨） |
| <mark style="background-color:green;">**top\_k = 2**</mark> （推奨）   | <mark style="background-color:green;">**top\_k = 40**</mark> （コーディングに推奨）   |
| **128K のコンテキスト長** 以下                                               | **200Kのコンテキスト長** 以下                                                        |
| **repeat\_penalty = 1.1**                                          |                                                                            |
| **max\_generate\_tokens = 16,384**                                 | **max\_generate\_tokens = 16,384**                                         |

* 次を使います: `--jinja` は llama.cpp の派生版向けです。 **チャットテンプレートの問題もいくつか修正しました！**

## GLM-4.6 のチュートリアルを実行：

実行方法のステップバイステップガイドをご覧ください [GLM-4.6V-Flash](#glm-4.6v-flash) および大きい方の [GLM-4.6](#glm-4.6) モデル。

### GLM-4.6V-Flash

{% hint style="success" %}
**2025年12月16日更新: GLM-4.6-V に視覚サポートが追加されました！**
{% endhint %}

#### ✨ llama.cpp で実行

{% 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 -DLLAMA_CURL=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` モデルを直接読み込むには、以下のようにできます（:Q8\_K\_XL は量子化タイプです）。Hugging Face 経由でもダウンロードできます（3番目のポイント）。これは次と同様です `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` で、特定の場所に保存するためのものです。モデルの最大コンテキスト長は 128K であることを忘れないでください。

```bash
export LLAMA_CACHE="unsloth/GLM-4.6V-Flash-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/GLM-4.6V-Flash-GGUF:UD-Q8_K_XL \
    --n-gpu-layers 99 \\
    --jinja \\
    --ctx-size 16384 \\
    --flash-attn on \\
    --temp 0.8 \
    --top-p 0.6 \
    --top-k 2 \
    --repeat-penalty 1.1 \
    -ot ".ffn_.*_exps.=CPU"
```

{% endstep %}

{% step %}
以下をインストールした後、( `pip install huggingface_hub hf_transfer` をインストール後）。 `UD-`Q4\_K\_XL（動的4bit量子化）や、以下のようなその他の量子化版 `Q8_K_XL` .

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0" # 時々レート制限が発生することがあるため、無効にするには 0 に設定します
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/GLM-4.6V-Flash-GGUF",
    local_dir = "unsloth/GLM-4.6V-Flash-GGUF",
    allow_patterns = ["*UD-Q8_K_XL*"],
)
```

{% endstep %}
{% endstepper %}

### GLM-4.6

#### :llama: Ollama で実行

{% stepper %}
{% step %}
インストール `ollama` まだの場合は！より多くのモデル派生版を実行するには、 [こちらを参照](https://unsloth.ai/docs/jp/moderu/tutorials/pages/1076a52a5c3ebf51b7a9fff0968fcea31aee4df1#run-in-llama.cpp).

```bash
apt-get update
apt-get install pciutils -y
curl -fsSL https://ollama.com/install.sh | sh
```

{% endstep %}

{% step %}
モデルを実行してください！必要に応じて `ollama serve`を別のターミナルで呼び出せます。失敗した場合でも大丈夫です！私たちの修正と推奨パラメータ（temperature など）はすべて `params` として Hugging Face のアップロードに含めています！

```
OLLAMA_MODELS=unsloth ollama serve &

OLLAMA_MODELS=unsloth ollama run hf.co/unsloth/GLM-4.6-GGUF:TQ1_0
```

{% endstep %}

{% step %}
他の量子化版を実行するには、まず下のコードのように GGUF の分割ファイルを1つに結合する必要があります。その後、モデルをローカルで実行します。

```bash
./llama.cpp/llama-gguf-split --merge \\
  GLM-4.6-GGUF/GLM-4.6-UD-Q2_K_XL/GLM-4.6-UD-Q2_K_XL-00001-of-00003.gguf \
	merged_file.gguf
```

```bash
OLLAMA_MODELS=unsloth ollama serve &

OLLAMA_MODELS=unsloth ollama run merged_file.gguf
```

{% endstep %}
{% endstepper %}

#### ✨ llama.cpp で実行

{% stepper %}
{% step %}
最新の `llama.cpp` を [GitHubこちら](https://github.com/ggml-org/llama.cpp)。以下のビルド手順に従うこともできます。変更してください `-DGGML_CUDA=ON` を `-DGGML_CUDA=OFF` GPUがない場合、またはCPU推論のみを使いたい場合は。

```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 -DLLAMA_CURL=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-quantize llama-cli llama-gguf-split llama-mtmd-cli llama-server
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endstep %}

{% step %}
を使いたい場合は `llama.cpp` で直接モデルを読み込むには、以下のようにできます。(:Q2\_K\_XL) は量子化タイプです。Hugging Face からもダウンロードできます（3番目のポイント）。これは `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` で、特定の場所に保存するためのものです。モデルの最大コンテキスト長は 128K であることを忘れないでください。

{% hint style="success" %}
ぜひお試しください `-ot ".ffn_.*_exps.=CPU"` を試して、すべての MoE 層を CPU にオフロードしてください！これにより、非MoE層すべてを1枚のGPUに収められるようになり、生成速度が向上します。GPU容量がさらにあれば、正規表現を調整してより多くの層を収めることもできます。

GPU メモリがもう少し多ければ、 `-ot ".ffn_(up|down)_exps.=CPU"` を試してください。これは up と down の projection MoE 層をオフロードします。

試してみてください `-ot ".ffn_(up)_exps.=CPU"` GPU メモリがさらに多い場合はこちら。これは up projection の MoE 層のみをオフロードします。

そして最後に、すべての層を `-ot ".ffn_.*_exps.=CPU"` でオフロードします。

これは最も少ない VRAM を使用します。 `-ot "\.(6|7|8|9|[0-9][0-9]|[0-9][0-9][0-9])\.ffn_(gate|up|down)_exps.=CPU"` は、6層目以降から gate、up、down の MoE 層をオフロードすることを意味します。
{% endhint %}

```bash
export LLAMA_CACHE="unsloth/GLM-4.6-GGUF"
./llama.cpp/llama-cli \
    --model GLM-4.6-GGUF/UD-Q2_K_XL/GLM-4.6-UD-Q2_K_XL-00001-of-00003.gguf \
    --n-gpu-layers 99 \\
    --jinja \\
    --ctx-size 16384 \\
    --flash-attn on \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 40 \
    -ot ".ffn_.*_exps.=CPU"
```

{% endstep %}

{% step %}
以下をインストールした後、( `pip install huggingface_hub hf_transfer` をインストール後）。 `UD-`Q2\_K\_XL（dynamic 2bit quant）または次のような他の量子化版 `Q4_K_XL` をインストールした後で）。 <mark style="background-color:green;">**2.7bit の動的量子化版を使うことを推奨します**</mark><mark style="background-color:green;">**&#x20;**</mark><mark style="background-color:green;">**`UD-Q2_K_XL`**</mark><mark style="background-color:green;">**&#x20;**</mark><mark style="background-color:green;">**サイズと精度のバランスを取るために**</mark>.

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0" # 時々レート制限が発生することがあるため、無効にするには 0 に設定します
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/GLM-4.6-GGUF",
    local_dir = "unsloth/GLM-4.6-GGUF",
    allow_patterns = ["*UD-Q2_K_XL*"], # 動的 2bit。動的 1bit には "*UD-TQ1_0*" を使用
)
```

{% endstep %}

{% step %}
編集できます `--threads 32` CPUスレッド数は `--ctx-size 16384` コンテキスト長は `--n-gpu-layers 2` GPUオフロードする層数です。GPUがメモリ不足になったら調整してみてください。CPUのみで推論する場合は削除してください。

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/GLM-4.6-GGUF/UD-Q2_K_XL/GLM-4.6-UD-Q2_K_XL-00001-of-00003.gguf \
    --jinja \\
    --n-gpu-layers 99 \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 40 \
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU"
```

{% endcode %}
{% endstep %}
{% endstepper %}

### ✨ llama-server と OpenAI の completion ライブラリでデプロイ

デプロイに llama-server を使うには、次のコマンドを使用してください：

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \
    --model unsloth/GLM-4.6-GGUF/UD-Q2_K_XL/GLM-4.6-UD-Q2_K_XL-00001-of-00003.gguf \
    --alias "unsloth/GLM-4.6" \
    --n-gpu-layers 999 \\
    -ot ".ffn_.*_exps.=CPU" \\
    --prio 3 \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --top-k 40 \
    --ctx-size 16384 \\
    --port 8001 \\
    --jinja
```

{% endcode %}

その後、OpenAI の Python ライブラリを使います。 `pip install openai` :

```python
from openai import OpenAI
import json
openai_client = OpenAI(
    base_url = "http://127.0.0.1:8001/v1",
    api_key = "sk-no-key-required",
)
completion = openai_client.chat.completions.create(
    model = "unsloth/GLM-4.6",
    messages = [{"role": "user", "content": "2+2 はいくつですか?"},],
)
print(completion.choices[0].message.content)
```

### :minidisc:モデルのアップロード

**当社のアップロードはすべて** — imatrix ベースでも動的でもないものを含め、会話、コーディング、言語タスク向けに特別に最適化された当社のキャリブレーションデータセットを使用しています。

* 完全な GLM-4.6 モデルのアップロードは以下です：

以下もアップロードしました [IQ4\_NL](https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/IQ4_NL) そして [Q4\_1](https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/Q4_1) それぞれ ARM デバイスと Apple デバイスで特に高速に動作する量子化版です。

<table data-full-width="false"><thead><tr><th>MoE ビット数</th><th>種類 + リンク</th><th>ディスクサイズ</th><th>詳細</th></tr></thead><tbody><tr><td>1.66bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF?show_file_info=GLM-4.6-UD-TQ1_0.gguf">TQ1_0</a></td><td><strong>84GB</strong></td><td>1.92/1.56bit</td></tr><tr><td>1.78bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-IQ1_S">IQ1_S</a></td><td><strong>96GB</strong></td><td>2.06/1.56bit</td></tr><tr><td>1.93bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-IQ1_M">IQ1_M</a></td><td><strong>107GB</strong></td><td>2.5/2.06/1.56</td></tr><tr><td>2.42bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-IQ2_XXS">IQ2_XXS</a></td><td><strong>115GB</strong></td><td>2.5/2.06bit</td></tr><tr><td>2.71bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-Q2_K_XL">Q2_K_XL</a></td><td><strong>135GB</strong></td><td>3.5/2.5bit</td></tr><tr><td>3.12bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-IQ3_XXS">IQ3_XXS</a></td><td><strong>145GB</strong></td><td>3.5/2.06bit</td></tr><tr><td>3.5bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-Q3_K_XL">Q3_K_XL</a></td><td><strong>158GB</strong></td><td>4.5/3.5bit</td></tr><tr><td>4.5bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-Q4_K_XL">Q4_K_XL</a></td><td><strong>204GB</strong></td><td>5.5/4.5bit</td></tr><tr><td>5.5bit</td><td><a href="https://huggingface.co/unsloth/GLM-4.6-GGUF/tree/main/UD-Q5_K_XL">Q5_K_XL</a></td><td><strong>252GB</strong></td><td>6.5/5.5bit</td></tr></tbody></table>

### :snowboarder: 生成速度の向上

VRAM がさらにあれば、より多くの MoE 層、または層全体のオフロードを試せます。

通常は、 `-ot ".ffn_.*_exps.=CPU"` すべての MoE 層を CPU にオフロードします！これにより、非MoE層すべてを1枚のGPUに収められるようになり、生成速度が向上します。GPU容量がさらにあれば、正規表現を調整してより多くの層を収めることもできます。

GPU メモリがもう少し多ければ、 `-ot ".ffn_(up|down)_exps.=CPU"` を試してください。これは up と down の projection MoE 層をオフロードします。

試してみてください `-ot ".ffn_(up)_exps.=CPU"` GPU メモリがさらに多い場合はこちら。これは up projection の MoE 層のみをオフロードします。

これは最も少ない VRAM を使用します。 `-ot "\.(6|7|8|9|[0-9][0-9]|[0-9][0-9][0-9])\.ffn_(gate|up|down)_exps.=CPU"` は、6層目以降から gate、up、down の MoE 層をオフロードすることを意味します。

Llama.cpp は高スループットモードも導入しています。 `llama-parallel`を使用してください。 [ここ](https://github.com/ggml-org/llama.cpp/tree/master/examples/parallel)について詳しくはこちらを読む **KV キャッシュを 4bit に量子化する** ことで、VRAM / RAM の移動を減らし、生成処理をさらに高速化できます。

### 📐長文コンテキストを収める方法（全200K）

より長いコンテキストに対応するには、 **KV キャッシュ量子化** を使って K と V のキャッシュをより低い bit に量子化できます。これにより、RAM / VRAM のデータ移動が減るため生成速度も上がります。K の量子化で使用できるオプション（デフォルトは `f16`）は以下の通りです。

`--cache-type-k f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1`

少し精度が向上する `_1` 版を使うべきです。少し遅くなりますが。たとえば `q4_1, q5_1`

V キャッシュも量子化できますが、その場合は **Flash Attention 対応で llama.cpp をコンパイルする必要があります** を `-DGGML_CUDA_FA_ALL_QUANTS=ON`で有効にし、 `--flash-attn` を使って有効化します。その後、 `--cache-type-k` :

`--cache-type-v f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1`


---

# 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/tutorials/glm-4.6-how-to-run-locally.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.
