[Unstructured_prune] add local_sparsity #916
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
为非结构化稀疏增加 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约束。