class_docstr: A key-value store for synchronization of values, over multiple devices.
class_docstr_tok: ["A","key-value","store","for","synchronization","of","values",",","over","multiple","devices","."]
docstr: Registers an optimizer with the kvstore.
  
  When using a single machine, this function updates the local optimizer.
  If using multiple machines and this operation is invoked from a worker node,
  it will serialized the optimizer with pickle and send it to all servers.
  The function returns after all servers have been updated.
  
  Parameters
  ----------
  optimizer : Optimizer
      The new optimizer for the store
  
  Examples
  --------
  
  >>> kv = mx.kv.create()
  >>> shape = (2, 2)
  >>> weight = mx.nd.zeros(shape)
  >>> kv.init(3, weight)
  >>> # set the optimizer for kvstore as the default SGD optimizer
  >>> kv.set_optimizer(mx.optimizer.SGD())
  >>> grad = mx.nd.ones(shape)
  >>> kv.push(3, grad)
  >>> kv.pull(3, out = weight)
  >>> # weight is updated via gradient descent
  >>> weight.asnumpy()
  array([[-0.01, -0.01],
         [-0.01, -0.01]], dtype=float32)
docstr_tok: ["Registers","an","optimizer","with","the","kvstore",".","When","using","a","single","machine",",","this","function","updates","the","local","optimizer",".","If","using","multiple","machines","and","this","operation","is","invoked","from","a","worker","node",",","it","will","serialized","the","optimizer","with","pickle","and","send","it","to","all","servers",".","The","function","returns","after","all","servers","have","been","updated",".","Parameters","--","--","--","--","--","optimizer",":","Optimizer","The","new","optimizer","for","the","store","Examples","--","--","--","--",">",">",">","kv","=","mx.kv.create","(",")",">",">",">","shape","=","(","2",",","2",")",">",">",">","weight","=","mx.nd.zeros","(","shape",")",">",">",">","kv.init","(","3",",","weight",")",">",">",">","#","set","the","optimizer","for","kvstore","as","the","default","SGD","optimizer",">",">",">","kv.set_optimizer","(","mx.optimizer.SGD","(",")",")",">",">",">","grad","=","mx.nd.ones","(","shape",")",">",">",">","kv.push","(","3",",","grad",")",">",">",">","kv.pull","(","3",",","out","=","weight",")",">",">",">","#","weight","is","updated","via","gradient","descent",">",">",">","weight.asnumpy","(",")","array","(","[","[","-0.01",",","-0.01","]",",","[","-0.01",",","-0.01","]","]",",","dtype=float32",")"]
code: def set_optimizer(self, optimizer):
      """Registers an optimizer with the kvstore.
  
      When using a single machine, this function updates the local optimizer.
      If using multiple machines and this operation is invoked from a worker node,
      it will serialized the optimizer with pickle and send it to all servers.
      The function returns after all servers have been updated.
  
      Parameters
      ----------
      optimizer : Optimizer
          The new optimizer for the store
  
      Examples
      --------
  
      >>> kv = mx.kv.create()
      >>> shape = (2, 2)
      >>> weight = mx.nd.zeros(shape)
      >>> kv.init(3, weight)
      >>> # set the optimizer for kvstore as the default SGD optimizer
      >>> kv.set_optimizer(mx.optimizer.SGD())
      >>> grad = mx.nd.ones(shape)
      >>> kv.push(3, grad)
      >>> kv.pull(3, out = weight)
      >>> # weight is updated via gradient descent
      >>> weight.asnumpy()
      array([[-0.01, -0.01],
             [-0.01, -0.01]], dtype=float32)
      """
      is_worker = ctypes.c_int()
      check_call(_LIB.MXKVStoreIsWorkerNode(ctypes.byref(is_worker)))
  
      # pylint: disable=invalid-name
      if (
          "dist" in self.type and is_worker.value
      ):  # pylint: disable=unsupported-membership-test
          # send the optimizer to server
          try:
              # use ASCII protocol 0, might be slower, but not a big ideal
              optim_str = py_str(pickle.dumps(optimizer, 0))
          except:
              raise
          cmd = _get_kvstore_server_command_type("kController")
          self._send_command_to_servers(cmd, optim_str)
          if optimizer.multi_precision:
              cmd = _get_kvstore_server_command_type(
                  "kSetMultiPrecision"
              )
              self._send_command_to_servers(cmd, "")
      else:
          self._set_updater(opt.get_updater(optimizer))
  
imports: import pickle
  import ctypes
  import os
  from ..ndarray import NDArray
  from ..ndarray import _ndarray_cls
  from ..base import _LIB, c_str
  from ..base import check_call, mx_uint, py_str
  from ..base import NDArrayHandle, KVStoreHandle
  from ..None import optimizer
  from .base import _ctype_key_value, _ctype_dict, KVStoreBase
label_desc: Use image node_id 11 for calling the KVStore obj's underlying member method code with example usage: obj.set_optimizer(optimizer) without return types