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

Stratified Batching #408

Merged
merged 19 commits into from
Sep 8, 2023

Conversation

snarayan21
Copy link
Collaborator

@snarayan21 snarayan21 commented Aug 31, 2023

Description of changes:

This PR lets users control the composition of each batch. Previously, users could set proportions for streams, which would be fulfilled in aggregate over the whole training run. Now, users can have each batch also consistently be stratified between streams in specified proportions as well. This will help customers training multimodal models and can also make some fancier dataset mixing strategies possible. Users can access this functionality by setting batching_method to stratified.

How it works:

  • make partition per stream, with 1 physical node and batch size 1
  • shuffle each partition
  • reshape to get global batch parts per stream, in order of traversal
  • discard batches with any padding at all
  • construct new overall batches by concatenating batch parts from each stream.

This is a useful feature that's good for multimodal applications and for some dataset mixing strategies. For example, we can combine text datasets with code datasets in definite proportions in every single batch, as long as the data is of the same dimension in each batch.

Ran multi-GPU tests with toy datasets to make sure that batches always had the same number of samples from each stream. Ran regression tests over 200 batches from different text datasets to ensure that elastic determinism and resumption still work when using stratified batching. These ran without issue and the results are here: https://wandb.ai/mosaic-ml/batching_methods/reports/new-batching-methods-testing--Vmlldzo1MzIxNjI1

Issue #, if available:

https://mosaicml.atlassian.net/browse/STR-130

Merge Checklist:

Put an x without space in the boxes that apply. If you are unsure about any checklist, please don't hesitate to ask. We are here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

  • I have read the contributor guidelines
  • This is a documentation change or typo fix. If so, skip the rest of this checklist.
  • I certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the MosaicML team.
  • I have updated any necessary documentation, including README and API docs (if appropriate).

Tests

  • I ran pre-commit on my change. (check out the pre-commit section of prerequisites)
  • I have added tests that prove my fix is effective or that my feature works (if appropriate).
  • I ran the tests locally to make sure it pass. (check out testing)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes.

@snarayan21 snarayan21 changed the title Consistent batch composition Apportioned Batching Sep 6, 2023
streaming/base/dataset.py Outdated Show resolved Hide resolved
streaming/base/dataset.py Outdated Show resolved Hide resolved
tests/test_streaming.py Outdated Show resolved Hide resolved
tests/test_streaming.py Show resolved Hide resolved
Copy link
Collaborator

@karan6181 karan6181 left a comment

Choose a reason for hiding this comment

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

Can you also update the description with what all integration testing that you have run to validate this PR ?

@snarayan21 snarayan21 changed the title Apportioned Batching Stratified Batching Sep 7, 2023
tests/test_streaming.py Outdated Show resolved Hide resolved
tests/test_streaming.py Outdated Show resolved Hide resolved
tests/test_streaming.py Outdated Show resolved Hide resolved
tests/test_streaming.py Outdated Show resolved Hide resolved
tests/test_streaming.py Outdated Show resolved Hide resolved
streaming/base/batching/stratified.py Show resolved Hide resolved
streaming/base/batching/stratified.py Outdated Show resolved Hide resolved
streaming/base/batching/stratified.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@karan6181 karan6181 left a comment

Choose a reason for hiding this comment

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

LGTM. Thank You!

@snarayan21 snarayan21 merged commit 95538bc into mosaicml:main Sep 8, 2023
5 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.

2 participants