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/09/30 07:50:10 UTC

[GitHub] [incubator-mxnet] sxjscience edited a comment on issue #11061: mx.nd.argmax is slow

sxjscience edited a comment on issue #11061:
URL: https://github.com/apache/incubator-mxnet/issues/11061#issuecomment-701217514


   Even in the latest MXNet 2.0, this performance issue was not solved:
   
   - Speed of topk(k=1)
   
   ```python
   import time
   import mxnet as mx
   import numpy as np
   import os
   tmp = mx.np.random.normal(-1, 1, (64,300000), ctx=mx.gpu())
   tic = time.time()
   for i in range(20):
      if (i == 5):
           begin = time.time();
      elif (i == 15):
           end = time.time();
      tic = time.time()
      out = mx.npx.topk(tmp, k=1, ret_typ='indices', axis=1, dtype=np.int32)
      out.wait_to_read()
      toc = time.time() - tic
      print ("used time %f:"%toc)
   avg = (end - begin) / 10
   print("avg time %f"%avg)
   ```
   
   
   Output:
   ```
   used time 0.001522:
   used time 0.001141:
   used time 0.001141:
   used time 0.001094:
   used time 0.001081:
   used time 0.001080:
   used time 0.001086:
   used time 0.001089:
   used time 0.001075:
   used time 0.001085:
   used time 0.00108
   ```
   
   - Speed of argmax:
   ```python
   import time
   import mxnet as mx
   import numpy as np
   import os
   tmp = mx.np.random.normal(-1, 1, (64,300000), ctx=mx.gpu())
   tic = time.time()
   for i in range(20):
      if (i == 5):
           begin = time.time();
      elif (i == 15):
           end = time.time();
      tic = time.time()
      out = mx.np.argmax(tmp, axis=1)
      out.wait_to_read()
      toc = time.time() - tic
      print ("used time %f:"%toc)
   avg = (end - begin) / 10
   print("avg time %f"%avg)
   ```
   
   Output
   ```
   used time 0.063610:
   used time 0.060543:
   used time 0.059911:
   used time 0.059865:
   used time 0.055048:
   used time 0.054780:
   used time 0.054773:
   used time 0.054817:
   used time 0.054653:
   used time 0.054758:
   used time 0.054723:
   used time 0.054765:
   used time 0.054680:
   used time 0.054769:
   ```
   
   - Speed of PyTorch
   
   ```
   import time
   import torch
   import numpy as np
   import os
   tmp = torch.normal(-1, 1, (64,300000)).cuda()
   tic = time.time()
   for i in range(20):
      if (i == 5):
           begin = time.time();
      elif (i == 15):
           end = time.time();
      tic = time.time()
      out = tmp.argmax().cpu().numpy()
      toc = time.time() - tic
      print ("used time %f:"%toc)
   avg = (end - begin) / 10
   print("avg time %f"%avg)
   ```
   ```
   used time 0.000696:
   used time 0.000167:
   used time 0.000153:
   used time 0.000149:
   used time 0.000148:
   used time 0.000151:
   used time 0.000148:
   used time 0.000148:
   used time 0.000148:
   used time 0.000148:
   used time 0.000155:
   used time 0.000149:
   used time 0.000148:
   used time 0.000148:
   used time 0.000148:
   used time 0.000156:
   used time 0.000149:
   used time 0.000149:
   used time 0.000147:
   ```


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