jinhuang415 commented on issue #10504: Can MXNet operator profiling work well 
using gluon model?
   Below is a simple gluon model I used (mainly copied from 
https://mxnet.incubator.apache.org/tutorials/gluon/gluon.html, only added 
wait_to_wait() call at the end in order to make sure OPs are executed):
   # import dependencies
   from __future__ import print_function
   import numpy as np
   import mxnet as mx
   import mxnet.ndarray as F
   import mxnet.gluon as gluon
   from mxnet.gluon import nn
   from mxnet import autograd
   class Net(gluon.Block):
       def __init__(self, **kwargs):
           super(Net, self).__init__(**kwargs)
           with self.name_scope():
               # layers created in name_scope will inherit name space
               # from parent layer.
               self.conv1 = nn.Conv2D(6, kernel_size=5)
               self.pool1 = nn.MaxPool2D(pool_size=(2,2))
               self.conv2 = nn.Conv2D(16, kernel_size=5)
               self.pool2 = nn.MaxPool2D(pool_size=(2,2))
               self.fc1 = nn.Dense(120)
               self.fc2 = nn.Dense(84)
               self.fc3 = nn.Dense(10)
       def forward(self, x):
           x = self.pool1(F.relu(self.conv1(x)))
           x = self.pool2(F.relu(self.conv2(x)))
           # 0 means copy over size from corresponding dimension.
           # -1 means infer size from the rest of dimensions.
           x = x.reshape((0, -1))
           x = F.relu(self.fc1(x))
           x = F.relu(self.fc2(x))
           x = self.fc3(x)
           return x
   net = Net()
   # Initialize on CPU. Replace with `mx.gpu(0)`, or `[mx.gpu(0), mx.gpu(1)]`,
   # etc to use one or more GPUs.
   net.collect_params().initialize(mx.init.Xavier(), ctx=mx.cpu())
   data = mx.nd.random_normal(shape=(10, 1, 32, 32))  # dummy data
   output = net(data)
   I also attached the generated profile json zip file FYI:

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:

With regards,
Apache Git Services

Reply via email to