> 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 [動的](/docs/jp/ji-ben/unsloth-dynamic-2.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 動的**](/docs/jp/ji-ben/unsloth-dynamic-2.0-ggufs.md) **量子化版** は重要な層を 8ビットにアップキャストし、1ビットには **310GB以上の VRAM/RAM** 構成が必要で&#x3059;**.** 損失なしの **損失なしの** Kimi K2.6 では、Q8（`UD-Q8_K_XL`）、これはわずか **10GB 大きい** Q4（`UD-Q4_K_XL`）を使用してください。Kimi K2.7 Code は Mac Studio または [DGX Station](/docs/jp/burogu/dgx-station.md).

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

| 動的 1ビット | 動的 2ビット   | 動的 Q3      | Q8（ロスレス） |
| ------- | --------- | ---------- | -------- |
| 310 GB  | 325〜350GB | 385〜470 GB | 605 GB   |

### 📊 量子化分析

〜と同様に [Kimi-K2.6](/docs/jp/moderu/kimi-k2.6.md), `UD-Q8_K_XL` はロスレスです。なぜなら Kimi は MoE 重みに int4 を、それ以外すべてに BF16 を使っており、 `Q8_K_XL` もそれに従うからです。したがって、Kimi-K2.6 の変換にも同じ Dynamic 手法を使用します。 `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（ロスレス） |
| -------- | ------------ | ------------ | ------------------ |
| ディスク容量   | 339 GB       | 584 GB       | 595 GB             |
| パープレキシティ | \~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": "1+1はいくつですか？"},])` 次のようになります:

{% code overflow="wrap" %}

```
<|im_user|>user<|im_middle|>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|>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/shii/studio.md)、ローカル AI 向けのオープンソース Web UI です。 **Unsloth Studio は自動的に RAM にオフロードし、マルチ GPU 構成を検出します**。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）
* [自動推論](/docs/jp/shii/studio.md#model-arena) パラメータ調整（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/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/shii/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/shii/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.
