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

Sparse conv pass #6836

Merged
merged 21 commits into from
Sep 10, 2021
Merged

Sparse conv pass #6836

merged 21 commits into from
Sep 10, 2021

Conversation

minghaoBD
Copy link
Contributor

@minghaoBD minghaoBD commented Sep 2, 2021

添加新功能:支持非结构化稀疏的推理计算(稀疏化矩阵乘法用以加速1x1卷积推理计算,以下简称SpMM)。由于整个PR的代码量较大,计划拆为3个PR提交,分别为:

  1. sparse pass
  2. armv8kernel的实现
  3. armv7 kernel的实现。

sparse pass的PR中,我们主要做了如下方面的更改,麻烦相关同学review下:

  • 添加sparse_conv_detect_pass, 用以检测每层参数的稀疏度是否大于某一个阈值(sparse_threshold),若大于,则编译模型时,将参数矩阵转换为稀疏矩阵乘法用的CSR格式;若不大于,则维持原本dense格式。
  • 定义了3个kernel函数:sparse_conv_fp32_pipelined,sparse_conv_int8_int8_pipelined,sparse_conv_int8_fp32_pipelined,用以支持fp32和int8的SpMM。
  • 为opt工具添加参数:sparse_threshold,用以控制sparse_conv_detect_pass。

Leonardo-Ding and others added 5 commits September 2, 2021 09:38
…=develop

[sparse_conv]add sparse conv fp32 profile,test=develop

[sparse_conv] add sparse conv int8 kernels and related pass,test=develop

[sparse_conv] fix sparse conv int8 precision,test=develop
@paddle-bot-old
Copy link

paddle-bot-old bot commented Sep 2, 2021

Thanks for your contribution!

@minghaoBD minghaoBD marked this pull request as ready for review September 2, 2021 12:58
@DannyIsFunny
Copy link
Collaborator

代码风格检查 pre-commit run -a

@minghaoBD
Copy link
Contributor Author

代码风格检查 pre-commit run -a

谢谢,已定位到问题并修正。

docs/api_reference/python_api/opt.md Show resolved Hide resolved
lite/backends/arm/math/sparse_conv_impl.cc Show resolved Hide resolved
return first_ic;
}

template int SparseConvDetectPass::ComputeSparseWeight<float>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

两个一样的函数名: SparseConvDetectPass::ComputeSparseWeight 有什么区别呢?能否在template 前面加上声明。解释每个参数含义和函数概功能

ic_diffs_t);
}

LOG(INFO) << "zero_num: " << zero_num << " weight_num: " << weight_num
Copy link
Collaborator

Choose a reason for hiding this comment

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

LOG 信息删除。或者改为VLOG(4)

lite/kernels/arm/sparse_conv_compute.cc Show resolved Hide resolved
lite/operators/op_params.h Show resolved Hide resolved
@CLAassistant
Copy link

CLAassistant commented Sep 6, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ minghaoBD
✅ hcms1994
❌ Leonardo-Ding
You have signed the CLA already but the status is still pending? Let us recheck it.

docs/api_reference/python_api/opt.md Show resolved Hide resolved
lite/api/paddle_api.h Show resolved Hide resolved
lite/api/paddle_api.h Show resolved Hide resolved
for (size_t i = 0; i < valid_places_.size(); i++) {
target = valid_places_[i].target;
if (target != TargetType::kARM) {
LOG(WARNING) << "sparse_model mode only supported on Arm. The model will "
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个除了warning,是不是应该return,不走sparse 设置额。应该走默认dense实现

Copy link
Contributor Author

@minghaoBD minghaoBD Sep 10, 2021

Choose a reason for hiding this comment

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

我的写法和你的描述是相符的:

  1. 这段代码的逻辑是:如果检测到valid_places_中包含ARM之外的place,就报warning,同时关闭sparse_pass按钮(https://github.com/minghaoBD/Paddle-Lite/blob/sparse_conv_PR/lite/api/tools/opt_base.cc#L68 )。
  2. sparse_pass按钮用于控制是否将该pass放入到这里去:https://github.com/minghaoBD/Paddle-Lite/blob/040589191b225e1f7aeeee5418e56d0aff3260e6/lite/api/cxx_api_impl.cc#L112 。所以会走到dense实现的。
  3. 我这么写的逻辑是参照了量化pass流程,我看军才也是通过quant_model开关来控制是否走post_quant_dynamic_pass。https://github.com/minghaoBD/Paddle-Lite/blob/040589191b225e1f7aeeee5418e56d0aff3260e6/lite/api/tools/opt_base.cc#L42

Copy link
Collaborator

@DannyIsFunny DannyIsFunny left a comment

Choose a reason for hiding this comment

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

LGTM

lite/api/tools/opt_base.cc Show resolved Hide resolved
@minghaoBD minghaoBD closed this Sep 10, 2021
@minghaoBD minghaoBD reopened this Sep 10, 2021
@DannyIsFunny DannyIsFunny merged commit 0a7ab07 into PaddlePaddle:develop Sep 10, 2021
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.

7 participants