Repository: sql-machine-learning/elasticdl

Issue:
Print information on master and worker
Both master and worker have a lot of command-line options.  Print values of these options to help users trace problems if there exists any.
Print information on master and worker
Both master and worker have a lot of command-line options.  Print values of these options to help users trace problems if there exists any.


Discussion:

Resolving patch:
diff --git a/elasticdl/python/common/args.py b/elasticdl/python/common/args.py
--- a/elasticdl/python/common/args.py
+++ b/elasticdl/python/common/args.py
@@ -1,3 +1,44 @@
+from elasticdl.python.common.log_util import default_logger as logger
+
+MODEL_SPEC_GROUP = [
+    "dataset_fn",
+    "eval_metrics_fn",
+    "model_def",
+    "model_params",
+    "optimizer",
+    "loss",
+    "output",
+    "minibatch_size",
+    "grads_to_wait",
+    "num_epochs",
+    "tensorboard_log_dir",
+    "training_data_dir",
+]
+
+EVALUATION_GROUP = [
+    "evaluation_steps",
+    "evaluation_data_dir",
+    "evaluation_start_delay_secs",
+    "evaluation_throttle_secs",
+]
+
+PREDICTION_GROUP = ["prediction_data_dir"]
+
+CHECKPOINT_GROUP = [
+    "checkpoint_filename_for_init",
+    "checkpoint_steps",
+    "keep_checkpoint_max",
+    "checkpoint_dir",
+]
+
+ALL_ARGS_GROUPS = [
+    MODEL_SPEC_GROUP,
+    EVALUATION_GROUP,
+    PREDICTION_GROUP,
+    CHECKPOINT_GROUP,
+]
+
+
 def pos_int(arg):
     res = int(arg)
     if res <= 0:
@@ -283,3 +324,34 @@ def add_predict_params(parser):
         help="The checkpoint file to initialize the training model",
         required=True,
     )
+
+
+def print_args(args, groups=None):
+    """
+    Args:
+        args: parsing results returned from `parser.parse_args`
+        groups: It is a list of a list. It controls which options should be
+        printed together. For example, we expect all model specifications such
+        as `optimizer`, `loss` are better printed together.
+        groups = [["optimizer", "loss"]]
+    """
+
+    def _get_attr(instance, attribute):
+        try:
+            return getattr(instance, attribute)
+        except AttributeError:
+            return None
+
+    dedup = set()
+    if groups:
+        for group in groups:
+            for element in group:
+                dedup.add(element)
+                logger.info("%s = %s", element, _get_attr(args, element))
+    other_options = [
+        (key, value)
+        for (key, value) in args.__dict__.items()
+        if key not in dedup
+    ]
+    for key, value in other_options:
+        logger.info("%s = %s", key, value)
diff --git a/elasticdl/python/master/args.py b/elasticdl/python/master/args.py
--- a/elasticdl/python/master/args.py
+++ b/elasticdl/python/master/args.py
@@ -1,9 +1,11 @@
 import argparse
 
 from elasticdl.python.common.args import (
+    ALL_ARGS_GROUPS,
     add_common_params,
     add_train_params,
     pos_int,
+    print_args,
 )
 
 
@@ -37,6 +39,7 @@ def parse_args():
     add_train_params(parser)
 
     args = parser.parse_args()
+    print_args(args, groups=ALL_ARGS_GROUPS)
 
     if all(
         v == "" or v is None
diff --git a/elasticdl/python/worker/main.py b/elasticdl/python/worker/main.py
--- a/elasticdl/python/worker/main.py
+++ b/elasticdl/python/worker/main.py
@@ -3,6 +3,7 @@
 import grpc
 
 from elasticdl.python.common import log_util
+from elasticdl.python.common.args import ALL_ARGS_GROUPS, print_args
 from elasticdl.python.common.constants import GRPC
 from elasticdl.python.worker.worker import Worker
 
@@ -85,6 +86,7 @@ def _parse_args():
 
 def main():
     args = _parse_args()
+    print_args(args, groups=ALL_ARGS_GROUPS)
     channel = grpc.insecure_channel(
         args.master_addr,
         options=[


Test patch: