abhinavs95 edited a comment on issue #13967: Hybrid Variable Pass Through [Bug]
URL: 
https://github.com/apache/incubator-mxnet/issues/13967#issuecomment-498426939
 
 
   Hi @stephenrawls, Wrapping `foo` in `F.identity()` solved the problem for 
me. Here is the full example:
   ```
   import mxnet as mx
   
   class Layer(mx.gluon.HybridBlock):
       def __init__(self, **kwargs):
           super(Layer,self).__init__(**kwargs)
   
           with self.name_scope():
               self.foo = self.params.get(name="foo", shape=(1), 
init=mx.init.Uniform(1))
   
       def hybrid_forward(self, F, x, foo):
           return F.identity(foo)
   
   
   net = Layer()
   net.initialize()
   net.hybridize()                                                              
                                                                                
                          
   
   with mx.autograd.record():
       y = net(mx.nd.ones(1))
       y = y * 2
       y.backward()
   
   print(net.collect_params()['layer0_foo'].grad())
   ```
   This works both with and without `net.hybridize()`. Does this solve your 
case? Fell free to close the issue if it does.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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