> 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/qwen3-coder-next.md).

# Qwen3-Coder-Next: ローカルでの実行方法

Qwen3-Coder-Nextをデバイス上でローカル実行するためのガイド！

QwenはQwen3-Coder-Nextをリリースしました。これは80BのMoEモデル（有効パラメータ3B）で、 **256Kコンテキスト** 高速なエージェント型コーディングとローカル利用向けです。有効パラメータが10～20倍多いモデルに匹敵する性能です。

動作には **46GBのRAM**/VRAM/ユニファイドメモリ（8-bitなら85GB）が必要で、超高速なコード応答のために非推論モードです。このモデルは、長期的な推論、複雑なツール利用、実行失敗からの復旧に優れています。

{% hint style="success" %}
**2月19日更新**: llama.cppのパース修正後、ツール呼び出しがさらに改善されるはずです。

**新登場！** こちらを参照 [量子化ベンチマーク](#gguf-quantization-benchmarks) Dynamic GGUF向け！

**2月4日:** `llama.cpp` の計算を修正するバグを直しました `ベクトル化された key_gdiff。` これで以前のループと出力の問題が修正されます。GGUFを更新したので、どうか **再ダウンロード** そして **更新** `llama.cpp` より良い出力のために。
{% endhint %}

Codex & Claude Codeでモデルを実行する方法も学べます。なお **ファインチューニング**、Qwen3-Next-CoderはUnslothのbf16 LoRAなら単一のB200 GPUに収まります。

Unsloth版Qwen3-Coder-Next [Dynamic GGUF](/docs/jp/ji-chu/dynamic-3.0-ggufs.md) 実行するには: [unsloth/Qwen3-Coder-Next-GGUF](https://huggingface.co/unsloth/Qwen3-Coder-Next-GGUF)

<a href="/docs/jp/moderu/qwen3-coder-next.md#run-qwen3-coder-next" class="button primary">GGUF実行チュートリアル</a><a href="https://unsloth.ai/docs/models/qwen3-coder-next#claude-codex" class="button secondary">Codex & Claude Code</a><a href="/docs/jp/moderu/qwen3-coder-next.md#fp8-qwen3-coder-next-in-vllm" class="button secondary">FP8 vLLMチュートリアル</a>

### ⚙️ 使用ガイド

46GBのRAMやユニファイドメモリがなくても大丈夫です。3ビットのような小さい量子化モデルを実行できます。モデルサイズは計算資源の合計（ **`ディスク容量 + RAM + VRAM ≥ 量子化サイズ）となるのが理想です。`** 量子化モデルがデバイスに完全に収まるなら、20トークン/秒以上が見込めます。収まらない場合でもオフロードで動作しますが、遅くなります。

最適な性能を達成するために、Qwenは次の設定を推奨しています:

* <mark style="background-color:blue;">`Temperature = 1.0`</mark>
* `Top_P = 0.95`
* `Top_K = 40`
* `Min_P = 0.01` （llama.cppのデフォルトは0.05）
* `繰り返しペナルティ` = 無効、または1.0

最大 `262,144` コンテキストをネイティブにサポートしますが、 `32,768` メモリ使用量を減らすためのトークン。

### 🖥️ Qwen3-Coder-Nextを実行

用途によって異なる設定を使う必要があります。このガイドでは4-bitを使うため、約46GBのRAM/ユニファイドメモリが必要です。最高の性能のため、少なくとも3-bit精度の使用を推奨します。

#### 🦥 Unsloth Studio ガイド

Qwen3-Coder-Nextは、 [Unsloth Studio](/docs/jp/shii/studio.md)。これはローカルAI向けの新しいオープンソースWeb UIです。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) + **web search**
* [**コード実行**](/docs/jp/shii/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/shii/studio.md#no-code-training) VRAMを70%削減して2倍高速
  {% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FFeQ0UUlnjXkDdqhcWglh%2Fskinny%20studio%20chat.png?alt=media&amp;token=c2ee045f-c243-4024-a8e4-bb4dbe7bae79" 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
```

{% hint style="success" %}
**インストールはすぐに終わり、約 1〜2 分かかります。**
{% endhint %}
{% endstep %}

{% step %}
**Unsloth を起動**

MacOS、Linux、WSL、Windows:

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

その後、 `http://localhost:8888` をブラウザで開いてください。
{% endstep %}

{% step %}
**Qwen3-Coder-Nextを検索してダウンロード**

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

それから [Unsloth Chat](/docs/jp/shii/studio/chat.md) タブで検索して **Qwen3-Coder-Next** を検索バーに入力し、希望するモデルと量子化版をダウンロードしてください。

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fit06amlW1KexxlYARKNV%2FScreenshot%202026-04-02%20at%201.57.55%E2%80%AFAM.png?alt=media&amp;token=74fb6c0f-fbd1-4506-be76-050f27de8d02" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Qwen3-Coder-Nextを実行**

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

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

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FXPQGEEr1YoKofrTatAKK%2Ftoolcallingif.gif?alt=media&amp;token=25d68698-fb13-4c46-99b2-d39fb025df08" alt="" width="563"><figcaption></figcaption></figure></div>
{% endstep %}
{% endstepper %}

#### Llama.cppチュートリアル（GGUF）:

llama.cpp で実行する手順（ほとんどのデバイスに収めるため、4bit を使用します）：

{% 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サポートはデフォルトで有効です。

{% code overflow="wrap" %}

```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
```

{% endcode %}
{% endstep %}

{% step %}
Hugging Faceから直接取得できます。RAM/VRAMに収まるなら、コンテキストを256Kまで増やせます。 `--fit on` を使うと、コンテキスト長も自動判定されます。

推奨パラメータを使用できます: `temperature=1.0`, `top_p=0.95`, `top_k=40`

```bash
./llama.cpp/llama-cli \
    -hf unsloth/Qwen3-Coder-Next-GGUF:UD-Q4_K_XL \\
    --ctx-size 16384 \\
    --temp 1.0 --top-p 0.95 --min-p 0.01 --top-k 40
```

{% endstep %}

{% step %}
以下をインストールした後、( `pip install huggingface_hub`をインストール後）。 `UD-Q4_K_XL` または他の量子化版を使ってください。ダウンロードが止まる場合は、こちらを参照してください [Hugging Face Hub、XET のデバッグ](/docs/jp/ji-chu/troubleshooting-and-faqs/hugging-face-hub-xet-debugging.md)

{% code overflow="wrap" %}

```bash
pip install -U huggingface_hub
hf download unsloth/Qwen3-Coder-Next-GGUF \
    --local-dir unsloth/Qwen3-Coder-Next-GGUF \
    --include "*UD-Q4_K_XL*"
```

{% endcode %}
{% endstep %}

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

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Qwen3-Coder-Next-GGUF/Qwen3-Coder-Next-UD-Q4_K_XL.gguf \\
    --seed 3407 \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --min-p 0.01 \\
    --top-k 40
```

{% endcode %}

また、調整してください **コンテキストウィンドウ** 必要に応じて、最大 `262,144`

{% hint style="info" %}
注意: このモデルは非思考モードのみをサポートし、 `<think></think>` 出力にブロックを生成しません。したがって、 `enable_thinking=False` はもはや必要ありません。
{% endhint %}
{% endstep %}
{% endstepper %}

### 🦙Llama-server のサービングとデプロイ

Qwen3-Coder-Nextを本番環境にデプロイするには、 `llama-server` 新しいターミナルで、たとえばtmux経由で起動します。次に、以下でモデルをデプロイします:

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \
    --model unsloth/Qwen3-Coder-Next-GGUF/Qwen3-Coder-Next-UD-Q4_K_XL.gguf \\
    --alias "unsloth/Qwen3-Coder-Next" \\
    --seed 3407 \\
    --temp 1.0 \\
    --top-p 0.95 \\
    --min-p 0.01 \\
    --top-k 40 \
    --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/Qwen3-Coder-Next",
    messages = [{"role": "user", "content": "HTMLでFlappy Birdゲームを作成してください"},],
)
print(completion.choices[0].message.content)
```

{% endcode %}

次のように出力されます:

{% columns %}
{% column width="66.66666666666666%" %}
{% code overflow="wrap" expandable="true" %}

````markdown
こちらは、単一ファイルにまとめられた完全に動作するFlappy Birdゲームです。

グラフィックスには **HTML5 Canvas** を、物理演算（重力、衝突判定、スコアリング）には **JavaScript** を使用しました。外部画像やダウンロードは不要で、コードで鳥とパイプを描画します。

### 実行方法:
1.  下のコードブロックをコピーします。
2.  `game.html` という名前で、コンピューター上に新しいファイルを作成します。
3.  そのファイルにコードを貼り付けて保存します。
4.  `game.html` をダブルクリックして、Webブラウザーで開きます。

```html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>シンプルなFlappy Bird</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #333;
            font-family: 'Courier New', Courier, monospace;
            color: white;
        }

        h1 {
            margin-bottom: 10px;
        }

        #game-container {
            position: relative;
            box-shadow: 0 0 20px rgba(0,0,0,0.5);
        }

        canvas {
            display: block;
            background-color: #70c5ce; /* 空色 */
            border: 4px solid #000;
        }

        #ui-layer {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none; /* クリックをcanvasに通す */
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
        }

        .message {
            background: rgba(255, 255, 255, 0.8);
            padding: 20px;
            border-radius: 10px;
            color: #333;
        }

        #score-board {
            position: absolute;
            top: 20px;
            width: 100%;
            text-align: center;
            font-size: 40px;
            font-weight: bold;
            color: white;
            text-shadow: 2px 2px 0 #000;
            z-index: 10;
        }
    </style>
</head>
<body>

    <h1>Flappy Birdクローン</h1>
    
    <div id="game-container">
        <div id="score-board">0</div>
        <canvas id="birdCanvas" width="320" height="480"></canvas>
        
        <div id="ui-layer">
            <div id="start-screen" class="message">
                <h2>飛ぶ準備はできた？</h2>
                <p><strong>Space</strong>または<strong>Click</strong>でジャンプ</p>
                <p>Spaceキーで開始</p>
            </div>
            <div id="game-over-screen" class="message" style="display: none;">
                <h2>ゲームオーバー</h2>
                <p>スコア: <span id="final-score">0</span></p>
                <p>ベスト: <span id="best-score">0</span></p>
                <p><strong>Space</strong>で再スタート</p>
            </div>
        </div>
    </div>

    <script>
        // --- 設定 ---
        const canvas = document.getElementById('birdCanvas');
        const ctx = canvas.getContext('2d');
        const scoreElement = document.getElementById('score-board');
        const startScreen = document.getElementById('start-screen');
        const gameOverScreen = document.getElementById('game-over-screen');
        const finalScoreSpan = document.getElementById('final-score');
        const bestScoreSpan = document.getElementById('best-score');

        // ゲーム変数
        let frames = 0;
        let score = 0;
        let highScore = localStorage.getItem('flappyHighScore') || 0;
        let gameState = 'START'; // START, PLAYING, GAMEOVER
        const gravity = 0.25;
        const speed = 2; // 左へ動くパイプの速度

        // --- 鳥オブジェクト ---
        const bird = {
            x: 50,
            y: 150,
            width: 30,
            height: 30,
            velocity: 0,
            jumpStrength: 4.5,
            radius: 15,
            draw: function() {
                ctx.fillStyle = "#FFD700"; // 金色
                ctx.beginPath();
                ctx.arc(this.x + this.radius, this.y + this.radius, this.radius, 0, Math.PI * 2);
                ctx.fill();
                ctx.lineWidth = 2;
                ctx.stroke();

                // 目
                ctx.fillStyle = "white";
                ctx.beginPath();
                ctx.arc(this.x + this.radius + 5, this.y + this.radius - 5, 5, 0, Math.PI * 2);
                ctx.fill();
                ctx.fillStyle = "black";
                ctx.beginPath();
                ctx.arc(this.x + this.radius + 7, this.y + this.radius - 5, 2, 0, Math.PI * 2);
                ctx.fill();
                
                // くちばし
                ctx.fillStyle = "orange";
                ctx.beginPath();
                ctx.moveTo(this.x + this.radius + 10, this.y + this.radius);
                ctx.lineTo(this.x + this.radius + 20, this.y + this.radius + 5);
                ctx.lineTo(this.x + this.radius + 10, this.y + this.radius + 10);
                ctx.fill();
                ctx.stroke();
            },
            update: function() {
                this.velocity += gravity;
                this.y += this.velocity;

                // 床との衝突
                if (this.y + this.height >= canvas.height) {
                    this.y = canvas.height - this.height;
                    gameOver();
                }
                
                // 天井との衝突（任意: パイプを飛び越えるのを防ぐ）
                if (this.y < 0) {
                    this.y = 0;
                    this.velocity = 0;
                }
            },
            jump: function() {
                this.velocity = -this.jumpStrength;
            },
            reset: function() {
                this.y = 150;
                this.velocity = 0;
            }
        };

        // --- パイプ配列 ---
        const pipes = {
            position: [],
            width: 50,
            gap: 120, // 上下のパイプの間隔
            dx: 2, // 移動速度

            draw: function() {
                for (let i = 0; i < this.position.length; i++) {
                    let p = this.position[i];
                    let topY = p.y;
                    let bottomY = p.y + this.gap;

                    ctx.fillStyle = "#228B22"; // 森の緑

                    // 上のパイプ
                    ctx.fillRect(p.x, 0, this.width, topY);
                    ctx.strokeRect(p.x, 0, this.width, topY);

                    // 下のパイプ
                    ctx.fillRect(p.x, bottomY, this.width, canvas.height - bottomY);
                    ctx.strokeRect(p.x, bottomY, this.width, canvas.height - bottomY);
                }
            },

            update: function() {
                // 120フレームごとに新しいパイプを追加（約2秒）
                if (frames % 120 === 0) {
                    // 上のパイプのランダムな高さ
                    // 最小高さ50、最大高さは canvas - gap - 50
                    let maxY = canvas.height - this.gap - 50;
                    let randomY = Math.floor(Math.random() * (maxY - 50 + 1) + 50);
                    
                    this.position.push({
                        x: canvas.width,
                        y: randomY
                    });
                }

                for (let i = 0; i < this.position.length; i++) {
                    let p = this.position[i];
                    p.x -= this.dx;

                    // 衝突判定
                    // ロジック: 鳥のXがパイプのX範囲内にあるか確認
                    if (bird.x + bird.width > p.x && bird.x < p.x + this.width) {
                        // ロジック: 鳥のYが上のパイプまたは下のパイプに当たっているか確認
                        if (bird.y < p.y || bird.y + bird.height > p.y + this.gap) {
                            gameOver();
                        }
                    }

                    // スコア更新（鳥がパイプを通過したとき）
                    if (p.x + this.width < bird.x && !p.passed) {
                        score++;
                        scoreElement.innerText = score;
                        p.passed = true;
                    }

                    // 画面外に出たパイプを削除
                    if (p.x + this.width <= 0) {
                        this.position.shift();
                        // 配列の長さが変わるので i を減らす
                        i--; 
                    }
                }
            },
            
            reset: function() {
                this.position = [];
            }
        };

        // --- 背景（雲/芝生） ---
        const background = {
            draw: function() {
                // 芝生を描画
                ctx.fillStyle = "#7cfc00"; // 芝生の緑
                ctx.fillRect(0, canvas.height - 20, canvas.width, 20);
                ctx.beginPath();
                ctx.moveTo(0, canvas.height - 20);
                ctx.lineTo(canvas.width, canvas.height - 20);
                ctx.stroke();
            }
        };

        // --- ゲーム制御関数 ---

        function loop() {
            // キャンバスをクリア
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            // 背景を描画
            background.draw();

            if (gameState === 'START') {
                bird.draw();
                // 地面の線を描く
                ctx.fillStyle = "#ded895";
                ctx.fillRect(0, canvas.height - 10, canvas.width, 10);
            } 
            else if (gameState === 'PLAYING') {
                bird.update();
                bird.draw();
                pipes.update();
                pipes.draw();
                frames++;
            } 
            else if (gameState === 'GAMEOVER') {
                pipes.draw();
                bird.draw();
                // フレームや位置は更新せず、停止させるだけ
            }

            requestAnimationFrame(loop);
        }

        function startGame() {
            gameState = 'PLAYING';
            startScreen.style.display = 'none';
            gameOverScreen.style.display = 'none';
            score = 0;
            frames = 0;
            scoreElement.innerText = score;
            bird.reset();
            pipes.reset();
        }

        function gameOver() {
            gameState = 'GAMEOVER';
            
            // ハイスコアを更新
            if (score > highScore) {
                highScore = score;
                localStorage.setItem('flappyHighScore', highScore);
            }

            finalScoreSpan.innerText = score;
            bestScoreSpan.innerText = highScore;
            gameOverScreen.style.display = 'block';
        }

        // --- 入力処理 ---

        function handleInput(e) {
            // Spaceキーのデフォルトのスクロール動作を防止
            if (e.type === 'keydown' && e.code === 'Space') {
                e.preventDefault();
            }

            if (e.code === 'Space' || e.type === 'mousedown' || e.type === 'touchstart') {
                switch (gameState) {
                    case 'START':
                        startGame();
                        bird.jump();
                        break;
                    case 'PLAYING':
                        bird.jump();
                        break;
                    case 'GAMEOVER':
                        startGame();
                        bird.jump();
                        break;
                }
            }
        }

        window.addEventListener('keydown', handleInput);
        canvas.addEventListener('mousedown', handleInput);
        canvas.addEventListener('touchstart', handleInput);

        // 初期化
        loop();

    </script>
</body>
</html>
```

### この版の機能:
1.  **物理演算:** リアルな重力とジャンプの仕組み。
2.  **衝突判定:** パイプ、床、天井に当たるとゲーム終了。
3.  **スコアシステム:** 通過したパイプ1本ごとに1点獲得。
4.  **ハイスコア:** ブラウザーのLocalStorageを使って、ページを更新してもベストスコアを記録します。
5.  **レスポンシブな操作:** **スペースバー**、**マウスクリック**、または**タッチ**（モバイル端末向け）に対応します。
6.  **グラフィックス:** 鳥はコードで描画され（目とくちばしを含む）、パイプには枠線があるため、画像リンク切れは発生しません。
````

{% endcode %}

HTMLを抽出して実行したところ、生成されたFlappy Birdのサンプルゲームはうまく動作しました！
{% endcolumn %}

{% column width="33.33333333333334%" %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F7ATJWz7O4jMxpVI6I1Wk%2Fimage.png?alt=media&amp;token=a81548fa-843b-499d-9db6-6f215ad5fb99" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### 👾 OpenAI Codex & Claude Code <a href="#claude-codex" id="claude-codex"></a>

ローカルのコーディングエージェントワークロードでモデルを実行するには、ガイドに従ってください。 `llama-server` を使い、モデル名を `GET /v1/models` （ `--alias` 上記の値を `unsloth/Qwen3-Coder-Next`）。Qwen3-Coder-Nextの正しいパラメータと使用手順に従ってください。

{% columns %}
{% column %}
{% content-ref url="/pages/ee610b22aa43d29d8415fd27eb7de15ba88f7385" %}
[Claude Code](/docs/jp/ji-chu/claude-code.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
{% content-ref url="/pages/c87896ff7159620f4c01bb39fe9df1fd1a55274e" %}
[OpenAI Codex](/docs/jp/ji-chu/codex.md)
{% endcontent-ref %}
{% endcolumn %}
{% endcolumns %}

たとえば Claude Code の手順に従った後、次のように表示されます:

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fup2DMSMPjNR8BM9pgR0v%2Fimage.png?alt=media&amp;token=152e9ee0-2491-4379-af18-8fca0789b19d" alt="" width="563"><figcaption></figcaption></figure>

すると、次のように依頼できます `チェスの Python ゲームを作成して` :

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F9TfMAoKSdMpb8OHKNnHH%2Fimage.png?alt=media&amp;token=771df3aa-91ab-4c1e-8676-1830058001ca" alt="" width="563"><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FWP3lI5mQW2EHB79qqgDz%2Fimage.png?alt=media&amp;token=55cf3189-e100-419c-a615-024b45948284" alt="" width="563"><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fn8DZddDODQZGCP8giKYY%2Fimage.png?alt=media&amp;token=996c8cb9-d199-4045-90f0-408690e02667" alt="" width="563"><figcaption></figcaption></figure></div>

もし `APIエラー: 400 {"error":{"code":400,"message":"request (16582 tokens) exceeds the available context size (16384 tokens), try increasing it","type":"exceed_context_size_error","n_prompt_tokens":16582,"n_ctx":16384}}` ということは、コンテキスト長を増やす必要があるか、こちらを参照してください [#how-to-fit-long-context-256k-to-1m](#how-to-fit-long-context-256k-to-1m "mention")

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FP6anV1XewSWIovaH3f7c%2Fimage.png?alt=media&amp;token=285a540b-f6fc-4541-b807-bf4f6dc3807b" alt=""><figcaption></figcaption></figure>

### 🎱 vLLMでFP8 Qwen3-Coder-Next

新しい [FP8 Dynamic quant](https://huggingface.co/unsloth/Qwen3-Coder-Next-FP8-Dynamic) を使って、プレミアムで高速な推論ができます。まずnightly版からvLLMをインストールしてください。 `--extra-index-url https://wheels.vllm.ai/nightly/cu130` を、 `nvidia-smi` -のみ `cu129` そして `cu130` で現在サポートされています。

{% hint style="success" %}
vLLM / SGLangを使う場合は、スループットを25%以上向上できるFP8-Dynamic量子化を試してください！詳細は [#fp8-qwen3-coder-next-in-vllm](#fp8-qwen3-coder-next-in-vllm "mention")
{% endhint %}

{% code overflow="wrap" %}

```bash
# 高速な環境セットアップのため、uvがない場合はインストールします
curl -LsSf https://astral.sh/uv/install.sh | sh

# 新しいPython環境を作成します - システム全体を変更したい場合は不要です
uv venv unsloth_fp8 --python 3.12 --seed
source unsloth_fp8/bin/activate

uv pip install --upgrade --force-reinstall vllm --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightly/cu130
uv pip install --upgrade --force-reinstall git+https://github.com/huggingface/transformers.git
uv pip install --force-reinstall numba
```

{% endcode %}

次に [Unslothの動的FP8版](https://huggingface.co/unsloth/Qwen3-Coder-Next-FP8-Dynamic) のモデルを提供します。さらに、次を追加することでFP8を有効化し、KVキャッシュのメモリ使用量を50%削減できます: `--kv-cache-dtype fp8` 4 GPUで提供しましたが、1 GPUしかない場合は、 `CUDA_VISIBLE_DEVICES='0'` を使い、 `--tensor-parallel-size 1` を設定するか、この引数を削除してください。 `tmux` を使って、下記を新しいターミナルで起動した後、CTRL+B+Dを押してください。 `tmux attach-session -t0` で戻れます。

```bash
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:False
CUDA_VISIBLE_DEVICES='0,1,2,3' vllm serve unsloth/Qwen3-Coder-Next-FP8-Dynamic \\
    --served-model-name unsloth/Qwen3-Coder-Next \\
    --tensor-parallel-size 4 \\
    --tool-call-parser qwen3_coder \\
    --enable-auto-tool-choice \\
    --dtype bfloat16 \\
    --seed 3407 \\
    --max-model-len 200000 \\
    --gpu-memory-utilization 0.93 \\
    --port 8001
```

下のような表示になるはずです。こちらを参照してください [#tool-calling-with-qwen3-coder-next](#tool-calling-with-qwen3-coder-next "mention") OpenAI APIとツール呼び出しを使ってQwen3-Coder-Nextを実際に使う方法については、こちらを参照してください。これはvLLMとllama-serverで動作します。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FxRdgnzg1gz3lBLPvftRx%2Fimage.png?alt=media&amp;token=4f43796b-397f-4ffb-86d2-68afd14994f9" alt=""><figcaption></figcaption></figure>

### :wrench:Qwen3-Coder-Nextによるツール呼び出し

新しいターミナルで、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"Executing terminal command `{command}`")
    try:
        return str(subprocess.run(command, capture_output = True, text = True, shell = True, check = True).stdout)
    except subprocess.CalledProcessError as e:
        return f"Command failed: {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 = 40,
    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"Using model = {model_name}")
    has_tool_calls = True
    original_messages_len = len(messages)
    while has_tool_calls:
        print(f"Current 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 %}

それでは、さまざまなユースケースで Tool Calling を実行する複数の方法を以下で紹介します：

#### 生成された Python コードを実行する

{% code overflow="wrap" %}

```python
messages = [{
    "role": "user",
    "content": [{"type": "text", "text": "Python でフィボナッチ関数を作成し、fib(20) を求めてください。"}],
}]
unsloth_inference(messages, temperature = 1.0, top_p = 0.95, top_k = 40, min_p = 0.00)
```

{% endcode %}

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F7fY3LSeNCjHXNjBwQkbI%2Fimage.png?alt=media&amp;token=50eba62e-f8b2-424a-833b-be56696b4710" alt=""><figcaption></figcaption></figure>

#### 任意のターミナル関数を実行する

{% code overflow="wrap" %}

```python
messages = [{
    "role": "user",
    "content": [{"type": "text", "text": "'I'm a happy Sloth' をファイルに書き込み、それを私に表示してください。"}],
}]
messages = unsloth_inference(messages, temperature = 1.0, top_p = 1.0, top_k = 40, min_p = 0.00)
```

{% endcode %}

ファイルが作成されたことを確認し、実際に作成されていました！

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FabplwVbEMlsCEJTmxzSA%2Fimage.png?alt=media&amp;token=eb27f30a-c91e-4aec-8fb0-f4a35921d3db" alt=""><figcaption></figcaption></figure>

こちらを参照 [Tool Calling Guide](/docs/jp/ji-chu/tool-calling-guide-for-local-llms.md) ツール呼び出しのさらなる例について。

## :triangular\_ruler:ベンチマーク

### GGUF量子化ベンチマーク

こちらは第三者の評価者によって実施された量子化ベンチマークです。

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FAc5D3rcKmF6NjlyoLCXJ%2Fqwen3-coder-next-oddly-usable-at-aggressive-quantization-v0-q9q4nsw11rkg1.webp?alt=media&amp;token=a92049ff-0bc2-4afa-a281-82bbacbfe42b" alt="" width="563"><figcaption><p>Aider Polyglotベンチマーク</p></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Ftbfnqq8ppzwFbeqPhnw0%2FHAfMRrrXQAALkQb.png?alt=media&amp;token=9730d4e1-3d4a-4ae6-92bf-32aa6724ab86" alt="" width="450"><figcaption><p>Benjamine Marieベンチマーク（<a href="https://x.com/bnjmn_marie/status/2019809651387514947/photo/1">出典</a>)</p></figcaption></figure></div>

{% columns %}
{% column %}
ベンチマークはAider Polyglotサーバー上で第三者の貢献者によって実行され、Aider PolyglotベンチマークにおけるUnsloth GGUF量子化（スコア対VRAM）を比較した。特筆すべきは、3ビット **`UD-IQ3_XXS`** 量子化は〜にかなり近く **BF16** の性能となっており、 **3ビットを妥当な最小値にしている** ことだ。

**NVFP4** BF16リファレンスをわずかに上回っており、これは試行回数の少なさによるサンプリングノイズかもしれない。しかし、全体的な傾向としては： **1ビット → 2ビット → 3ビット → 6ビット** と着実に改善しており、このベンチマークがUnsloth GGUF全体の有意な品質差を捉えていることを示している。 **非Unsloth** FP8は両方より性能が悪いようだ **`UD-IQ3_XXS`** そして **`UD-Q6_K_XL`**。これは量子化パイプラインの違い、あるいはやはりサンプリング不足を反映している可能性がある。
{% endcolumn %}

{% column %}
[Benjamin Marie（第三者）がベンチマークを実施](https://x.com/bnjmn_marie/status/2019809651387514947/photo/1) **Qwen3-Coder-Next** UnslothとQwen GGUFを用いて、ある **750プロンプトの混合スイートで** （LiveCodeBench v6、MMLU Pro、GPQA、Math500）を評価し、両方を報告しています **全体精度** そして **相対誤差増加** （量子化モデルが元モデルよりどれだけ多く誤るか）。

グラフは、UnslothのQ4\_K\_M量子化が標準のQ4\_K\_Mより明らかに優れていることを示している。Q3\_K\_Mは予想どおりLive Code Bench v6では標準Q4\_K\_Mより低い性能だが、驚くことにHumanEvalでは標準Q4\_K\_Mよりかなり良い。\
\
最も効率よく動作するようなので、少なくともQ4\_K\_Mの使用を推奨する。
{% endcolumn %}
{% endcolumns %}

### Qwen3-Coder-Nextベンチマーク

Qwen3-Coder-Nextは、その規模に対して最も高性能なモデルであり、その性能はアクティブパラメータ数が10〜20倍多いモデルに匹敵する。

<table data-full-width="true"><thead><tr><th>ベンチマーク</th><th align="right">Qwen3-Coder-Next（80B）</th><th align="right">DeepSeek-V3.2（671B）</th><th align="right">GLM-4.7（358B）</th><th align="right">MiniMax M2.1（229B）</th></tr></thead><tbody><tr><td>SWE-Bench Verified（SWE-Agent使用）</td><td align="right">70.6</td><td align="right">70.2</td><td align="right">74.2</td><td align="right">74.8</td></tr><tr><td>SWE-Bench Multilingual（SWE-Agent使用）</td><td align="right">62.8</td><td align="right">62.3</td><td align="right">63.7</td><td align="right">66.2</td></tr><tr><td>SWE-Bench Pro（SWE-Agent使用）</td><td align="right">44.3</td><td align="right">40.9</td><td align="right">40.6</td><td align="right">34.6</td></tr><tr><td>Terminal-Bench 2.0（Terminus-2 JSON使用）</td><td align="right">36.2</td><td align="right">39.3</td><td align="right">37.1</td><td align="right">32.6</td></tr><tr><td>Aider</td><td align="right">66.2</td><td align="right">69.9</td><td align="right">52.1</td><td align="right">61.0</td></tr></tbody></table>

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F0M7glBoWyRQjHUgaVEev%2Fbenchmarks.png?alt=media&amp;token=d215bbcb-358e-41c4-9f27-66df8d3d94d8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FKxPCUD7NhqHFwFcsmgfb%2Fswebench_pro.png?alt=media&amp;token=eb895603-6176-43d4-aa4d-9d127ef61381" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FxsChrrfjcNVTXN2R0ZRL%2Fqwencodermas.png?alt=media&amp;token=081a28bb-003c-4c92-b086-e2bef1ab91c2" alt=""><figcaption></figcaption></figure>


---

# 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/qwen3-coder-next.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.
