dmlc / minpy

NumPy interface with mixed backend execution
https://minpy.readthedocs.io/en/latest/
Other
1.11k stars 112 forks source link

minpy.core.Function handling top-down gradients w.r.t. multiple outputs #170

Closed GaiYu0 closed 7 years ago

GaiYu0 commented 7 years ago

Hi! I am using minpy.core.Function to call a MXNet symbol yielding multiple outputs. I am not sure whether minpy.core.Function works in backward phase if there are top-down gradients w.r.t. all these outputs.

It appears that minpy.core.Function only provides gradient w.r.t. one of these outputs to executor.backward: https://github.com/dmlc/minpy/blob/master/minpy/core.py#L169

(But I might be wrong)

GaiYu0 commented 7 years ago

Hi! Here is an example of the issue:

from mxnet.symbol import Group, Variable

p = Variable('p')
q = Variable('q')
group = Group((p, q))

from minpy.core import Function
function = Function(group, input_shapes={'p' : (1,), 'q' : (1,)})

def f(p, q):
    p, q = function(p=p, q=q)
    return p - q

from minpy.core import grad
df = grad(f, range(2))

import minpy.numpy as np

p = np.ones((1,))
q = np.zeros((1,))
df(p, q)

Exception raised: image

Taco-W commented 7 years ago

@GaiYu0 This should be closed?

GaiYu0 commented 7 years ago

I agree. Let me close the issue.