-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Dynamic Graph Support to ASP #38517
Dynamic Graph Support to ASP #38517
Conversation
1. Added functions step and clear_grad to OptimizerWithSparsityGuarantee. 2. Added step function to ASPHelper. 3. Added prune_model_by_layer and renamed original prune_mode to prune_model_by_program. 4. Move paddle.static.sparsity to paddle.sparsity
✅ This PR's description meets the template requirements! |
Thanks for your contribution! |
e6ba5d9
to
fdecf8b
Compare
fdecf8b
to
07a074a
Compare
07a074a
to
60efc18
Compare
60efc18
to
92a1b72
Compare
92a1b72
to
1511702
Compare
Sorry to inform you that 1511702's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
@@ -309,20 +441,24 @@ def decorate(optimizer): | |||
r""" | |||
This is the implementation of `sparsity.decorate`, for details please see explanation in `sparsity.decorate`. | |||
""" | |||
if in_dygraph_mode(): | |||
main_prog = paddle.static.default_main_program() | |||
startup_prog = paddle.static.default_startup_program() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是动态图,就不再存在program
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
線下討論結果:
此處的main_program, startup_program僅作為ASP內部存放mask variables位置的key, 並在step
階段透過key將mask取出來進行weight sparse masking.
為避免動靜態圖 (且靜態圖以default_main_program為main_program)混合使用的情境, 考慮使用None
作為動靜態圖的區分,待確定評審意見後進行對應修改。
@@ -281,12 +413,12 @@ class ASPHelper(object): | |||
""" | |||
|
|||
MASK_APPENDDED_NAME = '_asp_mask' | |||
SUPPORTED_LAYERS = {'fc': 'w_0', 'linear': 'w_0', 'conv2d': 'w_0'} | |||
PADDLE_WEIGHT_SUFFIX = "w_" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
也有可能会存在fc、linear、conv以外的算子,参数以w_
方式命名,这种方式不太保险啊。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
實際上的支援判斷規則有以下三點
- If the name of parameter in supported_list, then return True.
- If the name of parameter without type suffix in supported_list, then return True.
- If the class name of parameter without type suffix and counter in supported_list, then return True.
詳細規則可以參考ASPHelper._is_supported_layer
'The "mask_algo" should be one of ["mask_1d", "mask_2d_greedy", "mask_2d_best"]' | ||
|
||
prune_func = None | ||
if isinstance(model, paddle.nn.Layer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里使用 prune_layer或者prune_program 和在 prune_model_by_layer 中的动静态图if-else 是否可以合在一起呢 ?统一的在这里控制 ?
|
||
add_supported_layer('fc') | ||
add_supported_layer('linear') | ||
add_supported_layer('conv2d') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
小疑问:conv2d 是把核函数 weight 4:2 吗 ?
if with_mask: | ||
weight_mask_param = global_scope().find_var( | ||
ASPHelper._get_mask_name(param.name)) | ||
assert weight_mask_param is not None, \ | ||
'Cannot find {} variable, please call ASPHelper.minimize' \ | ||
'Cannot find {} variable, please call optimizer.minimize (' \ | ||
'paddle.sparsity.decorate(optimizer).minimize(loss)' \ | ||
' and initialization (exe.run(startup_program)) first!'.format(ASPHelper._get_mask_name(param.name)) | ||
weight_mask_tensor = weight_mask_param.get_tensor() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分计算有可能通过 Op 在 GPU 上计算吗 ?
Split this PR to two parts, 40253 (Add Support Layer List to ASP) and 41177 (Dynamic graph support to Automatic SParsity). |
Close this, due function are merged in #41177 |
很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。 |
PR types
New features
PR changes
APIs
Describe
Dynamic graph support to Automatic SParsity.
paddle.fluid.contrib.sparsity
).paddle.static.sparsity
topaddle.sparsity
.Usage Examples.