> 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/kimi-k2-thinking-how-to-run-locally.md).

# Kimi K2 Thinking: ローカル実行ガイド

Kimi-K2-ThinkingとKimi-K2を自分のローカルデバイスで実行するためのガイド！

{% hint style="success" %}
Kimi-K2-Thinkingがリリースされました。私たちの [Thinkingガイド](#kimi-k2-thinking-guide) またはアクセス [こちらでGGUFを入手](https://huggingface.co/unsloth/Kimi-K2-Thinking-GGUF).

また、Kimiチームと共同で [**システムプロンプトの修正**](#tokenizer-quirks-and-bug-fixes) をKimi-K2-Thinking向けに行いました。
{% endhint %}

Kimi-K2と **Kimi-K2-Thinking** は、知識、推論、コーディング、エージェントタスクでSOTA性能を達成します。Moonshot AIのフル1Tパラメータモデルは1.09TBのディスク容量を必要としますが、量子化された **Unsloth Dynamic 1.8ビット** 版ではこれがわずか230GB（サイズ-80%）に削減されま&#x3059;**:** [**Kimi-K2-GGUF**](https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF)

また、私たちの [**Kimi-K2-Thinking** GGUF](https://huggingface.co/unsloth/Kimi-K2-Thinking-GGUF).

すべてのアップロードは Unsloth の [Dynamic 2.0](/docs/jp/ji-chu/dynamic-3.0-ggufs.md) SOTA向けに [Aider Polyglot](/docs/jp/ji-chu/dynamic-3.0-ggufs/unsloth-dynamic-ggufs-on-aider-polyglot.md) および5ショットMMLU性能。私たちのDynamic 1〜2ビットGGUFが [コーディングベンチマークでどう動作するかをこちらでご覧ください](/docs/jp/ji-chu/dynamic-3.0-ggufs/unsloth-dynamic-ggufs-on-aider-polyglot.md).

<a href="#kimi-k2-thinking-guide" class="button primary">Thinkingを実行</a><a href="#kimi-k2-instruct-guide" class="button primary">Instructを実行</a>

### :gear: 推奨要件

{% hint style="info" %}
必要なのは **247GBのディスク容量** を1ビット量子化版を動かすために必要です！

必要条件は **`ディスク容量 + RAM + VRAM ≥ 247GB`**。つまり、モデルを実行するためにそれだけのRAMやVRAM（GPU）を持っている必要はありませんが、その場合はかなり遅くなります。
{% endhint %}

1.8ビット（UD-TQ1\_0）量子化版は、1枚の24GB GPUに収まります（すべてのMoE層をシステムRAMまたは高速ディスクへオフロードした場合）。さらに追加で256GBのRAMもあるなら、この構成で約1〜2 tokens/sを見込めます。完全版のKimi K2 Q8量子化は1.09TBのサイズで、少なくとも8台のH200 GPUが必要です。

最適な性能のためには少なくとも **247GBのユニファイドメモリ、または247GBの合計RAM+VRAM** が必要で、5+ tokens/sを目指せます。合計RAM+VRAMが247GB未満なら、モデルの速度は確実に低下します。

**247GBのRAM+VRAMがなくても心配ありません！** llama.cppには本来 **ディスクオフローディング**があるため、mmap経由でも動作はしますが、遅くなります。たとえば以前は1秒あたり5〜10トークン出ていたとしても、今では1トークン未満になります。

私たちの **UD-Q2\_K\_XL (360GB)** 量子化版を使って、サイズと精度のバランスを取りましょう！

{% hint style="success" %}
最高の性能を得るには、VRAM + RAMの合計をダウンロードする量子化版のサイズと同じにしてください。そうでなくてもディスクオフローディングで動作しますが、遅くなります！
{% endhint %}

## 💭Kimi-K2-Thinkingガイド

Kimi-K2-Thinkingは基本的にInstructモデルと同じ指示に従いますが、設定やチャットテンプレートなどの点でいくつか重要な違いがあります。

{% hint style="success" %}
**モデルをフル精度で実行するには、4ビットまたは5ビットのDynamic GGUF（例: UD\_Q4\_K\_XL）を使うだけで十分です。これはモデルが元々INT4形式で公開されたためです。**

量子化差が小さい場合に備えて、念のためより高ビットの量子化を選ぶこともできますが、ほとんどの場合は不要です。
{% endhint %}

### 🌙 公式推奨設定：

によると [Moonshot AI](https://huggingface.co/moonshotai/Kimi-K2-Thinking)、これはKimi-K2-Thinkingの推論に推奨される設定です：

* 次を設定してください <mark style="background-color:green;">**temperature 1.0**</mark> にすると、反復や不整合を減らせます。
* 推奨コンテキスト長 = 98,304（最大256K）
* 注：異なるツールを使う場合は別の設定が必要になることがあります

{% hint style="info" %}
設定することを推奨します <mark style="background-color:green;">**min\_pを0.01に**</mark> 低い確率の起こりにくいトークンの出現を抑えるためです。
{% endhint %}

例えば、ユーザーのメッセージが「1+1はいくつ？」の場合、以下のようになります：

{% code overflow="wrap" %}

```
<|im_system|>system<|im_middle|>あなたはMoonshot AIによって作成されたAIアシスタント、Kimiです。<|im_end|><|im_user|>user<|im_middle|>1+1はいくつですか？<|im_end|><|im_assistant|>assistant<|im_middle|>
```

{% endcode %}

### ✨ llama.cppでKimi K2 Thinkingを実行

{% hint style="success" %}
現在、最新の [llama.cpp](https://github.com/ggml-org/llama.cpp) を使ってモデルを実行できます：
{% endhint %}

1. 最新の `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-quantize llama-cli llama-gguf-split llama-mtmd-cli
cp llama.cpp/build/bin/llama-* llama.cpp
```

2. を使いたい場合は `llama.cpp` モデルを直接読み込むには、以下のようにできます：(:UD-TQ1\_0) は量子化タイプです。Hugging Face経由でもダウンロードできます（ポイント3）。これは次に似ています `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` 特定の場所に保存するには、

```bash
export LLAMA_CACHE="unsloth/Kimi-K2-Thinking-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/Kimi-K2-Thinking-GGUF:UD-TQ1_0 \\
    --n-gpu-layers 99 \\
    --temp 1.0 \\
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU"
```

3. 上記では約8GBのGPUメモリを使用します。合計GPUメモリが約360GBある場合は、 `-ot ".ffn_.*_exps.=CPU"` を削除して最大速度を得てください！

{% hint style="info" %}
ぜひお試しください `-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 %}

3. 以下をインストールした後、( `pip install huggingface_hub hf_transfer` ）。サイズと精度のバランスを取るため、2ビットのダイナミック量子化UD-Q2\_K\_XLの使用を推奨します。全バージョンはこちら： [huggingface.co/unsloth/Kimi-K2-Thinking-GGUF](https://huggingface.co/unsloth/Kimi-K2-Thinking-GGUF)

{% code overflow="wrap" %}

```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/Kimi-K2-Thinking-GGUF",
    local_dir = "unsloth/Kimi-K2-Thinking-GGUF",
    allow_patterns = ["*UD-TQ1_0*"], # Dynamic 2ビット (381GB) には "*UD-Q2_K_XL*" を使用
)
```

{% endcode %}

{% hint style="info" %}
ダウンロードが90〜95%あたりで止まる場合は、こちらをご覧ください <https://docs.unsloth.ai/basics/troubleshooting-and-faqs#downloading-gets-stuck-at-90-to-95>
{% endhint %}

4. 任意のプロンプトを実行できます。
5. 編集 `--threads -1` CPUスレッド数用（デフォルトではCPUの最大スレッド数に設定されています）、 `--ctx-size 16384` コンテキスト長は `--n-gpu-layers 99` GPUオフローディングで何層を担当するかを指定します。MoEのCPUオフローディングと組み合わせて99に設定すると最良の性能が得られます。GPUがメモリ不足になる場合は調整してみてください。また、CPUのみで推論する場合は削除してください。

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Kimi-K2-Thinking-GGUF/UD-TQ1_0/Kimi-K2-Thinking-UD-TQ1_0-00001-of-00006.gguf \\
    --n-gpu-layers 99 \\
    --temp 1.0 \\
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU"
```

{% endcode %}

### :thinking:**Thinkingタグがない？**

モデルを実行すると、 *思考* タグが表示されないことに気づくかもしれません。これは正常で意図された動作です。

あなたの `llama.cpp` スクリプトでは、必ず `--special` フラグをコマンドの最後に付けてください。そうすると、 `<think>` トークンが期待どおりに表示されます。

各回答の末尾が `<|im_end|>`になることもあります。これは正常です。 `<|im_end|>` 非表示にしたい場合は、 `<|im_end|>` 設定でstop文字列として指定できます。

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

に従ってllama.cppをインストールした後、 [#run-kimi-k2-thinking-in-llama.cpp](#run-kimi-k2-thinking-in-llama.cpp "mention")以下を使ってOpenAI互換サーバーを起動できます：

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \
    --model unsloth/Kimi-K2-Thinking-GGUF/UD-TQ1_0/Kimi-K2-Thinking-UD-TQ1_0-00001-of-00006.gguf \\
    --alias "unsloth/Kimi-K2-Thinking" \\
    -fa on \\
    --n-gpu-layers 999 \\
    -ot ".ffn_.*_exps.=CPU" \\
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --port 8001 \\
    --jinja
```

{% endcode %}

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

```python
from openai import OpenAI
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/Kimi-K2-Thinking",
    messages = [{"role": "user", "content": "2+2 はいくつですか?"},],
)
print(completion.choices[0].message.content)
```

## :mag:トークナイザーの癖とバグ修正

**2025年11月7日：Kimiチームに通知し、のデフォルトシステムプロンプトを修正しました。** `あなたはMoonshot AIによって作成されたAIアシスタント、Kimiです。` **が最初のユーザープロンプトに表示されない！** こちらを参照 <https://huggingface.co/moonshotai/Kimi-K2-Thinking/discussions/12>

私たちの問い合わせに非常に迅速に対応し、問題を速やかに修正してくれたMoonshot Kimiチームに心から感謝します！

**2025年7月16日：Kimi K2がトークナイザーを更新し、複数のツール呼び出しを可能にしました** に従って <https://x.com/Kimi_Moonshot/status/1945050874067476962>

**2025年7月18日：システムプロンプトを修正しました。Kimiもこの修正についてここでツイートしています：** <https://x.com/Kimi_Moonshot/status/1946130043446690030>。修正はここでも説明されています： <https://huggingface.co/moonshotai/Kimi-K2-Instruct/discussions/28>

古いチェックポイントをダウンロード済みでも心配ありません。変更された最初のGGUF分割ファイルだけをダウンロードしてください。あるいは、新しいファイルを何もダウンロードしたくない場合は、次のようにしてください：

```bash
wget https://huggingface.co/unsloth/Kimi-K2-Instruct/raw/main/chat_template.jinja
./llama.cpp ... --chat-template-file /dir/to/chat_template.jinja
```

Kimi K2のトークナイザーは触ってみると面白かったです - <mark style="background-color:green;">**動作はほぼGPT-4oのトークナイザーに似ています**</mark>！まず [tokenization\_kimi.py](https://huggingface.co/moonshotai/Kimi-K2-Instruct/blob/main/tokenization_kimi.py) ファイルで、Kimi K2が使用する次の正規表現（regex）を確認できます：

```python
pat_str = "|".join(
    [
        r"""[\p{Han}]+""",
        r"""[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}&&[^\p{Han}]]*[\p{Ll}\p{Lm}\p{Lo}\p{M}&&[^\p{Han}]]+(?i:'s|'t|'re|'ve|'m|'ll|'d)?""",
        r"""[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}&&[^\p{Han}]]+[\p{Ll}\p{Lm}\p{Lo}\p{M}&&[^\p{Han}]]*(?i:'s|'t|'re|'ve|'m|'ll|'d)?""",
        r"""\p{N}{1,3}""",
        r""" ?[^\s\p{L}\p{N}]+[\r\n]*""",
        r"""\s*[\r\n]+""",
        r"""\s+(?!\S)""",
        r"""\s+""",
    ]
)
```

注意深く調べたところ、Kimi K2はGPT-4oのトークナイザーの正規表現とほぼ同一であり、これは [llama.cppのソースコード](https://github.com/ggml-org/llama.cpp/blob/55c509daf51d25bfaee9c8b8ce6abff103d4473b/src/llama-vocab.cpp#L400).

{% code overflow="wrap" %}

```
[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]*[\p{Ll}\p{Lm}\p{Lo}\p{M}]+(?i:'s|'t|'re|'ve|'m|'ll|'d)?|[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]+[\p{Ll}\p{Lm}\p{Lo}\p{M}]*(?i:'s|'t|'re|'ve|'m|'ll|'d)?|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n/]*|\s*[\r\n]+|\s+(?!\S)|\s+
```

{% endcode %}

どちらも数字を1〜3個のグループ（9, 99, 999）にトークナイズし、似たパターンを使います。違いは「Han」や中国語文字の扱いだけのようで、Kimiのトークナイザーはそこをよりうまく処理しています。 [PRは](https://github.com/ggml-org/llama.cpp/pull/14654) によって <https://github.com/gabriellarson> いくつかの [こちらでの議論の後、これらの違いをうまく処理しています](https://github.com/ggml-org/llama.cpp/issues/14642#issuecomment-3067324745).

<mark style="background-color:green;">**また、正しいEOSトークンは\[EOS]ではなく<|im\_end|>であるべきだと分かり、モデル変換でも修正しました。**</mark>

## 🌝Kimi-K2-Instructガイド

Kimi K2 0905（9月5日更新）を含むInstruct Kimi K2モデルの実行手順を段階的に説明するガイド。

### 🌙 公式推奨設定：

によると [Moonshot AI](https://huggingface.co/moonshotai/Kimi-K2-Instruct)、これはKimi K2の推論に推奨される設定です：

* 次を設定してください <mark style="background-color:green;">**temperature 0.6**</mark> にすると、反復や不整合を減らせます。
* 元のデフォルトシステムプロンプトは次のとおりです：

  ```
  あなたは役立つアシスタントです
  ```
* （任意）Moonshotはシステムプロンプトに以下も推奨しています：

  ```
  あなたはMoonshot AIによって作成されたAIアシスタント、Kimiです。
  ```

{% hint style="success" %}
設定することを推奨します <mark style="background-color:green;">**min\_pを0.01に**</mark> 低い確率の起こりにくいトークンの出現を抑えるためです。
{% endhint %}

### :1234: チャットテンプレートとプロンプト形式

Kimi ChatではBOS（文頭トークン）を使用します。system、user、assistantの各ロールはすべて `<|im_middle|>` で囲まれており、これは興味深く、それぞれに対応する独自のトークンが割り当てられます `<|im_system|>, <|im_user|>, <|im_assistant|>`.

{% code overflow="wrap" %}

```python
<|im_system|>system<|im_middle|>あなたは役立つアシスタントです<|im_end|><|im_user|>user<|im_middle|>1+1はいくつですか？<|im_end|><|im_assistant|>assistant<|im_middle|>2<|im_end|>
```

{% endcode %}

会話の区切りを分けるために（各改行は削除する必要があります）、次のようになります：

{% code overflow="wrap" %}

```
<|im_system|>system<|im_middle|>あなたは役立つアシスタントです<|im_end|>
<|im_user|>user<|im_middle|>1+1はいくつですか？<|im_end|>
<|im_assistant|>assistant<|im_middle|>2<|im_end|>
```

{% endcode %}

### :floppy\_disk: モデルのアップロード

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

<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/Kimi-K2-Instruct-GGUF/tree/main/UD-TQ1_0">UD-TQ1_0</a></td><td><strong>245GB</strong></td><td>1.92/1.56bit</td></tr><tr><td>1.78bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-IQ1_S">UD-IQ1_S</a></td><td><strong>281GB</strong></td><td>2.06/1.56bit</td></tr><tr><td>1.93bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-IQ1_M">UD-IQ1_M</a></td><td><strong>304GB</strong></td><td>2.5/2.06/1.56</td></tr><tr><td>2.42bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-IQ2_XXS">UD-IQ2_XXS</a></td><td><strong>343GB</strong></td><td>2.5/2.06bit</td></tr><tr><td>2.71bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-Q2_K_XL">UD-Q2_K_XL</a></td><td><strong>381GB</strong></td><td>3.5/2.5bit</td></tr><tr><td>3.12bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-IQ3_XXS">UD-IQ3_XXS</a></td><td><strong>417GB</strong></td><td>3.5/2.06bit</td></tr><tr><td>3.5bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-Q3_K_XL">UD-Q3_K_XL</a></td><td><strong>452GB</strong></td><td>4.5/3.5bit</td></tr><tr><td>4.5bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-Q4_K_XL">UD-Q4_K_XL</a></td><td><strong>588GB</strong></td><td>5.5/4.5bit</td></tr><tr><td>5.5bit</td><td><a href="https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF/tree/main/UD-Q5_K_XL">UD-Q5_K_XL</a></td><td><strong>732GB</strong></td><td>6.5/5.5bit</td></tr></tbody></table>

以下の形式の版もアップロードしました [BF16 形式](https://huggingface.co/unsloth/Kimi-K2-Instruct-BF16).

### ✨ llama.cppでInstructを実行

1. 最新の `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
cp llama.cpp/build/bin/llama-* llama.cpp
```

2. を使いたい場合は `llama.cpp` モデルを直接読み込むには、以下のようにできます：(:UD-IQ1\_S) は量子化タイプです。Hugging Face経由でもダウンロードできます（ポイント3）。これは次に似ています `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` 特定の場所に保存するには、\ <mark style="background-color:green;">**モデルの2025年9月の新しい更新を実行するには、モデル名を'Kimi-K2-Instruct'から'Kimi-K2-Instruct-0905'に変更してください。**</mark>

{% hint style="info" %}
ぜひお試しください `-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/Kimi-K2-Instruct-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/Kimi-K2-Instruct-GGUF:TQ1_0 \\
    --n-gpu-layers 99 \\
    --temp 0.6 \
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU"
```

3. 以下をインストールした後、( `pip install huggingface_hub hf_transfer` をインストール後）。 `UD-TQ1_0`（動的1.8ビット量子化）または以下のような他の量子化版 `Q2_K_XL` をインストールした後で）。 <mark style="background-color:green;">**当社の 2 ビット動的量子化の使用を推奨します**</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>。他のバージョンはこちら: [huggingface.co/unsloth/Kimi-K2-Instruct-GGUF](https://huggingface.co/unsloth/Kimi-K2-Instruct-GGUF)

{% code overflow="wrap" %}

```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/Kimi-K2-Instruct-GGUF",
    local_dir = "unsloth/Kimi-K2-Instruct-GGUF",
    allow_patterns = ["*UD-TQ1_0*"], # Dynamic 1ビット (281GB) には "*UD-Q2_K_XL*" を使用
)
```

{% endcode %}

{% hint style="info" %}
ダウンロードが90〜95%あたりで止まる場合は、こちらをご覧ください <https://docs.unsloth.ai/basics/troubleshooting-and-faqs#downloading-gets-stuck-at-90-to-95>
{% endhint %}

4. 任意のプロンプトを実行できます。
5. 編集 `--threads -1` CPUスレッド数用（デフォルトではCPUの最大スレッド数に設定されています）、 `--ctx-size 16384` コンテキスト長は `--n-gpu-layers 99` GPUオフローディングで何層を担当するかを指定します。MoEのCPUオフローディングと組み合わせて99に設定すると最良の性能が得られます。GPUがメモリ不足になる場合は調整してみてください。また、CPUのみで推論する場合は削除してください。

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Kimi-K2-Instruct-GGUF/UD-TQ1_0/Kimi-K2-Instruct-UD-TQ1_0-00001-of-00005.gguf \\
    --n-gpu-layers 99 \\
    --temp 0.6 \
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU"
```

{% endcode %}

### :bird: Flappy Bird + その他のテスト <a href="#heptagon-test" id="heptagon-test"></a>

DeepSeek R1向けの1.58ビット量子化版が提供された際に、Flappy Birdテストを導入しました。Kimi K2は、このテストを含むすべてのタスクを一発でこなせた数少ないモデルの一つだと分かりました。 [Heptagon ](/docs/jp/moderu/tutorials/deepseek-r1-0528-how-to-run-locally.md#heptagon-test)2ビットでも他のテストでも同様でした。目的は、LLMにFlappy Birdゲームを作成させつつ、いくつかの特定の指示に従わせることです：

{% code overflow="wrap" %}

```
PythonでFlappy Birdゲームを作成してください。以下の内容を必ず含めてください：
1. pygame を使用する必要があります。
2. 背景色はランダムに選ばれる明るい色にしてください。最初は薄い青色にします。
3. SPACE を何度も押すと鳥が加速します。
4. 鳥の形は四角、円、三角形のいずれかをランダムに選びます。色はランダムに暗い色を選びます。
5. 画面下部に、ランダムに選ばれた濃い茶色または黄色の地面を配置します。
6. スコアを右上に表示します。パイプを通過してぶつからなければ加算してください。
7. 十分な間隔を空けて、ランダムな間隔でパイプを配置します。色はランダムに濃い緑、薄い茶色、または暗いグレー系の色にします。
8. 負けたら最高スコアを表示します。文字は画面内に表示してください。q または Esc を押すとゲームを終了します。再開はもう一度 SPACE を押します。
最終的なゲームは、Pythonのmarkdownセクション内に入れてください。最終markdownセクションの前にコードのエラーを確認し、修正してください。
```

{% endcode %}

また、Heptagonテストでもダイナミック量子化版を試せます。 [r/Localllama](https://www.reddit.com/r/LocalLLaMA/comments/1j7r47l/i_just_made_an_animation_of_a_ball_bouncing/) これは、移動する閉じた七角形の形の中で回転するボールをシミュレートする基本的な物理エンジンを作成できるかをモデルにテストするものです。

<figure><img src="https://docs.unsloth.ai/~gitbook/image?url=https%3A%2F%2F3215535692-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FxhOjnexMCB3dmuQFQ2Zq%252Fuploads%252F2O72oTw5yPUbcxXjDNKS%252Fsnapshot.jpg%3Falt%3Dmedia%26token%3Dce852f9f-20ee-4b93-9d7b-1a5f211b9e04&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=55d1134d&#x26;sv=2" alt="" width="563"><figcaption></figcaption></figure>

目的は七角形を回転させ、その中のボールも動くようにすることです。プロンプトは以下のとおりです：

{% code overflow="wrap" %}

```
回転する七角形の中で20個のボールが跳ねる様子を表示するPythonプログラムを書いてください:
- すべてのボールは同じ半径を持つ。
- すべてのボールには1から20までの番号が付いている。
- 開始時、すべてのボールは七角形の中心から落下する。
- 色は: #f8b862, #f6ad49, #f39800, #f08300, #ec6d51, #ee7948, #ed6d3d, #ec6800, #ec6800, #ee7800, #eb6238, #ea5506, #ea5506, #eb6101, #e49e61, #e45e32, #e17b34, #dd7a56, #db8449, #d66a35
- ボールは重力と摩擦の影響を受け、回転する壁に現実的に跳ね返る必要があります。ボール同士の衝突も必要です。
- すべてのボールの材質により、その跳ね返りの高さは七角形の半径を超えず、かつボールの半径よりは高くなければなりません。
- すべてのボールは摩擦を伴って回転し、ボール上の数字はボールの回転を示すために使えます。
- 七角形は中心の周りを回転し、回転速度は5秒で360度です。
- 七角形の大きさは、すべてのボールを収められる十分な大きさでなければなりません。
- pygameライブラリは使わず、衝突検出アルゴリズムや衝突応答などは自分で実装してください。以下のPythonライブラリは使用可能です: tkinter, math, numpy, dataclasses, typing, sys.
- すべてのコードは1つのPythonファイルにまとめてください。
```

{% endcode %}


---

# 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/kimi-k2-thinking-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.
