Add the auto_find_batch_size capability from Accelerate into Trainer#17068
Merged
Add the auto_find_batch_size capability from Accelerate into Trainer#17068
Conversation
sgugger
reviewed
May 3, 2022
Collaborator
sgugger
left a comment
There was a problem hiding this comment.
Thanks for working on this! Left a few comments to make the PR a bit better :-)
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
sgugger
reviewed
May 4, 2022
sgugger
approved these changes
May 4, 2022
Collaborator
sgugger
left a comment
There was a problem hiding this comment.
Thanks for all the work on this. Pinging @LysandreJik to have a second set of eye :-)
Contributor
Author
|
@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. |
Contributor
|
This will overcome the problem: |
Member
|
Please make sure all tests pass after resolving conflicts and before merging! |
elusenji
pushed a commit
to elusenji/transformers
that referenced
this pull request
Jun 12, 2022
…uggingface#17068) Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> - Adds auto_batch_size finder - Moves training loop to an inner training loop
Contributor
|
Any chance similar functionality could be supported for inference? 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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