Skip to content

Add support for YAML, TOML & JSON - #182

Merged
marcromeyn merged 16 commits into
mainfrom
two_way_config
Apr 16, 2025
Merged

marcromeyn merged 16 commits into
mainfrom
two_way_config

Conversation

@marcromeyn

@marcromeyn marcromeyn commented Mar 24, 2025 •

Copy link
Copy Markdown
Contributor

This PR enhances the NeMo Run CLI with improved support for configuration file formats, providing more flexible and powerful ways to manage experiments.

Key Improvements:

  • Multi-format Configuration Support: Unified integration with YAML, TOML, and JSON configuration files
  • Enhanced @ Syntax: Improved loading of configuration from external files with the @ syntax
  • Two-way Configuration: Added ability to both import configurations and export them with applied overrides
  • Configuration Export Options: Export complete configurations to YAML, TOML, or JSON using --to-yaml, --to-toml, and --to-json flags
  • Add guide for CLI usage.

Examples

>>> python script.py --factory @path/to/config.yaml
>>> python script.py model_config=@configs/model.yaml optimizer=@configs/optimizer.json
>>> python task.py --factory @task.yaml model.num_layers=5 --to-toml test.toml
File contents:
╭───────────────────────────────────────────────────────── test.toml ──────────────────────────────────────────────────────────╮
│ 1 partial = true
│ 2 target = "main.train_model"
│ 3 batch_size = 32
│ 4 epochs = 10
│ 5 
│ 6 [model]
│ 7 target = "main.Model"
│ 8 activation = "relu"
│ 9 hidden_size = 256
│ 10 num_layers = 5
│ 11 
│ 12 [optimizer]
│ 13 target = "main.Optimizer"
│ 14 betas = [ 0.9, 0.999,]
│ 15 learning_rate = 0.001
│ 16 weight_decay = 1e-5
│ 17 
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Export complete. Skipping execution.

Comment thread nemo_run/cli/api.py Fixed
Comment thread nemo_run/cli/cli_parser.py Fixed
Comment thread nemo_run/cli/cli_parser.py Fixed
Comment thread nemo_run/lazy.py Fixed
Comment thread nemo_run/lazy.py Fixed
Comment thread nemo_run/cli/api.py Fixed
Comment thread nemo_run/lazy.py Fixed
Comment thread nemo_run/cli/api.py Fixed

@hemildesai hemildesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests to ensure that the coverage stays within 1-2% of main? You can view this PR's coverage at https://github.com/NVIDIA/NeMo-Run/actions/runs/14054878771/job/39352052848?pr=182 and current coverage at https://app.codecov.io/gh/NVIDIA/NeMo-Run

PS I will add a check for this in the future

Comment thread nemo_run/core/serialization/yaml.py Resolved
Comment thread nemo_run/lazy.py Resolved
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Comment thread nemo_run/cli/api.py
from nemo_run.core.execution.base import Executor
from nemo_run.core.frontend.console.styles import BOX_STYLE, TABLE_STYLES
from nemo_run.lazy import LazyEntrypoint
from nemo_run.cli.config import ConfigSerializer

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [nemo_run.cli.config](1) begins an import cycle.

Copilot Autofix

AI over 1 year ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Comment thread nemo_run/cli/api.py
from nemo_run.core.frontend.console.styles import BOX_STYLE, TABLE_STYLES
from nemo_run.lazy import LazyEntrypoint
from nemo_run.cli.config import ConfigSerializer
from nemo_run.cli.lazy import LazyEntrypoint

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [nemo_run.cli.lazy](1) begins an import cycle.

Copilot Autofix

AI over 1 year ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Comment thread nemo_run/cli/config.py
import yaml
from fiddle._src import config as config_lib

from nemo_run.core.serialization.yaml import YamlSerializer

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [nemo_run.core.serialization.yaml](1) begins an import cycle.

Copilot Autofix

AI over 1 year ago

