models icon indicating copy to clipboard operation
models copied to clipboard

How to run object detection with multiple GPUs

Open wander1985 opened this issue 7 years ago • 16 comments

I am trying to run object detection on 4 GPUs on my school's supercomputer. I've successfully installed tensorFlow object detection on the supercomputer, and used the following script for training.

`#PBS -N TensorFlow #PBS -l nodes=2:ppn=40:gpus=2 #PBS -l walltime=10:00 #PBS -j oe #PBS -S /bin/bash

module load python/3.6-conda5.2 cuda/10.0.130 source activate tf-gpu2

cd ~/tensorflow/models/research/ export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

cd ~/tensorflow/models/research/object_detection python legacy/train.py --pipeline_config_path=training/faster_rcnn_inception_v2_coco.config --train_dir=training/ --logtostderr --worker_replicas=4 --num_clones=4 --ps_tasks=1`

This line tells the supercomputer how many GPUs I want to use. #PBS -l nodes=2:ppn=40:gpus=2 There are 2 GPUs for each node, so if I want to use 4 GPUs, the nodes value is set to 2.

But the training process would still use 2 GPUs no matter how large number is set for nodes. So I am wondering how to let the tensorflow api recognize the value in the nodes.

wander1985 avatar Apr 19 '19 14:04 wander1985

Tensorflow object detection API doesn't support multi-gpu training. By default, it uses the GPU 0.

kmadhugit avatar Apr 23 '19 15:04 kmadhugit

Tensorflow object detection API doesn't support multi-gpu training. By default, it uses the GPU 0.

Thanks.

wander1985 avatar Apr 25 '19 20:04 wander1985

Closing this issue since its resolved. Thanks!

ymodak avatar May 31 '19 21:05 ymodak

@kmadhugit, Yes, it's possible to run the training in multiple GPUs, with the options below,

--worker_replicas=8 --num_clones=8 --ps_tasks=1

Note: I have used 8 GPUs in AWS p2.8xlarge instance type. It's working good.

# nvidia-smi 

Thu Jul  4 14:39:36 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48                 Driver Version: 410.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:00:17.0 Off |                    0 |
| N/A   59C    P0    55W / 149W |   7070MiB / 11441MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 00000000:00:18.0 Off |                    0 |
| N/A   47C    P0    75W / 149W |   7070MiB / 11441MiB |     19%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla K80           Off  | 00000000:00:19.0 Off |                    0 |
| N/A   63C    P0    59W / 149W |   7070MiB / 11441MiB |      4%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla K80           Off  | 00000000:00:1A.0 Off |                    0 |
| N/A   52C    P0    79W / 149W |   7070MiB / 11441MiB |     43%      Default |
+-------------------------------+----------------------+----------------------+
|   4  Tesla K80           Off  | 00000000:00:1B.0 Off |                    0 |
| N/A   61C    P0    64W / 149W |   7070MiB / 11441MiB |     34%      Default |
+-------------------------------+----------------------+----------------------+
|   5  Tesla K80           Off  | 00000000:00:1C.0 Off |                    0 |
| N/A   52C    P0    75W / 149W |   7070MiB / 11441MiB |     39%      Default |
+-------------------------------+----------------------+----------------------+
|   6  Tesla K80           Off  | 00000000:00:1D.0 Off |                    0 |
| N/A   63C    P0    61W / 149W |   7070MiB / 11441MiB |     30%      Default |
+-------------------------------+----------------------+----------------------+
|   7  Tesla K80           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   55C    P0    76W / 149W |   7070MiB / 11441MiB |     28%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3987      C   python                                      7053MiB |
|    1      3987      C   python                                      7053MiB |
|    2      3987      C   python                                      7053MiB |
|    3      3987      C   python                                      7053MiB |
|    4      3987      C   python                                      7053MiB |
|    5      3987      C   python                                      7053MiB |
|    6      3987      C   python                                      7053MiB |
|    7      3987      C   python                                      7053MiB |
+-----------------------------------------------------------------------------+

laksgreen avatar Jul 04 '19 14:07 laksgreen

@laksgreen can you check the log to see if you are getting same losses for multiple steps?

INFO:tensorflow:global step 18515: loss = 0.9066 (0.276 sec/step)
INFO:tensorflow:global step 18515: loss = 0.9066 (0.276 sec/step)
INFO:tensorflow:global step 18516: loss = 0.1970 (0.249 sec/step)
INFO:tensorflow:global step 18516: loss = 0.1970 (0.249 sec/step)
INFO:tensorflow:global step 18517: loss = 0.4372 (0.262 sec/step)
INFO:tensorflow:global step 18517: loss = 0.4372 (0.262 sec/step)
INFO:tensorflow:global step 18518: loss = 0.3985 (0.269 sec/step)
INFO:tensorflow:global step 18518: loss = 0.3985 (0.269 sec/step)
INFO:tensorflow:global step 18519: loss = 0.2542 (0.252 sec/step)
INFO:tensorflow:global step 18519: loss = 0.2542 (0.252 sec/step)
INFO:tensorflow:global step 18520: loss = 0.4310 (0.242 sec/step)
INFO:tensorflow:global step 18520: loss = 0.4310 (0.242 sec/step)

