Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GRPO: Pack Responses within the same group.#3642

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
pramodith wants to merge21 commits intohuggingface:main
base:main
Choose a base branch
Loading
frompramodith:pramodith/grpo_group_packing

Conversation

pramodith
Copy link
Contributor

@pramodithpramodith commentedJun 24, 2025
edited
Loading

Pack Responses within the same group.

This PR addresses#3549 and packs all the responses belonging to the same group into a single row of the batch.

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 thecontributor 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.

@pramodithpramodith changed the titlePramodith/grpo group packingGRPO: Pack Responses within the same group.Jun 24, 2025
@pramodith
Copy link
ContributorAuthor

pramodith commentedJul 2, 2025
edited
Loading

@kashif and/or@qgallouedec wondering if either of you could take a look at this PR since you're familiar with how FA2 works with custom position ids. In particular I'm kind of lost on whytest_forward_pass_with_packing is failing. I've validated that the logic for packing the inputs and unpacking the logits is accurate through my test cases and debugging.

Just for some context I'm trying to pack all the responses for a given prompt/query into a single row in the batch, before running a forward pass through the reference, old and current policy models.

The thing I noticed is that despite sending in the right position ids FA2 doesn't seem to give me the same outputs with and without packing.

For example, I tried this out trying to simulate how a packed GRPO group would look like. Tokens[646,647,648] areprompt tokens here.

pad_token_id = trainer.processing_class.pad_token_id            sample_input_ids = torch.tensor(    [        [646, 647, 648, 649, pad_token_id],        [646, 647, 648, 650, 651],    ],    device=trainer.model.device,)sample_attention_mask = torch.tensor(    [        [1, 1, 1, 1, 0],        [1, 1, 1, 1, 1],    ],    device=trainer.model.device,)sample_packed_input_ids = torch.tensor(    [        [646, 647, 648, 649, 650, 651],    ],    device=trainer.model.device,)sample_position_ids = torch.tensor(    [        [0, 1, 2, 3, 3, 4],    ],    device=trainer.model.device,)reg_logs = trainer.model(input_ids=sample_input_ids, attention_mask=sample_attention_mask).logitsreg_logs = torch.gather(reg_logs, -1, sample_input_ids.unsqueeze(-1))packed_logs = trainer.model(    input_ids=sample_packed_input_ids,    position_ids=sample_position_ids,).logitspacked_logs = torch.gather(packed_logs, -1, sample_packed_input_ids.unsqueeze(-1))

I think that the logit scores for all the token ids[646,647,648,649,650, 651] should match forreg_logs andpacked_logs but I'm seeing that the logit scores for tokens650 and 651 do not match. So it seems like FA2 isn't correctly accounting for packing or I'm doing something wrong. Any pointers would be much appreciated. I think the attention_mask isn't correctly being generated for this use case inside FA2, so wondering if explicitly passing aattention_mask might help.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@pramodith

[8]ページ先頭

©2009-2025 Movatter.jp