To fix the cyclic import issue, we need to break the cycle by refactoring the code. One effective way to do this is to move the YamlSerializer class to a new module that can be imported by both nemo_run.cli.config and nemo_run.core.serialization.yaml without causing a cyclic dependency. This approach maintains the existing functionality while resolving the cyclic import.

  1. Create a new module, e.g., nemo_run.core.serialization.yaml_serializer, and move the YamlSerializer class to this new module.
  2. Update the import statements in both nemo_run.cli.config and nemo_run.core.serialization.yaml to import YamlSerializer from the new module.
Suggested changeset 1
nemo_run/cli/config.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/nemo_run/cli/config.py b/nemo_run/cli/config.py
--- a/nemo_run/cli/config.py
+++ b/nemo_run/cli/config.py
@@ -22,3 +22,3 @@
 
-from nemo_run.core.serialization.yaml import YamlSerializer
+from nemo_run.core.serialization.yaml_serializer import YamlSerializer
 
EOF
@@ -22,3 +22,3 @@

from nemo_run.core.serialization.yaml import YamlSerializer
from nemo_run.core.serialization.yaml_serializer import YamlSerializer

Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread nemo_run/cli/lazy.py
Raises:
ValueError: If the file path is invalid or the file doesn't exist
"""
from nemo_run.cli.config import ConfigSerializer

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [nemo_run.cli.config](1) begins an import cycle.

Copilot Autofix

AI over 1 year ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

A Buildable object (Config or Partial).
"""
from nemo_run.cli.cli_parser import parse_cli_args
from nemo_run.cli.lazy import dictconfig_to_dot_list

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [nemo_run.cli.lazy](1) begins an import cycle.

Copilot Autofix

AI over 1 year ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Comment thread test/cli/test_api.py Fixed
Comment thread test/cli/test_api.py Fixed
Comment thread test/cli/test_api.py Outdated
_get_return_type,
)
from test.dummy_factory import DummyModel, dummy_entrypoint
import nemo_run.cli.cli_parser # Import the module to mock its function

Check notice

Code scanning / CodeQL

Unused import

Import of 'nemo_run' is not used.

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to remove the unused import statement. This will clean up the code and remove the unnecessary dependency. The best way to fix this is to delete the line that imports nemo_run.cli.cli_parser.

Suggested changeset 1
test/cli/test_api.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/cli/test_api.py b/test/cli/test_api.py
--- a/test/cli/test_api.py
+++ b/test/cli/test_api.py
@@ -46,3 +46,3 @@
 from test.dummy_factory import DummyModel, dummy_entrypoint
-import nemo_run.cli.cli_parser  # Import the module to mock its function
+
 
EOF
@@ -46,3 +46,3 @@
from test.dummy_factory import DummyModel, dummy_entrypoint
import nemo_run.cli.cli_parser # Import the module to mock its function


Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread test/cli/test_api.py Fixed
Comment thread test/cli/test_lazy.py Fixed
Comment thread test/cli/test_lazy.py Fixed
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Comment thread test/cli/test_lazy.py
import_module,
_load_entrypoint_from_script,
)
from test.dummy_factory import DummyModel # noqa: F401

Check notice

Code scanning / CodeQL

Unused import

Import of 'DummyModel' is not used.

Copilot Autofix

AI over 1 year ago

To fix the problem, we need to remove the unused import statement. This will clean up the code and remove the unnecessary dependency. Specifically, we will delete the line from test.dummy_factory import DummyModel from the file test/cli/test_lazy.py.

Suggested changeset 1
test/cli/test_lazy.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/cli/test_lazy.py b/test/cli/test_lazy.py
--- a/test/cli/test_lazy.py
+++ b/test/cli/test_lazy.py
@@ -31,3 +31,3 @@
 )
-from test.dummy_factory import DummyModel  # noqa: F401
+
 import nemo_run.cli.api as api  # Import the api module
EOF
@@ -31,3 +31,3 @@
)
from test.dummy_factory import DummyModel # noqa: F401

import nemo_run.cli.api as api # Import the api module
Copilot is powered by AI and may make mistakes. Always verify output.
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>
Signed-off-by: Marc Romeyn <mromeijn@nvidia.com>

This branch was previously deployed

1 inactive deployment
public — 0b47be19 Deployed Apr 16, 2025 by marcromeyn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants