> 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)、任意の [ファインチューニングノートブック](/docs/jp/meru/unsloth-notebooks.md) VS Code で 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%2FJ1f5BS4EK0ok5QLy6vz5%2Fcolab_img_1.png?alt=media&amp;token=1faa7aac-c016-4c31-90ba-ccad655244e1" 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 は次を含むほとんどのモデルをサポートしています。 [埋め込み](/docs/jp/ji-chu/embedding-finetuning.md), [TTS](/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%2FleZtIzyflSgi1o1QcZDU%2Fcolab_img_2.png?alt=media&amp;token=805ebe8b-cb50-49a4-83d4-0daf96ad21c1" 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. クリックします **+ 新しい Colab サーバーを追加**
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 のワークフローを開始する様子を確認してください
* 専用の [ファインチューニング](/docs/jp/meru/fine-tuning-llms-guide.md) または [強化学習](/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.
