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

# Apprentissage par renforcement GSPO

Entraînez avec le RL GSPO (Group Sequence Policy Optimization) dans Unsloth.

Nous présentons GSPO, qui est une variante de [GRPO](/docs/fr/commencer/reinforcement-learning-rl-guide.md#from-rlhf-ppo-to-grpo-and-rlvr) créé par l’équipe Qwen d’Alibaba. Ils ont observé que lorsque GRPO attribue des poids d’importance à chaque jeton, alors que, intrinsèquement, les avantages ne varient ni ne changent avec chaque jeton. Cela a conduit à la création de GSPO, qui attribue désormais l’importance à la vraisemblance de la séquence plutôt qu’aux vraisemblances individuelles des jetons.

* Utilisez nos notebooks GSPO gratuits pour : [**gpt-oss-20b**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/gpt-oss-\(20B\)-GRPO.ipynb) et [**Qwen2.5-VL**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen2_5_7B_VL_GRPO.ipynb)

Activez GSPO dans Unsloth en définissant `importance_sampling_level = "sequence"` dans la configuration GRPO. La différence entre ces deux algorithmes peut être vue ci-dessous, d’après l’article sur GSPO de Qwen et Alibaba :

<figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-45d743dd5dcd590626777ce09cfab61808aa8c24%2Fimage.png?alt=media" alt="" width="563"><figcaption><p>Algorithme GRPO, source : <a href="https://arxiv.org/abs/2507.18071">Qwen</a></p></figcaption></figure>

<figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-ee755850cbe17482ce240dde227d55c62e9a3e64%2Fimage.png?alt=media" alt="" width="563"><figcaption><p>Algorithme GSPO, source : <a href="https://arxiv.org/abs/2507.18071">Qwen</a></p></figcaption></figure>

Dans l'équation 1, on voit que les avantages mettent à l'échelle chacune des lignes dans les logprobs des jetons avant que ce tenseur ne soit additionné. En substance, chaque jeton reçoit la même mise à l'échelle, même si celle-ci a été attribuée à l'ensemble de la séquence plutôt qu'à chaque jeton individuellement. Un simple schéma de cela est présenté ci-dessous :

<figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-b3c944808a15dde0a7ff45782f9f074993304bf1%2FCopy%20of%20GSPO%20diagram%20(1).jpg?alt=media" alt="" width="286"><figcaption><p>Rapport de logprob GRPO mis à l'échelle ligne par ligne avec les avantages</p></figcaption></figure>

L'équation 2 montre que les rapports de logprob de chaque séquence sont additionnés et exponentiés après le calcul des rapports de logprob, et que seuls les rapports de séquence obtenus sont ensuite multipliés ligne par ligne par les avantages.

<figure><img src="https://550366147-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-62fc5b50921e79cce155d2794201c9b96faf941e%2FGSPO%20diagram%20(1).jpg?alt=media" alt="" width="313"><figcaption><p>Rapport de séquence GSPO mis à l'échelle ligne par ligne avec les avantages</p></figcaption></figure>

Activer GSPO est simple, il suffit de définir le `importance_sampling_level = "sequence"` indicateur dans la configuration 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", # Définissez sur "wandb" si vous souhaitez enregistrer dans Weights & Biases
    num_train_epochs = 2, # Pour un test rapide, augmentez pour un entraînement complet
    
    # GSPO est ci-dessous :
    importance_sampling_level = "sequence",
    
    # Dr GRPO / GAPO etc
    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 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/fr/commencer/reinforcement-learning-rl-guide/advanced-rl-documentation/gspo-reinforcement-learning.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.
