class_docstr: BytePS backend for MXNet KVStore interface.
docstr: Broadcast the value NDArray at rank 0 to all ranks' out. If out is None,
  the result is stored in `value`.
  
  Parameters
  ----------
  key : str, or int
      The keys.
  value : NDArray, or list of NDArray
      Values corresponding to the key.
  out : NDArray, or lise of NDArray
      Values corresponding to the keys.
  
  Examples
  --------
  >>> # broadcast a single key-value pair
  >>> shape = (2,3)
  >>> kv = mx.kv.create('byteps')
  >>> a = mx.nd.zeros(shape)
  >>> kv.broadcast('3', mx.nd.ones(shape)*2, out=a)
  >>> print a.asnumpy()
  [[ 2.  2.  2.]
  [ 2.  2.  2.]]
docstr_tok: ["Broadcast","the","value","NDArray","at","rank","0","to","all","ranks","'","out",".","If","out","is","None",",","the","result","is","stored","in","`","value","`",".","Parameters","--","--","--","--","--","key",":","str",",","or","int","The","keys",".","value",":","NDArray",",","or","list","of","NDArray","Values","corresponding","to","the","key",".","out",":","NDArray",",","or","lise","of","NDArray","Values","corresponding","to","the","keys",".","Examples","--","--","--","--",">",">",">","#","broadcast","a","single","key-value","pair",">",">",">","shape","=","(","2,3",")",">",">",">","kv","=","mx.kv.create","(","'byteps","'",")",">",">",">","a","=","mx.nd.zeros","(","shape",")",">",">",">","kv.broadcast","(","'","3","'",",","mx.nd.ones","(","shape",")","*","2",",","out=a",")",">",">",">","print","a.asnumpy","(",")","[","[","2",".","2",".","2",".","]","[","2",".","2",".","2",".","]","]"]
code: def broadcast(self, key, value, out, priority=0):
      """Broadcast the value NDArray at rank 0 to all ranks' out. If out is None,
      the result is stored in `value`.
  
      Parameters
      ----------
      key : str, or int
          The keys.
      value : NDArray, or list of NDArray
          Values corresponding to the key.
      out : NDArray, or lise of NDArray
          Values corresponding to the keys.
  
      Examples
      --------
      >>> # broadcast a single key-value pair
      >>> shape = (2,3)
      >>> kv = mx.kv.create('byteps')
      >>> a = mx.nd.zeros(shape)
      >>> kv.broadcast('3', mx.nd.ones(shape)*2, out=a)
      >>> print a.asnumpy()
      [[ 2.  2.  2.]
      [ 2.  2.  2.]]
      """
      # do not accept list or tuple for key/value
      assert isinstance(key, (str, int))
  
      # unpack the list if it contains just one NDArray
      value = (
          value[0]
          if isinstance(value, list) and len(value) == 1
          else value
      )
      assert isinstance(
          value, NDArray
      ), "The type of value can only be NDArray or list of NDArray which has only one element."
      assert (
          value.context.device_type == "gpu"
      ), "Byteps KVStore only support GPU context for broadcast value."
  
      # optimzation when out = value or out = [value]
      if isinstance(out, (list, tuple)) and len(out) == 1:
          inplace = value is out[0]
      else:
          inplace = value is out
  
      if inplace:
          broadcast_value = value
      else:
          broadcast_value = value.copy()
      # for non-root-rank, assign value with 0, thus the result of pushpull will be
      # equal to the value of root-rank, thus implementing broadcast.
      root_rank = 0
      if self.rank != root_rank:
          broadcast_value.__imul__(0)
      self.handle.byteps_declare_tensor(str(key))
      self.handle.byteps_push_pull(
          broadcast_value,
          version=0,
          priority=priority,
          name=str(key),
          is_average=False,
      )
      # Make sure tensors pushed to MXNet engine get processed such that all
      # workers are synced before starting training.
      broadcast_value.wait_to_read()
  
      out = out if isinstance(out, list) else [out]
      for o in out:
          broadcast_value.copyto(o)
  
file_path: mxnet/python/mxnet/kvstore/byteps.py
imports: from __future__ import absolute_import
  from ..ndarray import NDArray
  from .base import KVStoreBase
label_desc: Use image node_id 2 for calling the BytePS obj's underlying member method code with example usage: obj.broadcast(key, value, out, priority) without return types