You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/06/03 21:15:12 UTC

[GitHub] [incubator-mxnet] abhinavs95 edited a comment on issue #13967: Hybrid Variable Pass Through [Bug]

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:
users@infra.apache.org


With regards,
Apache Git Services