-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Add A Single Line to Save Your Life #6867
Conversation
@imyhxy well done! |
Amazing fix @imyhxy! Do you have any intentions to open a pr with your yolov5 implementation? |
@fcakyon Yes, after I finished the training experiments and if everything OK I will open a PR for it. |
Hi @imyhxy , |
@ZwwWayne Merry Christmas 🎄 I have done some test on another server which is the same as before but have 4 GPU.
When setting
The Thread Number and CPU Time (us, sy) increase as the setNumThreads increases, but the training speed is slowing down only when the total CPU workload exceed some point (~55% on my system). On the above experiments, the training speed gets some significant slow down when |
Thank you @imyhxy ! |
* add DyHead * move and update DYReLU * update * replace stack with sum to reduce memory * clean and update * update to align inference accuracy (incomplete) * fix pad * update to align training accuracy and pick #6867 * add README and metafile * update docs * resolve comments * revert picking 6867 * update README.md * update metafile.yml * resolve comments and update urls
* [Enhancement] Upgrade isort in pre-commit hook (#7130) * upgrade isort to v5.10.1 * replace known_standard_library with extra_standard_library * upgrade isort to v5.10.1 replace known_standard_library with extra_standard_library * imports order changes * [Fix] cannot to save the best checkpoint when the key_score is None (#7101) * [Fix] Fix MixUp transform filter boxes failing case. Added test case (#7080) * [Fix] Update the version limitation of mmcv-full and pytorch in CI. (#7133) * Update * Update build.yml * Update build.yml * [Feature] Support TIMMBackbone (#7020) * add TIMMBackbone based on open-mmlab/mmpretrain#427 open-mmlab/mmsegmentation#998 * update and clean * fix unit test * Revert * add example configs * Create 2_new_data_model.md (#6476) fix some typo Co-authored-by: PJLAB\huanghaian <[email protected]> * [FIX] add Ci of pytorch 1.10 and comments for bbox clamp (#7081) (#7083) * add comments for bbox clamp * add CI of pytorch1.10 * add ci of pytorch1.10.1 * mmcv1.9.0->mmcv1.9 * add ci of pytorch1.10 * Add daily issue owners (#7163) * Add code owners Signed-off-by: del-zhenwu <[email protected]> * Update code owners Signed-off-by: del-zhenwu <[email protected]> * [Feature] Support visualization for Panoptic Segmentation (#7041) * First commit of v2 * split the functions * Support to show panoptic result * temp * Support to show gt * support show gt * fix lint * Support to browse datasets * Fix unit tests * Fix findContours * fix comments * Fix pre-commit * fix lint * Add the type of an argument * [Fix] confusion_matrix.py analysis tool handling NaNs (#7147) * [Fix] Added missing property in SABLHead (#7091) * Added missing property in SABLHead * set pre-commit-hooks to v0.1.0 * set maskdownlint to v0.11.0 * pre-commit-hooks Co-authored-by: Cedric Luo <[email protected]> * Update config.md (#7215) * [Fix] Fix wrong img name in onnx2tensorrt.py (#7157) * [Docs] fix albumentations installed way (#7143) * Update config.md fix some typos Co-authored-by: Jamie <[email protected]> Co-authored-by: BigDong <[email protected]> * [Feature] Support DyHead (#6823) * add DyHead * move and update DYReLU * update * replace stack with sum to reduce memory * clean and update * update to align inference accuracy (incomplete) * fix pad * update to align training accuracy and pick #6867 * add README and metafile * update docs * resolve comments * revert picking 6867 * update README.md * update metafile.yml * resolve comments and update urls * Fix broken colab link (#7218) * [Fix] Fix wrong img name in onnx2tensorrt.py (#7157) * [Docs] fix albumentations installed way (#7143) * Fix broken colab link Co-authored-by: Jamie <[email protected]> Co-authored-by: BigDong <[email protected]> * Remove the inplace addition in `FPN` (#7175) * [Fix] Fix wrong img name in onnx2tensorrt.py (#7157) * [Docs] fix albumentations installed way (#7143) * Remove the inplace addition in `FPN` * update Co-authored-by: Jamie <[email protected]> Co-authored-by: BigDong <[email protected]> Co-authored-by: PJLAB\huanghaian <[email protected]> * [Feature] Support OpenImages Dataset (#6331) * [Feature] support openimage group of eval * [Feature] support openimage group of eval * support openimage dataset * support openimage challenge dataset * fully support OpenImages-V6 and OpenImages Challenge 2019 * Fix some logic error * update config file * fix get data_infos error * fully support OpenImages evaluation * update OpenImages config files * [Feature] support OpenImages datasets * fix bug * support load image metas from pipeline * fix bug * fix get classes logic error * update code * support get image metas * support openimags * support collect image metas * support Open Images * fix openimages logic * minor fix * add a new function to compute openimages tpfp * minor fix * fix ci error * minor fix * fix indication * minor fix * fix returns * fix returns * fix returns * fix returns * fix returns * minor fix * update readme * support loading image level labels and fix some logic * minor fix * minor fix * add class names * minor fix * minor fix * minor fix * add openimages test unit * minor fix * minor fix * fix test unit * minor fix * fix logic error * minor fix * fully support openimages * minor fix * fix docstring * fix docstrings in readthedocs * update get image metas script * label_description_file -> label_file * update openimages readme * fix test unit * fix test unit * minor fix * update readme file * Update get_image_metas.py * [Enhance] Speed up SimOTA matching. (#7098) * [Feature] Add Maskformer to mmdet (#7212) * first commit * add README * move model description from config to readme add description for binary_input add description for dice loss add a independent panoptic gt processing function add a independent panoptic gt processing function remove compatibility of pretrain in maskformer * update comments in maskformer_head * update docs format * Add deprecation message for deploy tools (#7242) * Add CI for windows (#7228) * [Fix] Fix wrong img name in onnx2tensorrt.py (#7157) * [Docs] fix albumentations installed way (#7143) * Add mmrotate (#7216) * fix description for args in CSPDarknet (#7187) * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * Update build.yml * fix test_find_latest_checkpoint * fix data_infos__default_db_directories * fix test_custom_classes_override_default * Update test_custom_dataset.py * Update test_common.py * Update assign_result.py * use os.path.join * fix bug * Update test_common.py * Update assign_result.py * Update sampling_result.py * os.path -> osp * os.path -> osp Co-authored-by: Jamie <[email protected]> Co-authored-by: BigDong <[email protected]> Co-authored-by: Hyeokjoon Kwon <[email protected]> * add Chinese version of init_cfg (#7188) * [Fix] Fix wrong img name in onnx2tensorrt.py (#7157) * [Docs] fix albumentations installed way (#7143) * Create init_cfg.md * Update docs/zh_cn/tutorials/init_cfg.md Co-authored-by: Haian Huang(深度眸) <[email protected]> * update init_cfg.md * update init_cfg.md * update init_cfg.md * update init_cfg.md Co-authored-by: Jamie <[email protected]> Co-authored-by: BigDong <[email protected]> Co-authored-by: Haian Huang(深度眸) <[email protected]> * update MaskFormer readme and docs (#7241) * update docs for maskformer * update readme * update readme format * update link * update json link * update format of ConfigDict * update format of function returns * uncomment main in deployment/test.py * [Feature] ResNet Strikes Back. (#7001) * [Feature] ResNet Strikes Back. * add more cfg * add readme * update * update * update * update * update * update * Maskformer Visualization (#7247) * maskformer visualization * compatible with models that do not contain arg of pretrained * compatible with models that do not contain arg of pretrained * Bump versions to v2.22.0 (#7240) * Bump versions to v2.22.0 * Fix comments and add the latest PRs * fix the id of contributor * relax the version of mmcv * Add ResNet Strikes Back * Update README_zh-CN.md * Update README.md * fix typo * Update README_zh-CN.md Co-authored-by: Wenwei Zhang <[email protected]> * Maskformer metafile and rsb readme format (#7250) * [Fix] Fix Open Images testunit to avoid error in Windows CI (#7252) * [Feature] support openimage group of eval * [Feature] support openimage group of eval * support openimage dataset * support openimage challenge dataset * fully support OpenImages-V6 and OpenImages Challenge 2019 * Fix some logic error * update config file * fix get data_infos error * fully support OpenImages evaluation * update OpenImages config files * [Feature] support OpenImages datasets * fix bug * support load image metas from pipeline * fix bug * fix get classes logic error * update code * support get image metas * support openimags * support collect image metas * support Open Images * fix openimages logic * minor fix * add a new function to compute openimages tpfp * minor fix * fix ci error * minor fix * fix indication * minor fix * fix returns * fix returns * fix returns * fix returns * fix returns * minor fix * update readme * support loading image level labels and fix some logic * minor fix * minor fix * add class names * minor fix * minor fix * minor fix * add openimages test unit * minor fix * minor fix * fix test unit * minor fix * fix logic error * minor fix * fully support openimages * minor fix * fix docstring * fix docstrings in readthedocs * update get image metas script * label_description_file -> label_file * update openimages readme * fix test unit * fix test unit * minor fix * update readme file * Update get_image_metas.py * fix oid testunit to avoid some error in windows * minor fix to avoid some error in windows * minor fix * add comments in oid test unit * minor fix Co-authored-by: Cedric Luo <[email protected]> Co-authored-by: LuooChen <[email protected]> Co-authored-by: Daniel van Sabben Alsina <[email protected]> Co-authored-by: jbwang1997 <[email protected]> Co-authored-by: Yosuke Shinya <[email protected]> Co-authored-by: siatwangmin <[email protected]> Co-authored-by: PJLAB\huanghaian <[email protected]> Co-authored-by: del-zhenwu <[email protected]> Co-authored-by: Guangchen Lin <[email protected]> Co-authored-by: VIKASH RANJAN <[email protected]> Co-authored-by: Range King <[email protected]> Co-authored-by: Jamie <[email protected]> Co-authored-by: BigDong <[email protected]> Co-authored-by: Haofan Wang <[email protected]> Co-authored-by: Zhijian Liu <[email protected]> Co-authored-by: BigDong <[email protected]> Co-authored-by: RangiLyu <[email protected]> Co-authored-by: Yue Zhou <[email protected]> Co-authored-by: Hyeokjoon Kwon <[email protected]> Co-authored-by: Kevin Ye <[email protected]>
* add DyHead * move and update DYReLU * update * replace stack with sum to reduce memory * clean and update * update to align inference accuracy (incomplete) * fix pad * update to align training accuracy and pick #6867 * add README and metafile * update docs * resolve comments * revert picking 6867 * update README.md * update metafile.yml * resolve comments and update urls
* add DyHead * move and update DYReLU * update * replace stack with sum to reduce memory * clean and update * update to align inference accuracy (incomplete) * fix pad * update to align training accuracy and pick open-mmlab#6867 * add README and metafile * update docs * resolve comments * revert picking 6867 * update README.md * update metafile.yml * resolve comments and update urls
I know the title is a bit frivolous, but I think it satisfies this PR.
Thanks for your excellent works, the
mmdetection
is a very flexible and powerful deep learning framework.Threads number is insane
Currently, I was implementing the popular YOLOv5 model with
mmdetection
, but when I try to train my new model, I found out that the training speed is much slower than the official implementation of YOLOv5 (almost ~4x slower). I can't afford that time overhead. So I digged into it for some day and notice that themmdetection
always spawn thousands of threads for data preprocessing. Compare tommdetection
, offical YOLOv5 only fork hundreds of threads (~2000 v.s. 400). Because of such insane number of threads, almost half of the CPU workload is occupied by the kernel, which used to manager the threads.The CPU is too busy to handle the threads making the whole training speed is slow, and the system also get very lagging. The reason is that the
cv2
module will activate multi-processing automatically and the processes number is equal to the CPU core. Which means if you have a more powerful CPU, it hurts the performance harder. My server has a 64-core CPU and 8 T4 GPU, if I set theworkers_per_gpu
to 4, the number of cv2-threads will be8*4*64 = 2048
. If I set theworkers_per_gpu
to 8, there will be 4096 theads. Each of this will overwhleming my system.Lower the
workers_per_gpu
won't helpI have tried to lower the
workers_per_gpu
, but that just don't fixed the kernel overhead issue, and also slow down the data preprocessing speed. So it't hard to find an optimizedworkers_per_gpu
number for good training speed because there is no one.Solution
The solution is trival, disable the multi-processsing of
cv2
manually, just involve thecv2.setNumThreads(0)
anywhere before involve the cv2.Comparison
My setup:
I have do some
before-after
experiments:RetinaNet
The preprocessing of retinanet is so slim, and the default
workers_per_gpu
for retinanet is 2, so the speed gain is none. If people use retinanet to do performance test, they will not notice the threads and kernel overhead problem.before:
after:
YOLOX:
before:
after:
YOLOV5 (Custom, data preprocessing very similar to YOLOX, but have efficent backbone and loss calculation)
I configure the YOLOv5 with
workers_per_gpu=8
, and never run YOLOv5 inspawn
because it requires more than256GB
memory tospawn
all the threads, so I just run it infork
mode.before:
after:
Other recommandation
Change default multiprocessing start method from
spawn
tofork
. I know there maybe some thread or namespace safety problem when usefork
, butfork
is so fast, and it's fast enough for me to take that risk and give it a test first. Another reson is it requires less resource (CPU, memory). So I think it good to give it a position in the config file.Disable all unnecessary data preprocessing stages and tweak the
workers_per_gpu
orcv2.setNumThread()
to glance what is the optimized training speed for your model, after that, add the preprocessing stage back and see which one hinder your training speed. In my opinion, the preprocessing should not increase the training speed at all if the preprocessing not increase the training data (e.g.Mosaic
will increase the trainging time because it add more instances to calculate the loss)Conclusion
spawn
tofork
can reduce startup time and resources requirement.