You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/11/14 07:23:06 UTC

[GitHub] [incubator-mxnet] samskalicky edited a comment on issue #19535: [RFC] Need to export all HybridBlocks in a Gluon model

samskalicky edited a comment on issue #19535:
URL: https://github.com/apache/incubator-mxnet/issues/19535#issuecomment-727159044


   Heres a silly example of a hierarchical Block/HybridBlock to play around with:
   ```
   class MyBlock(mx.gluon.nn.Block):
       def __init__(self, **kwargs):
           super(MyBlock, self).__init__(**kwargs)
       def add(self, block):
           self._children[block.name + str(len(self._children))] = block
       def forward(self, x, *args):
           out = (x,) + args
           for block in self._children.values():
               out = block(*out)
           return out
   
   # create the Model
   inside = MyBlock()
   inside.add(mx.gluon.nn.Dense(10))
   net = MyBlock()
   net.add(inside)
   net.add(mx.gluon.nn.Dense(10))
   net.initialize()
   x = mx.nd.empty((1,10))
   out = net(x)
   
   #hybridize and create cached_graphs
   net.hybridize()
   out = net(x)
   
   #save cached_graphs
   save_cached_graphs(net)
   ```
   
   The hierarchy should look like:
   ```
   - MyBlock(0)
            |
            - MyBlock(1)
            |     |
            |     - Dense(0)
            - Dense(1)
   ```


----------------------------------------------------------------
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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org