mmrazor icon indicating copy to clipboard operation
mmrazor copied to clipboard

[Feature] Add Recorder to improve Distiller

Open pppppM opened this issue 3 years ago • 1 comments

Motivation

Currently, the distiller can only get the output of the PyTorch module, and MMRazor cannot reproduce some more complex distillation algorithms, such as #17 .

This pr designs a more robust mechanism for obtaining various data that the distillation algorithm may need, temporarily called Recorder.

Different types of data can be obtained by using different types of recorders. ModuleOutputsRecorder can replace the original feature of obtaining module outputs in the distiller.

Furthermore, there are ModuleInputsRecorder for obtaining module outputs, FunctionOutputsRecorder for obtaining python function's outputs, and ParameterRecorder for obtaining the Pytorch module's parameter.

Modification

  1. Add recorder registry and build function
  2. Add the base class for Recorder.
  3. Implement some standard Recorders based on the base class.
  4. Add a RecorderManager to manage various types of Recorders

Use cases (Optional)

Every recorder's use case can be found in the corresponding class's doc-string

Checklist

Before PR:

  • [ ] Pre-commit or other linting tools are used to fix the potential lint issues.
  • [ ] Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • [ ] The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  • [ ] The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • [ ] If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • [ ] CLA has been signed and all committers have signed the CLA in this PR.

pppppM avatar Apr 11 '22 10:04 pppppM

Codecov Report

Merging #137 (9101b82) into dev_v0.4.0 (e4e9513) will decrease coverage by 1.26%. The diff coverage is 43.58%.

@@              Coverage Diff               @@
##           dev_v0.4.0     #137      +/-   ##
==============================================
- Coverage       66.31%   65.04%   -1.27%     
==============================================
  Files              92      100       +8     
  Lines            3369     3562     +193     
  Branches          613      642      +29     
==============================================
+ Hits             2234     2317      +83     
- Misses           1033     1143     +110     
  Partials          102      102              
Flag Coverage Δ
unittests 65.01% <43.58%> (-1.27%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...mrazor/core/recorders/function_outputs_recorder.py 36.36% <36.36%> (ø)
mmrazor/core/recorders/method_outputs_recorder.py 36.36% <36.36%> (ø)
mmrazor/core/recorders/recorder_manager.py 37.03% <37.03%> (ø)
mmrazor/core/recorders/base_recorder.py 40.00% <40.00%> (ø)
mmrazor/core/recorders/module_inputs_recorder.py 40.90% <40.90%> (ø)
mmrazor/core/recorders/module_outputs_recorder.py 40.90% <40.90%> (ø)
mmrazor/core/recorders/param_recorder.py 60.00% <60.00%> (ø)
mmrazor/core/builder.py 71.42% <66.66%> (-3.58%) :arrow_down:
mmrazor/core/__init__.py 100.00% <100.00%> (ø)
mmrazor/core/recorders/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e4e9513...9101b82. Read the comment docs.

codecov[bot] avatar Apr 11 '22 11:04 codecov[bot]

Implemented in dev-1.x https://github.com/open-mmlab/mmrazor/tree/dev-1.x

pppppM avatar Jan 03 '23 09:01 pppppM