> 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/glm-5.1.md).

# GLM-5.1 - ローカルでの実行方法

GLM-5.1 は Z.ai の新しいオープンモデルです。と比べて [GLM-5](/docs/jp/moderu/tutorials/glm-5.md)、コーディング、エージェント的なツール使用、推論、ロールプレイ、長期的なエージェントタスク、全体的なチャット品質が大幅に向上しています。

フルサイズの 744B パラメータ（40B アクティブ）の GLM-5.1 モデルは **200K コンテキスト** のウィンドウを持ち、 **1.65TB** のディスク容量が必要です。Unsloth Dynamic 2-bit GGUF によりサイズは **220GB** **(-80%)**&#x306B;削減され、動的 **1-bit は 200GB（-85%）です：** [**GLM-5.1-GGUF**](https://huggingface.co/unsloth/GLM-5.1-GGUF)

すべてのアップロードは Unsloth [Dynamic 2.0](/docs/jp/ji-ben/unsloth-dynamic-2.0-ggufs.md) を使用して SOTA の量子化性能を実現しています。つまり、低ビットでは重要な層が 8-bit または 16-bit にアップキャストされています。Z.ai が Unsloth に初日アクセスを提供してくれたことに感謝します。

#### :gear: 使用ガイド

中程度の 2-bit 動的量子化 `UD-IQ2_M` は **236GB** のディスク容量を使用します。これは直接 **256GB ユニファイドメモリの Mac** に収まり、 **1x24GB GPU** および **256GB の RAM** で MoE オフローディングを使っても問題なく動作します。 **1-bit** 量子化は 220GB の RAM に収まり、8-bit では 805GB の RAM が必要です。

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

### 推奨設定

用途ごとに異なる設定を使ってください：

| デフォルト設定（ほとんどのタスク）       | Terminal Bench         |
| ----------------------- | ---------------------- |
| `temperature` = 1.0     | `temperature` = 0.7    |
| `top_p` = 0.95          | `top_p` = 1.0          |
| max new tokens = 131072 | max new tokens = 16384 |

* **最大コンテキストウィンドウ：** `202,752`.
* GLM-5.1 では、thinking はデフォルトで有効です。thinking を無効にするには：

{% code expandable="true" %}

```bash
    --chat-template-kwargs '{"enable_thinking":false}'
```

{% endcode %}

#### チャットテンプレートの更新

GLM-5.1 は GLM-5 と同じアーキテクチャを採用しており、違うのは `chat_template.jinja` だけです。

* Claude の検索ツールをサポートしています。 `defer_loading=True` のツールはシステムプロンプトから省かれ、代わりにツール結果に表示されます。
* 空の推論ブロック（`<think></think>`）をアシスタントメッセージ内で許可します。連続するアシスタントメッセージは、thinking か non-thinking のどちらか同じモードを維持する必要があります。
* 全体として、GLM-5.1 は主にツール露出、推論履歴の再構築、ツールメッセージのレンダリングを改善しています。

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

