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

fix accelerator prepare during eval only mode #24014

Merged
merged 4 commits into from Jun 7, 2023

Conversation

pacman100
Copy link
Contributor

@pacman100 pacman100 commented Jun 5, 2023

What does this PR do?

  1. As mentioned in find cpu_amp is incorrect set, it's only set if self.sharded_ddp is n… #23957 (comment), currently the accelerate prepare method is happening only during training loop. If the user is directly doing eval/predict without the training loop, the model isn't prepared leading to wrong behaviour. This PR is aimed at fixing it.
  2. Should be merged after Instead go with evaluation_mode accelerate#1540

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 5, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Unless I'm missing something, this changes the whole logic of the evaluation in the Trainer and should not be done.


model = self._wrap_model(self.model, training=False, dataloader=dataloader)

if len(self.accelerator._models) == 0 and model is self.model:
model = self.accelerator.prepare(model)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No we only want to do this for DeepSpeed, not all the time. Putting a model in DistributedDataParallel just for evaluation will waste some memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do agree on the DDP case and hence I didn't update it earlier but as mentioned below we will be missing mixed precision coverage for eval-only mode

@pacman100
Copy link
Contributor Author

The thing is that mixed precision application for eval only mode won't work unless we prepare model

@pacman100 pacman100 merged commit d1c039e into main Jun 7, 2023
22 checks passed
@pacman100 pacman100 deleted the smangrul/fix-mp-in-eval-pred branch June 7, 2023 19:33
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
* fix mixed precision prep during eval only mode

* update to address comments

* update to reflect the changes in accelerate
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.

None yet

3 participants