> 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/qwen3.8/train.md).

# Qwen3.8ファインチューニングガイド

Unslothを使ってQwen3.8-27Bをファインチューニングする方法を学びましょう。

Qwen3.8-27Bは現在、以下を介して強化学習（RL）による微調整と学習が可能です [Unsloth](https://github.com/unslothai/unsloth)。これはネイティブのテキスト、画像、動画サポート、思考制御、262Kのコンテキストウィンドウを備えた、密な27B統合視覚言語モデルです。

* UnslothはQwen3.8を **約1.5倍高速に** 、 **約50%少ないVRAMで** FA2構成よりも（精度低下なし）
* Qwen3.8-27Bを微調整 私たちの **無料の** **Kaggleノートブック経由で**:

| [**会話型**](https://www.kaggle.com/notebooks/welcome?src=https://github.com/unslothai/notebooks/blob/main/nb/Kaggle-Qwen3.8_\(27B\)-Conversational.ipynb\&accelerator=nvidiaTeslaT4) （Visionを有効にできます） | [**RL GRPO**](https://www.kaggle.com/notebooks/welcome?src=https://github.com/unslothai/notebooks/blob/main/nb/Kaggle-Muse_Glimmer_\(30B\)-GRPO.ipynb\&accelerator=nvidiaTeslaT4) |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

* **QLoRAは24GBで動作します** そしてLoRAには36GB超が必要です
* Qwen3.8は [強化学習](#reinforcement-learning-rl) （RL）を無料で、または24GBのVRAMで実行することもできます。
* **フルファインチューニング（FFT）** も動作しますが、VRAMを4倍多く使用します。
* Unslothは **Flash Linear Attentionカーネル** を活用して、効率的なQwen3.8学習を実現します
* 使用 [`Qwen3.8-27B-unsloth-bnb-4bit`](https://huggingface.co/unsloth/Qwen3.8-27B-unsloth-bnb-4bit) を4ビットQLoRAに使用し、次に **エクスポート** してNVFP4、FP8、GGUFなどへ。
* 推論能力を保持したい場合は、推論スタイルの例と直接回答を混ぜ、推論データを少なくとも75%含めてください。

最新のTransformers v5を使用してください。Qwen3.8は `qwen3_5` アーキテクチャを使用しています。Gated DeltaNetカーネルのコンパイル中は、初回実行に時間がかかる場合があります。

{% hint style="success" %}
以下を介したQwen3.8-27Bの無料ファインチューニングには [Unsloth](https://github.com/unslothai/unsloth)、私たちは複数のKaggleノートブックを提供しており、 **2基のTesla T4 GPUで30時間の無料GPU利用を提供します**。KaggleはGoogleの製品で、Google Colabに似ており、自前のGPUハードウェアなしでファインチューニングのワークフローを実行する便利な方法を提供します。
{% endhint %}

### 🦥 Unslothガイド

{% columns %}
{% column %}
Qwen3.8は [Unsloth](/docs/jp/xin-zhe/studio.md) Desktopで実行・ファインチューニングできます。これはローカルAI向けの新しいオープンソースWeb UIです。

Unsloth Studioを使えば、モデルをローカルで **MacOS、Windows**、Linuxで実行でき、NVIDIA GPUで学習できます。Intel、MLX、AMDの学習サポートは今月対応予定です。
{% endcolumn %}

{% column %}

<div data-with-frame="true"><figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FD7qpbGJLY5YMv0E0QgrB%2Ftrainingrun_LLM-unsloth.gif?alt=media&amp;token=feb766a7-1a7b-4f47-b5f4-b38e3a0d1470" alt=""><figcaption></figcaption></figure></div>
{% endcolumn %}
{% endcolumns %}

{% stepper %}
{% step %}

#### Unslothをインストール

始める最も簡単な方法は、以下をダウンロードすることです [Unsloth Desktopアプリ](/docs/jp/desktop.md)。対応OSは [macOS](/docs/jp/meru/install/mac.md), [Windows](/docs/jp/meru/install/windows-installation.md)、 [Linux](/docs/jp/meru/install/linux.md).

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">Unslothをダウンロード</a>

* <i class="fa-apple">:apple:</i> [macOS用をダウンロード](https://unsloth.ai/download/mac)
* <i class="fa-windows">:windows:</i> [Windows用をダウンロード](https://unsloth.ai/download/windows)
* <i class="fa-linux">:linux:</i> [Linux用をダウンロード](https://unsloth.ai/download/linux)

または、手動でインストールしたい場合は：

MacOS、Linux、WSL：

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

Windows PowerShell：

```bash
irm https://unsloth.ai/install.ps1 | iex
```

{% endstep %}

{% step %}

#### Qwen3.8を学習

Trainタブに移動し、検索バーでQwen3.8-27Bを検索して、目的のモデルとデータセットを選択します。次に、必要に応じてハイパーパラメータとコンテキスト長を調整してください。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FD7qpbGJLY5YMv0E0QgrB%2Ftrainingrun_LLM-unsloth.gif?alt=media&amp;token=feb766a7-1a7b-4f47-b5f4-b38e3a0d1470" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### 学習進捗を監視

学習開始をクリックすると、モデルの学習進捗を監視・確認できます。学習損失は着実に減少するはずです。\
完了すると、モデルは自動的に保存されます。
{% endstep %}

{% step %}

#### ファインチューニング済みモデルをエクスポート

完了すると、Unsloth StudioでモデルをGGUF、safetensorなどの形式へエクスポートできます。
{% endstep %}

{% step %}

#### ファインチューニング済みモデルと元モデルを比較

をクリック `比較モード` してLoRAアダプターと元モデルを比較します。
{% endstep %}
{% endstepper %}

### SFTレシピ

以下はテキストのみのファインチューニング用の最小限のSFTレシピです。データセットには `text` 列が必要で、Qwenのチャットテンプレートで既にレンダリングされている必要があります。

```python
from unsloth import FastModel
from datasets import load_dataset
from trl import SFTTrainer, SFTConfig

max_seq_length = 2048

dataset = load_dataset(
    "json",
    data_files = "train.jsonl",
    split = "train",
)

model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/Qwen3.8-27B-unsloth-bnb-4bit",
    max_seq_length = max_seq_length,
    load_in_4bit = True,
    full_finetuning = False,
    offload_embedding = True,
)

model = FastModel.get_peft_model(
    model,
    finetune_vision_layers     = False,
    finetune_language_layers   = True,
    finetune_attention_modules = True,
    finetune_mlp_modules       = True,

    r = 16,
    lora_alpha = 16,
    lora_dropout = 0,
    bias = "none",
    use_gradient_checkpointing = "unsloth",
    random_state = 3407,
    use_rslora = False,
    loftq_config = None,
)

trainer = SFTTrainer(
    model = model,
    tokenizer = tokenizer,
    train_dataset = dataset,
    args = SFTConfig(
        dataset_text_field = "text",
        max_seq_length = max_seq_length,
        per_device_train_batch_size = 1,
        gradient_accumulation_steps = 4,
        warmup_steps = 10,
        max_steps = 100,
        learning_rate = 2e-4,
        logging_steps = 1,
        optim = "adamw_8bit",
        output_dir = "outputs_qwen38",
        seed = 3407,
        dataset_num_proc = 1,
        report_to = "none",
    ),
)

trainer.train()
```

`offload_embedding=True` はオプションで、大きな非結合入力埋め込みをRAMに保持することで、常駐VRAMを削減します。Unslothは対応していないプラットフォームでは自動的にこれを無効にします。

OOMになったら、 `max_seq_length` を下げ、バッチサイズ1を維持して `"unsloth"` の勾配チェックポイントを使用してください。

### Visionファインチューニング

Qwen3.8はネイティブの画像入力と動画入力をサポートしています。マルチモーダル学習では、Vision層を有効にし、以下を用いた会話型Visionデータセットを使用してください `UnslothVisionDataCollator`.

```python
model = FastModel.get_peft_model(
    model,
    finetune_vision_layers     = True,
    finetune_language_layers   = True,
    finetune_attention_modules = True,
    finetune_mlp_modules       = True,

    r = 16,
    lora_alpha = 16,
    lora_dropout = 0,
    bias = "none",
    use_gradient_checkpointing = "unsloth",
    random_state = 3407,
    use_rslora = False,
    loftq_config = None,
)
```

設定してください `finetune_vision_layers=False` データセットがテキストのみの場合。

### 強化学習（RL）

Qwen3.8は同じ `qwen3_5` アーキテクチャを使用しているため、Qwen3.5のUnsloth RLパスを使い、高速vLLM推論を無効にしてください：

```python
from unsloth import FastModel

model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/Qwen3.8-27B-unsloth-bnb-4bit",
    max_seq_length = 2048,
    load_in_4bit = True,
    fast_inference = False,
)
```

### ファインチューニング済みモデルの保存 / エクスポート

デプロイ時には、学習時と同じチャットテンプレートとEOSトークンを使用してください。

**GGUFに保存**

```python
model.save_pretrained_gguf(
    "qwen38_gguf",
    tokenizer,
    quantization_method = "q4_k_m",
)

# model.push_to_hub_gguf(
#     "hf_username/qwen38_gguf",
#     tokenizer,
#     quantization_method = "q4_k_m",
# )
```

**vLLMに保存**

```python
model.save_pretrained_merged(
    "qwen38_finetuned",
    tokenizer,
    save_method = "merged_16bit",
)
```

LoRAアダプターのみを保存するには：

```python
model.save_pretrained("qwen38_lora")
tokenizer.save_pretrained("qwen38_lora")
```


---

# 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 dynamically by asking a question.

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

```
GET https://unsloth.ai/docs/jp/moderu/qwen3.8/train.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
