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

GPU not utilizing 100% memory #9949

Closed
1 task done
KxFxN opened this issue Oct 28, 2022 · 7 comments
Closed
1 task done

GPU not utilizing 100% memory #9949

KxFxN opened this issue Oct 28, 2022 · 7 comments
Labels
question Further information is requested Stale Stale and schedule for closing soon

Comments

@KxFxN
Copy link

KxFxN commented Oct 28, 2022

Search before asking

Question

GPU not utilizing 100% memory !!

I tried Train multiple GPUs but Ram not use 100% memory

device for me.
GTX 1080 Ti 11GB
GTX 1070 8GB

python 3.9.13
torch 1.12.1+cu113
torchaudio 0.12.1+cu113
torchvision 0.13.1+cu113

python train.py --img 480 --batch 2 --epochs 100 --data ./data/coco_CBZ.yaml --weights ./models/yolov5s.pt --device 0,1 --name CBZ

What is the problem? Help me

utoAnchor: 6.40 anchors/target, 1.000 Best Possible Recall (BPR). Current anchors are a good fit to dataset
Plotting labels to runs\train\CBZ4\labels.jpg... 
Image sizes 480 train, 480 val
Using 2 dataloader workers
Logging results to runs\train\CBZ4
Starting training for 100 epochs...

      Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
  0%|          | 0/239 [00:00<?, ?it/s]                                                                                                                                              C:\Users\kuy50\AppData\Roaming\Python\Python39\site-packages\torch\cuda\nccl.py:15: UserWarning: PyTorch is not compiled with NCCL support
  warnings.warn('PyTorch is not compiled with NCCL support')
       0/99     0.312G     0.1153    0.09853    0.06285         14        480: 100%|██████████| 239/239 [01:54<00:00,  2.09it/s]
                 Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 120/120 [00:29<00:00,  4.02it/s]
                   all        478       4773     0.0232      0.115     0.0149    0.00374

      Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
       1/99     0.776G    0.09581    0.09177    0.05947         31        480: 100%|██████████| 239/239 [01:41<00:00,  2.36it/s]
                 Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 120/120 [00:21<00:00,  5.48it/s]
                   all        478       4773     0.0467      0.209     0.0442     0.0132

      Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
       2/99     0.776G    0.08696    0.08272    0.05724         32        480: 100%|██████████| 239/239 [01:40<00:00,  2.38it/s]
                 Class     Images  Instances          P          R      mAP50   mAP50-95: 100%|██████████| 120/120 [00:17<00:00,  6.92it/s]
                   all        478       4773     0.0387      0.153     0.0539      0.024

      Epoch    GPU_mem   box_loss   obj_loss   cls_loss  Instances       Size
       3/99     0.776G    0.09386    0.06784    0.05689         23        480:   4%|         | 9/239 [00:04<01:50,  2.08it/s]

Additional

No response

@KxFxN KxFxN added the question Further information is requested label Oct 28, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2022

👋 Hello @kaofang38573, 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 [email protected].

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

YOLOv5 CI

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

@glenn-jocher
Copy link
Member

glenn-jocher commented Nov 1, 2022

👋 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 > YOLOv5n
  • 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!

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Dec 2, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2022
@ghost
Copy link

ghost commented May 12, 2023

@glenn-jocher Hello and firstly thanks for this awesome piece of work :) My question is i am getting cuda out of memory error even with autobatch --batch-size -1
Autobatch calculates 16 for my batch size which is %80 of my VRAM (GTX 1070 - 8GB) but training stops with error before it fills my GPU memory (like at %20)

Windows 10
yolov5m.pt
Image size = 640

@glenn-jocher
Copy link
Member

@k00r hello there! Thank you for your kind words about YOLOv5 🚀!

Regarding your question, even though AutoBatch calculates a 90% CUDA memory utilisation batch size, there are many variables that may contribute to CUDA out of memory errors, such as the size of your model, image size, data augmentation, number of classes, and number of GPUs.

You may want to try some of the following methods to reduce your memory usage:

  • Reduce --batch-size even further
  • Reduce --img-size
  • Reduce the number of classes or use smaller anchor sizes
  • Train with fewer augmentations
  • Train on a smaller sub-set of data

It is also important to check the error message you received as it may include helpful information about the cause of your CUDA out of memory error. You could provide more information about the error message or consult the documentation to debug the issue further.

I hope this helps, and good luck with your training!

@ghost
Copy link

ghost commented May 15, 2023

@glenn-jocher It was image size for me :) the error disappeared when i reduced the size of my images in my dataset

@glenn-jocher
Copy link
Member

@k00r great to hear that you have resolved your issue! Yes, the image size plays a significant role in the memory usage of YOLOv5 while training your custom data. By reducing the image size, you reduce the numbers of pixels that your GPU needs to process, which, in turn, reduces the memory requirements during training.

If you have any other questions or issues, please don't hesitate to ask! We are always here to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

2 participants