> 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/kimi-k2.7-code.md).

# Kimi K2.7 Code - ローカルでの実行方法

Kimi K2.7 Codeは、Moonshot AIのエージェント型コーディングモデルで、 [K2.6](/docs/jp/moderu/kimi-k2.6.md) タスク完了率を向上させつつ、思考トークンを約30%削減します。1Tパラメータ（32B有効）のMoEモデルは、推論のみ、画像認識、256Kコンテキストをサポートします。画像、コーディング、エージェント、長文コンテキスト、チャットの各タスクで、オープンモデルとして最高水準の性能を発揮します。完全精度では605GBのディスク容量が必要です。Unsloth [Dynamic](/docs/jp/ji-ben/dynamic-3.0-ggufs.md) 2ビットには **325GB（-48%）**&#x304C;必要です。 [**Kimi-K2.7-Code-GGUF**](https://huggingface.co/unsloth/Kimi-K2.7-Code-GGUF) をUnsloth Studioまたはllama.cpp経由で実行できます。

[**Unsloth Dynamic**](/docs/jp/ji-ben/dynamic-3.0-ggufs.md) **量子化** 重要なレイヤーを8ビットにアップキャストし、1ビットには **310GB以上のVRAM/RAM** の構成が必要で&#x3059;**.** 〜に対して **損失なしの** Kimi K2.7を使う場合は、Q8（`UD-Q8_K_XL`）を使用してください。これは **10GB大きい** で、Q4（`UD-Q4_K_XL`）を使用してください。Mac Studioまたは [DGX Station](/docs/jp/burogu/dgx-station.md).

**表: ハードウェア要件** （単位 = 合計メモリ: RAM + VRAM、またはユニファイドメモリ）

| ダイナミック1ビット | ダイナミック2ビット | ダイナミックQ3  | Q8（損失なし） |
| ---------- | ---------- | --------- | -------- |
| 310GB      | 325〜350GB  | 385〜470GB | 605GB    |

### 📊 量子化分析

のように、 [Kimi-K2.6](/docs/jp/moderu/kimi-k2.6.md), `UD-Q8_K_XL` は損失なしです。これはKimiがMoE重みにint4を使い、それ以外すべてにBF16を使っているためで、 `Q8_K_XL` もそれに従います。そのため、Kimi-K2.6の変換でも同じダイナミック方式を使用します。 `UD-Q4_K_XL` は似ていますが、残りのテンソルは `Q8_0`なので、ほぼ完全精度であり、600GBのRAM/VRAMが必要です。 `UD-Q8_K_XL` は「真に損失なし」です。

| 測定       | UD-Q2\_K\_XL | UD-Q4\_K\_XL | UD-Q8\_K\_XL（損失なし） |
| -------- | ------------ | ------------ | ------------------ |
| ディスク容量   | 339GB        | 584GB        | 595GB              |
| パープレキシティ | \~2.4131     | \~1.8420     | \~1.8419           |

私たちは [jukofyork](https://github.com/jukofyork)の発見に従いました。それは `const float d = max / -7;` をデフォルトの `const float d = max / -8;` の代わりに、量子化処理中はMoEレイヤーにのみ適用するというものです。このINT4ネイティブMoEへの双射パッチにより、 `Q4_0` 量子化タイプは絶対誤差を1.8%からほぼ0%（epsilon）まで減らせます。以下はKimi-K2.7-Codeのヒストグラムの例で、-8が完全に未使用であることが分かります:

<figure><img src="/files/6b830e5a31b26b188363997af81f145df4235841" alt=""><figcaption></figcaption></figure>

なお、他のレイヤーもBF16のままにする必要があり、賢く「Q4\_0」にしてはいけません。以下に、BF16ベースラインと比較した両者の誤差プロットを示します。 `UD-Q8-K_XL` は、Q4\_0からBF16へ変換する際に機械イプシロン程度の差はあるものの、真に「損失なし」です。したがってQ4\_K\_XLにはQ8\_0を使用しているため量子化誤差がありますが、Q8\_K\_XLはBF16の丸め誤差を除けばほぼ損失なしです。

<figure><img src="/files/3ebf28ab37d68474ba981640171048d414d58711" alt=""><figcaption></figcaption></figure>

Q4\_K\_XLについては、Q8\_0とBF16のテンソルごとの誤差もプロットしています。一般に、Q8\_K\_XL（ほぼ損失なし）とQ4\_K\_XLの間にはある程度の誤差がありますが、大きくはありません。

<figure><img src="/files/53ec344bcdcbeaa0795f45db4591b16650067976" alt=""><figcaption></figcaption></figure>

### :gear: 使用ガイド

Kimi K2.7 Codeは **推論のみ**で、 **`preserve_thinking` が常に有効です**。インスタントモードはサポートされていません。

| デフォルト（推論モード）      |
| ----------------- |
| temperature = 1.0 |
| top\_p = 0.95     |

* 推奨コンテキスト長 = `98,304` （最大 `262,144`)

モデルが収まれば、B200を使用すると100トークン/秒以上が得られます。私たちは `UD-Q2_K_XL` （345GB）を、サイズと品質のバランスが良いものとして推奨します。最も簡単な目安は、RAM+VRAM ≈ 量子化サイズです。そうでなくても動作はしますが、オフロードのため遅くなります。

#### Kimi K2.7-Codeのチャットテンプレート

実行中 `tokenizer.apply_chat_template([{"role": "user", "content": "What is 1+1?"},])` を実行すると:

{% code overflow="wrap" %}

```
<|im_user|>user<|im_middle|>What is 1+1?<|im_end|><|im_assistant|>assistant<|im_middle|><think>
```

{% endcode %}

また、で参照されているツールも入力すると [Tool Calling Guide](/docs/jp/ji-ben/tool-calling-guide-for-local-llms.md)、以下のようになります:

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

```
<|im_system|>tool_declare<|im_middle|># ツール

## 関数
namespace functions {
// 2つの数を足します。
type add_number = (_: {
  // 1つ目の数。
  a: string,
  // 2つ目の数。
  b: string
}) => any;
// 2つの数を掛けます。
type multiply_number = (_: {
  // 1つ目の数。
  a: string,
  // 2つ目の数。
  b: string
}) => any;
// 2つの数を引きます。
type subtract_number = (_: {
  // 1つ目の数。
  a: string,
  // 2つ目の数。
  b: string
}) => any;
// ランダムな物語を書きます。
type write_a_story = (_: {}) => any;
// ターミナルから操作を実行します。
type terminal = (_: {
  // 起動したいコマンド。例: `ls`、`rm` など
  command: string
}) => any;
// 実行されるPythonコードを指定してPythonインタープリタを呼び出します。
type python = (_: {
  // 実行するPythonコード
  code: string
}) => any;
}
<|im_end|><|im_user|>user<|im_middle|>What is 1+1?<|im_end|><|im_assistant|>assistant<|im_middle|><think>
```

{% endcode %}

## Kimi K2.7 Code 実行ガイド

### 🦥 Unsloth StudioでKimi-K2.7-Codeを実行

Kimi K2.7 Codeは [Unsloth Studio](/docs/jp/xin-zhe/studio.md)で実行できます。これはローカルAI向けのオープンソースWeb UIです。 **Unsloth Studioは自動的にRAMへオフロードし、マルチGPU構成を検出します**。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) + **ウェブ検索**
* [**コード実行**](/docs/jp/xin-zhe/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/xin-zhe/studio.md#no-code-training) VRAMを70%削減しつつ2倍高速
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="/files/c32867f999db074387ac16732ce548485cc593de" 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
```

**Unslothを起動**

MacOS、Linux、WSL、およびWindows：

```bash
unsloth studio -H 0.0.0.0 -p 8888
```

次に開く `http://127.0.0.1:8888` （またはお使いのURL）をブラウザで。
{% endstep %}

{% step %}
**Kimi K2.7-Codeを検索してダウンロード**

Unsloth Studioは自動的にRAMへオフロードし、マルチGPU構成を検出します。初回起動時には、アカウントを保護するためのパスワードを作成し、後で再度サインインする必要があります。

次に〜へ移動し [Unsloth Chat](/docs/jp/xin-zhe/studio/chat.md) タブで **Kimi-K2.7 Code** を検索バーで検索し、希望するモデルと量子化をダウンロードしてください。モデルを実行するのに十分な計算資源があることを確認してください。

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

{% step %}
**Kimi-K2.7-Codeを実行**

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

詳細については、次を参照してください [Unsloth Studio推論ガイド](/docs/jp/xin-zhe/studio/chat.md).

<div data-with-frame="true"><figure><img src="/files/aefe9115149da8c8069575f294893ffc6e2b9d80" alt="" width="563"><figcaption><p>ツール呼び出しを使ったQwen3.6の実行例</p></figcaption></figure></div>
{% endstep %}
{% endstepper %}

### 🦙 llama.cppでKimi K2.7 Codeを実行

このガイドでは、 `UD-Q2_K_XL` 量子化を実行します。これには少なくとも345GBのRAMが必要です。量子化タイプは自由に変更できます。GGUF: [**Kimi-K2.7-Code-GGUF**](https://huggingface.co/unsloth/Kimi-K2.7-Code-GGUF)

これらのチュートリアルでは、 [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 %}
**まず画像を取得しましょう！** 画像をアップロードすることもできます。ここでは <https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/unsloth%20made%20with%20love.png>を使用します。これは、Unslothでファインチューニングがどのように作られているかを示す、私たちのミニロゴです:

{% code overflow="wrap" %}

```bash
wget https://raw.githubusercontent.com/unslothai/unsloth/refs/heads/main/images/unsloth%20made%20with%20love.png -O unsloth.png
```

{% endcode %}

<figure><img src="/files/8ae02fb49d0894924cd953777ab38bc4d56ba3f8" alt="" width="188"><figcaption></figcaption></figure>

2枚目の画像は <https://files.worldwildlife.org/wwfcmsprod/images/Sloth_Sitting_iStock_3_12_2014/story_full_width/8l7pbjmj29_iStock_000011145477Large_mini__1_.jpg>

{% code overflow="wrap" %}

```bash
wget https://files.worldwildlife.org/wwfcmsprod/images/Sloth_Sitting_iStock_3_12_2014/story_full_width/8l7pbjmj29_iStock_000011145477Large_mini__1_.jpg -O picture.png
```

{% endcode %}

<figure><img src="/files/5e1b9352de623a1d57f735cf6be692f421bca972" alt="" width="188"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
これで次を使用できます `llama.cpp` モデルの読み込みとダウンロードに直接使えます。次と同じように `ollama run`。まず、次のように希望する量子化タイプを選択します `Q2_K_XL`。また、次も使用します `export LLAMA_CACHE="folder"` して `llama.cpp` を特定の場所に保存するよう強制できます。このダウンロード प्रक्रियाはかなり遅い場合があるため、次のセクションの手動ダウンロード手順を使うのがおそらく最善です。

```bash
export LLAMA_CACHE="unsloth/Kimi-K2.7-Code-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/Kimi-K2.7-Code-GGUF:UD-Q2_K_XL \\
    --temp 1.0 \
    --top-p 0.95
```

{% endstep %}

{% step %}
モデルを手動でダウンロードしたい場合は、以下のコードでダウンロードできます（次をインストールした後） `pip install huggingface_hub`。ダウンロードが止まった場合は、次を参照してください： [Hugging Face Hub、XET のデバッグ](/docs/jp/ji-ben/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

```bash
hf download unsloth/Kimi-K2.7-Code-GGUF \\
    --local-dir unsloth/Kimi-K2.7-Code-GGUF \\
    --include "*mmproj-F16*" \\
    --include "*UD-Q2_K_XL*" # フル精度には "*UD-Q8_K_XL*" を使用
```

{% endstep %}

{% step %}
それでは、会話モードでモデルを実行します:

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Kimi-K2.7-Code-GGUF/UD-Q2_K_XL/Kimi-K2.7-Code-UD-Q2_K_XL-00001-of-00008.gguf \\
    --mmproj unsloth/Kimi-K2.7-Code-GGUF/mmproj-F16.gguf \\
    --temp 1.0 \
    --top-p 0.95
```

{% endcode %}

すると、以下のように表示されます:\
![](/files/02c4df21ea6e09c54585d47490b95cd8db643a11)
{% endstep %}

{% step %}
次に `/image` を使って両方の画像を読み込み、「この画像は何ですか」と尋ねます:

<figure><img src="/files/cdb9a202276fea64e9d39c7380498181ba500e02" alt=""><figcaption></figcaption></figure>

すると、以下のような結果が得られます:

<figure><img src="/files/9176d6f19ea61f4fc44b926be9dddaf42fb33b75" alt=""><figcaption></figcaption></figure>

ナマケモノの2枚目の画像では:

<figure><img src="/files/504b85d66a8d3ecbbbc935a9275d4672f7e70d71" alt=""><figcaption></figcaption></figure>

次のようになります:

<figure><img src="/files/c7d95757516534db9e50b97226ab77157e20bb05" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### 📊 ベンチマーク

ベンチマークは、以下の表形式でもご覧いただけます:

<div data-with-frame="true"><figure><img src="/files/73e5355606acfe3ad8f5901a8f7798bba3cd12f6" alt="" width="563"><figcaption></figcaption></figure></div>

|        ベンチマーク        | Kimi K2.7 Code | Kimi K2.6 | GPT-5.5 | Claude Opus 4.8 |
| :------------------: | :------------: | :-------: | :-----: | :-------------: |
|      **コーディング**      |                |           |         |                 |
|  Kimi Code Bench v2  |      62.0      |    50.9   |   69.0  |       67.4      |
|     Program Bench    |      53.6      |    48.3   |   69.1  |       63.8      |
|    MLS Bench Lite    |      35.1      |    26.7   |   35.5  |       42.8      |
|      **エージェント型**     |                |           |         |                 |
| Kimi Claw 24/7 Bench |      46.9      |    42.9   |   52.8  |       50.4      |
|       MCP Atlas      |      76.0      |    69.4   |   79.4  |       81.3      |
|   MCP Mark Verified  |      81.1      |    72.8   |   92.9  |       76.4      |


---

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