Skip to content

🐙 MPO #2544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Jul 21, 2025
Merged

🐙 MPO #2544

merged 41 commits into from
Jul 21, 2025

Conversation

qgallouedec
Copy link
Member

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ariG23498
Copy link
Collaborator

Here is a rough colab notebook that I have created.

In the notebook:

  1. Installed trl from the branch
  2. Used the openbmb/RLAIF-V-Dataset dataset
  3. Used the HuggingFaceTB/SmolVLM-Instruct model

Here are my queries:

  1. Reading the code, we expect the loss_type to be a str with , seperated losses.
    training_args = DPOConfig(
        ...
        loss_type="sigmoid, bco_pair", # <-- a collection of losses
    )
    As far as I understand the MPO paper, it comprises of three losses, the DPO loss, the BCO loss, and the SFT loss. Here I have added the BCO and used sigmoid for the DPO loss, do we also have a way to add the SFT loss here somehow (which I think would be cross entropy loss?)
  2. The weighting parameter in the config (as in this comment)

@ariG23498 ariG23498 marked this pull request as ready for review January 24, 2025 07:24
@ariG23498
Copy link
Collaborator

@qgallouedec Here is a rough colab notebook with the current MPO training.

Let me know what you think.

Copy link
Member Author

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Some initial comments :)

@qgallouedec
Copy link
Member Author

qgallouedec commented Jan 24, 2025

Really nice!!!

But don't do this (important):

    # Apply the chat template
    prompt = processor.apply_chat_template(prompt, tokenize=False)
    chosen = processor.apply_chat_template(chosen, tokenize=False)
    rejected = processor.apply_chat_template(rejected, tokenize=False)

The DPO Trainer handle applying the chat template. See #1930 for more info.

This code snippet is present in so many examples online, it's a scourge. 😩

@@ -15,7 +15,7 @@
import warnings
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Callable, Optional, Union
from typing import Any, Callable, Optional, Union, List, Dict
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use list and dict instead

@qgallouedec qgallouedec changed the title MPO 🐙 MPO Jul 21, 2025
@qgallouedec qgallouedec requested a review from kashif July 21, 2025 17:50
@qgallouedec qgallouedec merged commit d870230 into main Jul 21, 2025
10 of 11 checks passed
@qgallouedec qgallouedec deleted the mpo branch July 21, 2025 18:13
@sergiopaniego sergiopaniego restored the mpo branch July 22, 2025 09:49
@sergiopaniego sergiopaniego deleted the mpo branch July 22, 2025 13:11
marcandrelarochelle pushed a commit to marcandrelarochelle/trl that referenced this pull request Jul 29, 2025
Co-authored-by: ariG23498 <aritra.born2fly@gmail.com>
Co-authored-by: Kashif Rasul <kashif.rasul@gmail.com>
Co-authored-by: sergiopaniego <sergiopaniegoblanco@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants