> 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/reinforcement-learning-rl-guide/advanced-rl-documentation/gspo-reinforcement-learning.md).

# GSPO強化学習

GSPOを導入します。これは〜の変種です [GRPO](/docs/jp/meru/reinforcement-learning-rl-guide.md#from-rlhf-ppo-to-grpo-and-rlvr) AlibabaのQwenチームによって作られました。彼らは、GRPOが各トークンに重要度重みを適用する一方で、本質的にはアドバンテージは各トークンごとにスケールも変化もしないという観察に気づきました。これによりGSPOが生まれ、現在では個々のトークンの尤度ではなく、系列の尤度に重要度を割り当てるようになっています。

* 以下のために、無料のGSPOノートブックをご利用ください: [**gpt-oss-20b**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/gpt-oss-\(20B\)-GRPO.ipynb) および [**Qwen2.5-VL**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2_5_7B_VL_GRPO.ipynb)

次を設定して、UnslothでGSPOを有効にします `importance_sampling_level = "sequence"` をGRPO設定に入れます。これら2つのアルゴリズムの違いは、以下のQwenとAlibabaによるGSPO論文から見ることができます:

<figure><img src="/files/c0d1bd14ae4cfd7ab35f62653f2899685e1a6a2e" alt="" width="563"><figcaption><p>GRPOアルゴリズム、出典: <a href="https://arxiv.org/abs/2507.18071">Qwen</a></p></figcaption></figure>

<figure><img src="/files/8660c492a063a1c7d89fb26d4b1f53ff3e657dab" alt="" width="563"><figcaption><p>GSPOアルゴリズム、出典: <a href="https://arxiv.org/abs/2507.18071">Qwen</a></p></figcaption></figure>

式1では、テンソルが合計される前に、アドバンテージが各行をトークンの対数確率へスケールしていることがわかります。本質的には、そのスケーリングは各個別トークンではなく系列全体に対して与えられたにもかかわらず、各トークンに同じスケーリングが与えられています。これを示す簡単な図を以下に示します:

<figure><img src="/files/d314595a5083d6127105a3e8423ae2f1885f0a4c" alt="" width="286"><figcaption><p>GRPOの対数確率比をアドバンテージで行ごとにスケーリング</p></figcaption></figure>

式2では、各系列の対数確率比が、対数確率比を計算した後に合計され指数化され、その結果として得られた系列比のみがアドバンテージによって行ごとに乗算されることが示されています。

<figure><img src="/files/53071bdf0521d59acc2643eb5ac40e555ffd68a2" alt="" width="313"><figcaption><p>GSPOの系列比をアドバンテージで行ごとにスケーリング</p></figcaption></figure>

GSPOの有効化は簡単です。必要なのは、次を設定するだけです `importance_sampling_level = "sequence"` フラグをGRPO設定に入れることです。

```python
training_args = GRPOConfig(
    output_dir = "vlm-grpo-unsloth",
    per_device_train_batch_size = 8,
    gradient_accumulation_steps = 4,
    learning_rate = 5e-6,
    adam_beta1 = 0.9,
    adam_beta2 = 0.99,
    weight_decay = 0.1,
    warmup_ratio = 0.1,
    lr_scheduler_type = "cosine",
    optim = "adamw_8bit",
    # beta = 0.00,
    epsilon = 3e-4,
    epsilon_high = 4e-4,
    num_generations = 8,    
    max_prompt_length = 1024,
    max_completion_length = 1024,
    log_completions = False,
    max_grad_norm = 0.1,
    temperature = 0.9,
    # report_to = "none", # Weights & Biasesにログを記録したい場合は "wandb" に設定
    num_train_epochs = 2, # 簡単なテスト実行用。フル学習では増やしてください
    
    # GSPOは以下です:
    importance_sampling_level = "sequence",
    
    # Dr GRPO / GAPO など
    loss_type = "dr_grpo",
)
```


---

# 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:

```
GET https://unsloth.ai/docs/jp/meru/reinforcement-learning-rl-guide/advanced-rl-documentation/gspo-reinforcement-learning.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.
