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

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

{% stepper %}
{% step %}

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

始めるにあたり、次が必要です：

* インストール済み [VS Code](https://code.visualstudio.com/)。ノートブックのリポジトリをクローンするための Git は通常デフォルトでインストールされています。
* 1つの **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%2FJ1f5BS4EK0ok5QLy6vz5%2Fcolab_img_1.png?alt=media&#x26;token=1faa7aac-c016-4c31-90ba-ccad655244e1" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

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

1. Unsloth の [notebooks リポジトリをクローンする](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&#x26;token=7a72c2ec-6f94-4015-8355-27e76ba9b974" alt="" width="375"><figcaption></figcaption></figure>

2. 目的のノートブックを開きます。Unsloth は埋め込み（embedding）や音声合成（TTS）などのほとんどのモデルをサポートしています。 [埋め込み](https://unsloth.ai/docs/jp/ji-ben/embedding-finetuning), [TTS](https://unsloth.ai/docs/jp/ji-ben/text-to-speech-tts-fine-tuning)。例えば、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%2FleZtIzyflSgi1o1QcZDU%2Fcolab_img_2.png?alt=media&#x26;token=805ebe8b-cb50-49a4-83d4-0daf96ad21c1" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

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

ノートブックのツールバーで、 **Select Kernel**をクリックし、次に **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&#x26;token=ba3d8f1d-9cbb-44ed-8e52-8d0e52280607" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 新しい Colab サーバーを追加する

を選ぶと、サーバーオプションのドロップダウンが表示されます。 **Colab**最初は Google 認証のためにブラウザウィンドウが開くことがあります

1. クリック **+ Add New Colab Server**
2. ログインしてアクセスを許可し、VS Code に戻ってください
   * ログインし、アクセスを許可してから 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&#x26;token=a7c3642f-db35-4215-933f-99c17ebc92a2" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

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

1. に設定する **Hardware accelerator** を **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&#x26;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&#x26;token=391e343d-d2fa-4a77-8e3f-ef244adfcb4c" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

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

* クリック **Run All** をノートブックのツールバーで実行する（またはセルを上から順に実行）
* セットアップ用セルが依存関係をインストールし、その後 Unsloth ワークフローが開始されるのを確認します
* より詳しく始め方を知りたい場合は、専用の [ファインチューニング](https://unsloth.ai/docs/jp/meru/fine-tuning-llms-guide) または [強化学習](https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide) ガイドを参照してください。
  {% 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 ランタイムに接続されていない：** 再確認してください **Select Kernel → Colab** を選び、Colab サーバーがアクティブであることを確認してください。
* **アカウント／地域の制限や上限に達している：** 待つか、別の Google アカウント／プランを使用する必要があるかもしれません。

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

Colab ランタイムは **エフェメラル（短命）**&#x3067;す。サーバーが再起動したときは、通常セットアップ／インストールセル（多くの場合ノートブックの最初の数セル）を再実行する必要があります。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/jp/meru/install/vs-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
