> 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/qwen3-how-to-run-and-fine-tune/qwen3-2507.md).

# Qwen3-2507: ローカル実行ガイド

Qwen3-30B-A3B-2507と235B-A22BのThinking版およびInstruct版をデバイス上でローカル実行しましょう！

Qwenは自社の2507（2025年7月）アップデートを公開しました [Qwen3](/docs/jp/moderu/tutorials/qwen3-how-to-run-and-fine-tune.md) 4B、30B、235Bモデル向けに、"thinking" と "non-thinking" の両方のバリエーションを導入しています。非推論版の '**Qwen3-30B-A3B-Instruct-2507**' と '**Qwen3-235B-A22B-Instruct-2507'** は256Kのコンテキストウィンドウ、改善された指示追従、多言語対応、アライメントを備えています。

推論モデルの '**Qwen3-30B-A3B-Thinking-2507**' と '**Qwen3-235B-A22B-Thinking-2507**' は推論に優れており、235Bは論理、数学、科学、コーディング、上級学術タスクでSOTA結果を達成しています。

[Unsloth](https://github.com/unslothai/unsloth) も、今ではファインチューニングと [強化学習（RL）](/docs/jp/meru/reinforcement-learning-rl-guide.md) Qwen3-2507モデルの — 2倍高速で、VRAMは70%少なく、コンテキスト長は8倍長い

<a href="#run-qwen3-30b-a3b-2507-tutorials" class="button secondary">30B-A3Bを実行</a><a href="/docs/jp/moderu/tutorials/qwen3-how-to-run-and-fine-tune/qwen3-2507.md#run-qwen3-235b-a22b-2507-tutorials" class="button secondary">235B-A22Bを実行</a><a href="#fine-tuning-qwen3-2507-with-unsloth" class="button secondary">Qwen3-2507をファインチューニング</a>

**Unsloth** [**Dynamic 2.0**](/docs/jp/ji-chu/dynamic-3.0-ggufs.md) **GGUF:**

| モデル                      | 実行するためのGGUF:                                                                                                                                           |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Qwen3-**4B-2507**        | [インストラクト](https://huggingface.co/unsloth/Qwen3-4B-Instruct-2507-GGUF) • [思考](https://huggingface.co/unsloth/Qwen3-4B-Thinking-2507-GGUF)               |
| Qwen3-**30B-A3B**-2507   | [インストラクト](#llama.cpp-run-qwen3-30b-a3b-instruct-2507-tutorial) • [思考](https://huggingface.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF)                 |
| Qwen3-**235B-A22B**-2507 | [インストラクト](https://huggingface.co/unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF) • [思考](https://huggingface.co/unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF) |

## ⚙️ベストプラクティス

{% hint style="success" %}
ThinkingモデルとInstructモデルの設定は異なります。\
Thinkingモデルでは temperature = 0.6 を使用しますが、Instructモデルでは temperature = 0.7 を使用します。\
Thinkingモデルでは top\_p = 0.95 を使用しますが、Instructモデルでは top\_p = 0.8 を使用します。
{% endhint %}

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

| Instructモデルの設定:                                                            | Thinkingモデルの設定:                                                            |
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| <mark style="background-color:blue;">`Temperature = 0.7`</mark>            | <mark style="background-color:blue;">`Temperature = 0.6`</mark>            |
| `Min_P = 0.00` （llama.cppのデフォルトは0.1です）                                     | `Min_P = 0.00` （llama.cppのデフォルトは0.1です）                                     |
| `Top_P = 0.80`                                                             | `Top_P = 0.95`                                                             |
| `TopK = 20`                                                                | `TopK = 20`                                                                |
| `presence_penalty = 0.0 ～ 2.0` （llama.cppのデフォルトでは無効ですが、繰り返しを減らすためにこれを使えます） | `presence_penalty = 0.0 ～ 2.0` （llama.cppのデフォルトでは無効ですが、繰り返しを減らすためにこれを使えます） |

**十分な出力長**: 出力長を `32,768` トークンを使用します。これはほとんどのクエリには十分です。

Thinking版とInstruct版の両方のチャットテンプレートは以下のとおりです（Thinkingには `<think></think>`があります）:

```
<|im_start|>user
やあ！<|im_end|>
<|im_start|>assistant
1+1はいくつ？<|im_end|>
<|im_start|>user
2<|im_end|>
<|im_start|>assistant
```

## 📖 Qwen3-30B-A3B-2507チュートリアルを実行

以下は、 [思考](#thinking-qwen3-30b-a3b-thinking-2507) そして [インストラクト](#instruct-qwen3-30b-a3b-instruct-2507) モデルの各バージョン向けガイドです。

### Instruct: Qwen3-30B-A3B-Instruct-2507

これは非推論モデルなので、 `thinking=False` を設定する必要はなく、モデルは `<think> </think>` ブロックを生成しません。

#### ⚙️ベストプラクティス

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

* 以下の使用を推奨します `temperature=0.7, top_p=0.8, top_k=20, min_p=0.0` `presence_penalty` を0から2の間で設定してください。フレームワークが対応していれば、終わりのない繰り返しを減らせます。
* **`temperature = 0.7`**
* `top_k = 20`
* `min_p = 0.00` （llama.cppのデフォルトは0.1です）
* **`top_p = 0.80`**
* `presence_penalty = 0.0 ～ 2.0` （llama.cppのデフォルトでは無効ですが、繰り返しを減らすためにこれを使えます） たとえば1.0を試してください。
* 最大 `262,144` コンテキストをネイティブにサポートしますが、 `32,768` トークンに設定してRAM使用量を減らせます

#### 🦙 Ollama: Qwen3-30B-A3B-Instruct-2507チュートリアルを実行

1. インストール `ollama` まだインストールしていない場合は！サイズが32Bまでのモデルしか実行できません。

```bash
apt-get update
apt-get install pciutils -y
curl -fsSL https://ollama.com/install.sh | sh
```

2. モデルを実行してください！必要に応じて `ollama serve`を別のターミナルで呼び出せます。失敗した場合でも大丈夫です！私たちの修正と推奨パラメータ（temperature など）はすべて `params` として Hugging Face のアップロードに含めています！

```bash
ollama run hf.co/unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF:UD-Q4_K_XL
```

#### :sparkles: Llama.cpp: Qwen3-30B-A3B-Instruct-2507チュートリアルを実行

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-cli llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

2. HuggingFace から直接、以下を使って取得できます:

   ```bash
   ./llama.cpp/llama-cli \
       -hf unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF:Q4_K_XL \
       --jinja -ngl 99 --ctx-size 32768 \
       --temp 0.7 --min-p 0.0 --top-p 0.80 --top-k 20 --presence-penalty 1.0
   ```
3. 以下をインストールした後、( `pip install huggingface_hub hf_transfer` ）。UD\_Q4\_K\_XL または他の量子化版を選べます。

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF",
    local_dir = "unsloth/Qwen3-30B-A3B-Instruct-2507-GGUF",
    allow_patterns = ["*UD-Q4_K_XL*"],
)
```

### Thinking: Qwen3-30B-A3B-Thinking-2507

このモデルは、thinkingモードと256Kのコンテキストウィンドウのみをネイティブにサポートします。デフォルトのチャットテンプレートでは `<think>` が自動的に追加されるため、出力には閉じる `</think>` タグだけが表示される場合があります。

#### ⚙️ベストプラクティス

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

* 以下の使用を推奨します `temperature=0.6, top_p=0.95, top_k=20, min_p=0.0` `presence_penalty` を0から2の間で設定してください。フレームワークが対応していれば、終わりのない繰り返しを減らせます。
* **`temperature = 0.6`**
* `top_k = 20`
* `min_p = 0.00` （llama.cppのデフォルトは0.1です）
* **`top_p = 0.95`**
* `presence_penalty = 0.0 ～ 2.0` （llama.cppのデフォルトでは無効ですが、繰り返しを減らすためにこれを使えます） たとえば1.0を試してください。
* 最大 `262,144` コンテキストをネイティブにサポートしますが、 `32,768` トークンに設定してRAM使用量を減らせます

#### 🦙 Ollama: Qwen3-30B-A3B-Instruct-2507チュートリアルを実行

1. インストール `ollama` まだインストールしていない場合は！サイズが32Bまでのモデルしか実行できません。フルの235B-A22Bモデルを実行するには、 [こちらを参照](#run-qwen3-235b-a22b-instruct-2507).

```bash
apt-get update
apt-get install pciutils -y
curl -fsSL https://ollama.com/install.sh | sh
```

2. モデルを実行してください！必要に応じて `ollama serve`を別のターミナルで呼び出せます。失敗した場合でも大丈夫です！私たちの修正と推奨パラメータ（temperature など）はすべて `params` として Hugging Face のアップロードに含めています！

```bash
ollama run hf.co/unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:UD-Q4_K_XL
```

#### :sparkles: Llama.cpp: Qwen3-30B-A3B-Instruct-2507チュートリアルを実行

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-cli llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

2. Hugging Faceから直接以下で取得できます:

   ```bash
   ./llama.cpp/llama-cli \
       -hf unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF:Q4_K_XL \
       --jinja -ngl 99 --ctx-size 32768 \
       --temp 0.6 --min-p 0.0 --top-p 0.95 --top-k 20 --presence-penalty 1.0
   ```
3. 以下をインストールした後、( `pip install huggingface_hub hf_transfer` ）。UD\_Q4\_K\_XL または他の量子化版を選べます。

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF",
    local_dir = "unsloth/Qwen3-30B-A3B-Thinking-2507-GGUF",
    allow_patterns = ["*UD-Q4_K_XL*"],
)
```

## 📖 実行 **Qwen3-235B-A22B-2507** チュートリアル

以下は、 [思考](#run-qwen3-235b-a22b-thinking-via-llama.cpp) そして [インストラクト](#run-qwen3-235b-a22b-instruct-via-llama.cpp) モデルの各バージョン向けガイドです。

### Thinking: Qwen3-**235B-A22B**-Thinking-2507

このモデルは、thinkingモードと256Kのコンテキストウィンドウのみをネイティブにサポートします。デフォルトのチャットテンプレートでは `<think>` が自動的に追加されるため、出力には閉じる `</think>` タグだけが表示される場合があります。

#### :gear: ベストプラクティス

最適なパフォーマンスを得るために、QwenはThinkingモデルに次の設定を推奨しています:

* **`temperature = 0.6`**
* `top_k = 20`
* `min_p = 0.00` （llama.cppのデフォルトは0.1です）
* `top_p = 0.95`
* `presence_penalty = 0.0 ～ 2.0` （llama.cppのデフォルトでは無効ですが、繰り返しを減らすためにこれを使えます） たとえば1.0を試してください。
* **十分な出力長**: 出力長を `32,768` トークンを使用します。これはほとんどのクエリには十分です。

#### :sparkles:llama.cpp経由でQwen3-235B-A22B-Thinkingを実行:

Qwen3-235B-A22Bでは、最適化された推論と豊富なオプションのために、特にLlama.cppを使用します。

{% hint style="success" %}
もし **フル精度の非量子化版**が欲しいなら、当社の `Q8_K_XL、Q8_0` または `BF16` 版をご利用ください！
{% 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-cli llama-gguf-split
   cp llama.cpp/build/bin/llama-* llama.cpp
   ```
2. モデルのダウンロードには llama.cpp を直接使うこともできますが、通常は `huggingface_hub` llama.cpp を直接使うには、以下を実行します:

   ```bash
   ./llama.cpp/llama-cli \
       -hf unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF:Q2_K_XL \
       --ctx-size 16384 \\
       --n-gpu-layers 99 \\
       -ot ".ffn_.*_exps.=CPU" \\
       --temp 0.6 \
       --min-p 0.0 \\
       --top-p 0.95 \\
       --top-k 20 \\
       --presence-penalty 1.0
   ```
3. 以下をインストールした後、( `pip install huggingface_hub hf_transfer` )。UD-Q2\_K\_XL やその他の量子化版を選べます。

   ```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/Qwen3-235B-A22B-Thinking-2507-GGUF",
       local_dir = "unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF",
       allow_patterns = ["*UD-Q2_K_XL*"],
   )
   ```
4. モデルを実行して、任意のプロンプトを試してください。
5. 編集 `--threads -1` CPUスレッド数は `--ctx-size` コンテキスト長には 262114、 `--n-gpu-layers 99` GPUオフロードする層数です。GPUがメモリ不足になったら調整してみてください。CPUのみで推論する場合は削除してください。

{% hint style="success" %}
次を使います: `-ot ".ffn_.*_exps.=CPU"` を試して、すべての MoE 層を CPU にオフロードしてください！これにより、非MoE層すべてを1枚のGPUに収められるようになり、生成速度が向上します。GPU容量がさらにあれば、正規表現を調整してより多くの層を収めることもできます。
{% endhint %}

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Qwen3-235B-A22B-Thinking-2507-GGUF/UD-Q2_K_XL/Qwen3-235B-A22B-Thinking-2507-UD-Q2_K_XL-00001-of-00002.gguf \
    --ctx-size 16384 \\
    --n-gpu-layers 99 \\
    -ot ".ffn_.*_exps.=CPU" \\
    --seed 3407 \\
    --temp 0.6 \
    --min-p 0.0 \\
    --top-p 0.95 \\
    --top-k 20
    --presence-penalty 1.0
```

{% endcode %}

### Instruct: Qwen3-**235B-A22B**-Instruct-2507

これは非推論モデルなので、 `thinking=False` を設定する必要はなく、モデルは `<think> </think>` ブロックを生成しません。

#### ⚙️ベストプラクティス

最適なパフォーマンスを得るために、以下の設定を推奨します:

**1. サンプリングパラメータ**: 以下の使用を提案します `temperature=0.7、top_p=0.8、top_k=20、min_p=0 を` `presence_penalty` を0から2の間で設定してください。フレームワークが対応していれば、終わりのない繰り返しを減らせます。

2\. **十分な出力長**: 出力長は `16,384` トークンを使用することを推奨します。これはInstructモデルには十分です。

3\. **出力形式を標準化する:** ベンチマーク時には、モデルの出力を標準化するためにプロンプトを使用することを推奨します。

* **数学の問題**: を含めてください `段階的に推論し、最終回答を \boxed{} の中に入れてください。` をプロンプトに。
* **多肢選択問題**: 応答を標準化するために、次のJSON構造をプロンプトに追加してください: \`answer\` フィールドには選択肢の文字だけを入れて選択を示してください。例: \`"answer": "C"\`。

#### :sparkles:llama.cpp経由でQwen3-235B-A22B-Instructを実行:

Qwen3-235B-A22Bでは、最適化された推論と豊富なオプションのために、特にLlama.cppを使用します。

{% hint style="info" %}
もし **フル精度の非量子化版**が欲しいなら、当社の `Q8_K_XL、Q8_0` または `BF16` 版をご利用ください！
{% 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-cli llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

2\. llama.cpp を使って直接モデルをダウンロードできますが、通常は `huggingface_hub` llama.cpp を直接使うには、次のようにします:\\

```bash
./llama.cpp/llama-cli \
    -hf unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF:Q2_K_XL \
    --ctx-size 16384 \\
    --n-gpu-layers 99 \\
    -ot ".ffn_.*_exps.=CPU" \\
    --temp 0.7 \\
    --min-p 0.0 \\
    --top-p 0.8 \
    --top-k 20 \\
    --repeat-penalty 1.0
```

3\. （インストール後に）以下を通じてモデルをダウンロード: `pip install huggingface_hub hf_transfer` )。UD-Q2\_K\_XL やその他の量子化版を選べます。

```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/Qwen3-235B-A22B-Instruct-2507-GGUF",
    local_dir = "unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF",
    allow_patterns = ["*UD-Q2_K_XL*"],
)
```

4\. モデルを実行して任意のプロンプトを試してください。5. 編集 `--threads -1` CPUスレッド数は `--ctx-size` コンテキスト長には 262114、 `--n-gpu-layers 99` GPUオフロードする層数です。GPUがメモリ不足になったら調整してみてください。CPUのみで推論する場合は削除してください。

{% hint style="success" %}
次を使います: `-ot ".ffn_.*_exps.=CPU"` を試して、すべての MoE 層を CPU にオフロードしてください！これにより、非MoE層すべてを1枚のGPUに収められるようになり、生成速度が向上します。GPU容量がさらにあれば、正規表現を調整してより多くの層を収めることもできます。
{% endhint %}

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/Qwen3-235B-A22B-Instruct-2507-GGUF/UD-Q2_K_XL/Qwen3-235B-A22B-Instruct-2507-UD-Q2_K_XL-00001-of-00002.gguf \
    --ctx-size 16384 \\
    --n-gpu-layers 99 \\
    -ot ".ffn_.*_exps.=CPU" \\
    --temp 0.7 \\
    --min-p 0.0 \\
    --top-p 0.8 \
    --top-k 20
```

{% endcode %}

### 🛠️ 生成速度の改善 <a href="#improving-generation-speed" id="improving-generation-speed"></a>

VRAM がさらにあれば、より多くの MoE 層、または層全体のオフロードを試せます。

通常は、 `-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 層のみをオフロードします。

これは最も少ない 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 層をオフロードすることを意味します。

その [最新のllama.cppリリース](https://github.com/ggml-org/llama.cpp/pull/14363) には高スループットモードも導入されています。 `llama-parallel`を使用してください。 [ここ](https://github.com/ggml-org/llama.cpp/tree/master/examples/parallel)について詳しくはこちらを読む **KV キャッシュを 4bit に量子化する** たとえばVRAM / RAM間の移動を減らすために使用してください。これにより生成プロセスも高速化できます。 [次のセクション](#how-to-fit-long-context-256k-to-1m) ではKVキャッシュの量子化について説明します。

### 📐長いコンテキストに収める方法 <a href="#how-to-fit-long-context-256k-to-1m" id="how-to-fit-long-context-256k-to-1m"></a>

より長いコンテキストに対応するには、 **KV キャッシュ量子化** を使って K と V のキャッシュをより低い bit に量子化できます。これにより、RAM / VRAM のデータ移動が減るため生成速度も上がります。K の量子化で使用できるオプション（デフォルトは `f16`）は以下の通りです。

`--cache-type-k f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1`

少し精度が向上する `_1` 版を使うべきです。少し遅くなりますが。たとえば `q4_1, q5_1` そのため、 `--cache-type-k q4_1`

V キャッシュも量子化できますが、その場合は **Flash Attention 対応で llama.cpp をコンパイルする必要があります** を `-DGGML_CUDA_FA_ALL_QUANTS=ON`で有効にし、 `--flash-attn` を有効にして試してください。Flash Attentionをインストールした後は、 `--cache-type-v q4_1`

## 🦥 UnslothでQwen3-2507をファインチューニング

Unslothは [Qwen3](/docs/jp/moderu/tutorials/qwen3-how-to-run-and-fine-tune.md#fine-tuning-qwen3-with-unsloth) Qwen3-2507のファインチューニングを2倍高速化し、VRAMを70%少なくし、8倍長いコンテキスト長をサポートします。Qwen3-2507は30Bバリアントでのみリリースされたため、QLoRA（4-bit）でモデルをファインチューニングするには約40GBのA100 GPUが必要になります。

ノートブックでは、モデルがColabの無料16GB GPUに収まらないため、40GBのA100を使う必要があります。会話用ノートブックを利用できますが、データセットはお好きなものに置き換えてください。今回はモデルに推論機能がないため、データセットに推論を組み込む必要はありません。

* [Qwen3 (14B) 推論 + 会話ノートブック](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(14B\)-Reasoning-Conversational.ipynb)

古いバージョンのUnslothを使っている場合、および/またはローカルでファインチューニングする場合は、最新バージョンのUnslothをインストールしてください:

```bash
pip install --upgrade --force-reinstall --no-cache-dir unsloth unsloth_zoo
```

### Qwen3-2507 MOEモデルのファインチューニング

ファインチューニングのサポートにはMOEモデルも含まれます: 30B-A3B と 235B-A22B。Qwen3-30B-A3BはUnslothで30GBのVRAM上で動作します。MoEのファインチューニングではルーター層をファインチューニングするのはおそらく良い考えではないため、既定では無効化しています。

**Qwen3-2507-4B用ノートブック:** [思考](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(4B\)-Thinking.ipynb) そして [インストラクト](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(4B\)-Instruct.ipynb)

30B-A3Bは30GBのVRAMに収まりますが、QLoRAファインチューニングのためにフルの16-bitモデルをダウンロードしてその場で4-bitに変換する必要があるため、RAMやディスク容量が不足する可能性があります。これは4-bitのBnB MOEモデルを直接インポートする際の問題によるものです。これはMOEモデルにのみ影響します。

{% hint style="warning" %}
MOEモデルをファインチューニングする場合は、 `FastModel` そして `FastLanguageModel`
{% endhint %}

```python
from unsloth import FastModel
import torch
model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/Qwen3-30B-A3B-Instruct-2507",
    max_seq_length = 2048, # 長いコンテキスト用に任意の値を選択！
    load_in_4bit = True,  # メモリ削減のための 4bit 量子化
    load_in_8bit = False, # [NEW!] 少し高精度で、メモリを2倍使用します
    full_finetuning = False, # [NEW!] いまはフルファインチューニングも可能です！
    # token = "hf_...", # ゲート付きモデルを使う場合は1つ使用してください
)
```

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-be34c101c627020c7a6cfb6cd249f2462587d235%2Fqwen33%20mascot.png?alt=media" 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/tutorials/qwen3-how-to-run-and-fine-tune/qwen3-2507.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.
