> 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/deepseek-r1-0528-how-to-run-locally.md).

# DeepSeek-R1-0528: ローカルでの実行方法

Qwen3を含むDeepSeek-R1-0528を自分のローカルデバイスで実行する方法のガイド！

DeepSeek-R1-0528は、DeepSeekのR1推論モデルに対する新しいアップデートです。フルの671Bパラメータモデルには715GBのディスク容量が必要です。量子化された動的 **1.66ビット** 版は162GBを使用します（サイズを80%削減）。GGUF: [DeepSeek-R1-0528-GGUF](https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF)

DeepSeekは、Qwen3（8B）をファインチューニングしたR1-0528の蒸留版も公開しました。この蒸留版はQwen3（235B）に匹敵する性能を達成します。 ***また、*** [***Qwen3 Distillをファインチューニングできます***](#fine-tuning-deepseek-r1-0528-with-unsloth) ***Unslothで***。Qwen3 GGUF: [DeepSeek-R1-0528-Qwen3-8B-GGUF](https://huggingface.co/unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF)

すべてのアップロードは Unsloth の [Dynamic 2.0](/docs/jp/ji-chu/dynamic-3.0-ggufs.md) は、SOTA の 5-shot MMLU と KL Divergence の性能向けであり、量子化された DeepSeek LLM を精度損失を最小限に抑えて実行・ファインチューニングできることを意味します。

**チュートリアルナビゲーション:**

<a href="#run-qwen3-distilled-r1-in-llama.cpp" class="button secondary">llama.cpp で実行</a><a href="#run-in-ollama-open-webui" class="button secondary">Ollama/Open WebUI で実行</a><a href="#fine-tuning-deepseek-r1-0528-with-unsloth" class="button secondary">R1-0528のファインチューニング</a>

{% hint style="success" %}
新機能: ツール呼び出しが大幅に改善され、チャットテンプレートの修正も行われました。\
\
新しい [TQ1\_0 動的1.66ビット量子化](https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF?show_file_info=DeepSeek-R1-0528-UD-TQ1_0.gguf) - サイズは162GB。192GB RAM（Macを含む）およびOllamaユーザーに最適です。試してみてください: `ollama run hf.co/unsloth/DeepSeek-R1-0528-GGUF:TQ1_0`
{% endhint %}

## :gear: 推奨設定

DeepSeek-R1-0528-Qwen3-8Bについては、このモデルはほぼどんな環境にも収まり、RAMが20GBしかない場合でも動作します。事前準備は不要です。\
\
ただし、サイズが715GBのフルR1-0528モデルには追加の準備が必要です。1.78ビット（IQ1\_S）量子化版は24GB GPU 1枚（全レイヤーをオフロード）に収まります。この構成に加えて128GBのRAMがあれば、約5トークン/秒を期待できます。

この量子化版を実行するには、少なくとも64GBのRAMが推奨されます（GPUなしでは1トークン/秒になります）。最適な性能には少なくとも **180GBのユニファイドメモリ、または合計180GBのRAM+VRAMが必要です** で、5トークン/秒以上になります。

サイズと精度のバランスを取るために、2.7ビット（Q2\_K\_XL）または2.4ビット（IQ2\_XXS）の量子化版を使うことを推奨します！2.4ビット版もよく動作します。

{% hint style="success" %}
必須ではありませんが、最高の性能を得るには、VRAM + RAMの合計をダウンロードする量子化版のサイズに合わせてください。
{% endhint %}

### 🐳 公式推奨設定:

によると [DeepSeek](https://huggingface.co/deepseek-ai/DeepSeek-R1-0528)、これらはR1の推論に推奨される設定です（R1-0528とQwen3蒸留版も同じ設定を使うべきです）:

* 次を設定してください <mark style="background-color:green;">**temperature 0.6**</mark> にすると、反復や不整合を減らせます。
* 設定してください <mark style="background-color:green;">**top\_p を 0.95 に**</mark> （推奨）
* 信頼できる評価のために、複数回テストして結果を平均してください。

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

R1-0528は元のR1モデルと同じチャットテンプレートを使用します。強制する必要はありません `<think>\n` 、ただし追加しても構いません！

```
<｜begin▁of▁sentence｜><｜User｜>1+1は何ですか？<｜Assistant｜>答えは 2 です。<｜end▁of▁sentence｜><｜User｜>もっと説明して！<｜Assistant｜>
```

BOS は強制的に追加され、EOS が各やり取りを区切ります。推論時の二重 BOS トークンを避けるには、次だけを呼び出してください `tokenizer.encode(..., add_special_tokens = False)` チャットテンプレートがBOSトークンも自動で追加するためです。\
llama.cpp / GGUF推論では、自動で追加されるのでBOSは省略してください:

```
<｜User｜>1+1は何ですか？<｜Assistant｜>
```

その `<think>` そして `</think>` トークンにはそれぞれ専用のトークンが割り当てられます。

## モデルのアップロード

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

* Qwen3（8B）蒸留版: [DeepSeek-R1-0528-Qwen3-8B-GGUF](https://huggingface.co/unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF)
* 完全版のDeepSeek-R1-0528モデルのアップロードは以下:

以下もアップロードしました [IQ4\_NL](https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/IQ4_NL) そして [Q4\_1](https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/Q4_1) それぞれ ARM デバイスと Apple デバイスで特に高速に動作する量子化版です。

<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/DeepSeek-R1-0528-GGUF?show_file_info=DeepSeek-R1-0528-UD-TQ1_0.gguf">TQ1_0</a></td><td><strong>162GB</strong></td><td>1.92/1.56bit</td></tr><tr><td>1.78bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-IQ1_S">IQ1_S</a></td><td><strong>185GB</strong></td><td>2.06/1.56bit</td></tr><tr><td>1.93bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-IQ1_M">IQ1_M</a></td><td><strong>200GB</strong></td><td>2.5/2.06/1.56</td></tr><tr><td>2.42bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-IQ2_XXS">IQ2_XXS</a></td><td><strong>216GB</strong></td><td>2.5/2.06bit</td></tr><tr><td>2.71bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-Q2_K_XL">Q2_K_XL</a></td><td><strong>251GB</strong></td><td>3.5/2.5bit</td></tr><tr><td>3.12bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-IQ3_XXS">IQ3_XXS</a></td><td><strong>273GB</strong></td><td>3.5/2.06bit</td></tr><tr><td>3.5bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-Q3_K_XL">Q3_K_XL</a></td><td><strong>296GB</strong></td><td>4.5/3.5bit</td></tr><tr><td>4.5bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-Q4_K_XL">Q4_K_XL</a></td><td><strong>384GB</strong></td><td>5.5/4.5bit</td></tr><tr><td>5.5bit</td><td><a href="https://huggingface.co/unsloth/DeepSeek-R1-0528-GGUF/tree/main/UD-Q5_K_XL">Q5_K_XL</a></td><td><strong>481GB</strong></td><td>6.5/5.5bit</td></tr></tbody></table>

以下の形式の版もアップロードしました [BF16 形式](https://huggingface.co/unsloth/DeepSeek-R1-0528-BF16)、および元の [FP8（float8）形式](https://huggingface.co/unsloth/DeepSeek-R1-0528).

## DeepSeek-R1-0528チュートリアルを実行:

### :llama: Ollama/Open WebUI で実行

1. インストール `ollama` まだの場合は！実行できるのは最大32Bサイズのモデルまでです。フルの720GB R1-0528モデルを実行するには、 [こちらを参照](#run-full-r1-0528-on-ollama-open-webui).

```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/DeepSeek-R1-0528-Qwen3-8B-GGUF:Q4_K_XL
```

3. <mark style="color:緑;background-color:yellow;">**（新規）OllamaでフルのR1-0528モデルを実行するには、TQ1\_0（162GB量子化版）を使用できます:**</mark>

```bash
OLLAMA_MODELS=unsloth_downloaded_models ollama serve &

ollama run hf.co/unsloth/DeepSeek-R1-0528-GGUF:TQ1_0
```

### :llama: Ollama/Open WebUIでフルR1-0528を実行

Open WebUIは、R1の実行方法についてのステップごとのチュートリアルをここで公開しています。R1-0528では、R1を新しい0528量子化版に置き換えるだけです: <https://docs.openwebui.com/tutorials/integrations/llm-providers/deepseekr1-dynamic>

<mark style="background-color:green;">**（新規）OllamaでフルのR1-0528モデルを実行するには、TQ1\_0（162GB量子化版）を使用できます:**</mark>

```bash
OLLAMA_MODELS=unsloth_downloaded_models ollama serve &

ollama run hf.co/unsloth/DeepSeek-R1-0528-GGUF:TQ1_0
```

OllamaでTQ1\_0（162GB）より大きい量子化版を使いたい場合は、まず下のコードのように3つのGGUF分割ファイルを1つに結合する必要があります。その後、モデルをローカルで実行する必要があります。

```bash
./llama.cpp/llama-gguf-split --merge \\
  DeepSeek-R1-0528-GGUF/DeepSeek-R1-0528-UD-IQ1_S/DeepSeek-R1-0528-UD-IQ1_S-00001-of-00003.gguf \
	merged_file.gguf
```

### ✨ llama.cppでQwen3蒸留R1を実行

1. <mark style="background-color:yellow;">**フルの720GB R1-0528モデルを実行するには、**</mark> [<mark style="background-color:yellow;">**こちらを参照**</mark>](#run-full-r1-0528-on-llama.cpp)<mark style="background-color:yellow;">**.**</mark> 最新の `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を直接使ってモデルをダウンロードします:

```bash
./llama.cpp/llama-cli -hf unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF:Q4_K_XL --jinja
```

### ✨ llama.cppでフルR1-0528を実行

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` モデルを直接読み込むには、以下を実行できます: (:IQ1\_S) は量子化タイプです。Hugging Face 経由でもダウンロードできます（3 を参照）。これは次と似ています `ollama run` に似ています。 `export LLAMA_CACHE="folder"` を使って `llama.cpp` 特定の場所に保存するには、

{% hint style="success" %}
ぜひお試しください `-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/DeepSeek-R1-0528-GGUF"
./llama.cpp/llama-cli \
    -hf unsloth/DeepSeek-R1-0528-GGUF:IQ1_S \
    --cache-type-k q4_0 \\
    --threads -1 \
    --n-gpu-layers 99 \\
    --prio 3 \\
    --temp 0.6 \
    --top-p 0.95 \\
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU"
```

3. 以下をインストールした後、( `pip install huggingface_hub hf_transfer` をインストール後）。 `UD-IQ1_S`（動的 1.78bit 量子化）または次のような他の量子化版 `Q4_K_M` をインストールした後で）。 <mark style="background-color:green;">**2.7bit の動的量子化版を使うことを推奨します**</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>。他のバージョンはこちら: <https://huggingface.co/unsloth/DeepSeek-R1-0528-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/DeepSeek-R1-0528-GGUF",
    local_dir = "unsloth/DeepSeek-R1-0528-GGUF",
    allow_patterns = ["*UD-IQ1_S*"], # 動的 1bit (168GB) 動的 2bit (251GB) には "*UD-Q2_K_XL*" を使用
)
```

{% endcode %}

4. DeepSeek R1向けの1.58bit動的量子化で説明したとおりに、UnslothのFlappy Birdテストを実行してください。
5. 編集 `--threads 32` CPUスレッド数は `--ctx-size 16384` コンテキスト長は `--n-gpu-layers 2` GPUオフロードする層数です。GPUがメモリ不足になったら調整してみてください。CPUのみで推論する場合は削除してください。

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/DeepSeek-R1-0528-GGUF/UD-IQ1_S/DeepSeek-R1-0528-UD-IQ1_S-00001-of-00004.gguf \
    --cache-type-k q4_0 \\
    --threads -1 \
    --n-gpu-layers 99 \\
    --prio 3 \\
    --temp 0.6 \
    --top-p 0.95 \\
    --min-p 0.01 \\
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU" \\
    -no-cnv \\
    --prompt "<｜User｜>Python で Flappy Bird ゲームを作ってください。次の内容を含める必要があります:\n1. pygame を使用する必要があります。\n2. 背景色はランダムに選ばれる明るい色にしてください。最初は薄い青色にします。\n3. SPACE を何度も押すと鳥が加速します。\n4. 鳥の形は四角、円、三角形のいずれかをランダムに選びます。色はランダムに暗い色を選びます。\n5. 画面下部に、ランダムに選ばれた濃い茶色または黄色の地面を配置します。\n6. スコアを右上に表示します。パイプを通過してぶつからなければ加算してください。\n7. 十分な間隔を空けて、ランダムな間隔でパイプを配置します。色はランダムに濃い緑、薄い茶色、または暗いグレー系の色にします。\n8. 負けたら最高スコアを表示します。文字は画面内に表示してください。q または Esc を押すとゲームを終了します。再開はもう一度 SPACE を押します。\n最終的なゲームは Python の markdown セクション内に入れてください。最終的な markdown セクションの前にコードのエラーを確認し、修正してください。<｜Assistant｜>"
```

{% endcode %}

## :8ball: 七角形テスト

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-1371de5a93c6c5b0e43e8bb51980d84554b199f4%2Fsnapshot.jpg?alt=media" alt="" width="563"><figcaption><p>目的は七角形を回転させ、その中のボールを動かすことです。</p></figcaption></figure>

<details>

<summary>モデルを実行するための完全なプロンプト</summary>

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-cli \
    --model unsloth/DeepSeek-R1-0528-GGUF/UD-IQ1_S/DeepSeek-R1-0528-UD-IQ1_S-00001-of-00004.gguf \
    --cache-type-k q4_0 \\
    --threads -1 \
    --n-gpu-layers 99 \\
    --prio 3 \\
    --temp 0.6 \
    --top_p 0.95 \
    --min_p 0.01 \
    --ctx-size 16384 \\
    --seed 3407 \\
    -ot ".ffn_.*_exps.=CPU" \\
    -no-cnv \\
    --prompt "<｜User｜>回転する七角形の中で20個のボールが跳ねるPythonプログラムを書いてください:\n- すべてのボールは同じ半径です。\n- すべてのボールには1から20までの数字が付いています。\n- すべてのボールは開始時に七角形の中心から落下します。\n- 色は次のとおりです: #f8b862, #f6ad49, #f39800, #f08300, #ec6d51, #ee7948, #ed6d3d, #ec6800, #ec6800, #ee7800, #eb6238, #ea5506, #ea5506, #eb6101, #e49e61, #e45e32, #e17b34, #dd7a56, #db8449, #d66a35\n- ボールは重力と摩擦の影響を受け、回転する壁で現実的に跳ね返らなければなりません。ボール同士の衝突も必要です。\n- すべてのボールの材質により、衝突時の跳ね返りの高さは七角形の半径を超えないが、ボールの半径よりは高くなるようにしてください。\n- すべてのボールは摩擦で回転し、ボール上の数字でボールのスピンを示せます。\n- 七角形は中心の周りを回転しており、回転速度は5秒で360度です。\n- 七角形の大きさは、すべてのボールを収められるのに十分な大きさにしてください。\n- pygameライブラリは使用せず、衝突検出アルゴリズムや衝突応答などを自分で実装してください。以下のPythonライブラリは使用可能です: tkinter, math, numpy, dataclasses, typing, sys。\n- すべてのコードは1つのPythonファイルにまとめてください。<｜Assistant｜>"
```

{% endcode %}

</details>

## 🦥 UnslothでDeepSeek-R1-0528をファインチューニング

ファインチューニングするには **DeepSeek-R1-0528-Qwen3-8B** Unslothを使って、私たちは新しいGRPOノートブックを作成しました。そこには、多言語出力を大幅に強化するためのカスタム報酬関数が含まれており、特に望ましい言語での応答率（この例ではインドネシア語を使用していますが、任意の言語を使えます）を40%以上向上させます。

* [**DeepSeek-R1-0528-Qwen3-8Bノートブック**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/DeepSeek_R1_0528_Qwen3_\(8B\)_GRPO.ipynb) **- 新規**

多くの推論LLMは多言語対応ですが、推論トレース内で英語と目的言語が混在した出力をしばしば生成します。私たちの報酬関数は、目的言語での出力を強く促すことでこの問題を効果的に軽減し、言語の一貫性を大幅に向上させます。

この報酬関数は完全にカスタマイズ可能で、他の言語向けに適応したり、特定のドメインやユースケース向けにファインチューニングしたりできます。

{% hint style="success" %}
この報酬関数とノートブックの最大の利点は、モデルに特定の言語を学習させるための言語データセットが不要なことです。ノートブックにはインドネシア語データセットはありません。
{% endhint %}

Unslothにより、R1-Qwen3蒸留版のファインチューニングは2倍高速になり、VRAM使用量は70%削減され、8倍長いコンテキスト長に対応します。


---

# 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/deepseek-r1-0528-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.