I have two gpus and if you can see closely, the steps and loss just repeats twice

shahidammer avatar Jul 29 '19 16:07 shahidammer

what is "replicas_to_aggregate" used for in "train_config" then ?

aloisDeLaComble avatar Sep 02 '19 08:09 aloisDeLaComble

@laksgreen I understand that now, but is it possible to to run (load inference graph) to do real-time detection using multiGPU?

ManafMukred avatar Nov 18 '19 08:11 ManafMukred

@shahidammer - No, it's repeating twice, I have used 8 GPU. If it's repeating multiple times you have to check your application I think so.

laksgreen avatar Dec 02 '19 11:12 laksgreen

worker_replicas

where can i found those values

DevLob-zz avatar Jan 26 '20 10:01 DevLob-zz

worker_replicas

where can i found those values

In "trainer.py" file

emitoooo avatar Feb 24 '20 08:02 emitoooo

@kmadhugit, Yes, it's possible to run the training in multiple GPUs, with the options below,

--worker_replicas=8 --num_clones=8 --ps_tasks=1

Note: I have used 8 GPUs in AWS p2.8xlarge instance type. It's working good.

# nvidia-smi 

Thu Jul  4 14:39:36 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48                 Driver Version: 410.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:00:17.0 Off |                    0 |
| N/A   59C    P0    55W / 149W |   7070MiB / 11441MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 00000000:00:18.0 Off |                    0 |
| N/A   47C    P0    75W / 149W |   7070MiB / 11441MiB |     19%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla K80           Off  | 00000000:00:19.0 Off |                    0 |
| N/A   63C    P0    59W / 149W |   7070MiB / 11441MiB |      4%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla K80           Off  | 00000000:00:1A.0 Off |                    0 |
| N/A   52C    P0    79W / 149W |   7070MiB / 11441MiB |     43%      Default |
+-------------------------------+----------------------+----------------------+
|   4  Tesla K80           Off  | 00000000:00:1B.0 Off |                    0 |
| N/A   61C    P0    64W / 149W |   7070MiB / 11441MiB |     34%      Default |
+-------------------------------+----------------------+----------------------+
|   5  Tesla K80           Off  | 00000000:00:1C.0 Off |                    0 |
| N/A   52C    P0    75W / 149W |   7070MiB / 11441MiB |     39%      Default |
+-------------------------------+----------------------+----------------------+
|   6  Tesla K80           Off  | 00000000:00:1D.0 Off |                    0 |
| N/A   63C    P0    61W / 149W |   7070MiB / 11441MiB |     30%      Default |
+-------------------------------+----------------------+----------------------+
|   7  Tesla K80           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   55C    P0    76W / 149W |   7070MiB / 11441MiB |     28%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3987      C   python                                      7053MiB |
|    1      3987      C   python                                      7053MiB |
|    2      3987      C   python                                      7053MiB |
|    3      3987      C   python                                      7053MiB |
|    4      3987      C   python                                      7053MiB |
|    5      3987      C   python                                      7053MiB |
|    6      3987      C   python                                      7053MiB |
|    7      3987      C   python                                      7053MiB |
+-----------------------------------------------------------------------------+

Hi, I am having a memory limit error while training but I have 2 gpus. Can I increase the memory with this method?

emitoooo avatar Feb 24 '20 09:02 emitoooo

@kmadhugit, Yes, it's possible to run the training in multiple GPUs, with the options below,

--worker_replicas=8 --num_clones=8 --ps_tasks=1

Note: I have used 8 GPUs in AWS p2.8xlarge instance type. It's working good.

# nvidia-smi 

