Skip to content

Commit facb363

Browse files
authored
Allow setting auto_config in the YAML configuration file (#883)
1 parent 70772d2 commit facb363

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Below is an exhaustive and documented configuration. **You should NOT copy and u
6262
# The directory is created if it does not exist.
6363
model_dir: toy-ende
6464

65+
# (optional) Enable automatic parameters based on the selected model.
66+
# Can also be set with the command line option --auto_config.
67+
auto_config: true
68+
6569
data:
6670
# (required for train run type).
6771
train_features_file: data/toy-ende/src-train.txt

opennmt/bin/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def main():
4949
)
5050
parser.add_argument(
5151
"--auto_config",
52-
default=False,
52+
default=None,
5353
action="store_true",
5454
help="Enable automatic configuration values.",
5555
)

opennmt/runner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Runner(object):
5252
"""Class for running and exporting models."""
5353

5454
def __init__(
55-
self, model, config, auto_config=False, mixed_precision=False, seed=None
55+
self, model, config, auto_config=None, mixed_precision=False, seed=None
5656
):
5757
"""Initializes the runner parameters.
5858
@@ -61,7 +61,7 @@ def __init__(
6161
returns such instance.
6262
config: The run configuration.
6363
auto_config: If ``True``, use automatic configuration values defined by
64-
:obj:`model`.
64+
:obj:`model`. If not set, the parameter is read from the run configuration.
6565
mixed_precision: Enable mixed precision.
6666
seed: The random seed to set.
6767
@@ -86,6 +86,8 @@ def __init__(
8686
self._config["data"] = config_util.try_prefix_paths(
8787
self._config["model_dir"], config["data"]
8888
)
89+
if auto_config is None:
90+
auto_config = self._config.get("auto_config", False)
8991
self._auto_config = auto_config
9092
self._mixed_precision = mixed_precision
9193
if seed is not None:

0 commit comments

Comments
 (0)