> 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/burogu/fine-tuning-llms-with-nvidia-dgx-spark-and-unsloth.md).

# NVIDIA DGX Spark と Unsloth で LLM をファインチューニングする

NVIDIA DGX Spark 上で OpenAI gpt-oss を使ってファインチューニングと強化学習（RL）を行う方法のチュートリアル。

Unslothを使えば、LLMのローカルなファインチューニングを最大 **2000億パラメータまで** NVIDIA DGX™ Spark上で行えます。128GBのユニファイドメモリがあれば、次のような大規模モデルを学習でき、 **gpt-oss-120b**さらに、推論をDGX Spark上で直接実行またはデプロイできます。

で示されたように [OpenAI DevDay](https://x.com/UnslothAI/status/1976284209842118714)、gpt-oss-20b はDGX Spark上でRLとUnslothを使って学習され、2048で自動勝利できるようになりました。Unslothは、DGX Spark上のDockerコンテナまたは仮想環境で使用して学習できます。

<div align="center" data-full-width="false"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-ff5c4752dccb8f922b937f8e3b0db58e2d836507%2Funsloth%20nvidia%20dgx%20spark.png?alt=media" alt="" width="375"><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-a8472482c49e1763378b609f8f537ca89df60260%2FNotebooks%20on%20dgx.png?alt=media" alt="" width="375"><figcaption></figcaption></figure></div>

このチュートリアルでは、DGX SparkにUnslothをインストールした後、Unslothノートブックを使ってRLでgpt-oss-20bを学習します。gpt-oss-120bはおよそ **68GB** のユニファイドメモリを使用します。

1,000ステップと4時間のRL学習の後、gpt-ossモデルは2048で元のモデルを大きく上回り、さらに長く学習すれば結果はさらに向上します。

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-3bdcb0fda2ad188142e58f04c855b6dcfbd5ba94%2Fopenai%20devday%20unsloth%20feature.png?alt=media" alt="" width="375"><figcaption><p>OpenAI DevDay 2025で紹介されたUnslothを視聴できます <a href="https://youtu.be/1HL2YHRj270?si=8SR6EChF34B1g-5r&#x26;t=1080">ここ</a>.</p></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-4a8bd4ecc7ee3d123c19158df5dfdcec35df8532%2FScreenshot%202025-10-13%20at%204.22.32%E2%80%AFPM.png?alt=media" alt="" width="375"><figcaption><p>RLで学習したgpt-ossは、2048で一貫してより良い結果を出します。</p></figcaption></figure></div>

### ⚡ ステップバイステップチュートリアル

{% stepper %}
{% step %}
**DGX Spark向けのUnsloth Dockerイメージから始める**

まず、DGX Spark Dockerfileを使ってDockerイメージをビルドします。Dockerfileは [こちらで入手できます](https://raw.githubusercontent.com/unslothai/notebooks/main/Dockerfile_DGX_Spark)。また、DGX Sparkのターミナルで以下を実行することもできます：

```bash
sudo apt update && sudo apt install -y wget
wget -O Dockerfile "https://raw.githubusercontent.com/unslothai/notebooks/main/Dockerfile_DGX_Spark"
```

次に、保存したDockerfileを使って学習用Dockerイメージをビルドします：

```bash
docker build -f Dockerfile -t unsloth-dgx-spark .
```

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-7ebcf195c154b0e569115e1f9513cf002ee57b16%2Fdgx1.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<details>

<summary>クリックして、DGX Spark用Dockerfileの全文を見ることもできます</summary>

```python
FROM nvcr.io/nvidia/pytorch:25.09-py3

# CUDA環境変数を設定
ENV CUDA_HOME=/usr/local/cuda-13.0/
ENV CUDA_PATH=$CUDA_HOME
ENV PATH=$CUDA_HOME/bin:$PATH
ENV LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
ENV C_INCLUDE_PATH=$CUDA_HOME/include:$C_INCLUDE_PATH
ENV CPLUS_INCLUDE_PATH=$CUDA_HOME/include:$CPLUS_INCLUDE_PATH

# 最新のBlackwell対応のため、ソースからtritonをインストール
RUN git clone https://github.com/triton-lang/triton.git && \
    cd triton && \
    git checkout c5d671f91d90f40900027382f98b17a3e04045f6 && \
    pip install -r python/requirements.txt && \
    pip install . && \
    cd ..

# Blackwell対応のため、ソースからxformersをインストール
RUN git clone --depth=1 https://github.com/facebookresearch/xformers --recursive && \
    cd xformers && \
    export TORCH_CUDA_ARCH_LIST="12.1" && \
    python setup.py install && \
    cd ..

# unslothとその他の依存関係をインストール
RUN pip install unsloth unsloth_zoo bitsandbytes==0.48.0 transformers==4.56.2 trl==0.22.2

# シェルを起動
CMD ["/bin/bash"]
```

</details>
{% endstep %}

{% step %}
**コンテナを起動**

GPUアクセスとボリュームマウントを指定して学習コンテナを起動します：

```bash
docker run -it \
    --gpus=all \
    --net=host \
    --ipc=host \
    --ulimit memlock=-1 \
    --ulimit stack=67108864 \
    -v $(pwd):$(pwd) \
    -v $HOME/.cache/huggingface:/root/.cache/huggingface \
    -w $(pwd) \
    unsloth-dgx-spark
```

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-a67c36494f5c4ab4017748d490fb258655cd2378%2Fdgx2.png?alt=media" alt=""><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-b7758db087ab8b724049361781952b5ed154dfe8%2Fdgx5.png?alt=media" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Jupyterを起動してノートブックを実行**

コンテナ内でJupyterを起動し、必要なノートブックを実行します。Reinforcement Learning gpt-oss 20b を使って2048で勝つことができます [ノートブックはこちら](https://github.com/unslothai/notebooks/blob/main/nb/gpt_oss_\(20B\)_Reinforcement_Learning_2048_Game_DGX_Spark.ipynb)。実際、すべての [Unslothノートブック](https://docs.unsloth.ai/get-started/unsloth-notebooks) はDGX Sparkで動作し、 **120b** のノートブックも含まれます！ インストール用セルを削除するだけです。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-a8472482c49e1763378b609f8f537ca89df60260%2FNotebooks%20on%20dgx.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

以下のコマンドでもRLノートブックを実行できます。Jupyter Notebookを起動したら、「`gpt_oss_20B_RL_2048_Game.ipynb`」

```bash
NOTEBOOK_URL="https://raw.githubusercontent.com/unslothai/notebooks/refs/heads/main/nb/gpt_oss_(20B)_Reinforcement_Learning_2048_Game_DGX_Spark.ipynb"
wget -O "gpt_oss_20B_RL_2048_Game.ipynb" "$NOTEBOOK_URL"

jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser --allow-root
```

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-0862eed0acf0656ff0cb802b6aebc30892997e3b%2Fdgx6.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Unslothでは次のこともできるのを忘れないでください [保存して実行](/docs/jp/ji-chu/inference-and-deployment.md) できます。ファインチューニング後のモデルをそのままDGX Spark上でローカルにデプロイできます。
{% endstep %}
{% endstepper %}

多大なご協力をいただいた [Lakshmi Ramesh](https://www.linkedin.com/in/rlakshmi24/) そして [Barath Anandan](https://www.linkedin.com/in/barathsa/) NVIDIAの皆様、UnslothのDGX Sparkでの立ち上げとDockerイメージの構築にご協力いただき、ありがとうございます。

### ユニファイドメモリ使用量

gpt-oss-120bのQLoRA 4ビットファインチューニングでは、およそ **68GB** のユニファイドメモリを使用します。ユニファイドメモリ使用量の目安は次のようになります **先に** （左）と **〜した後** （右）の学習：

<div><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-e079a9aa8d853b319520fe0f0fbcca2e85b31ea6%2Fdgx7.png?alt=media" alt=""><figcaption></figcaption></figure> <figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-c389a73a48ad059bbb92121b328fa7ccc61bee95%2Fdgx8.png?alt=media" alt=""><figcaption></figcaption></figure></div>

以上です！ NVIDIA DGX Spark上で、LLMの学習と実行を完全にローカルで楽しんでください！

### 動画チュートリアル

のTimに感謝します [AnythingLLM](https://github.com/Mintplex-Labs/anything-llm) DGX Spark上でUnslothを使った素晴らしいファインチューニングチュートリアルを提供してくれたことに感謝します：

{% embed url="<https://www.youtube.com/watch?t=962s&v=zs-J9sKxvoM>" %}


---

# 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/burogu/fine-tuning-llms-with-nvidia-dgx-spark-and-unsloth.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.