Thu Jul  4 14:39:36 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48                 Driver Version: 410.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:00:17.0 Off |                    0 |
| N/A   59C    P0    55W / 149W |   7070MiB / 11441MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 00000000:00:18.0 Off |                    0 |
| N/A   47C    P0    75W / 149W |   7070MiB / 11441MiB |     19%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla K80           Off  | 00000000:00:19.0 Off |                    0 |
| N/A   63C    P0    59W / 149W |   7070MiB / 11441MiB |      4%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla K80           Off  | 00000000:00:1A.0 Off |                    0 |
| N/A   52C    P0    79W / 149W |   7070MiB / 11441MiB |     43%      Default |
+-------------------------------+----------------------+----------------------+
|   4  Tesla K80           Off  | 00000000:00:1B.0 Off |                    0 |
| N/A   61C    P0    64W / 149W |   7070MiB / 11441MiB |     34%      Default |
+-------------------------------+----------------------+----------------------+
|   5  Tesla K80           Off  | 00000000:00:1C.0 Off |                    0 |
| N/A   52C    P0    75W / 149W |   7070MiB / 11441MiB |     39%      Default |
+-------------------------------+----------------------+----------------------+
|   6  Tesla K80           Off  | 00000000:00:1D.0 Off |                    0 |
| N/A   63C    P0    61W / 149W |   7070MiB / 11441MiB |     30%      Default |
+-------------------------------+----------------------+----------------------+
|   7  Tesla K80           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   55C    P0    76W / 149W |   7070MiB / 11441MiB |     28%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3987      C   python                                      7053MiB |
|    1      3987      C   python                                      7053MiB |
|    2      3987      C   python                                      7053MiB |
|    3      3987      C   python                                      7053MiB |
|    4      3987      C   python                                      7053MiB |
|    5      3987      C   python                                      7053MiB |
|    6      3987      C   python                                      7053MiB |
|    7      3987      C   python                                      7053MiB |
+-----------------------------------------------------------------------------+

I followed your way to train the model successfully. However, when I evaluate and export the inference, it came up with an issue I have never seen in single GPU.

W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key BoxPredictor_0/BoxEncodingPredictor/act_quant/max not found in checkpoint

donald2016 avatar May 07 '20 08:05 donald2016

Hey this method does not work. It still just uses 1 gpu

csingh27 avatar Jul 15 '20 12:07 csingh27

what i was did is to build a code to set which GPU is Idle and assign the task to first Idl GPU

put this in your file before any command

where gpuIndex is Idle GPU Index

you can easily iterate you GPUS and check state for every one

if int(gpuIndex) >= 0: os.environ["CUDA_VISIBLE_DEVICES"]=str(gpuIndex)

this worked with me on multiple machine

best reagards

DevLob-zz avatar Jul 15 '20 13:07 DevLob-zz

@kmadhugit, Yes, it's possible to run the training in multiple GPUs, with the options below,

--worker_replicas=8 --num_clones=8 --ps_tasks=1

Note: I have used 8 GPUs in AWS p2.8xlarge instance type. It's working good.

# nvidia-smi 

Thu Jul  4 14:39:36 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48                 Driver Version: 410.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K80           Off  | 00000000:00:17.0 Off |                    0 |
| N/A   59C    P0    55W / 149W |   7070MiB / 11441MiB |      2%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K80           Off  | 00000000:00:18.0 Off |                    0 |
| N/A   47C    P0    75W / 149W |   7070MiB / 11441MiB |     19%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla K80           Off  | 00000000:00:19.0 Off |                    0 |
| N/A   63C    P0    59W / 149W |   7070MiB / 11441MiB |      4%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla K80           Off  | 00000000:00:1A.0 Off |                    0 |
| N/A   52C    P0    79W / 149W |   7070MiB / 11441MiB |     43%      Default |
+-------------------------------+----------------------+----------------------+
|   4  Tesla K80           Off  | 00000000:00:1B.0 Off |                    0 |
| N/A   61C    P0    64W / 149W |   7070MiB / 11441MiB |     34%      Default |
+-------------------------------+----------------------+----------------------+
|   5  Tesla K80           Off  | 00000000:00:1C.0 Off |                    0 |
| N/A   52C    P0    75W / 149W |   7070MiB / 11441MiB |     39%      Default |
+-------------------------------+----------------------+----------------------+
|   6  Tesla K80           Off  | 00000000:00:1D.0 Off |                    0 |
| N/A   63C    P0    61W / 149W |   7070MiB / 11441MiB |     30%      Default |
+-------------------------------+----------------------+----------------------+
|   7  Tesla K80           Off  | 00000000:00:1E.0 Off |                    0 |
| N/A   55C    P0    76W / 149W |   7070MiB / 11441MiB |     28%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      3987      C   python                                      7053MiB |
|    1      3987      C   python                                      7053MiB |
|    2      3987      C   python                                      7053MiB |
|    3      3987      C   python                                      7053MiB |
|    4      3987      C   python                                      7053MiB |
|    5      3987      C   python                                      7053MiB |
|    6      3987      C   python                                      7053MiB |
|    7      3987      C   python                                      7053MiB |
+-----------------------------------------------------------------------------+

8 clones per worker. SO, shouldn't it be 8 * 8 = 64 GPUs? I am having the same results. How can I run multi worker training?

ahnaf012 avatar Sep 27 '20 06:09 ahnaf012

--worker_replicas=8 --num_clones=8 --ps_tasks=1 @pkulzc How we can increase the GPU utilization ? GPU's are utilized only 30-40%? how we can utilized all of them 100%?

sainisanjay avatar Mar 30 '21 13:03 sainisanjay