example/mnist/train_mnist.py fails when using GPU
See original GitHub issueWhen I executed chainer/chainer/example/mnist/train_mnist.py
with GPU, the following error occurred.
It seems that it uses both of numpy.ndarray and cupy.ndarray.
I used the latest official docker container GPU : TITAN-X
root@ce05d3cc6624:~/work/chainer/examples/mnist# ./train_mnist.py --gpu=0
GPU: 0
# unit: 1000
# Minibatch-size: 100
# epoch: 20
/usr/local/lib/python2.7/dist-packages/chainer/training/extensions/plot_report.py:24: UserWarning: matplotlib is not installed on your environment, so nothing will be plotted at this time. Please install matplotlib to plot figures.
$ pip install matplotlib
warnings.warn('matplotlib is not installed on your environment, '
Traceback (most recent call last):
File "./train_mnist.py", line 137, in <module>
main()
File "./train_mnist.py", line 133, in main
trainer.run()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/trainer.py", line 295, in run
update()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/updater.py", line 177, in update
self.update_core()
File "/usr/local/lib/python2.7/dist-packages/chainer/training/updater.py", line 189, in update_core
optimizer.update(loss_func, *in_vars)
File "/usr/local/lib/python2.7/dist-packages/chainer/optimizer.py", line 411, in update
loss = lossfun(*args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/chainer/links/model/classifier.py", line 67, in __call__
self.y = self.predictor(*x)
File "./train_mnist.py", line 39, in __call__
h1 = F.relu(self.l1(x))
File "/usr/local/lib/python2.7/dist-packages/chainer/links/connection/linear.py", line 93, in __call__
return linear.linear(x, self.W, self.b)
File "/usr/local/lib/python2.7/dist-packages/chainer/functions/connection/linear.py", line 107, in linear
return LinearFunction()(x, W, b)
File "/usr/local/lib/python2.7/dist-packages/chainer/function.py", line 199, in __call__
outputs = self.forward(in_data)
File "/usr/local/lib/python2.7/dist-packages/chainer/functions/connection/linear.py", line 40, in forward
.format(type(W), type(x)))
ValueError: numpy and cupy must not be used together
type(W): <type 'numpy.ndarray'>, type(x): <type 'cupy.core.core.ndarray'>
root@ce05d3cc6624:~/work/chainer/examples/mnist#
Another error said that there is not self.init_scope()
, so I modified the MLP class as following:
# Network definition
class MLP(chainer.Chain):
# def __init__(self, n_units, n_out):
# super(MLP, self).__init__()
# with self.init_scope():
# # the size of the inputs to each layer will be inferred
# self.l1 = L.Linear(None, n_units) # n_in -> n_units
# self.l2 = L.Linear(None, n_units) # n_units -> n_units
# self.l3 = L.Linear(None, n_out) # n_units -> n_out
def __init__(self, n_units, n_out):
super(MLP, self).__init__()
# the size of the inputs to each layer will be inferred
self.l1 = L.Linear(None, n_units) # n_in -> n_units
self.l2 = L.Linear(None, n_units) # n_units -> n_units
self.l3 = L.Linear(None, n_out) # n_units -> n_out
def __call__(self, x):
h1 = F.relu(self.l1(x))
h2 = F.relu(self.l2(h1))
return self.l3(h2)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
GPU memory error with train.py and eval.py running together
Evaluation fails with an error about the GPU being out of memory (training continues though in the other terminal window with no problem)....
Read more >Using GPU error when use TensorFlow to train image
It seems that you Tensorflow is not detecting any gpu as available but maps the operations to GPU:0. First try this:
Read more >Python, Performance, and GPUs - Towards Data Science
Probably the easiest way for a Python programmer to get access to GPU performance is to use a GPU-accelerated Python library.
Read more >vGPU Enabled UVMs May be Unable to be Created, or May ...
Summary: The vGPU option may appear greyed out and unavailable when using Nvidia GRID with certain Tesla GPUs if the GPU is configured...
Read more >Tensorflow Plugin - Metal - Apple Developer
Mac computers with Apple silicon or AMD GPUs · macOS 12.0 or later (Get the latest beta) · Python 3.8 or later ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I could run
python train_mnist.py
. But I couldn’t run `python train_mnist.py --gpu=0’, and the following error occurred.This issue will be solved in https://github.com/chainer/chainer/pull/3902 (see also: https://github.com/chainer/chainer/pull/3898#issuecomment-345194894)