Closed dmitriy-serdyuk closed 6 years ago
It is written in the error itself that on line 6 it is described "np." which the compiler is unable to classify , it should be : _bh2 = tangent.astype(tangent.unreduce(bout, numpy.shape(h2), None, numpy._NoValue), h2)
@rikudoayush The code is actually generated by Tangent, so @dmitriy-serdyuk wouldn't be able to change it easily. It is indeed a bug.
What is happening is this: If a function is called without keyword arguments, we take the default values from the function signature and use those to call the backward function. In this case we take keepdims=np._NoValue
from numpy.sum
, and we make sure that we call the gradient function (unreduce
) with that value. This works if the keyword argument defaults are None
, True
, etc. but if it's an actual object (like the singleton np._NoValue
) it breaks if that object isn't available in the namespace of the backward pass, which is what happens here.
Fixing this would require a bit of machinery, or maybe we should just require adjoints to explicitly specify the defaults of the function they are wrapping. Having a look at it now.
For example, this fails: