models icon indicating copy to clipboard operation
models copied to clipboard

[object detection feature request]: use multiple gpu for training

Open chakpongchung opened this issue 9 years ago • 43 comments

System information

  • What is the top-level directory of the model you are using:
  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Linux Ubuntu 16.04
  • TensorFlow installed from (source or binary): from pip
  • TensorFlow version (use command below):

('v1.2.0-5-g435cdfc', '1.2.1')

  • Bazel version (if compiling from source):
  • CUDA/cuDNN version:
  • GPU model and memory: 1080TI *2
  • Exact command to reproduce:

You can collect some of this information using our environment capture script:

https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh

You can obtain the TensorFlow version with

python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"

I am trying to use two gpu to speed up the training with data parallelism, does the code have such features? Would Model parallelism be faster?

chakpongchung avatar Jul 17 '17 14:07 chakpongchung

@jch1 : Do tweaks need to be made for multi-GPU support? Is that on the cards?

asimshankar avatar Jul 18 '17 00:07 asimshankar

Hi @chakpongchung , @asimshankar - Multi-GPU is already supported, but we don't have documentation for it (and currently don't have the cycles to work on this) --- it relies on slim's model_deploy package (which is also under tensorflow/models) and to control it, you have to set the num_clones parameter in train.py --- but you may have to tweak a few other things such as queue sizes to control memory usage.

jch1 avatar Jul 18 '17 01:07 jch1

I have four GPU and set num_clones=4,it seems just use one GPU and the speed just as same as use one GPU,did I should set other parameters?? @jch1

YanLiang0813 avatar Jul 20 '17 16:07 YanLiang0813

@YanLiang0813 Did you success training it on multi GPU? I also increased batch_size to 2 with num_clones=2, so each clone get 1 images. However there was error in backpropagation. What parameteres did you also changed?

insikk avatar Jul 28 '17 08:07 insikk

by just changing num_clones=2 I have two GPU running, with about 50% speed increase, (on azure K60 GPUs)

drorhilman avatar Aug 26 '17 18:08 drorhilman

@drorhilman I'm trying to configure usage of multiple GPUs on Azure N-series (specifically NC with the K80s). However, the GPUs seem to not have peer to peer access. How were you able to get them to communicate with one another in order to use multiple GPUs? I made a forum thread here: https://social.msdn.microsoft.com/Forums/en-US/c81a26b7-3770-4772-acc8-6ef5bd868108/training-neural-network-or-other-machine-learning-model-on-multiple-gpus-using-the-nseries?forum=MachineLearning

danvass avatar Sep 24 '17 09:09 danvass

I have:

  • Two 1080Ti's
  • CUDA 8.0 and cuDNN 6
  • Changed num_clones=2 and increased batch_size to 2.

It only trained for one class, and the detection/eval results for that one class were very bad, as in no recognition of the desired objects at all, even after many iterations. I also did not notice any increase in speed, is it safe to assume that the effective number of steps doubles?

I then switched back to just using one GPU and everything trained fine.

@drorhilman, did you end up getting good results?

louisquinn avatar Sep 26 '17 05:09 louisquinn

I also just set the num_clones=2, and change the setting file batch_size = 2 (originally 1). I got about almost the same or a little slower speed of steps per second. This meets my expectation; I suppose the speed should be slower a little, as batch size also doubled.

I also not understand why @drorhilman can get 50% speed increase. If still set batch_size to 1, it would be meaningless of using two GPUs, right? If set to 2, the speed should be slower a little, right?

ybsave avatar Nov 01 '17 17:11 ybsave

my way:

python3 train.py  --logtostderr  \
          --pipeline_config_path=model/ssd_inception_v2.config \
          --train_dir=model/train \
          --num_clones=2 --ps_tasks=1

I had two 1080ti

PS: you have to add ps_tasks

(tensorflow) root@odte:/opt/swiper.model/labs/v43# nvidia-smi
Thu Nov  2 12:28:26 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.90                 Driver Version: 384.90                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:01:00.0  On |                  N/A |
| 48%   68C    P2   218W / 250W |  10798MiB / 11171MiB |     97%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:02:00.0 Off |                  N/A |
| 38%   64C    P2   235W / 250W |  10796MiB / 11172MiB |     97%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1076      G   /usr/lib/xorg/Xorg                            60MiB |
|    0      1629      C   python3                                    10723MiB |
|    1      1629      C   python3                                    10783MiB |
+-----------------------------------------------------------------------------+

wendal avatar Nov 02 '17 04:11 wendal

@wendal In your case,the batch_size=1or 2? Because when I set batch_size=2, as my tf record is about 9G, I get the OOM error immediately, but which works well when I use just one GPU.

chenyuZha avatar Nov 09 '17 12:11 chenyuZha

@chakpongchung I use two gpu, so num_clones=2,

  • ssd_inception_v2 batch_size=16
  • faster_rcnn_resnet101 batch_size=8

which GPU you using ??

wendal avatar Nov 09 '17 13:11 wendal

my train.tfrecord is about 5.5G

BTW, I don't run eval at same machine, it slow down the training.

wendal avatar Nov 09 '17 13:11 wendal

I got an error running the code that @wendal offered under 1.2 version, but updating to 1.4 version works fine for me.

zihuaweng avatar Dec 07 '17 10:12 zihuaweng

@wendal Thanks for your comments. I solved using 'dual gpu' issue.

woody-kwon avatar Jan 09 '18 04:01 woody-kwon

@woody-kwon can you share how you solved it ? I didn't find any 'dual gpu' issue , thank you

obendidi avatar Jan 23 '18 13:01 obendidi

I solved "dual cpu issue" using options "--num_clones=2 --ps_tasks=1". plz refer wendal`s article.

woody-kwon avatar Jan 24 '18 02:01 woody-kwon

This is incredibly helpful, thank you @wendal and others!

Has anyone successfully used multiple GPUs with the OD API running in the cloud on GCP ML Engine? If so, how do you set num_clones and ps_tasks in order to use the GPUs on the master and all of the worker machines in the cluster? (Do these arguments just affect an individual machine, or the total number of GPUs in a cluster?)

Also, if you were successful, what TF runtime were you using, and did you have to make any other special mods to the code to fix other bugs (several of which have been reported)?

davidblumntcgeo avatar May 12 '18 15:05 davidblumntcgeo

2 GPUs for Faster R-CNN can use 4 bitch size? @wendal

a819721810 avatar May 17 '18 10:05 a819721810

@a819721810 depens on your GPU memory. if it is too high, tf will throw OOM

wendal avatar May 17 '18 11:05 wendal

@wendal I can't run multiple-gpu with faster_rcnn_resnet101_pets.config. Have you tried with faster RCNN ?

Traceback (most recent call last):
File "object_detection/train.py", line 183, in
tf.app.run()
File "/home/sangpilk/pyenv/py27/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 126, in run _sys.exit(main(argv))
File "object_detection/train.py", line 179, in main
graph_hook_fn=graph_rewriter_fn)
File "/home/sangpilk/git/dash_net/research/object_detection/trainer.py", line 287, in train
clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue])
File "/home/sangpilk/git/dash_net/research/slim/deployment/model_deploy.py", line 193, in create_clones
outputs = model_fn(*args, **kwargs)
File "/home/sangpilk/git/dash_net/research/object_detection/trainer.py", line 179, in _create_losses
train_config.use_multiclass_scores)
ValueError: need more than 0 values to unpack

spk921 avatar Jul 13 '18 21:07 spk921