From 6bfc6d0ca335def6daf1da539a87545d62a0ae34 Mon Sep 17 00:00:00 2001 From: Can Balioglu Date: Thu, 9 Jan 2025 08:01:11 -0500 Subject: [PATCH] Fix dump-config bug (#961) --- src/fairseq2/recipes/cli.py | 10 ++++++---- src/fairseq2/recipes/runner.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/fairseq2/recipes/cli.py b/src/fairseq2/recipes/cli.py index 78cd17b69..fb931771d 100644 --- a/src/fairseq2/recipes/cli.py +++ b/src/fairseq2/recipes/cli.py @@ -52,8 +52,8 @@ ) from fairseq2.typing import safe_cast from fairseq2.utils.file import StandardFileSystem -from fairseq2.utils.structured import StructureError -from fairseq2.utils.yaml import YamlDumper, dump_yaml, load_yaml +from fairseq2.utils.structured import StructureError, unstructure +from fairseq2.utils.yaml import YamlDumper, YamlError, dump_yaml, load_yaml class Cli: @@ -632,9 +632,11 @@ def run(self, args: Namespace) -> None: ) if args.dump_config: + unstructured_config = unstructure(config) + try: - self._yaml_dumper(config, sys.stdout) - except OSError as ex: + self._yaml_dumper(unstructured_config, sys.stdout) + except YamlError as ex: raise SetupError( "The recipe configuration cannot be dumped to stdout. See the nested exception for details." ) from ex diff --git a/src/fairseq2/recipes/runner.py b/src/fairseq2/recipes/runner.py index 96b124636..a92c03460 100644 --- a/src/fairseq2/recipes/runner.py +++ b/src/fairseq2/recipes/runner.py @@ -194,7 +194,7 @@ def run( try: self._yaml_dumper(unstructured_config, config_file) - except OSError as ex: + except (OSError, YamlError) as ex: raise SetupError( f"The recipe configuration cannot be saved to the '{config_file}' file. See the nested exception for details." ) from ex