Skip to content

Commit

Permalink
Fix dump-config bug (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbalioglu authored Jan 9, 2025
1 parent e3d81c1 commit 6bfc6d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/fairseq2/recipes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/fairseq2/recipes/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6bfc6d0

Please sign in to comment.