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

YOLOv5 support model-parallel training with multi gpu? #6523

Closed
1 task done
p890040 opened this issue Feb 3, 2022 · 7 comments
Closed
1 task done

YOLOv5 support model-parallel training with multi gpu? #6523

p890040 opened this issue Feb 3, 2022 · 7 comments
Labels
question Further information is requested

Comments

@p890040
Copy link

p890040 commented Feb 3, 2022

Search before asking

Question

Hi guys!

I have a question about this.
Does yolov5 provide model-parallel training with multi gpu?
I have checked Multi-GPU Training tutorial and issues.
I found no one was talking about this function.

Because I have two GPU and wanna set img_size larger, and batch size 1 is still OOM.
So I'm trying some way to achieve it.

Thanks!

Additional

No response

@p890040 p890040 added the question Further information is requested label Feb 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2022

👋 Hello @p890040, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 3, 2022

@p890040 👋 Hello! Thanks for asking about CUDA memory issues. YOLOv5 🚀 can be trained on CPU, single-GPU, or multi-GPU. When training on GPU it is important to keep your batch-size small enough that you do not use all of your GPU memory, otherwise you will see a CUDA Out Of Memory (OOM) Error and your training will crash. You can observe your CUDA memory utilization using either the nvidia-smi command or by viewing your console output:

Screenshot 2021-05-28 at 12 19 51

CUDA Out of Memory Solutions

If you encounter a CUDA OOM error, the steps you can take to reduce your memory usage are:

  • Reduce --batch-size
  • Reduce --img-size
  • Reduce model size, i.e. from YOLOv5x -> YOLOv5l -> YOLOv5m -> YOLOv5s
  • Train with multi-GPU at the same --batch-size
  • Upgrade your hardware to a larger GPU
  • Train on free GPU backends with up to 16GB of CUDA memory: Open In Colab Open In Kaggle

AutoBatch

You can use YOLOv5 AutoBatch (NEW) to find the best batch size for your training by passing --batch-size -1. AutoBatch will solve for a 90% CUDA memory-utilization batch-size given your training settings. AutoBatch is experimental, and only works for Single-GPU training. It may not work on all systems, and is not recommended for production use.

Screenshot 2021-11-06 at 12 31 10

Good luck 🍀 and let us know if you have any other questions!

@chiehpower
Copy link

chiehpower commented Feb 3, 2022

hi @glenn-jocher

Thanks for your detailed explanation!

Let me elaborate more on what my friend @p890040 and I encountered problems, and we will be grateful if you can give us some hints!

Recently we got a dataset that the model could get a good performance on it after we adjusted a higher input size.
Hence, we plan to adjust the larger input size to see the results; however, because the input size was very huge (~3360) even we already set the batch size as 1, the training still happens OOM issue. We ask for the best performance, so we have to use the biggest model size for training (i.e., 5x6). Our GPU specifications are two A100 (40GB), and we know there is a way of DistributedDataParallel from YOLO, but it cannot solve the OOM issue if we use a single image (batch size=1) with large input size.

My train of thought is that suppose training a single image with input size 3360 on YOLOv5x6 weight will account for 50GB GPU memory. I want to allocate 25 GB memory for first A100 GPU, and allocate the rest of 25 GB memory for second A100 GPU.

As far as I know, PyTorch DDP could combine with Model Parallelism ref. I am wondering does YOLOv5 support this feature? Or is there any tip for us to handle the large input size situation?

Thank you in advance!

Best regards,
Chieh

@glenn-jocher
Copy link
Member

No there is no model parallelism support currently.

It looks like on a single device YOLOv5x6 at --img 3840 will use about 53GB of CUDA memory, so you should be fine to train at 3360 on a single 40GB device.

Screenshot 2022-02-03 at 16 19 01

@p890040
Copy link
Author

p890040 commented Feb 3, 2022

@glenn-jocher
Thanks for your kind response!
We will try to figure out the solution, even add the model-parallelism implement. Meanwhile, we're looking to the powerful YOLOv5 team to release this feature ^___^.

@glenn-jocher
Copy link
Member

glenn-jocher commented Feb 3, 2022

@p890040 hi, thank you for your feature suggestion on how to improve YOLOv5 🚀! Yes this might be a useful addition, though I think parallelism is typically more used in language models where the parameter count can run into the billions.

The fastest and easiest way to incorporate your ideas into the official codebase is to submit a Pull Request (PR) implementing your idea, and if applicable providing before and after profiling/inference/training results to help us understand the improvement your feature provides. This allows us to directly see the changes in the code and to understand how they affect workflows and performance.

Please see our ✅ Contributing Guide to get started.

@chiehpower
Copy link

hi @glenn-jocher

Thanks for your reply and testing!
Sure! We will keep trying and developing on YOLOv5!

BR,
Chieh

@p890040 p890040 closed this as completed Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants