Ajoo opened a new issue #8438: HybridBlocks don't work with constant NDArray 
initialized Parameters
URL: https://github.com/apache/incubator-mxnet/issues/8438
 
 
   Hi. HybridBlocks with parameters initialized with a constant NDArray 
parameter don't seem to work with hybridize(). I always get a "TypeError: 
Object of type 'NDArray' is not JSON serializable" whan running hybridize() or 
tojson() on a symbol passed through.
   
   I guess a minimal example to reproduce this error would be:
   
   
       import mxnet as mx
   
       class LinearMap(mx.gluon.HybridBlock):
           def __init__(self, A, **kwargs):
               super(LinearMap, self).__init__(**kwargs)
               with self.name_scope():
                   self.A = self.params.get('A', shape=A.shape, 
init=mx.init.Constant(A))
   
           def hybrid_forward(self, F, x, A=None):
               return F.dot(A, x)
       
       l = LinearMap(mx.nd.ones((2,2)))
       l.initialize()
   
       l(mx.nd.array([1., 2.])) #this runs fine
       l.hybridize()
       l(mx.nd.array([1., 2.])) #this throws a TypeError
   
   
   The same example runs fine when the initializer is replaced with any other, 
I'm guessing it just can't serialize the NDArray used to initialize with a 
constant.
   
   As an aside, I didn't know that hybrid_forward would be called with 
parameters passed as keyword arguments. None of the tutorials mention it and 
the API docs aren't very explicit about it... I don't know if this is how 
hybrid_forward is supposed to be used.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to