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

Disable quantization aware training observers #8540

Merged

Conversation

manipopopo
Copy link
Contributor

@manipopopo manipopopo commented Jul 24, 2021

What does this PR do?

Fixes #8507

With this PR, the observers belonging to fake-quantization modules (torch.quantization.FakeQuantizeBase) will be disabled by QuantizationAwareTraining during validating, testing and predicting stages by default. The fake-quantization modules can use observers to do calibration only in the stages listed in observer_enabled_stages, which is ("train",) by default.

QuantizationAwareTraining don't disable observers during the sanity check as the model hasn't been calibrated with training data yet. After the sanity check, the fake-quantization modules are restored to initial states.

Note that we only handle observers belonging to fake-quantization modules.

Does your PR introduce any breaking changes ? If yes, please list them.

The quantization aware training observers belonging to fake-quantization modules (torch.quantization.FakeQuantizeBase) will be disabled during validating, testing and predicting stages by default. The old behavior can be recovered by passing observer_enabled_stages=("train", "validate", "test", "predict") to pytorch_lightning.callbacks.QuantizationAwareTraining.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)
  • Did you list all the breaking changes introduced by this pull request?

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Jul 24, 2021

Codecov Report

Merging #8540 (fdf161b) into master (f95ba20) will increase coverage by 0%.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #8540   +/-   ##
======================================
  Coverage      89%     89%           
======================================
  Files         182     182           
  Lines       16111   16165   +54     
======================================
+ Hits        14273   14327   +54     
  Misses       1838    1838           

@Borda Borda self-assigned this Jul 24, 2021
@Borda Borda added this to the v1.5 milestone Jul 24, 2021
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
tests/callbacks/test_quantization.py Outdated Show resolved Hide resolved
@Borda Borda requested a review from tchaton July 26, 2021 14:27
@Borda Borda modified the milestones: v1.5, v1.4 Jul 26, 2021
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

pls add typing to all impemented hooks

pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
@manipopopo manipopopo requested a review from Borda July 26, 2021 17:29
@awaelchli awaelchli added the bug Something isn't working label Jul 26, 2021
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
tests/callbacks/test_quantization.py Outdated Show resolved Hide resolved
tests/callbacks/test_quantization.py Outdated Show resolved Hide resolved
@manipopopo manipopopo requested a review from awaelchli July 27, 2021 13:38
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

last suggestion, then it looks good to me 🐰

pytorch_lightning/callbacks/quantization.py Outdated Show resolved Hide resolved
@manipopopo manipopopo requested a review from Borda July 28, 2021 05:02
Borda
Borda previously requested changes Jul 28, 2021
tests/callbacks/test_quantization.py Show resolved Hide resolved
tests/callbacks/test_quantization.py Show resolved Hide resolved
@rohitgr7 rohitgr7 force-pushed the bugfix/8507_disable_qat_observer branch from cd3cce0 to 5ca972d Compare October 25, 2021 12:06
@manipopopo manipopopo requested a review from rohitgr7 as a code owner October 25, 2021 12:06
@mergify mergify bot removed the has conflicts label Oct 25, 2021
@rohitgr7 rohitgr7 disabled auto-merge October 25, 2021 12:06
@rohitgr7 rohitgr7 enabled auto-merge (squash) October 25, 2021 12:07
@rohitgr7 rohitgr7 merged commit cfb2d87 into Lightning-AI:master Oct 25, 2021
ninginthecloud pushed a commit to ninginthecloud/pytorch-lightning that referenced this pull request Oct 27, 2021
Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
Co-authored-by: tchaton <thomas@grid.ai>
Co-authored-by: rohitgr7 <rohitgr1998@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Observers are updated with validation data in quantization aware training
5 participants