<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="x = tf.zeros([10])
tf.gradients(tf.reduce_prod(x, 0), [x])"><pre class="notranslate"><code class="notranslate">x = tf.zeros([10])
tf.gradients(tf.reduce_prod(x, 0), [x])
</code></pre></div>
<p dir="auto">Gives</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="more traceback

/home/***/.local/lib/python2.7/site-packages/tensorflow/python/ops/math_grad.pyc in _ProdGrad(op, grad)
    128   reduced = math_ops.cast(op.inputs[1], dtypes.int32)
    129   idx = math_ops.range(0, array_ops.rank(op.inputs[0]))
--&gt; 130   other, _ = array_ops.listdiff(idx, reduced)
    131   perm = array_ops.concat(0, [reduced, other])
    132   reduced_num = math_ops.reduce_prod(array_ops.gather(input_shape, reduced))

more traceback"><pre class="notranslate"><code class="notranslate">more traceback

/home/***/.local/lib/python2.7/site-packages/tensorflow/python/ops/math_grad.pyc in _ProdGrad(op, grad)
    128   reduced = math_ops.cast(op.inputs[1], dtypes.int32)
    129   idx = math_ops.range(0, array_ops.rank(op.inputs[0]))
--&gt; 130   other, _ = array_ops.listdiff(idx, reduced)
    131   perm = array_ops.concat(0, [reduced, other])
    132   reduced_num = math_ops.reduce_prod(array_ops.gather(input_shape, reduced))

more traceback
</code></pre></div>
<p dir="auto">In line 128, <code class="notranslate">op.inputs[1]</code> could be a scalar, which will cause a shape mismatch when passed to <code class="notranslate">array_ops.listdiff</code> in line 130.</p>
<p dir="auto">TF version: master branch a week ago</p>
<p dir="auto">Installed TensorFlow using pip package for v0.10.0rc0 on Ubuntu with python 2.7</p>
<p dir="auto">Pip package <a href="https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp27-none-linux_x86_64.whl" rel="nofollow">https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp27-none-linux_x86_64.whl</a></p>
<p dir="auto">The same error appears in the GPU build.</p>
<p dir="auto">The following minimal code example produces raise an exception at the definition of z</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="u = tf.placeholder(dtype=tf.float64, shape=(30,30))
v = tf.reduce_prod(u, reduction_indices=[0]) 
w = tf.gradients( v, u )

x = tf.placeholder(dtype=tf.float64, shape=(30,30))
y = tf.reduce_prod(x, reduction_indices=0) 
z = tf.gradients( y, x )"><pre class="notranslate"><code class="notranslate">u = tf.placeholder(dtype=tf.float64, shape=(30,30))
v = tf.reduce_prod(u, reduction_indices=[0]) 
w = tf.gradients( v, u )

x = tf.placeholder(dtype=tf.float64, shape=(30,30))
y = tf.reduce_prod(x, reduction_indices=0) 
z = tf.gradients( y, x )
</code></pre></div>
<blockquote>
<p dir="auto">z = tf.gradients( y, x )<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gradients.py", line 478, in gradients<br>
in_grads = _AsList(grad_fn(op, *out_grads))<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_grad.py", line 130, in _ProdGrad<br>
other, _ = array_ops.listdiff(idx, reduced)<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1201, in list_diff<br>
result = _op_def_lib.apply_op("ListDiff", x=x, y=y, name=name)<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op<br>
op_def=op_def)<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2312, in create_op<br>
set_shapes_for_outputs(ret)<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1704, in set_shapes_for_outputs<br>
shapes = shape_func(op)<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1981, in _ListDiffShape<br>
op.inputs[1].get_shape().assert_has_rank(1)<br>
File "HOME/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 621, in assert_has_rank<br>
raise ValueError("Shape %s must have rank %d" % (self, rank))<br>
ValueError: Shape () must have rank 1</p>
</blockquote>
<p dir="auto">The top code for u,v and w does not raise an error but the similar code for x,y, and z does. It looks like the shape code for reduce_prod cannot cope with the case where the reduction_indices is a single integer rather than a list. If you replace reduce_prod with reduce_sum in the above snippet then it does not raise an error.</p>