haojin2 commented on issue #10208: [MXNET-117] Sparse operator 
broadcast_mul/div(csr, dense) = csr
URL: https://github.com/apache/incubator-mxnet/pull/10208#issuecomment-379527460
 
 
   Update on 4/8:
   A small benchmark for this operator is added to compare the new 
implementation with the fallback implementation
   ```
   import mxnet as mx
   import scipy
   import numpy as np
   import time
   
   def measure_cost(repeat, f, *args, **kwargs):
       # start bench
       start = time.time()
       results = []
       for i in range(repeat):
           results.append(f(*args, **kwargs))
       for result in results:
           result.wait_to_read()
       end = time.time()
       diff = end - start
       return diff / repeat
   
   def main():
       shape_lhs = (256, 1000000)
       vec = np.random.uniform(size=(256, 1))
       mx_vec = mx.nd.array(vec)
       for density in [0.01, 0.005, 0.001]:
           csr = scipy.sparse.random(256, 1000000, density=density, format = 
'csr', dtype=np.float32)
           mx_csr = mx.nd.sparse.csr_matrix((csr.data, csr.indices, 
csr.indptr), shape=shape_lhs, ctx=mx.cpu())
           mx_dns = mx_csr.tostype('default')
           sparse_cost = 0.0
           dns_cost = 0.0
           for i in range(10):
               sparse_cost += measure_cost(100, mx.nd.broadcast_mul, mx_csr, 
mx_vec)
               dns_cost += measure_cost(100, mx.nd.broadcast_mul, mx_dns, 
mx_vec)
           print("%.2f %%" % (density*100), dns_cost / sparse_cost)
   
   
   if __name__ == "__main__":
       main()
   ```
   Results on p2.8xlarge instance with 
commit(2ae0bd598b83f4d51481cd8f19ea241da31c16bb):
   (density speedup)
   (1.00%  9.453656599452351)
   (0.50% 18.406541290116778)
   (0.10%  53.18159853487238)

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


With regards,
Apache Git Services

Reply via email to