Repository: Theano/Theano

Issue:
A typo that prevents T.grad on gpuarray.pool
See this line:
https://github.com/Theano/Theano/blob/a7900bd8ddbfceda9249f235e21005e0ee970884/theano/gpuarray/pool.py#L100

I think it should be
```
out = self(img, ws, stride, pad)
```
rather than 
```
out = self(inp, ws, stride, pad)
```
Otherwise, I'm getting the error below.


```
Traceback (most recent call last):
  File "alex_net.py", line 490, in <module>
    model = AlexNet(config)
  File "alex_net.py", line 103, in __init__
    self.grads = T.grad(self.cost,self.params)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 553, in grad
    grad_dict, wrt, cost_name)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1317, in _populate_grad_dict
    rval = [access_grad_cache(elem) for elem in wrt]
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1272, in access_grad_cache
    term = access_term_cache(node)[idx]
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 965, in access_term_cache
    output_grads = [access_grad_cache(var) for var in node.outputs]
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1272, in access_grad_cache
    term = access_term_cache(node)[idx]
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 965, in access_term_cache
    output_grads = [access_grad_cache(var) for var in node.outputs]

......


  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1272, in access_grad_cache
    term = access_term_cache(node)[idx]
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1106, in access_term_cache
    new_output_grads)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1106, in access_term_cache
    new_output_grads)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gof/op.py", line 700, in L_op
    return self.grad(inputs, output_grads)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gpuarray/pool.py", line 100, in grad
    out = self(inp, ws, stride, pad)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gof/op.py", line 604, in __call__
    node = self.make_node(*inputs, **kwargs)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gpuarray/pool.py", line 44, in make_node
    ctx_name = infer_context_name(inp)
  File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gpuarray/basic_ops.py", line 108, in infer_context_name
    if isinstance(v.type, GpuArrayType):
AttributeError: 'list' object has no attribute 'type'
```


Discussion:
That seem a good fix. Do you want to make a PR out of this?

thanks

On Fri, Jan 13, 2017 at 2:39 PM, He Ma <notifications@github.com> wrote:

> See this line:
> https://github.com/Theano/Theano/blob/a7900bd8ddbfceda9249f235e21005
> e0ee970884/theano/gpuarray/pool.py#L100
>
> I think it should be
>
> out = self(img, ws, stride, pad)
>
> rather than
>
> out = self(inp, ws, stride, pad)
>
> Otherwise, I'm getting the error below.
>
> Traceback (most recent call last):
>   File "alex_net.py", line 490, in <module>
>     model = AlexNet(config)
>   File "alex_net.py", line 103, in __init__
>     self.grads = T.grad(self.cost,self.params)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 553, in grad
>     grad_dict, wrt, cost_name)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1317, in _populate_grad_dict
>     rval = [access_grad_cache(elem) for elem in wrt]
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1272, in access_grad_cache
>     term = access_term_cache(node)[idx]
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 965, in access_term_cache
>     output_grads = [access_grad_cache(var) for var in node.outputs]
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1272, in access_grad_cache
>     term = access_term_cache(node)[idx]
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 965, in access_term_cache
>     output_grads = [access_grad_cache(var) for var in node.outputs]
>
> ......
>
>
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1272, in access_grad_cache
>     term = access_term_cache(node)[idx]
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1106, in access_term_cache
>     new_output_grads)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gradient.py", line 1106, in access_term_cache
>     new_output_grads)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gof/op.py", line 700, in L_op
>     return self.grad(inputs, output_grads)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gpuarray/pool.py", line 100, in grad
>     out = self(inp, ws, stride, pad)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gof/op.py", line 604, in __call__
>     node = self.make_node(*inputs, **kwargs)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gpuarray/pool.py", line 44, in make_node
>     ctx_name = infer_context_name(inp)
>   File "/export/mlrg/hma02/.local/lib/python2.7/site-packages/theano/gpuarray/basic_ops.py", line 108, in infer_context_name
>     if isinstance(v.type, GpuArrayType):
> AttributeError: 'list' object has no attribute 'type'
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/Theano/Theano/issues/5409>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AALC-9RH765goVdWqlJgkMZOyTyk7yZSks5rR9L0gaJpZM4LjO2o>
> .
>


Resolving patch:
diff --git a/theano/gpuarray/pool.py b/theano/gpuarray/pool.py
--- a/theano/gpuarray/pool.py
+++ b/theano/gpuarray/pool.py
@@ -97,7 +97,7 @@ def grad(self, inp, grads):
 
         disc = [theano.gradient.DisconnectedType()() for i in inp[1:]]
         if self.mode == 'max':
-            out = self(inp, ws, stride, pad)
+            out = self(img, ws, stride, pad)
             g_out = GpuMaxPoolGrad(ndim=self.ndim,
                                    ignore_border=self.ignore_border)(
                                        img, out, grad, ws, stride, pad)


Test patch: