Skip to content

Conversation

shirinyamani
Copy link
Member

@shirinyamani shirinyamani commented Apr 7, 2025

What does this PR do?

changes:

  • simplified completion_mask to not change anything in the loss compute to be compatible with the lig-loss,
  • intended to further extend it to remove the truncated_mask_completions from the Advtg

simple script to take it for spin;

from datasets import load_dataset
from trl.trainer.grpo_trainer import GRPOTrainer
from trl.trainer.grpo_config import GRPOConfig


dataset = load_dataset("trl-lib/tldr", split="train[:200]")


def reward_func(completions, **kwargs):
    return [len(set(c)) for c in completions]

args = GRPOConfig(
    output_dir="mask_truncated_ture_with_max_completion_length",
    use_vllm=False,
    bf16=True,
    gradient_checkpointing=True,
    logging_steps=50,
    mask_truncated_completions=True, 
    num_train_epochs=1,
    per_device_train_batch_size=4,
    gradient_accumulation_steps=1,
    num_generations=4,  
    max_completion_length=50,
)


trainer = GRPOTrainer(
    model="Qwen/Qwen2.5-0.5B",
    args=args,
    reward_funcs=reward_func,
    train_dataset=dataset,
)


trainer.train() 

then do;

accelerate launch 3248.py

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?
  • 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.

Copy link
Member Author

@shirinyamani shirinyamani left a comment

Choose a reason for hiding this comment

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

I don't think it's logged

🤔 hmm, any comment on how to fix it ?

@qgallouedec
Copy link
Member

The advantage calculation always takes truncated samples into account, doesn't it?

shirinyamani and others added 2 commits April 7, 2025 21:59
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
@qgallouedec
Copy link
Member

There are still some minor things to do:

  • revert changes in docs/source/grpo_trainer.md and examples/scripts/sft_video_llm.py
  • fix CI
  • update PR name

@shirinyamani shirinyamani changed the title [WIP] Overlong-filtering2 Overlong-filtering2 Apr 8, 2025
@shirinyamani
Copy link
Member Author

There are still some minor things to do:

  • revert changes in docs/source/grpo_trainer.md and examples/scripts/sft_video_llm.py
  • fix CI
  • update PR name

It is very surprising!! cuz I did
git checkout -- examples/scripts/sft_video_llm.py

learning_rate=0.1,
per_device_train_batch_size=3,
num_generations=3,
max_completion_length=8,
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious to see if the CI will pass. What I foresee is that considering the small size of the completion, all completions are truncated, so they are all filtered and the model never updates.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes actually the dataset in use has completions are too short, (initials are only 1 token)

Copy link
Member

Choose a reason for hiding this comment

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

Knew it!

FAILED tests/test_grpo_trainer.py::GRPOTrainerTester::test_training_with_mask_truncated_completions - AssertionError: True is not false : Parameter model.embed_tokens.weight has not changed.

Copy link
Member

Choose a reason for hiding this comment

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

451bec9 should fix it

@qgallouedec qgallouedec changed the title Overlong-filtering2 ☕ Overlong-filtering for GRPO Apr 8, 2025
@qgallouedec
Copy link
Member

Feel free to merge, CI failing is not related to this PR

@shirinyamani shirinyamani merged commit 1d7b8c4 into main Apr 8, 2025
9 of 10 checks passed
@shirinyamani shirinyamani deleted the overlong-filtering2 branch April 8, 2025 18:52
yxliu-TAMU pushed a commit to mincheolseong/ECEN743-GRPO-Project-Proposal that referenced this pull request Apr 20, 2025
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.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.

4 participants