-
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
Optimizing Mask R-CNN Training Performance #55907
Comments
环境配置: PaddleDetection 环境安装# export LD_LIBRARY_PATH=/usr/lib64/
git clone -b develop https://github.com/PaddlePaddle/PaddleDetection --depth=1
python -m pip install paddlepaddle-gpu==2.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
cd PaddleDetection
pip install -r requirements.txt --user -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py install --user
python ppdet/modeling/tests/test_architectures.py 测试环境准备# 提前下载一个小型的coco数据集用于测试
wget -nc -P ./dataset/coco/ https://bj.bcebos.com/v1/paddledet/data/cocomini.zip --no-check-certificate
cd ./dataset/coco/ && unzip cocomini.zip
mv -u cocomini/* ./
# 回到PaddleDetection目录
cd ../../
wget https://paddle-qa.bj.bcebos.com/benchmark/tools.tar.gz && tar xvf tools.tar.gz && export BENCHMARK_ROOT=$PWD/tools/
# test_tipc 在 PaddleDetection目录下
bash test_tipc/prepare.sh test_tipc/configs/mask_rcnn/mask_rcnn_r50_1x_coco_train_infer_python.txt benchmark_train;
bash test_tipc/benchmark_train.sh test_tipc/configs/mask_rcnn/mask_rcnn_r50_1x_coco_train_infer_python.txt benchmark_train dynamic_bs2_fp32_DP_N1C1; dynamic_bs2_fp32_DP_N1C1,表示的是bs=2,fp32训练,N1C1单机单卡。如果要换bs,就相应改为dynamic_bs4_fp32_DP_N1C1;换amp训练就改为dynamic_bs2_fp16_DP_N1C1 |
如何使用 Profiler 生成 log: 首先按照环境配置文档配置环境,接着将赛题群中的
Profiler 生成的 log 会保存在 [1] profiler使用文档. |
@AndSonder 环境配置文档的链接打不开 |
可以打开,但是需要搭配梯子,我直接给写在Issue里面吧 |
@AndSonder 能提供一下赛题群中的 |
加你v了,麻烦同意下~ |
@zeroRains 领取加速 polygons_to_mask 任务 |
更新任务:优化 RPNTargetAssign |
@AndSonder 领取加速 RPNTargetAssign 任务 |
@luotao1 麻烦问下 PaddleDetection 的 PR 应该找谁 review 呢 |
赛题进展
1. 背景
飞桨深度学习框架已经发布了很多涵盖多个领域的开源模型,本赛题旨在通过对飞桨深度学习框架支持的开源模型进行优化,提高模型的训练性能,探索飞桨在模型上的性能优化最佳实践。欢迎对深度学习框架和模型优化感兴趣的开发者,展示在模型优化领域的经验和创新性。
本赛题详细介绍见中国软件开源创新大赛:飞桨框架任务挑战赛-赛题9,主要需求为:
2. 参考资料
这里我们将任务相关的参考资料列出,也会持续补充......
2.1 官方参考资料
2.2 模型分析报告
2.2.1 MaskRCNN 各部分性能
下表为使用 Profier 记录的 MaskRCNN 三大部分(bbox head, rpn head, mask head)CPU与GPU的使用情况
根据表格可得出如下可能的优化点:
BBoxHead
中self.bbox_assigner
CPU 操作占用时间较多,且该操作中GPU利用率不高;RPNHead
的self.gen_proposal
CPU 和 GPU 操作均占用较多时间,且根据Timeline可得该操作中有较多的GPU空闲时间;结合 Profier 进一步定位可得,
self.gen_proposal
中rpn_target_assign
有着较多的CPU耗时。相关代码如下:通过优化 RPNTargetAssign 的代码,使得更多的操作在GPU上进行,可优化模型的推理速度,预计优化幅度 10ms+。
MaskHead
中self.mask_assigner
中 CPU 操作占据了大部分时间;经过进一步的分析,在
self.mask_assigner
中使用了 cocoapi 中的polygons_to_mask
。该操作只能在 CPU 上进行计算。现在有两种优化方案:第一种是将
PolygonToMask
部分的计算放在dataloader里面并行计算加速。第二种是参考 OneFlow 的写法,自定义一个PolygonToMask
Kernel 对该部分运算进行加速。 预估优化时间 15ms +。参考资料:
2.2.2 耗时较长的Op
根据 Profier 分析可得,下列 Operator 耗时较多,可考虑进行优化
3. 运行说明
3.1 使用飞桨profier进行性能分析
首先按照环境配置文档配置环境,接着将赛题群中的
trainer.py
替换本地的trainer.py
。Profiler 生成的 log 会保存在
profier.txt
当中。也可以直接下载赛题群中的profier3.txt
查看3.2 使用nsight进行性能分析
使用
nsys
生成 nsys-rep 文件导入到nsight
中进行分析:nsys profile --stats=true -t cuda,nvtx -o train_report -f true bash test_tipc/benchmark_train.sh test_tipc/configs/mask_rcnn/mask_rcnn_r50_1x_coco_train_infer_python.txt benchmark_train dynamic_bs2_fp32_DP_N1C1
4. 优化进展
The text was updated successfully, but these errors were encountered: