eric-haibin-lin commented on a change in pull request #15124: [MXNET-1294] 
Priority-based parameter propagation for improved data parallel training 
throughput
URL: https://github.com/apache/incubator-mxnet/pull/15124#discussion_r370486731
 
 

 ##########
 File path: python/mxnet/kvstore/kvstore.py
 ##########
 @@ -104,8 +104,22 @@ def broadcast(self, key, value, out, priority=0):
         [ 2.  2.  2.]]
 
         """
-        self.init(key, value)
-        self.pull(key, out=out, priority=priority)
+        cvkeys, cvals, use_str_keys = _ctype_key_value(key, value)
+        if out is not None:
+            cokeys, couts, _ = _ctype_key_value(key, out)
+        else:
+            cokeys = cvkeys
+            couts = cvals
+
+        if use_str_keys:
+            check_call(_LIB.MXKVStoreBroadcastEx(
+                self.handle, mx_uint(len(cvkeys)), cvkeys, 
mx_uint(len(cokeys)), cokeys,
+                cvals, couts, ctypes.c_int(priority)))
+        else:
+            check_call(_LIB.MXKVStoreBroadcast(
+                self.handle, mx_uint(len(cvkeys)), cvkeys, 
mx_uint(len(cokeys)), cokeys,
+                cvals, couts, ctypes.c_int(priority)))
+
 
 
 Review comment:
   What about adding a name flag to `register`? I had a quick test:
   ```
   import mxnet as mx
   import warnings
   from mxnet.kvstore import KVStoreBase
   
   @staticmethod
   def register(klass, name=None):
       assert(isinstance(klass, type))
       if name is None:
           name = klass.__name__.lower()
       else:
          name = name.lower()
       if name in KVStoreBase.kv_registry:
           warnings.warn('WARNING: New kvstore %s.%s is overriding '
                         'existing kvstore %s.%s' %
                         (klass.__module__, klass.__name__,
                          KVStoreBase.kv_registry[name].__module__,
                          KVStoreBase.kv_registry[name].__name__))
       KVStoreBase.kv_registry[name] = klass
       return klass
   
   mx.kvstore.KVStoreBase.register = register
   class MyClass:
       pass
   
   # manually call register multiple times 
   mx.kvstore.KVStoreBase.register(MyClass, name='class_dist')
   mx.kvstore.KVStoreBase.register(MyClass, name='class_dist_device')
   
   print(KVStoreBase.kv_registry)
   ```
   
   returns 
   ```
   {'teststore': <class 'mxnet.kvstore.base.TestStore'>, 
   'class_dist': <class '__main__.MyClass'>, 
   'class_dist_device': <class '__main__.MyClass'>}
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to