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

[Unstructured_prune] add local_sparsity #916

Merged
merged 2 commits into from
Nov 11, 2021
Merged

[Unstructured_prune] add local_sparsity #916

merged 2 commits into from
Nov 11, 2021

Conversation

minghaoBD
Copy link
Collaborator

@minghaoBD minghaoBD commented Nov 8, 2021

为非结构化稀疏增加 local_sparsity功能,可以在构建UnstructuredPruner对象时,传入这个开关。当传入 ratio=0.5时,local_sparsity效果如下:
local_sparsity==True: 在确保模型整体稀疏度为50%时,每个参与稀疏的特征矩阵稀疏度均为50%,这样可以提升推理性能。
local_sparsity==False: 只确保了模型整体稀疏度为50%,每个参与稀疏的特征矩阵稀疏度可能不同,尤其是如果存在较低稀疏度的矩阵(10%,20%, 30%等),甚至会损伤推理性能。

注意,local_sparsity==True只能在 mode=='ratio'时使用,该限制已经在代码中通过assert约束。

@@ -240,6 +254,7 @@ def _get_skip_params(self, program):
if 'norm' in op.type() and 'grad' not in op.type():
for input in op.all_inputs():
skip_params.add(input.name())
print(skip_params)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这一句如果要保留的话,需要说明下print的是什么信息。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这是我debug时的一个冗余输出,后续PR会删除。

@wanghaoshuang wanghaoshuang merged commit 5ec83b6 into PaddlePaddle:develop Nov 11, 2021
minghaoBD added a commit that referenced this pull request Dec 20, 2021
* [cherry-pick][Unstructured_prune] add local_sparsity (#916)

* [cherry-pick][unstructured_pruner] add local_sparsity args in demo (#920)

* [Unstructured_prune] add local_sparsity demo
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

Successfully merging this pull request may close these issues.

2 participants