今すぐ GLM-5.1 を [llama.cpp](#run-in-llama.cpp) および [Unsloth Studio](#run-in-unsloth-studio).

### 🦥 Unsloth Studio で実行

GLM-5.1 は現在 [Unsloth Studio](/docs/jp/xin-zhe/studio.md)で実行できます。これはローカル AI 向けの新しいオープンソース Web UI です。Unsloth Studio を使うと、次の環境でモデルをローカル実行できます **MacOS、Windows**、Linux および：

{% columns %}
{% column %}

* 検索、ダウンロード、 [GGUF の実行](/docs/jp/xin-zhe/studio.md#run-models-locally) および safetensor モデル
* [**自己修復** ツール呼び出し](/docs/jp/xin-zhe/studio.md#execute-code--heal-tool-calling) + **Web 検索**
* [**コード実行**](/docs/jp/xin-zhe/studio.md#run-models-locally) （Python、Bash）
* [自動推論](/docs/jp/xin-zhe/studio.md#model-arena) パラメータ調整（temp、top-p など）
* 高速な CPU + GPU 推論と CPU オフロードのために llama.cpp を使用します
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/52ac81606e9a31b3f691aabcec5c0ad84f45aee2" 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://localhost:8888` をブラウザで開いてください。**
{% endstep %}

{% step %}

#### GLM-5.1 を検索してダウンロード

初回起動時には、アカウントを保護するためのパスワードを作成し、後で再度サインインする必要があります。その後、モデル、データセット、基本設定を選ぶ簡単なオンボーディングウィザードが表示されます。いつでもスキップできます。

次から選べます `UD-Q2_K_XL` （動的 2bit 量子化）または `UD-Q4_K_XL` のような他の量子化版も選べます。 <mark style="background-color:green;">**サイズと精度のバランスを取るため、当社の 2bit 動的量子化の使用を**</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>。ダウンロードが止まる場合は、 [Hugging Face Hub、XETデバッグ](/docs/jp/ji-ben/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

次に [Studio Chat](/docs/jp/xin-zhe/studio/chat.md) タブに移動し、検索バーで GLM-5.1 を検索して、希望するモデルと量子化版をダウンロードしてください。サイズが大きいためダウンロードに時間がかかるので、しばらくお待ちください。高速な推論を確保するには、 [十分な RAM/VRAM](#usage-guide)があることを確認してください。そうでない場合でも推論は動作しますが、Unsloth は CPU にオフロードします。

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

{% step %}

#### GLM-5.1 を実行

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

詳細については、 [Unsloth Studio 推論ガイド](/docs/jp/xin-zhe/studio/chat.md).
{% endstep %}
{% endstepper %}

### 🦙 llama.cpp で実行

{% stepper %}
{% step %}
最新のものを取得 `llama.cpp` **で** [**GitHub はこちら**](https://github.com/ggml-org/llama.cpp)で入手してください。以下のビルド手順に従うこともできます。GPU がない場合、または CPU 推論だけを使いたい場合は、 `-DGGML_CUDA=ON` を `-DGGML_CUDA=OFF` に変更してください。 **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` をモデル読み込みに直接使いたいなら、以下のようにできます：（`IQ2_M`）は量子化タイプです。Hugging Face（3番）経由でもダウンロードできます。これは `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` 保存先を特定の場所に強制できます。モデルの最大コンテキスト長は 200K であることを忘れないでください。

これに従って **一般的な指示** の用途：

```bash
export LLAMA_CACHE="unsloth/GLM-5.1-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/GLM-5.1-GGUF:UD-IQ2_M \
    --ctx-size 16384 \
    --temp 0.7 \
    --top-p 1.0
```

これに従って **ツール呼び出し** の用途：

```bash
export LLAMA_CACHE="unsloth/GLM-5.1-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/GLM-5.1-GGUF:UD-IQ2_M \
    --ctx-size 16384 \
    --temp 1.0 \
    --top-p 0.95
```

{% endstep %}

{% step %}
（ `pip install huggingface_hub hf_transfer` をインストールした後に）モデルをダウンロードします。 `UD-Q2_K_XL` （動的 2bit 量子化）または `UD-Q4_K_XL` のような他の量子化版も選べます。 <mark style="background-color:green;">**サイズと精度のバランスを取るため、当社の 2bit 動的量子化の使用を**</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>。ダウンロードが止まる場合は、 [Hugging Face Hub、XETデバッグ](/docs/jp/ji-ben/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
pip install -U huggingface_hub
hf download unsloth/GLM-5.1-GGUF \
    --local-dir unsloth/GLM-5.1-GGUF \
    --include "*UD-IQ2_M*" # 動的 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-5.1-GGUF/UD-IQ2_M/GLM-5.1-UD-IQ2_M-00001-of-00006.gguf \
    --temp 1.0 \
    --top-p 0.95 \
    --ctx-size 16384 \
    --seed 3407
```

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

#### 🦙 Llama-server の提供と OpenAI の completion ライブラリ

本番環境で GLM-5.1 をデプロイするには、 `llama-server` を使用します。tmux 経由などで新しいターミナルを開き、次のようにモデルをデプロイします：

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \
    --model unsloth/GLM-5.1-GGUF/UD-IQ2_M/GLM-5.1-UD-IQ2_M-00001-of-00006.gguf \
    --alias "unsloth/GLM-5.1" \
    --prio 3 \
    --temp 1.0 \
    --top-p 0.95 \
    --ctx-size 16384 \
    --port 8001
```

{% endcode %}

次に、新しいターミナルで `pip install openai`を実行したあと、次を行います：

{% code overflow="wrap" %}

```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-5.1",
    messages = [{"role": "user", "content": "Snake ゲームを作成して。"},],
)
print(completion.choices[0].message.content)
```

{% endcode %}

その後、OpenAI API 経由で提供中のモデルを呼び出せます：

```python
from openai import AsyncOpenAI, OpenAI
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8001/v1"
client = OpenAI( # または AsyncOpenAI
    api_key = openai_api_key,
    base_url = openai_api_base,
)
```

### :hammer:GLM-5.1 でのツール呼び出し

詳細は [Tool Calling Guide](/docs/jp/ji-ben/tool-calling-guide-for-local-llms.md) をご覧ください。新しいターミナルで（tmux を使う場合は CTRL+B+D を使用）、2つの数値の加算、Python コードの実行、Linux 関数の実行など、いくつかのツールを作成します：

{% code expandable="true" %}

```python
import json, subprocess, random
from typing import Any
def add_number(a: float | str, b: float | str) -> float:
    return float(a) + float(b)
def multiply_number(a: float | str, b: float | str) -> float:
    return float(a) * float(b)
def subtract_number(a: float | str, b: float | str) -> float:
    return float(a) - float(b)
def write_a_story() -> str:
    return random.choice([
        "昔々、はるか彼方の銀河で…",
        "ナマケモノとコードが大好きな 2 人の友人がいました…",
        "すべてのナマケモノが超人的知能を持つよう進化したため、世界は終末を迎えていました…",
        "ある友人は知らないうちに、もう一人の友人がうっかりナマケモノを進化させるプログラムを書いていました…",
    ])
def terminal(command: str) -> str:
    if "rm" in command or "sudo" in command or "dd" in command or "chmod" in command:
        msg = "'rm, sudo, dd, chmod' コマンドは危険なので実行できません"
        print(msg); return msg
    print(f"ターミナルコマンド `{command}` を実行中")
    try:
        return str(subprocess.run(command, capture_output = True, text = True, shell = True, check = True).stdout)
    except subprocess.CalledProcessError as e:
        return f"コマンドに失敗しました: {e.stderr}"
def python(code: str) -> str:
    data = {}
    exec(code, data)
    del data["__builtins__"]
    return str(data)
MAP_FN = {
    "add_number": add_number,
    "multiply_number": multiply_number,
    "subtract_number": subtract_number,
    "write_a_story": write_a_story,
    "terminal": terminal,
    "python": python,
}
tools = [
    {
        "type": "function",
        "function": {
            "name": "add_number",
            "description": "2つの数値を加算します。",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string",
                        "description": "最初の数値。",
                    },
                    "b": {
                        "type": "string",
                        "description": "2番目の数値。",
                    },
                },
                "required": ["a", "b"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "multiply_number",
            "description": "2つの数値を掛け算します。",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string",
                        "description": "最初の数値。",
                    },
                    "b": {
                        "type": "string",
                        "description": "2番目の数値。",
                    },
                },
                "required": ["a", "b"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "subtract_number",
            "description": "2つの数値を引き算します。",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {
                        "type": "string",
                        "description": "最初の数値。",
                    },
                    "b": {
                        "type": "string",
                        "description": "2番目の数値。",
                    },
                },
                "required": ["a", "b"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "write_a_story",
            "description": "ランダムな物語を書きます。",
            "parameters": {
                "type": "object",
                "properties": {},
                "required": [],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "terminal",
            "description": "ターミナルから操作を実行します。",
            "parameters": {
                "type": "object",
                "properties": {
                    "command": {
                        "type": "string",
                        "description": "起動したいコマンド。例: `ls`, `rm`, ...",
                    },
                },
                "required": ["command"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "python",
            "description": "実行される Python コードを指定して Python インタープリタを呼び出します。",
            "parameters": {
                "type": "object",
                "properties": {
                    "code": {
                        "type": "string",
                        "description": "実行する Python コード",
                    },
                },
                "required": ["code"],
            },
        },
    },
]
```

{% endcode %}

その後、以下の関数を使用します（コピーして貼り付けて実行）。これにより関数呼び出しが自動的に解析され、任意のモデルに対して OpenAI エンドポイントが呼び出されます：

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

```python
from openai import OpenAI
def unsloth_inference(
    messages,
    temperature = 1.0,
    top_p = 0.95,
    top_k = -1,
    min_p = 0.01,
    repetition_penalty = 1.0,
):
    messages = messages.copy()
    openai_client = OpenAI(
        base_url = "http://127.0.0.1:8001/v1",
        api_key = "sk-no-key-required",
    )
    model_name = next(iter(openai_client.models.list())).id
    print(f"使用するモデル = {model_name}")
    has_tool_calls = True
    original_messages_len = len(messages)
    while has_tool_calls:
        print(f"現在の messages = {messages}")
        response = openai_client.chat.completions.create(
            model = model_name,
            messages = messages,
            temperature = temperature,
            top_p = top_p,
            tools = tools if tools else None,
            tool_choice = "auto" if tools else None,
            extra_body = {"top_k": top_k, "min_p": min_p, "repetition_penalty" :repetition_penalty,}
        )
        tool_calls = response.choices[0].message.tool_calls or []
        content = response.choices[0].message.content or ""
        tool_calls_dict = [tc.to_dict() for tc in tool_calls] if tool_calls else tool_calls
        messages.append({"role": "assistant", "tool_calls": tool_calls_dict, "content": content,})
        for tool_call in tool_calls:
            fx, args, _id = tool_call.function.name, tool_call.function.arguments, tool_call.id
            out = MAP_FN[fx](**json.loads(args))
            messages.append({"role": "tool", "tool_call_id": _id, "name": fx, "content": str(out),})
        else:
            has_tool_calls = False
    return messages
```

{% endcode %}

GLM 5.1 を `llama-server` で起動した後 [#deploy-with-llama-server-and-openais-completion-library](#deploy-with-llama-server-and-openais-completion-library "mention") のように [Tool Calling Guide](/docs/jp/ji-ben/tool-calling-guide-for-local-llms.md) 、または詳細は

### 📊 ベンチマーク

以下で、GLM-5.1 のベンチマークを表形式で確認できます：

<div><figure><img src="/files/f831845f9d64920d05aae618731b807f4aeb53a6" alt=""><figcaption></figcaption></figure> <figure><img src="/files/315fd794da5b52d4d4ae634513f406020a580847" alt=""><figcaption></figcaption></figure></div>

| ベンチマーク                         | GLM-5.1           | GLM-5             | Qwen3.6-Plus | Minimax M2.7      | DeepSeek-V3.2     | Kimi K2.5 | Claude Opus 4.6 | Gemini 3.1 Pro | GPT-5.4          |
| ------------------------------ | ----------------- | ----------------- | ------------ | ----------------- | ----------------- | --------- | --------------- | -------------- | ---------------- |
| HLE                            | 31.0              | 30.5              | 28.8         | 28.0              | 25.1              | 31.5      | 36.7            | **45.0**       | 39.8             |
| HLE（ツール付き）                     | 52.3              | 50.4              | 50.6         | -                 | 40.8              | 51.8      | **53.1**\*      | 51.4\*         | 52.1\*           |
| AIME 2026                      | 95.3              | 95.4              | 95.1         | 89.8              | 95.1              | 94.5      | 95.6            | 98.2           | **98.7**         |
| HMMT 2025年11月                  | 94.0              | **96.9**          | 94.6         | 81.0              | 90.2              | 91.1      | 96.3            | 94.8           | 95.8             |
| HMMT 2026年2月                   | 82.6              | 82.8              | 87.8         | 72.7              | 79.9              | 81.3      | 84.3            | 87.3           | **91.8**         |
| IMOAnswerBench                 | 83.8              | 82.5              | 83.8         | 66.3              | 78.3              | 81.8      | 75.3            | 81.0           | **91.4**         |
| GPQA-Diamond                   | 86.2              | 86.0              | 90.4         | 87.0              | 82.4              | 87.6      | 91.3            | **94.3**       | 92.0             |
| SWE-Bench Pro                  | **58.4**          | 55.1              | 56.6         | 56.2              | -                 | 53.8      | 57.3            | 54.2           | 57.7             |
| NL2Repo                        | 42.7              | 35.9              | 37.9         | 39.8              | -                 | 32.0      | **49.8**        | 33.4           | 41.3             |
| Terminal-Bench 2.0（Terminus-2） | 63.5              | 56.2              | 61.6         | -                 | 39.3              | 50.8      | 65.4            | **68.5**       | -                |
| Terminal-Bench 2.0（自己申告最高値）    | 66.5（Claude Code） | 56.2（Claude Code） | -            | 57.0（Claude Code） | 46.4（Claude Code） | -         | -               | -              | **75.1** （Codex） |
| CyberGym                       | **68.7**          | 48.3              | -            | -                 | 17.3              | 41.3      | 66.6            | -              | -                |
| BrowseComp                     | **68.0**          | 62.0              | -            | -                 | 51.4              | 60.6      | -               | -              | -                |
| BrowseComp（コンテキスト管理付き）         | 79.3              | 75.9              | -            | -                 | 67.6              | 74.9      | 84.0            | **85.9**       | 82.7             |
| τ³-Bench                       | 70.6              | 69.2              | 70.7         | 67.6              | 69.2              | 66.0      | 72.4            | 67.1           | **72.9**         |
| MCP-Atlas（公開セット）               | 71.8              | 69.2              | **74.1**     | 48.8              | 62.2              | 63.8      | 73.8            | 69.2           | 67.2             |
| Tool-Decathlon                 | 40.7              | 38.0              | 39.8         | 46.3              | 35.2              | 27.8      | 47.2            | 48.8           | **54.6**         |
| Vending Bench 2                | $5,634.00         | $4,432.12         | $5,114.87    | -                 | $1,034.00         | $1,198.46 | **$8,017.59**   | $911.21        | $6,144.18        |


---

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

```
GET https://unsloth.ai/docs/jp/moderu/glm-5.1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
