Skip to content

Instantly share code, notes, and snippets.

@bayerj
Created July 14, 2014 12:20
Show Gist options
  • Save bayerj/f659687cd7cbc78ca043 to your computer and use it in GitHub Desktop.
Save bayerj/f659687cd7cbc78ca043 to your computer and use it in GitHub Desktop.
Theano reshape with -1 does not work on GPU in case of tensor3
from theano import tensor as T
import theano
import numpy as np
x = T.tensor3('')
xf = x.flatten()
xr1 = x.reshape((x.shape[0] * x.shape[1], x.shape[-1]))
xr2 = x.reshape((-1, x.shape[-1]))
ff = theano.function([x], xf)
fr1 = theano.function([x], xr1)
fr2 = theano.function([x], xr2)
ff(np.zeros((81, 243, 16)).astype('float32'))
fr1(np.zeros((81, 243, 16)).astype('float32'))
fr2(np.zeros((81, 243, 16)).astype('float32'))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-fcf5c7edf3ee> in <module>()
1 ff(np.zeros((81, 243, 16)).astype('float32'))
2 fr1(np.zeros((81, 243, 16)).astype('float32'))
----> 3 fr2(np.zeros((81, 243, 16)).astype('float32'))
/uhome/jbayer/devel/Theano/theano/compile/function_module.pyc in __call__(self, *args, **kwargs)
586 # For the CVM
587 gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error],
--> 588 self.fn.thunks[self.fn.position_of_error])
589 else:
590 # For the c linker
/uhome/jbayer/devel/Theano/theano/compile/function_module.pyc in __call__(self, *args, **kwargs)
577 t0_fn = time.time()
578 try:
--> 579 outputs = self.fn()
580 except Exception:
581 if hasattr(self.fn, 'position_of_error'):
/uhome/jbayer/devel/Theano/theano/gof/op.pyc in rval(p, i, o, n)
642
643 def rval(p=p, i=node_input_storage, o=node_output_storage, n=node):
--> 644 r = p(n, [x[0] for x in i], o)
645 for o in node.outputs:
646 compute_map[o][0] = True
/uhome/jbayer/devel/Theano/theano/sandbox/cuda/basic_ops.py in perform(self, node, inp, out_)
2202 ' has incorrect length %i'
2203 ', should be %i' % (len(shp), self.ndim), shp)
-> 2204 out[0] = x.reshape(tuple(shp))
2205
2206
ValueError: size must remain unchanged, changed from 314928 to -16
Apply node that caused the error: GpuReshape{2}(GpuFromHost.0, MakeVector.0)
Inputs types: [CudaNdarrayType(float32, 3D), TensorType(int64, vector)]
Inputs shapes: [(81, 243, 16), (2,)]
Inputs strides: [(3888, 16, 1), (8,)]
Inputs scalar values: ['not scalar', 'not scalar']
HINT: Re-running with most Theano optimization disabled could give you a back-traces when this node was created. This can be done with by setting the Theano flags optimizer=fast_compile
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint of this apply node.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment