goodfeli / theano_exercises

Exercises for my tutorials on Theano
BSD 3-Clause "New" or "Revised" License
672 stars 324 forks source link

Block gradients in 03_energy.py #2

Open mateuszmalinowski opened 10 years ago

mateuszmalinowski commented 10 years ago

Not really an issue, but rather a question.

I don't see the difference between both cases in the 03_energy.py example:

  1. taking V and H as constants
  2. differentianting over them

If I comment out the _ElemwiseNoGradient class and use T.grad(energy(W,V,H).mean(),W) in grad_expected_energy I still get correct answer.

On the other hand I get an error if I switch mode to FAST_COMPILE (both cases).

Error: MethodNotDefined: ('perform', <class 'theano.sandbox.rng_mrg.GPU_mrg_uniform'>, 'GPU_mrg_uniform') Apply node that caused the error: GPU_mrg_uniform{CudaNdarrayType(float32, vector),no_inplace}(<CudaNdarrayType(float32, vector)>, TensorConstant{(1,) of 12}) Inputs types: [CudaNdarrayType(float32, vector), TensorType(int32, (True,))] Inputs shapes: [(12,), (1,)] Inputs strides: [(1,), (4,)] Inputs scalar values: ['not scalar', array([12], dtype=int32)]

Backtrace when the node is created: File "03_energy.py", line 55, in W = rng_factory.normal(size=(nv, nh), dtype=v0.dtype) File "/local/lib/python2.7/site-packages/theano/sandbox/rng_mrg.py", line 1328, in normal nstreams=nstreams) File "/local/lib/python2.7/site-packages/theano/sandbox/rng_mrg.py", line 1210, in uniform ndim, dtype, size)) File "/local/lib/python2.7/site-packages/theano/sandbox/rng_mrg.py", line 545, in new return op(rstate, cast(v_size, 'int32'))

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint of this apply node.