# Buggy code
def __init__(
    self,
    model_file,
    channel=None,
    max_retrain_num=DEFAULT_MAX_MINIBATCH_RETRAIN_NUM,
    codec_type=None,
):
    """
    Arguments:
        model_module: A module to define the model
        channel: grpc channel
        max_retrain_num: max number of a minibatch retrain as its gradients are not accepted by master
    """

    model_module = load_user_model(model_file)
    self._model = model_module.model
    self._feature_columns = model_module.feature_columns()
    self._all_columns = self._feature_columns + model_module.label_columns()
    build_model(self._model, self._feature_columns)
    self._input_fn = model_module.input_fn
    self._opt_fn = model_module.optimizer
    self._loss = model_module.loss

    if channel is None:
        self._stub = None
    else:
        self._stub = master_pb2_grpc.MasterStub(channel)
    self._max_retrain_num = max_retrain_num
    self._model_version = -1
    self._codec_type = codec_type


# Traceback (AssertionError)
python -m unittest elasticdl/worker/*_test.py
/usr/local/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
2019-05-21 13:57:07.262725: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
WARNING:tensorflow:From /usr/local/anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:642: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
must be str, not NoneType
FLoss is  3.090042
Loss is  1.4608976
Loss is  0.913306
Loss is  0.5969497
Loss is  0.66515267
Loss is  0.3935135
Loss is  0.37774342
Loss is  0.289928
.
======================================================================
FAIL: test_distributed_train (elasticdl.worker.worker_test.WorkerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/l.zou/git/elasticdl/elasticdl/worker/worker_test.py", line 96, in test_distributed_train
self.assertTrue(res)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 2 tests in 0.165s

# Fixed code
def __init__(
    self,
    model_file,
    channel=None,
    max_retrain_num=DEFAULT_MAX_MINIBATCH_RETRAIN_NUM,
    codec_type=None,
):
    """
    Arguments:
        model_module: A module to define the model
        channel: grpc channel
        max_retrain_num: max number of a minibatch retrain as its gradients are not accepted by master
    """
    model_module = load_user_model(model_file)
    self._model = model_module.model
    self._feature_columns = model_module.feature_columns()
    build_model(self._model, self._feature_columns)
    self._input_fn = model_module.input_fn
    self._opt_fn = model_module.optimizer
    self._loss = model_module.loss
    all_columns = self._feature_columns + model_module.label_columns()
    if codec_type == "tf_example":
        self._codec = TFExampleCodec(all_columns)
    elif codec_type == "bytes":
        self._codec = BytesCodec(all_columns)
    else:
        raise ValueError("invalid codec_type: " + codec_type)

    if channel is None:
        self._stub = None
    else:
        self._stub = master_pb2_grpc.MasterStub(channel)
    self._max_retrain_num = max_retrain_num
    self._model_version = -1
    self._codec_type = codec_type