We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Move _pos_int and _non_neg_int to python/common/args.py
`_pos_int` and `_non_neg_int` should be common functions

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `elasticdl/python/master/args.py`
Content:
```
1 import argparse
2 
3 from elasticdl.python.common.args import add_common_params, add_train_params
4 
5 
6 def _pos_int(arg):
7     res = int(arg)
8     if res <= 0:
9         raise ValueError("Positive integer argument required. Got %s" % res)
10     return res
11 
12 
13 def _non_neg_int(arg):
14     res = int(arg)
15     if res < 0:
16         raise ValueError(
17             "Non-negative integer argument required. Get %s" % res
18         )
19     return res
20 
21 
22 def parse_args():
23     parser = argparse.ArgumentParser(description="ElasticDL Master")
24     parser.add_argument(
25         "--port",
26         default=50001,
27         type=_pos_int,
28         help="The listening port of master",
29     )
30     parser.add_argument(
31         "--worker_image", help="Docker image for workers", default=None
32     )
33     parser.add_argument(
34         "--worker_pod_priority", help="Priority requested by workers"
35     )
36     parser.add_argument(
37         "--prediction_data_dir",
38         help="Prediction data directory. Files should be in RecordIO format",
39         default="",
40     )
41     parser.add_argument(
42         "--log_level",
43         choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
44         type=str.upper,
45         default="INFO",
46         help="The logging level. Default to WARNING",
47     )
48     add_common_params(parser)
49     add_train_params(parser)
50 
51     args = parser.parse_args()
52 
53     if all(
54         v == "" or v is None
55         for v in [
56             args.training_data_dir,
57             args.evaluation_data_dir,
58             args.prediction_data_dir,
59         ]
60     ):
61         raise ValueError(
62             "At least one of the data directories needs to be provided"
63         )
64 
65     if args.prediction_data_dir and (
66         args.training_data_dir or args.evaluation_data_dir
67     ):
68         raise ValueError(
69             "Running prediction together with training or evaluation "
70             "is not supported"
71         )
72     if args.prediction_data_dir and not args.checkpoint_filename_for_init:
73         raise ValueError(
74             "checkpoint_filename_for_init is required for running "
75             "prediction job"
76         )
77 
78     return args
79
```

Path: `elasticdl/python/common/args.py`
Content:
```
1 def add_common_params(parser):
2     parser.add_argument(
3         "--model_zoo",
4         help="The directory that contains user-defined model files "
5         "or a specific model file",
6         required=True,
7     )
8     parser.add_argument(
9         "--docker_image_prefix",
10         default="",
11         help="The prefix for generated Docker images, if set, the image is "
12         "also pushed to the registry",
13     )
14     parser.add_argument("--image_base", help="Base Docker image.")
15     parser.add_argument("--job_name", help="ElasticDL job name", required=True)
16     parser.add_argument(
17         "--master_resource_request",
18         default="cpu=0.1,memory=1024Mi",
19         type=str,
20         help="The minimal resource required by master, "
21         "e.g. cpu=0.1,memory=1024Mi,disk=1024Mi,gpu=1",
22     )
23     parser.add_argument(
24         "--master_resource_limit",
25         type=str,
26         help="The maximal resource required by master, "
27         "e.g. cpu=0.1,memory=1024Mi,disk=1024Mi,gpu=1, "
28         "default to master_resource_request",
29     )
30     parser.add_argument(
31         "--num_workers", type=int, help="Number of workers", default=0
32     )
33     parser.add_argument(
34         "--worker_resource_request",
35         default="cpu=1,memory=4096Mi",
36         type=str,
37         help="The minimal resource required by worker, "
38         "e.g. cpu=1,memory=1024Mi,disk=1024Mi,gpu=1",
39     )
40     parser.add_argument(
41         "--worker_resource_limit",
42         type=str,
43         help="The maximal resource required by worker, "
44         "e.g. cpu=1,memory=1024Mi,disk=1024Mi,gpu=1,"
45         "default to worker_resource_request",
46     )
47     parser.add_argument(
48         "--master_pod_priority", help="The requested priority of master pod"
49     )
50     parser.add_argument(
51         "--volume",
52         help="The Kubernetes volume information, "
53         'e.g. "claim_name=c1,mount_path=/path1".',
54     )
55     parser.add_argument(
56         "--image_pull_policy",
57         default="Always",
58         help="The image pull policy of master and worker",
59     )
60     parser.add_argument(
61         "--restart_policy",
62         default="Never",
63         help="The pod restart policy when pod crashed",
64     )
65     parser.add_argument(
66         "--extra_pypi_index", help="The extra python package repository"
67     )
68     parser.add_argument(
69         "--namespace",
70         default="default",
71         type=str,
72         help="The name of the Kubernetes namespace where ElasticDL "
73         "pods will be created",
74     )
75     parser.add_argument("--records_per_task", type=int, required=True)
76     parser.add_argument(
77         "--minibatch_size",
78         type=int,
79         help="Minibatch size used by workers",
80         required=True,
81     )
82     parser.add_argument(
83         "--dataset_fn",
84         type=str,
85         default="dataset_fn",
86         help="The name of the dataset function defined in the model file",
87     )
88     parser.add_argument(
89         "--eval_metrics_fn",
90         type=str,
91         default="eval_metrics_fn",
92         help="The name of the evaluation metrics function defined "
93         "in the model file",
94     )
95     parser.add_argument(
96         "--model_def",
97         type=str,
98         required=True,
99         help="The import path to the model definition function/class in the "
100         'model zoo, e.g. "cifar10_subclass.cifar10_subclass.CustomModel"',
101     )
102     parser.add_argument(
103         "--model_params",
104         type=str,
105         default="",
106         help="The dictionary of model parameters in a string that will be "
107         'used to instantiate the model, e.g. "param1=1,param2=2"',
108     )
109     parser.add_argument(
110         "--cluster_spec",
111         help="The file that contains user-defined cluster specification",
112         default="",
113     )
114 
115 
116 def add_train_params(parser):
117     parser.add_argument(
118         "--tensorboard_log_dir",
119         default="",
120         type=str,
121         help="Directory where TensorBoard will look to find "
122         "TensorFlow event files that it can display. "
123         "TensorBoard will recursively walk the directory "
124         "structure rooted at log dir, looking for .*tfevents.* "
125         "files. You may also pass a comma separated list of log "
126         "directories, and TensorBoard will watch each "
127         "directory.",
128     )
129     parser.add_argument("--num_epochs", type=int, default=1)
130     parser.add_argument(
131         "--grads_to_wait",
132         type=int,
133         help="Number of gradients to wait before updating model",
134         default=2,
135     )
136     parser.add_argument(
137         "--training_data_dir",
138         help="Training data directory. Files should be in RecordIO format",
139         default="",
140     )
141     parser.add_argument(
142         "--evaluation_data_dir",
143         help="Evaluation data directory. Files should be in RecordIO format",
144         default="",
145     )
146     parser.add_argument(
147         "--evaluation_steps",
148         type=int,
149         help="Evaluate the model every this many steps."
150         "If 0, step-based evaluation is disabled",
151         default=0,
152     )
153     parser.add_argument(
154         "--evaluation_start_delay_secs",
155         type=int,
156         help="Start time-based evaluation only after waiting for "
157         "this many seconds",
158         default=100,
159     )
160     parser.add_argument(
161         "--evaluation_throttle_secs",
162         type=int,
163         help="Do not re-evaluate unless the last evaluation was started "
164         "at least this many seconds ago."
165         "If 0, time-based evaluation is disabled",
166         default=0,
167     )
168     parser.add_argument(
169         "--checkpoint_steps",
170         type=int,
171         help="Save checkpoint every this many steps."
172         "If 0, no checkpoints to save.",
173         default=0,
174     )
175     parser.add_argument(
176         "--checkpoint_dir",
177         help="The directory to store the checkpoint files",
178         default="",
179     )
180     parser.add_argument(
181         "--keep_checkpoint_max",
182         type=int,
183         help="The maximum number of recent checkpoint files to keep."
184         "If 0, keep all.",
185         default=0,
186     )
187     parser.add_argument(
188         "--checkpoint_filename_for_init",
189         help="The checkpoint file to initialize the training model",
190         default="",
191     )
192     parser.add_argument(
193         "--loss",
194         type=str,
195         default="loss",
196         help="The name of the loss function defined in the model file",
197     )
198     parser.add_argument(
199         "--optimizer",
200         type=str,
201         default="optimizer",
202         help="The name of the optimizer defined in the model file",
203     )
204     parser.add_argument(
205         "--output",
206         type=str,
207         default="",
208         help="The path to save the final trained model",
209     )
210 
211 
212 def add_evaluate_params(parser):
213     parser.add_argument(
214         "--evaluation_data_dir",
215         help="Evaluation data directory. Files should be in RecordIO format",
216         required=True,
217     )
218     parser.add_argument(
219         "--checkpoint_filename_for_init",
220         help="The checkpoint file to initialize the training model",
221         required=True,
222     )
223 
224 
225 def add_predict_params(parser):
226     parser.add_argument(
227         "--prediction_data_dir",
228         help="Prediction data directory. Files should be in RecordIO format",
229         required=True,
230     )
231     parser.add_argument(
232         "--checkpoint_filename_for_init",
233         help="The checkpoint file to initialize the training model",
234         required=True,
235     )
236
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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,19 @@
+def pos_int(arg):
+    res = int(arg)
+    if res <= 0:
+        raise ValueError("Positive integer argument required. Got %s" % res)
+    return res
+
+
+def non_neg_int(arg):
+    res = int(arg)
+    if res < 0:
+        raise ValueError(
+            "Non-negative integer argument required. Get %s" % res
+        )
+    return res
+
+
 def add_common_params(parser):
     parser.add_argument(
         "--model_zoo",
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,22 +1,10 @@
 import argparse
 
-from elasticdl.python.common.args import add_common_params, add_train_params
-
-
-def _pos_int(arg):
-    res = int(arg)
-    if res <= 0:
-        raise ValueError("Positive integer argument required. Got %s" % res)
-    return res
-
-
-def _non_neg_int(arg):
-    res = int(arg)
-    if res < 0:
-        raise ValueError(
-            "Non-negative integer argument required. Get %s" % res
-        )
-    return res
+from elasticdl.python.common.args import (
+    add_common_params,
+    add_train_params,
+    pos_int,
+)
 
 
 def parse_args():
@@ -24,7 +12,7 @@
     parser.add_argument(
         "--port",
         default=50001,
-        type=_pos_int,
+        type=pos_int,
         help="The listening port of master",
     )
     parser.add_argument(

{"golden_diff": "diff --git a/elasticdl/python/common/args.py b/elasticdl/python/common/args.py\n--- a/elasticdl/python/common/args.py\n+++ b/elasticdl/python/common/args.py\n@@ -1,3 +1,19 @@\n+def pos_int(arg):\n+    res = int(arg)\n+    if res <= 0:\n+        raise ValueError(\"Positive integer argument required. Got %s\" % res)\n+    return res\n+\n+\n+def non_neg_int(arg):\n+    res = int(arg)\n+    if res < 0:\n+        raise ValueError(\n+            \"Non-negative integer argument required. Get %s\" % res\n+        )\n+    return res\n+\n+\n def add_common_params(parser):\n     parser.add_argument(\n         \"--model_zoo\",\ndiff --git a/elasticdl/python/master/args.py b/elasticdl/python/master/args.py\n--- a/elasticdl/python/master/args.py\n+++ b/elasticdl/python/master/args.py\n@@ -1,22 +1,10 @@\n import argparse\n \n-from elasticdl.python.common.args import add_common_params, add_train_params\n-\n-\n-def _pos_int(arg):\n-    res = int(arg)\n-    if res <= 0:\n-        raise ValueError(\"Positive integer argument required. Got %s\" % res)\n-    return res\n-\n-\n-def _non_neg_int(arg):\n-    res = int(arg)\n-    if res < 0:\n-        raise ValueError(\n-            \"Non-negative integer argument required. Get %s\" % res\n-        )\n-    return res\n+from elasticdl.python.common.args import (\n+    add_common_params,\n+    add_train_params,\n+    pos_int,\n+)\n \n \n def parse_args():\n@@ -24,7 +12,7 @@\n     parser.add_argument(\n         \"--port\",\n         default=50001,\n-        type=_pos_int,\n+        type=pos_int,\n         help=\"The listening port of master\",\n     )\n     parser.add_argument(\n", "issue": "Move _pos_int and _non_neg_int to python/common/args.py\n`_pos_int` and `_non_neg_int` should be common functions\n", "before_files": [{"content": "import argparse\n\nfrom elasticdl.python.common.args import add_common_params, add_train_params\n\n\ndef _pos_int(arg):\n    res = int(arg)\n    if res <= 0:\n        raise ValueError(\"Positive integer argument required. Got %s\" % res)\n    return res\n\n\ndef _non_neg_int(arg):\n    res = int(arg)\n    if res < 0:\n        raise ValueError(\n            \"Non-negative integer argument required. Get %s\" % res\n        )\n    return res\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(description=\"ElasticDL Master\")\n    parser.add_argument(\n        \"--port\",\n        default=50001,\n        type=_pos_int,\n        help=\"The listening port of master\",\n    )\n    parser.add_argument(\n        \"--worker_image\", help=\"Docker image for workers\", default=None\n    )\n    parser.add_argument(\n        \"--worker_pod_priority\", help=\"Priority requested by workers\"\n    )\n    parser.add_argument(\n        \"--prediction_data_dir\",\n        help=\"Prediction data directory. Files should be in RecordIO format\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--log_level\",\n        choices=[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"],\n        type=str.upper,\n        default=\"INFO\",\n        help=\"The logging level. Default to WARNING\",\n    )\n    add_common_params(parser)\n    add_train_params(parser)\n\n    args = parser.parse_args()\n\n    if all(\n        v == \"\" or v is None\n        for v in [\n            args.training_data_dir,\n            args.evaluation_data_dir,\n            args.prediction_data_dir,\n        ]\n    ):\n        raise ValueError(\n            \"At least one of the data directories needs to be provided\"\n        )\n\n    if args.prediction_data_dir and (\n        args.training_data_dir or args.evaluation_data_dir\n    ):\n        raise ValueError(\n            \"Running prediction together with training or evaluation \"\n            \"is not supported\"\n        )\n    if args.prediction_data_dir and not args.checkpoint_filename_for_init:\n        raise ValueError(\n            \"checkpoint_filename_for_init is required for running \"\n            \"prediction job\"\n        )\n\n    return args\n", "path": "elasticdl/python/master/args.py"}, {"content": "def add_common_params(parser):\n    parser.add_argument(\n        \"--model_zoo\",\n        help=\"The directory that contains user-defined model files \"\n        \"or a specific model file\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--docker_image_prefix\",\n        default=\"\",\n        help=\"The prefix for generated Docker images, if set, the image is \"\n        \"also pushed to the registry\",\n    )\n    parser.add_argument(\"--image_base\", help=\"Base Docker image.\")\n    parser.add_argument(\"--job_name\", help=\"ElasticDL job name\", required=True)\n    parser.add_argument(\n        \"--master_resource_request\",\n        default=\"cpu=0.1,memory=1024Mi\",\n        type=str,\n        help=\"The minimal resource required by master, \"\n        \"e.g. cpu=0.1,memory=1024Mi,disk=1024Mi,gpu=1\",\n    )\n    parser.add_argument(\n        \"--master_resource_limit\",\n        type=str,\n        help=\"The maximal resource required by master, \"\n        \"e.g. cpu=0.1,memory=1024Mi,disk=1024Mi,gpu=1, \"\n        \"default to master_resource_request\",\n    )\n    parser.add_argument(\n        \"--num_workers\", type=int, help=\"Number of workers\", default=0\n    )\n    parser.add_argument(\n        \"--worker_resource_request\",\n        default=\"cpu=1,memory=4096Mi\",\n        type=str,\n        help=\"The minimal resource required by worker, \"\n        \"e.g. cpu=1,memory=1024Mi,disk=1024Mi,gpu=1\",\n    )\n    parser.add_argument(\n        \"--worker_resource_limit\",\n        type=str,\n        help=\"The maximal resource required by worker, \"\n        \"e.g. cpu=1,memory=1024Mi,disk=1024Mi,gpu=1,\"\n        \"default to worker_resource_request\",\n    )\n    parser.add_argument(\n        \"--master_pod_priority\", help=\"The requested priority of master pod\"\n    )\n    parser.add_argument(\n        \"--volume\",\n        help=\"The Kubernetes volume information, \"\n        'e.g. \"claim_name=c1,mount_path=/path1\".',\n    )\n    parser.add_argument(\n        \"--image_pull_policy\",\n        default=\"Always\",\n        help=\"The image pull policy of master and worker\",\n    )\n    parser.add_argument(\n        \"--restart_policy\",\n        default=\"Never\",\n        help=\"The pod restart policy when pod crashed\",\n    )\n    parser.add_argument(\n        \"--extra_pypi_index\", help=\"The extra python package repository\"\n    )\n    parser.add_argument(\n        \"--namespace\",\n        default=\"default\",\n        type=str,\n        help=\"The name of the Kubernetes namespace where ElasticDL \"\n        \"pods will be created\",\n    )\n    parser.add_argument(\"--records_per_task\", type=int, required=True)\n    parser.add_argument(\n        \"--minibatch_size\",\n        type=int,\n        help=\"Minibatch size used by workers\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--dataset_fn\",\n        type=str,\n        default=\"dataset_fn\",\n        help=\"The name of the dataset function defined in the model file\",\n    )\n    parser.add_argument(\n        \"--eval_metrics_fn\",\n        type=str,\n        default=\"eval_metrics_fn\",\n        help=\"The name of the evaluation metrics function defined \"\n        \"in the model file\",\n    )\n    parser.add_argument(\n        \"--model_def\",\n        type=str,\n        required=True,\n        help=\"The import path to the model definition function/class in the \"\n        'model zoo, e.g. \"cifar10_subclass.cifar10_subclass.CustomModel\"',\n    )\n    parser.add_argument(\n        \"--model_params\",\n        type=str,\n        default=\"\",\n        help=\"The dictionary of model parameters in a string that will be \"\n        'used to instantiate the model, e.g. \"param1=1,param2=2\"',\n    )\n    parser.add_argument(\n        \"--cluster_spec\",\n        help=\"The file that contains user-defined cluster specification\",\n        default=\"\",\n    )\n\n\ndef add_train_params(parser):\n    parser.add_argument(\n        \"--tensorboard_log_dir\",\n        default=\"\",\n        type=str,\n        help=\"Directory where TensorBoard will look to find \"\n        \"TensorFlow event files that it can display. \"\n        \"TensorBoard will recursively walk the directory \"\n        \"structure rooted at log dir, looking for .*tfevents.* \"\n        \"files. You may also pass a comma separated list of log \"\n        \"directories, and TensorBoard will watch each \"\n        \"directory.\",\n    )\n    parser.add_argument(\"--num_epochs\", type=int, default=1)\n    parser.add_argument(\n        \"--grads_to_wait\",\n        type=int,\n        help=\"Number of gradients to wait before updating model\",\n        default=2,\n    )\n    parser.add_argument(\n        \"--training_data_dir\",\n        help=\"Training data directory. Files should be in RecordIO format\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--evaluation_data_dir\",\n        help=\"Evaluation data directory. Files should be in RecordIO format\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--evaluation_steps\",\n        type=int,\n        help=\"Evaluate the model every this many steps.\"\n        \"If 0, step-based evaluation is disabled\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--evaluation_start_delay_secs\",\n        type=int,\n        help=\"Start time-based evaluation only after waiting for \"\n        \"this many seconds\",\n        default=100,\n    )\n    parser.add_argument(\n        \"--evaluation_throttle_secs\",\n        type=int,\n        help=\"Do not re-evaluate unless the last evaluation was started \"\n        \"at least this many seconds ago.\"\n        \"If 0, time-based evaluation is disabled\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--checkpoint_steps\",\n        type=int,\n        help=\"Save checkpoint every this many steps.\"\n        \"If 0, no checkpoints to save.\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--checkpoint_dir\",\n        help=\"The directory to store the checkpoint files\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--keep_checkpoint_max\",\n        type=int,\n        help=\"The maximum number of recent checkpoint files to keep.\"\n        \"If 0, keep all.\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--checkpoint_filename_for_init\",\n        help=\"The checkpoint file to initialize the training model\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--loss\",\n        type=str,\n        default=\"loss\",\n        help=\"The name of the loss function defined in the model file\",\n    )\n    parser.add_argument(\n        \"--optimizer\",\n        type=str,\n        default=\"optimizer\",\n        help=\"The name of the optimizer defined in the model file\",\n    )\n    parser.add_argument(\n        \"--output\",\n        type=str,\n        default=\"\",\n        help=\"The path to save the final trained model\",\n    )\n\n\ndef add_evaluate_params(parser):\n    parser.add_argument(\n        \"--evaluation_data_dir\",\n        help=\"Evaluation data directory. Files should be in RecordIO format\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--checkpoint_filename_for_init\",\n        help=\"The checkpoint file to initialize the training model\",\n        required=True,\n    )\n\n\ndef add_predict_params(parser):\n    parser.add_argument(\n        \"--prediction_data_dir\",\n        help=\"Prediction data directory. Files should be in RecordIO format\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--checkpoint_filename_for_init\",\n        help=\"The checkpoint file to initialize the training model\",\n        required=True,\n    )\n", "path": "elasticdl/python/common/args.py"}], "after_files": [{"content": "import argparse\n\nfrom elasticdl.python.common.args import (\n    add_common_params,\n    add_train_params,\n    pos_int,\n)\n\n\ndef parse_args():\n    parser = argparse.ArgumentParser(description=\"ElasticDL Master\")\n    parser.add_argument(\n        \"--port\",\n        default=50001,\n        type=pos_int,\n        help=\"The listening port of master\",\n    )\n    parser.add_argument(\n        \"--worker_image\", help=\"Docker image for workers\", default=None\n    )\n    parser.add_argument(\n        \"--worker_pod_priority\", help=\"Priority requested by workers\"\n    )\n    parser.add_argument(\n        \"--prediction_data_dir\",\n        help=\"Prediction data directory. Files should be in RecordIO format\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--log_level\",\n        choices=[\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"],\n        type=str.upper,\n        default=\"INFO\",\n        help=\"The logging level. Default to WARNING\",\n    )\n    add_common_params(parser)\n    add_train_params(parser)\n\n    args = parser.parse_args()\n\n    if all(\n        v == \"\" or v is None\n        for v in [\n            args.training_data_dir,\n            args.evaluation_data_dir,\n            args.prediction_data_dir,\n        ]\n    ):\n        raise ValueError(\n            \"At least one of the data directories needs to be provided\"\n        )\n\n    if args.prediction_data_dir and (\n        args.training_data_dir or args.evaluation_data_dir\n    ):\n        raise ValueError(\n            \"Running prediction together with training or evaluation \"\n            \"is not supported\"\n        )\n    if args.prediction_data_dir and not args.checkpoint_filename_for_init:\n        raise ValueError(\n            \"checkpoint_filename_for_init is required for running \"\n            \"prediction job\"\n        )\n\n    return args\n", "path": "elasticdl/python/master/args.py"}, {"content": "def pos_int(arg):\n    res = int(arg)\n    if res <= 0:\n        raise ValueError(\"Positive integer argument required. Got %s\" % res)\n    return res\n\n\ndef non_neg_int(arg):\n    res = int(arg)\n    if res < 0:\n        raise ValueError(\n            \"Non-negative integer argument required. Get %s\" % res\n        )\n    return res\n\n\ndef add_common_params(parser):\n    parser.add_argument(\n        \"--model_zoo\",\n        help=\"The directory that contains user-defined model files \"\n        \"or a specific model file\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--docker_image_prefix\",\n        default=\"\",\n        help=\"The prefix for generated Docker images, if set, the image is \"\n        \"also pushed to the registry\",\n    )\n    parser.add_argument(\"--image_base\", help=\"Base Docker image.\")\n    parser.add_argument(\"--job_name\", help=\"ElasticDL job name\", required=True)\n    parser.add_argument(\n        \"--master_resource_request\",\n        default=\"cpu=0.1,memory=1024Mi\",\n        type=str,\n        help=\"The minimal resource required by master, \"\n        \"e.g. cpu=0.1,memory=1024Mi,disk=1024Mi,gpu=1\",\n    )\n    parser.add_argument(\n        \"--master_resource_limit\",\n        type=str,\n        help=\"The maximal resource required by master, \"\n        \"e.g. cpu=0.1,memory=1024Mi,disk=1024Mi,gpu=1, \"\n        \"default to master_resource_request\",\n    )\n    parser.add_argument(\n        \"--num_workers\", type=int, help=\"Number of workers\", default=0\n    )\n    parser.add_argument(\n        \"--worker_resource_request\",\n        default=\"cpu=1,memory=4096Mi\",\n        type=str,\n        help=\"The minimal resource required by worker, \"\n        \"e.g. cpu=1,memory=1024Mi,disk=1024Mi,gpu=1\",\n    )\n    parser.add_argument(\n        \"--worker_resource_limit\",\n        type=str,\n        help=\"The maximal resource required by worker, \"\n        \"e.g. cpu=1,memory=1024Mi,disk=1024Mi,gpu=1,\"\n        \"default to worker_resource_request\",\n    )\n    parser.add_argument(\n        \"--master_pod_priority\", help=\"The requested priority of master pod\"\n    )\n    parser.add_argument(\n        \"--volume\",\n        help=\"The Kubernetes volume information, \"\n        'e.g. \"claim_name=c1,mount_path=/path1\".',\n    )\n    parser.add_argument(\n        \"--image_pull_policy\",\n        default=\"Always\",\n        help=\"The image pull policy of master and worker\",\n    )\n    parser.add_argument(\n        \"--restart_policy\",\n        default=\"Never\",\n        help=\"The pod restart policy when pod crashed\",\n    )\n    parser.add_argument(\n        \"--extra_pypi_index\", help=\"The extra python package repository\"\n    )\n    parser.add_argument(\n        \"--namespace\",\n        default=\"default\",\n        type=str,\n        help=\"The name of the Kubernetes namespace where ElasticDL \"\n        \"pods will be created\",\n    )\n    parser.add_argument(\"--records_per_task\", type=int, required=True)\n    parser.add_argument(\n        \"--minibatch_size\",\n        type=int,\n        help=\"Minibatch size used by workers\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--dataset_fn\",\n        type=str,\n        default=\"dataset_fn\",\n        help=\"The name of the dataset function defined in the model file\",\n    )\n    parser.add_argument(\n        \"--eval_metrics_fn\",\n        type=str,\n        default=\"eval_metrics_fn\",\n        help=\"The name of the evaluation metrics function defined \"\n        \"in the model file\",\n    )\n    parser.add_argument(\n        \"--model_def\",\n        type=str,\n        required=True,\n        help=\"The import path to the model definition function/class in the \"\n        'model zoo, e.g. \"cifar10_subclass.cifar10_subclass.CustomModel\"',\n    )\n    parser.add_argument(\n        \"--model_params\",\n        type=str,\n        default=\"\",\n        help=\"The dictionary of model parameters in a string that will be \"\n        'used to instantiate the model, e.g. \"param1=1,param2=2\"',\n    )\n    parser.add_argument(\n        \"--cluster_spec\",\n        help=\"The file that contains user-defined cluster specification\",\n        default=\"\",\n    )\n\n\ndef add_train_params(parser):\n    parser.add_argument(\n        \"--tensorboard_log_dir\",\n        default=\"\",\n        type=str,\n        help=\"Directory where TensorBoard will look to find \"\n        \"TensorFlow event files that it can display. \"\n        \"TensorBoard will recursively walk the directory \"\n        \"structure rooted at log dir, looking for .*tfevents.* \"\n        \"files. You may also pass a comma separated list of log \"\n        \"directories, and TensorBoard will watch each \"\n        \"directory.\",\n    )\n    parser.add_argument(\"--num_epochs\", type=int, default=1)\n    parser.add_argument(\n        \"--grads_to_wait\",\n        type=int,\n        help=\"Number of gradients to wait before updating model\",\n        default=2,\n    )\n    parser.add_argument(\n        \"--training_data_dir\",\n        help=\"Training data directory. Files should be in RecordIO format\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--evaluation_data_dir\",\n        help=\"Evaluation data directory. Files should be in RecordIO format\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--evaluation_steps\",\n        type=int,\n        help=\"Evaluate the model every this many steps.\"\n        \"If 0, step-based evaluation is disabled\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--evaluation_start_delay_secs\",\n        type=int,\n        help=\"Start time-based evaluation only after waiting for \"\n        \"this many seconds\",\n        default=100,\n    )\n    parser.add_argument(\n        \"--evaluation_throttle_secs\",\n        type=int,\n        help=\"Do not re-evaluate unless the last evaluation was started \"\n        \"at least this many seconds ago.\"\n        \"If 0, time-based evaluation is disabled\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--checkpoint_steps\",\n        type=int,\n        help=\"Save checkpoint every this many steps.\"\n        \"If 0, no checkpoints to save.\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--checkpoint_dir\",\n        help=\"The directory to store the checkpoint files\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--keep_checkpoint_max\",\n        type=int,\n        help=\"The maximum number of recent checkpoint files to keep.\"\n        \"If 0, keep all.\",\n        default=0,\n    )\n    parser.add_argument(\n        \"--checkpoint_filename_for_init\",\n        help=\"The checkpoint file to initialize the training model\",\n        default=\"\",\n    )\n    parser.add_argument(\n        \"--loss\",\n        type=str,\n        default=\"loss\",\n        help=\"The name of the loss function defined in the model file\",\n    )\n    parser.add_argument(\n        \"--optimizer\",\n        type=str,\n        default=\"optimizer\",\n        help=\"The name of the optimizer defined in the model file\",\n    )\n    parser.add_argument(\n        \"--output\",\n        type=str,\n        default=\"\",\n        help=\"The path to save the final trained model\",\n    )\n\n\ndef add_evaluate_params(parser):\n    parser.add_argument(\n        \"--evaluation_data_dir\",\n        help=\"Evaluation data directory. Files should be in RecordIO format\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--checkpoint_filename_for_init\",\n        help=\"The checkpoint file to initialize the training model\",\n        required=True,\n    )\n\n\ndef add_predict_params(parser):\n    parser.add_argument(\n        \"--prediction_data_dir\",\n        help=\"Prediction data directory. Files should be in RecordIO format\",\n        required=True,\n    )\n    parser.add_argument(\n        \"--checkpoint_filename_for_init\",\n        help=\"The checkpoint file to initialize the training model\",\n        required=True,\n    )\n", "path": "elasticdl/python/common/args.py"}]}