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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested combination of Runner and AmpOptimWrapper does not result in mixed precision training [Docs] #1515

Open
JMQuehl opened this issue Mar 15, 2024 · 0 comments

Comments

@JMQuehl
Copy link

JMQuehl commented Mar 15, 2024

馃摎 The doc issue

According to this documentation:

MMEngine provides the wrapper AmpOptimWrapper for auto-mixing precision training, just set type='AmpOptimWrapper' in optim_wrapper to enable auto-mixing precision training, no other code changes are needed.

The example code builds a Runner and sets an AmpOptimWrapper.
However, accordings to this documentation of the Optim_Wrapper, optim_context has to be called in order to activate the mixed precision training for the model.

I checked by putting a breakpoint into the optim_context method when using a Runner and found that the optim_context method is never called when using the Runner. And also there does not seem to be any performance change as well.

So my conclusion is that either

  1. The documentation here is wrong that optim_context has to be called in order for mixed precision to work and autocast was simply not able to have any impact on my model or
  2. The documentation here is wrong that "no other code changes are needed" or
  3. There is a bug in the Runner class which does not factor in how the AmpOptimWrapper has to be used.

Suggest a potential alternative/fix

Either change the Runner to call the optim_context method if an AmpOptimWrapper is specified or further specify here what additional steps are needed in order to make the AmpOptimWrapper work with the Runner class.

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

No branches or pull requests

1 participant