-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Add the auto_find_batch_size capability from Accelerate into Trainer #17068
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
Conversation
sgugger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Left a few comments to make the PR a bit better :-)
Co-authored-by: Sylvain Gugger <[email protected]>
sgugger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work on this. Pinging @LysandreJik to have a second set of eye :-)
Co-authored-by: Sylvain Gugger <[email protected]>
|
@stas00 I'm getting a test failure on the metrics: tests/trainer/test_trainer.py:1426: in check_mem_metrics
metrics = trainer.train().metrics
src/transformers/trainer.py:1215: in train
ignore_keys_for_eval=ignore_keys_for_eval,
src/transformers/trainer.py:1571: in _inner_training_loop
self._memory_tracker.stop_and_update_metrics(metrics)
src/transformers/trainer_utils.py:536: in stop_and_update_metrics
stage = self.derive_stage()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <transformers.trainer_utils.TrainerMemoryTracker object at 0x7f929f787e10>
def derive_stage(self):
"""derives the stage/caller name automatically"""
caller = inspect.currentframe().f_back.f_back.f_code.co_name
if caller in self.stages:
return self.stages[caller]
else:
raise ValueError(
> f"was called from {caller}, but only expect to be called from one of {self.stages.keys()}"
)
E ValueError: was called from _inner_training_loop, but only expect to be called from one of dict_keys(['__init__', 'train', 'evaluate', 'predict'])Any advice on how to approach a solution? |
62c7bd3 to
ff6caca
Compare
|
The documentation is not available anymore as the PR was closed or merged. |
|
This will overcome the problem: |
LysandreJik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, looks good to me!
|
Please make sure all tests pass after resolving conflicts and before merging! |
…uggingface#17068) Co-authored-by: Sylvain Gugger <[email protected]> - Adds auto_batch_size finder - Moves training loop to an inner training loop
|
Any chance similar functionality could be supported for inference? 🙏 |
What does this PR do?
This PR introduces the
find_executable_batch_sizedecorator intoTrainer, so the training loop is repeated if a CUDA OOM is reached, lowering the batch size.The API looks as so:
By default it is False, and requires
Acceleratebe installed to use.Fixes # (issue)
Partially solves #16987
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.
@sgugger