Skip to content
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

[data_loader] Optionally also propagate set_epoch to batch sampler #3246

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

tomaarsen
Copy link
Member

@tomaarsen tomaarsen commented Nov 19, 2024

What does this PR do?

When training with the transformers Trainer or related (Sentence Transformers, SpanMarker, SetFit, etc.), set_epoch is called on the dataloader. This is propagated down to the dataloader.batch_sampler.sampler if that has a set_epoch , but not to dataloader.batch_sampler.

This prevents epoch-specific generator seeding in custom batch samplers, such as the ones that are common in Sentence Transformers: https://sbert.net/docs/package_reference/sentence_transformer/sampler.html

See also UKPLab/sentence-transformers#3069 by @antigregory which showed that set_epoch in my Batch Samplers is not called like I expected them to be.

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 or the forum? 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, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@muellerzr (p.s. get better soon!)

  • Tom Aarsen

@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
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Thanks for propagating! Can you confirm it fixes your issue? (If so, we either should add a test, or add SentenceTransformer test subsets into accelerate)

@tomaarsen
Copy link
Member Author

tomaarsen commented Nov 20, 2024

Can you confirm it fixes your issue?

It does indeed. I think I can write a test to go alongside this PR - it doesn't need to be ST-specific.

  • Tom Aarsen

@tomaarsen
Copy link
Member Author

This test roughly mirrors my use case and should act as an effective test to make sure ST should work. Feel free to update it if e.g. you don't normally use Accelerator in the data_loader tests.

  • Tom Aarsen

Copy link
Collaborator

@muellerzr muellerzr left a comment

Choose a reason for hiding this comment

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

Thanks for adding!

@muellerzr muellerzr merged commit 77f2b62 into huggingface:main Nov 20, 2024
25 checks passed
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.

3 participants