nncf
nncf copied to clipboard
Post-training Activation Pruning algorithm
Changes
Add torch backend implementation for Post-training Activation Pruning algorithm.
The current interface is
nncf.experimental.torch.sparsify_activations.sparsify_activations(
torch_model, calibration_dataset,
target_sparsity_by_scope={"{re}.*linear.*": 0.5},
ignored_scope=IgnoredScope(),
)
See model accuracy check at https://github.com/openvinotoolkit/nncf/pull/2683#issuecomment-2161049420
Tests
Added unit tests at tests/torch/experimental/sparsify_activations
Added conformance tests at tests/post_training/experimental/sparsify_activations
Thanks for the contribution!
Could you add to the description any results by accuracy and performance?
Thanks for your reply! We will add this by the beginning of ww24.
Codecov Report
Attention: Patch coverage is 0%
with 187 lines
in your changes missing coverage. Please review.
Project coverage is 62.10%. Comparing base (
3d11e8a
) to head (3c9a7b7
). Report is 49 commits behind head on develop.
Additional details and impacted files
@@ Coverage Diff @@
## develop #2683 +/- ##
============================================
+ Coverage 47.13% 62.10% +14.96%
============================================
Files 495 486 -9
Lines 45986 46630 +644
============================================
+ Hits 21675 28959 +7284
+ Misses 24311 17671 -6640
Files | Coverage Δ | |
---|---|---|
...xperimental/torch/sparsify_activations/__init__.py | 0.00% <0.00%> (ø) |
|
.../sparsify_activations/sparsify_activations_impl.py | 0.00% <0.00%> (ø) |
|
...mental/torch/sparsify_activations/torch_backend.py | 0.00% <0.00%> (ø) |
... and 223 files with indirect coverage changes
Flag | Coverage Δ | |
---|---|---|
COMMON | 41.93% <ø> (-1.64%) |
:arrow_down: |
ONNX | 34.04% <0.00%> (-0.71%) |
:arrow_down: |
OPENVINO | 40.80% <0.00%> (+0.87%) |
:arrow_up: |
TENSORFLOW | 29.27% <0.00%> (?) |
Flags with carried forward coverage won't be shown. Click here to find out more.
Components | Coverage Δ | |
---|---|---|
common | 87.56% <ø> (+17.89%) |
:arrow_up: |
torch | 32.82% <0.00%> (-0.37%) |
:arrow_down: |
tensorflow | 93.26% <ø> (+93.26%) |
:arrow_up: |
onnx | 93.06% <ø> (+<0.01%) |
:arrow_up: |
openvino | 94.51% <ø> (+0.36%) |
:arrow_up: |
ptq | 82.04% <ø> (+2.64%) |
:arrow_up: |
Model accuracy check:
Llama-2-7b-hf
model-level sparsity | avg. zero-shot accuracy (8 tasks) | wikitext perplexity | ||
---|---|---|---|---|
FP16 baseline | - | 71.15 | 8.79 | |
FP16 sparse | 25% (up/gate32%+down52%) | 70.73 (-0.59%) | 9.01 | |
INT8 sparse | 25% (up/gate32%+down52%) | 70.88 (-0.38%) | 9.01 |
Mixtral-8x7B-Instruct-v0.1
model-level sparsity | avg. zero-shot accuracy (8 tasks) | wikitext perplexity | ||
---|---|---|---|---|
FP16 baseline | - | 80.08 | 6.22 | |
FP16 sparse | 40% (up/gate42%+down52%) | 79.70 (-0.48%) | 6.56 |
Tasks: 'arc_easy', 'arc_challenge', 'boolq', "piqa", 'lambada_openai', 'winogrande', 'sciq', 'hellaswag'
Remaining issues at this moment:
- [x] README markdown at the algo folder
- [x] Documentation: example of using the interface
- [x]
target_sparsity_by_scope
interface design
@daniil-lyakhov could you please review the PyTorch backend part of the implementation, specifically PTSparsifyActivationsAlgoBackend
class?
@daniil-lyakhov Hi Daniil, thanks for reviewing this PR. Are there any openings that we need to change?
Conformance test build (id=12) has passed. The time it takes is about half an hour.
The only thing left is some documentation of the method.
There is a failed test but seems not caused by this PR:
FAILED tests/common/graph/test_dot_file_rw.py::test_colons_are_replaced_in_written_dot_file - AssertionError: assert False
+ where False = <function cmp at 0x7f52758f80d0>(PosixPath('/tmp/pytest-of-runner/pytest-0/popen-gw0/test_colons_are_replaced_in_wr0/graph.dot'), PosixPath('/home/runner/work/nncf/nncf/tests/common/data/reference_graphs/dot_rw_reference.dot'))
+ where <function cmp at 0x7f52758f80d0> = filecmp.cmp
Update: the failed test can pass after retry
Thank you all for the reviews! Since we have resolved all the issues, I wonder whether this PR is ready to be merged. If there are any further changes needed, we would be glad to deal with them. 🙂
@alexsu52, please take a look. The PR should be ready for merging.
cc @AlexKoff88 @MaximProshin