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

scale gradient accumulation steps with train batch size to keep effective batch size about the same #33281

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

winglian
Copy link
Contributor

@winglian winglian commented Sep 3, 2024

What does this PR do?

goes with huggingface/accelerate#3071

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

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.

@winglian winglian force-pushed the auto_find_batch_size_compensate branch from ab90906 to 56cbbba Compare September 3, 2024 18:39
Copy link
Contributor

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

Nice start!

Comment on lines +1976 to +1983
def reduce_batch_size_fn_wrapper(train_batch_size, args):
effective_batch_size = args.gradient_accumulation_steps * train_batch_size
def reduce_batch_size_fn():
nonlocal train_batch_size
train_batch_size = train_batch_size // 2
args.gradient_accumulation_steps = effective_batch_size // train_batch_size
return train_batch_size
return reduce_batch_size_fn
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's put this in trainer_utils I think since that's where we have find_executable_batch_size defined.

args.gradient_accumulation_steps = effective_batch_size // train_batch_size
return train_batch_size
return reduce_batch_size_fn

inner_training_loop = find_executable_batch_size(
Copy link
Contributor

Choose a reason for hiding this comment

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

The trainer_utils's find_executable_batch_size will then also need changing.

Also need to be careful about versioning inside that func

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be set as >=0.34.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, I forgot to commit a file. should be there now

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