> 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/meru/install/vs-code.md).

# UnslothとColab GPUを使ってVS CodeでLLMをファインチューニングする方法

UnslothとGoogle Colabを通じてVisual Studio Codeでモデルを直接ファインチューニングするためのガイド。

Visual Studio Code（VSCode）から直接、ローカル環境またはGoogle Colabの拡張機能を使ってLLMをファインチューニングできるようになりました。このガイドでは、オープンソースのトレーニング用 [リポジトリ Unsloth](https://github.com/unslothai/unsloth)を使って、VS Codeのあらゆる [ファインチューニング用ノートブック](https://unsloth.ai/docs/jp/meru/unsloth-notebooks.md) をColabランタイムに接続し、ローカルまたはColabの無料GPUでトレーニングする方法を説明します。動画チュートリアルも [こちら](#video-tutorial).

{% stepper %}
{% step %}

### VS CodeとColabのチュートリアル：

まず、次のものが必要です。

* インストール済みの [VS Code](https://code.visualstudio.com/)。Git（ノートブックリポジトリのクローンに使用）は、通常デフォルトでインストールされています。
* Google **アカウント** （Colabでの認証に使用）
* 推奨： **Jupyter** 拡張機能（ほとんどのVS Code環境にはすでにインストールされています）
  {% endstep %}

{% step %}

#### VS CodeにColab拡張機能をインストールする

1. VS Codeで **拡張機能** を開き（`Ctrl+Shift+X` / `Cmd+Shift+X`)
2. を押して **「Colab」** を検索し、 **Google Colab** 拡張機能をインストールします。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FnITq5t7dffCUGSW2EVsm%2Fcolab_img_1.optimized.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Unslothのノートブックを開く

1. Unslothの [ノートブックリポジトリ](https://github.com/unslothai/notebooks):

```bash
git clone https://github.com/unslothai/notebooks
cd notebooks/nb
```

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FwRL8pvgtLRpz5rcmS6vy%2FScreenshot%202026-02-18%20at%206.29.16%E2%80%AFPM.png?alt=media&amp;token=7a72c2ec-6f94-4015-8355-27e76ba9b974" alt="" width="375"><figcaption></figcaption></figure>

2. 使用するノートブックを開きます。Unslothは、次のようなモデルを含む、ほとんどのモデルに対応しています。 [埋め込み](https://unsloth.ai/docs/jp/ji-chu/embedding-finetuning.md), [TTS](https://unsloth.ai/docs/jp/ji-chu/text-to-speech-tts-fine-tuning.md)。例として、Qwen3-4B RLを使います。 `nb/Qwen3_(4B)-GRPO.ipynb`

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FVBqwvArAyclTQjb7YL5I%2Fcolab_img_2.optimized.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### カーネルを選択してColabを選ぶ

ノートブックのツールバーで **カーネルの選択**をクリックし、 **Colab**

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FleGtAKSVehrlspPGvDy2%2Fcolab_img_3.png?alt=media&amp;token=ba3d8f1d-9cbb-44ed-8e52-8d0e52280607" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### を選びます。

新しいColabサーバーを追加する **Colab**を選択すると、サーバーの選択肢がドロップダウンに表示されます。

1. 「 **+ Add New Colab Server**
2. 」をクリックします。初回は、Google認証のためにブラウザーウィンドウが開くことがあります。
   * ログインしてアクセスを許可し、VS Codeに戻ります

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FZcDsB2i0aUStIKEeFTvF%2Fcolab_img_4.png?alt=media&amp;token=a7c3642f-db35-4215-933f-99c17ebc92a2" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### GPUを選択してサーバーに名前を付ける

1. 設定 **ハードウェアアクセラレータ** を **GPU**
2. GPUの種類を選択します（たとえば **T4**（利用可能な場合））
3. サーバーに好きな名前を付けます

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FLuK8oheihdCNn9MAZSlk%2Fcolab_img_5.png?alt=media&amp;token=e5ed396f-afe2-4c09-b1b8-120c7301793c" alt="" width="375"><figcaption></figcaption></figure>

{% hint style="info" %}
注：GPUの利用可否は、Colabのプランと現在の空き状況によって異なります。GPUの選択肢が表示されない場合は、下記のトラブルシューティングを参照してください。
{% endhint %}
{% endstep %}

{% step %}

#### Pythonカーネルを選択する

Colabサーバーに接続したら、 **Python** カーネルを選択します。このランタイム用に表示されるカーネル（通常はPython 3カーネル）を選んでください。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FBexUiXJ7LRFBXs95tX2S%2Fcolab_img_6.png?alt=media&amp;token=391e343d-d2fa-4a77-8e3f-ef244adfcb4c" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### ノートブックを実行する

* ノートブックのツールバーで **すべて実行** をクリックします（または、セルを上から順に実行します）。
* セットアップ用のセルで依存関係がインストールされ、その後Unslothのワークフローが開始されることを確認します。
* 詳しくは、専用の [ファインチューニング](https://unsloth.ai/docs/jp/meru/fine-tuning-llms-guide.md) または [強化学習](https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide.md) ガイドをご覧ください。Unslothの始め方を詳しく説明しています。
  {% endstep %}
  {% endstepper %}

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

{% embed url="<https://youtu.be/5NNggTrEWNQ>" %}

### トラブルシューティング

#### Colabサーバーが切断された後、新しいサーバーでノートブックを実行できない

**原因：**\
Colabサーバーが切断されたときにノートブックを開いたままにしていると、再接続後にVS Codeのカーネルまたはランタイムの状態が不整合になることがあります。関連する [GitHubのissue](https://github.com/googlecolab/colab-vscode/issues/200).

**解決方法：** ノートブックのタブを完全に閉じてから、ノートブックを開き直してください。

#### GPUを選択できない（CPUしか表示されない）

考えられる原因と対処方法：

* **Colab無料プランの容量制限：** GPUが一時的に利用できない場合があります → 後でもう一度お試しください。
* **Colabランタイムに接続されていない：** もう一度確認し、 **カーネルの選択 → Colab** を選んで、Colabサーバーが起動していることを確認してください。
* **アカウントや地域の制限、または利用上限に達している：** しばらく待つか、別のGoogleアカウントまたはプランを利用してください。

#### すべて正常に動作したのに、再接続後にパッケージが「消えている」

Colabランタイムは **一時的なもの**です。サーバーが再起動すると、通常はセットアップ／インストール用のセル（多くの場合、ノートブックの最初の数セル）を再実行する必要があります。


---

# 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/meru/install/vs-code.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.
