mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

context mismatch with special gpu indexing

Open 5urprise opened this issue 10 years ago • 7 comments

I get an the following context indexing problem, probably connected to the operator refactor, when training with multiple gpus leaving out the first device, e.g gpus 1 and 2:

Node[0] Start training with [gpu(1), gpu(2)]
src/operator/operator_util.cc:648: Check failed: (lhs.ctx()) == (rhs.ctx()) operands context mismatch 3 1 vs. 3 0

with gpus 2,1:

Node[0] Start training with [gpu(2), gpu(1)]
src/operator/operator_util.cc:648: Check failed: (lhs.ctx()) == (rhs.ctx()) operands context mismatch 3 2 vs. 3 0

When training with gpus "0,1" or "0,1,2" or "0,2", everything works as expected.```

Node[0] Start training with [gpu(0), gpu(1)]
Node[0] Epoch[0] Batch [50] Speed: 11418.95 samples/sec Train-accuracy=0.685937

Gpu0 is a titan, Gpu1,2 are one k80

5urprise avatar Apr 22 '16 14:04 5urprise

@tqchen

piiswrong avatar Apr 23 '16 04:04 piiswrong

Can you use the NaiveEngine to check were does the mismatch comes from in python side?

@piiswrong can you check if you can reproduce the error on your machine?

tqchen avatar Apr 23 '16 15:04 tqchen

Hello,

I've faced the same issue. When I do calculation on GPUs 0,1 training works properly, but when I set GPUs 4,5 I've got the following error message.

$> MXNET_ENGINE_TYPE=NaiveEngine  \
   PYTHONPATH=/opt/mxnet/python   \
   python train_mnist.py --gpus 4,5
2016-04-23 21:56:09,358 Node[0] start with arguments Namespace(batch_size=128, data_dir='mnist/', gpus='4,5', kv_store='local', load_epoch=None, lr=0.1, lr_factor=1, lr_factor_epoch=1, model_prefix=None, network='mlp', num_epochs=10, num_examples=60000, save_model_prefix=None)
[21:56:11] src/io/iter_mnist.cc:91: MNISTIter: load 60000 images, shuffle=1, shape=(128,784)
[21:56:11] src/engine/engine.cc:36: MXNet start using engine: NaiveEngine
[21:56:11] src/io/iter_mnist.cc:91: MNISTIter: load 10000 images, shuffle=1, shape=(128,784)
2016-04-23 21:56:11,968 Node[0] Start training with [gpu(4), gpu(5)]
[21:56:13] /opt/mxnet/dmlc-core/include/dmlc/logging.h:235: [21:56:13] src/operator/operator_util.cc:651: Check failed: (lhs.ctx()) == (rhs.ctx()) operands context mismatch 3 4 vs. 3 0
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 314, in 'calling callback function'
  File "/opt/mxnet/python/mxnet/kvstore.py", line 45, in updater_handle
    updater(key, lhs, rhs)
  File "/opt/mxnet/python/mxnet/optimizer.py", line 773, in updater
    optimizer.update(index, weight, grad, states[index])
  File "/opt/mxnet/python/mxnet/optimizer.py", line 302, in update
    mom[:] += -lr * (grad + wd * weight)
  File "/opt/mxnet/python/mxnet/ndarray.py", line 97, in __add__
    return add(self, other)
  File "/opt/mxnet/python/mxnet/ndarray.py", line 535, in add
    return NDArray._plus(lhs, rhs)
  File "/opt/mxnet/python/mxnet/ndarray.py", line 1060, in binary_ndarray_function
    c_array(ctypes.c_char_p, [])))
  File "/opt/mxnet/python/mxnet/base.py", line 77, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))

Thank you for your help in advance!

kozmad avatar Apr 23 '16 20:04 kozmad

This should be fixed by #1940

tqchen avatar Apr 23 '16 20:04 tqchen

Thank you, it works like a charm!

kozmad avatar Apr 23 '16 20:04 kozmad

@tqchen @piiswrong @tornadomeet Hi, I encountered a similar problem when running the FCN example with --retrain argument. When I set ctx to gpu(3) (https://github.com/dmlc/mxnet/blob/master/example/fcn-xs/fcn_xs.py#L14), the error message I got is mxnet.base.MXNetError: [10:37:36] src/operator/operator_util.cc:886: Check failed: lhs.ctx() == rhs.ctx() operands context mismatch 2 3 vs. 1 0 And with ctx set to gpu(0), the message is "... 2 0 vs. 1 0".

Using NaiveEngine, I found the error comes from self.updater(key, arr, self.arg_params[key]) (https://github.com/dmlc/mxnet/blob/master/example/fcn-xs/solver.py#L86). I was wondering why this happens and how it can be resolved.

II-Matto avatar Dec 09 '16 02:12 II-Matto

@tqchen @piiswrong @tornadomeet I did another experiment of training FCN8s. When setting the --retrain argument with the provided FCN8s_VGG16-0019.params, the training run normally with ctx set to gpu(0) and terminated with error with ctx set to gpu(3) (... operands context mismatch 2 3 vs. 2 0). Does this mean I have to use the same GPU ID for fine-tuning as that used in learning the pre-trained model? But this makes no sense and is not reasonable at all. Currently I can only train FCN from scratch with customized ctx.

II-Matto avatar Dec 09 '16 03:12 II-Matto