class_docstr: A subclass of MXNet gluon.Trainer.
  
  There are two differences between DistributedTrainer and Trainer:
  1. DistributedTrainer calculates gradients using BytePS push pull
     API while Trainer does it using kvstore push/pull APIs;
  2. DistributedTrainer performs push_pull(summation) and average,
     while Trainer only performs push_pull(summation).
  
  Parameters
  ----------
  params : ParameterDict
      The set of parameters to optimize.
  optimizer : str or Optimizer
      The optimizer to use. See
      `help <http://mxnet.io/api/python/optimization/optimization.html#the-mxnet-optimizer-package>`_
      on Optimizer for a list of available optimizers.
  optimizer_params : dict
      Key-word arguments to be passed to optimizer constructor. For example,
      `{'learning_rate': 0.1}`. All optimizers accept learning_rate, wd (weight decay),
      clip_gradient, and lr_scheduler. See each optimizer's
      constructor for a list of additional supported arguments
  root_rank : int
      rank of root
  compression_params : dict
      Key-word arguments to be passed to gradient compression constructor. For example, 
      `{'compressor': 'onebit', 'ef': 'vanilla', 'momentum': 'nesterov', 'scaling': true}`.
      All compressor accept 'compressor', 'ef'. See each compressor's constructor for a list 
      of additional supported arguments
class_docstr_tok: ["A","subclass","of","MXNet","gluon.Trainer",".","There","are","two","differences","between","DistributedTrainer","and","Trainer",":","1",".","DistributedTrainer","calculates","gradients","using","BytePS","push","pull","API","while","Trainer","does","it","using","kvstore","push\/pull","APIs",";","2",".","DistributedTrainer","performs","push_pull","(","summation",")","and","average",",","while","Trainer","only","performs","push_pull","(","summation",")",".","Parameters","--","--","--","--","--","params",":","ParameterDict","The","set","of","parameters","to","optimize",".","optimizer",":","str","or","Optimizer","The","optimizer","to","use",".","See","`","help","<","http",":","\/\/mxnet.io\/api\/python\/optimization\/optimization.html","#","the-mxnet-optimizer-package",">","`","_","on","Optimizer","for","a","list","of","available","optimizers",".","optimizer_params",":","dict","Key-word","arguments","to","be","passed","to","optimizer","constructor",".","For","example",",","`","{","'learning_rate","'",":","0.1","}","`",".","All","optimizers","accept","learning_rate",",","wd","(","weight","decay",")",",","clip_gradient",",","and","lr_scheduler",".","See","each","optimizer's","constructor","for","a","list","of","additional","supported","arguments","root_rank",":","int","rank","of","root","compression_params",":","dict","Key-word","arguments","to","be","passed","to","gradient","compression","constructor",".","For","example",",","`","{","'compressor","'",":","'onebit","'",",","'ef","'",":","'vanilla","'",",","'momentum","'",":","'nesterov","'",",","'scaling","'",":","true","}","`",".","All","compressor","accept","'compressor","'",",","'ef","'",".","See","each","compressor","'s","constructor","for","a","list","of","additional","supported","arguments"]
docstr: Register compressor for BytePS
  
  params : mx.gluon.ParameterDict 
  optimizer_params : dict
  compression_params : dict
docstr_tok: ["Register","compressor","for","BytePS","params",":","mx.gluon.ParameterDict","optimizer_params",":","dict","compression_params",":","dict"]
code: def _register_compressor(
      self, params, optimizer_params, compression_params
  ):
      """Register compressor for BytePS
  
      params : mx.gluon.ParameterDict
      optimizer_params : dict
      compression_params : dict
      """
      intra_compressor = Compression.none
      if not compression_params:
          return intra_compressor
  
      if compression_params.get("fp16"):
          intra_compressor = Compression.fp16
  
      if "compressor" not in compression_params:
          warnings.warn("Compressor is not defined")
          return intra_compressor
  
      check_list = ["compressor", "ef", "momentum"]
  
      for _, param in params.items():
          # generic
          for item in check_list:
              if compression_params.get(item):
                  if isinstance(compression_params[item], str):
                      setattr(
                          param,
                          "byteps_%s_type" % item,
                          compression_params[item],
                      )
                  else:
                      raise TypeError("%s should be str" % item)
  
          # need parameter
          compressor = compression_params["compressor"]
          if compressor == "onebit":
              setattr(
                  param,
                  "byteps_compressor_onebit_scaling",
                  str(compression_params.get("scaling", False)),
              )
          elif (
              compressor == "topk"
              or compressor == "randomk"
              or compressor == "dithering"
          ):
              # raise KeyError if 'k' is not found
              setattr(
                  param, "byteps_compressor_k", compression_params["k"]
              )
  
          if compression_params.get("momentum"):
              setattr(
                  param,
                  "byteps_momentum_mu",
                  optimizer_params["momentum"],
              )
  
          if compression_params.get("seed", None) is not None:
              setattr(param, "byteps_seed", compression_params["seed"])
  
          if compression_params.get("partition"):
              if compression_params["partition"] == "linear":
                  setattr(param, "byteps_dithering_partition", "0")
              elif compression_params["partition"] == "natural":
                  setattr(param, "byteps_dithering_partition", "1")
              else:
                  raise ValueError("Unsupported partition")
  
          if compression_params.get("normalize"):
              if compression_params["normalize"] == "max":
                  setattr(param, "byteps_dithering_normalize", "0")
              elif compression_params["normalize"] == "l2":
                  setattr(param, "byteps_dithering_normalize", "1")
              else:
                  raise ValueError("Unsupported normalization")
  
      # the following code will delete some items in `optimizer_params`
      # to avoid duplication
      if compression_params.get("momentum"):
          threshold = int(
              os.environ.get("BYTEPS_MIN_COMPRESS_BYTES", 65536)
          )
          mu = optimizer_params["momentum"]
  
          # 1bit compressor use an additional momentum for weight decay
          if compressor == "onebit" and "wd" in optimizer_params:
              wd = optimizer_params["wd"]
              intra_compressor = Compression.wdmom(
                  intra_compressor, mu, wd, threshold
              )
              del optimizer_params["wd"]
  
          intra_compressor = Compression.nag(
              intra_compressor, mu, threshold
          )
          del optimizer_params["momentum"]
  
      return intra_compressor
  
imports: from __future__ import absolute_import, division, print_function
  import copy
  import os
  import struct
  import warnings
  import mxnet
  import mxnet.ndarray
  from byteps.mxnet.compression import Compression
  from byteps.mxnet.ops import byteps_declare_tensor, byteps_push_pull, init, local_rank, local_size, rank, resume, shutdown, size, suspend
label_desc: Use image node_id 3 for calling the DistributedTrainer obj's underlying member method code with example usage: obj._register_compressor(params, optimizer_params, compression_params) and returns: intra_compressor, intra_compressor, intra_compressor