# Buggy 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 "fp16" in compression_params:
        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 item in compression_params:
                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 == "multibit"
        ):
            # raise KeyError if 'k' is not found
            setattr(param, "byteps_compressor_k", compression_params["k"])

        if "momentum" in compression_params:
            setattr(param, "byteps_momentum_mu", optimizer_params["momentum"])

    # change
    if "momentum" in compression_params:
        # 1bit compressor use an additional momentum for weight decay
        if compressor == "onebit" and "wd" in optimizer_params:
            intra_compressor = Compression.wdmom(
                intra_compressor, optimizer_params["momentum"], optimizer_params["wd"]
            )
            del optimizer_params["wd"]

        del optimizer_params["momentum"]

    return intra_compressor


# Traceback (TypeError)
In [1]: import tensorflow as tf

In [2]: import byteps.tensorflow as bps
WARNING: Logging before flag parsing goes to stderr.
W0627 11:36:47.010180 139917697820480 deprecation_wrapper.py:119] From /private/home/yuxinwu/.local/lib/python3.6/site-packages/byteps/tensorflow/__init__.py:79: The name tf.train.SessionRunHook is deprecated. Please use tf.estimator.SessionRunHook instead.

W0627 11:36:47.010504 139917697820480 deprecation_wrapper.py:119] From /private/home/yuxinwu/.local/lib/python3.6/site-packages/byteps/tensorflow/__init__.py:111: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.


In [3]: bps.push_pull(tf.constant([0.0]))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-fc0e9eb4f2bb> in <module>()
----> 1 bps.push_pull(tf.constant([0.0]))

~/.local/lib/python3.6/site-packages/byteps/tensorflow/__init__.py in push_pull(tensor, scope, average, device_dense, device_sparse, compression)
50         byteps_size = tf.cast(size(), dtype=tensor.dtype)
51         tensor_compressed, ctx = compression.compress(tensor)
---> 52         summed_tensor_compressed = _push_pull(tensor_compressed, scope)
53         summed_tensor = compression.decompress(summed_tensor_compressed, ctx)
54         new_tensor = (tf.div(summed_tensor, byteps_size)

~/.local/lib/python3.6/site-packages/byteps/tensorflow/ops.py in _push_pull(tensor, scope, name)
80     if name is None and not _executing_eagerly():
81         name = 'BytePSPushPull_%s' % _normalize_name(tensor.name)
---> 82     TF_LIB_CTYPES.byteps_tensorflow_declare_tensor(ctypes.c_char_p(scope+name))
83     return C_LIB.byteps_push_pull(tensor, name=name)
84

TypeError: bytes or integer address expected instead of str instance

# Fixed 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 "fp16" in compression_params:
        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 item in compression_params and compression_params[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 == "multibit"
        ):
            # raise KeyError if 'k' is not found
            setattr(param, "byteps_compressor_k", compression_params["k"])

        if "momentum" in compression_params:
            setattr(param, "byteps_momentum_mu", optimizer_params["momentum"])

    # change
    if "momentum" in compression_params:
        # 1bit compressor use an additional momentum for weight decay
        if compressor == "onebit" and "wd" in optimizer_params:
            intra_compressor = Compression.wdmom(
                intra_compressor, optimizer_params["momentum"], optimizer_params["wd"]
            )
            del optimizer_params["wd"]

        del optimizer_params["momentum"]

    return intra_compressor