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

Post-training Activation Pruning algorithm #2683

Merged

Conversation

yujiepan-work
Copy link
Contributor

@yujiepan-work yujiepan-work commented May 16, 2024

Changes

Add torch backend implementation for Post-training Activation Pruning algorithm.

The current interface is

from nncf import IgnoredScope
from nncf.experimental.torch.sparsify_activations import TargetScope

nncf.experimental.torch.sparsify_activations.sparsify_activations(
  torch_model, calibration_dataset, 
  target_sparsity_by_scope={
    TargetScope(patterns=[".*linear.*"]): 0.5,
  },
  ignored_scope=IgnoredScope(),
)

See model accuracy check at #2683 (comment)

Tests

Added unit tests at tests/torch/experimental/sparsify_activations
Added conformance tests at tests/post_training/experimental/sparsify_activations

@yujiepan-work yujiepan-work force-pushed the 24h1/sparse-activation/nncf-pr branch 2 times, most recently from f2a2cbc to c6c753d Compare May 23, 2024 08:20
@github-actions github-actions bot added the NNCF PT Pull requests that updates NNCF PyTorch label May 29, 2024
@github-actions github-actions bot added the NNCF PTQ Pull requests that updates NNCF PTQ label Jun 6, 2024
@yujiepan-work yujiepan-work marked this pull request as ready for review June 7, 2024 01:15
@yujiepan-work yujiepan-work requested a review from a team as a code owner June 7, 2024 01:15
Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

Could you add to the description any results by accuracy and performance?

@yujiepan-work
Copy link
Contributor Author

yujiepan-work commented Jun 7, 2024

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.

Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

Great work with the implementation, Yujie! Also, the tests are very thorough. Mostly minor comments from my side.

Copy link

codecov bot commented Jun 7, 2024

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

Impacted file tree graph

@@             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%) ⬇️
ONNX 34.04% <0.00%> (-0.71%) ⬇️
OPENVINO 40.80% <0.00%> (+0.87%) ⬆️
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%) ⬆️
torch 32.82% <0.00%> (-0.37%) ⬇️
tensorflow 93.26% <ø> (+93.26%) ⬆️
onnx 93.06% <ø> (+<0.01%) ⬆️
openvino 94.51% <ø> (+0.36%) ⬆️
ptq 82.04% <ø> (+2.64%) ⬆️

@yujiepan-work yujiepan-work changed the title Statistical-Conditioned Activation Pruning (SCAP) for LLMs Post-training Activation Pruning algorithm Jun 11, 2024
@yujiepan-work
Copy link
Contributor Author

yujiepan-work commented Jun 11, 2024

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'

@yujiepan-work yujiepan-work force-pushed the 24h1/sparse-activation/nncf-pr branch 3 times, most recently from f9af328 to 61a0fc8 Compare June 25, 2024 05:55
@yujiepan-work
Copy link
Contributor Author

yujiepan-work commented Jun 25, 2024

Remaining issues at this moment:

  • README markdown at the algo folder
  • Documentation: example of using the interface
  • target_sparsity_by_scope interface design

Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

Another round of review. Awaiting addition of activation sparsity test pipeline to our CI to check the conformance test results there.

@nikita-savelyevv
Copy link
Collaborator

@daniil-lyakhov could you please review the PyTorch backend part of the implementation, specifically PTSparsifyActivationsAlgoBackend class?

@yujiepan-work yujiepan-work force-pushed the 24h1/sparse-activation/nncf-pr branch 2 times, most recently from 7c81fc5 to 17792bd Compare July 8, 2024 18:50
@yujiepan-work
Copy link
Contributor Author

@daniil-lyakhov Hi Daniil, thanks for reviewing this PR. Are there any openings that we need to change?

Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@yujiepan-work yujiepan-work force-pushed the 24h1/sparse-activation/nncf-pr branch from e1f7af2 to 63a87e8 Compare July 10, 2024 10:03
@nikita-savelyevv
Copy link
Collaborator

nikita-savelyevv commented Jul 10, 2024

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.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jul 12, 2024
@yujiepan-work yujiepan-work force-pushed the 24h1/sparse-activation/nncf-pr branch from 5cb146a to f3fcea8 Compare July 12, 2024 16:26
Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

Looks good! I can suggest only some minor tweaks

@yujiepan-work
Copy link
Contributor Author

yujiepan-work commented Jul 16, 2024

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

@yujiepan-work yujiepan-work force-pushed the 24h1/sparse-activation/nncf-pr branch from 007c04a to 5f04275 Compare July 16, 2024 08:40
@yujiepan-work
Copy link
Contributor Author

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. 🙂

@nikita-savelyevv
Copy link
Collaborator

@alexsu52, please take a look. The PR should be ready for merging.

cc @AlexKoff88 @MaximProshin

Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@alexsu52 alexsu52 merged commit 49e9820 into openvinotoolkit:develop Jul 19, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation experimental NNCF PT Pull requests that updates NNCF PyTorch NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants