Repository: NVIDIA-NeMo/Run

Issue:
Breaking change in cli parsing behavior
```
from dataclasses import dataclass
from typing import List, Sequence
import nemo_run as run



@dataclass
class Model:
    """Dummy model config"""
    hidden_size: int
    num_layers: int
    activation: str

@dataclass
class Optimizer:
    """Dummy optimizer config"""
    learning_rate: float
    weight_decay: float
    betas: List[float]

@run.cli.factory
@run.autoconvert
def my_model(
    hidden_size: int = 256,
    num_layers: int = 3,
    activation: str = 'relu'
) -> Model:
    """Create a model configuration."""
    return Model(hidden_size=hidden_size, num_layers=num_layers, activation=activation)

@run.cli.factory
@run.autoconvert
def my_model_2(
    hidden_size: int = 512,
    num_layers: int = 3,
    activation: str = 'relu'
) -> Model:
    """Create a model configuration."""
    return Model(hidden_size=hidden_size, num_layers=num_layers, activation=activation)

@run.cli.factory
def my_optimizer(
    learning_rate: float = 0.001,
    weight_decay: float = 1e-5,
    betas: Sequence[float] = (0.9, 0.999,)
) -> run.Config[Optimizer]:
    """Create an optimizer configuration."""
    return run.Config(Optimizer, learning_rate=learning_rate, weight_decay=weight_decay, betas=list(betas))

@run.cli.entrypoint
def train_model(
    model: Model = my_model(),
    optimizer: Optimizer = my_optimizer(),
    epochs: int = 10,
    batch_size: int = 32
) -> None:
    """
    Train a model using the specified configuration.

    Args:
        model: Configuration for the model.
        optimizer: Configuration for the optimizer.
        epochs: Number of training epochs. Defaults to 10.
        batch_size: Batch size for training. Defaults to 32.
    """
    print(f"Training model with the following configuration:")
    print(f"Model: {model}")
    print(f"Optimizer: {optimizer}")
    print(f"Epochs: {epochs}")
    print(f"Batch size: {batch_size}")

    # Simulating model training
    for epoch in range(epochs):
        print(f"Epoch {epoch + 1}/{epochs}")

    print("Training completed!")

if __name__ == "__main__":
    run.cli.main(train_model)

```
In this example when I run

```
python example.py model=my_model_2 model.num_layers=10
```
The expected behavior/old behavior is that the cli args are parsed properly. But on `main`(I don't know exactly when this is broken) getting
```
Resolved Arguments
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Argument Name        ┃ Resolved Value                                               ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ batch_size           │ 32                                                           │
│ epochs               │ 10                                                           │
│ model                │ Model(num_layers=10)                                         │
│ optimizer            │ Optimizer(learning_rate=0.001, weight_decay=1e-05,           │
│                      │ betas=[0.9, 0.999])                                          │
└──────────────────────┴──────────────────────────────────────────────────────────────┘
Continue? [y/N]: y
Launching train_model...
Unexpected error: Model.__init__() missing 2 required positional arguments: 'hidden_size' and 'activation'
```

Hints from issue comments:
@marcromeyn: Thanks for reporting this! I put in a small fix for this: https://github.com/NVIDIA/NeMo-Run/pull/235.

Solution patch:
diff --git a/nemo_run/cli/lazy.py b/nemo_run/cli/lazy.py
index 882b018..efee05b 100644
--- a/nemo_run/cli/lazy.py
+++ b/nemo_run/cli/lazy.py
@@ -721,7 +721,10 @@ def _args_to_dictconfig(args: list[tuple[str, str, Any]]) -> DictConfig:
             if part not in current:
                 current[part] = {}
             elif not isinstance(current[part], dict):
-                current[part] = {}  # Convert to dict if it wasn't already
+                if isinstance(current[part], str):
+                    current[part] = {"_factory_": current[part]}
+                else:
+                    current[part] = {}  # Convert to dict if it wasn't already
             current = current[part]
 
         # Add the operator suffix if it's not a simple assignment


Test patch:
diff --git a/test/cli/test_api.py b/test/cli/test_api.py
index f0f3210..da359c1 100644
--- a/test/cli/test_api.py
+++ b/test/cli/test_api.py
@@ -631,6 +631,13 @@ def my_model(hidden_size: int = 256, num_layers: int = 3, activation: str = "rel
     return Model(hidden_size=hidden_size, num_layers=num_layers, activation=activation)
 
 
+@run.cli.factory
+@run.autoconvert
+def my_other_model(hidden_size: int = 512, num_layers: int = 3, activation: str = "relu") -> Model:
+    """Create a model configuration."""
+    return Model(hidden_size=hidden_size, num_layers=num_layers, activation=activation)
+
+
 @run.cli.factory
 def my_optimizer(
     learning_rate: float = 0.001, weight_decay: float = 1e-5, betas: List[float] = [0.9, 0.999]
@@ -880,6 +887,26 @@ class TestEntrypointRunner:
         value_1: int
         value_2: int
 
+    def test_with_factory_and_overwrite(self, runner, app):
+        # Test CLI execution with factory and parameter overwrite
+        result = runner.invoke(
+            app,
+            [
+                "my_llm",
+                "train_model",
+                "model=my_other_model",
+                "model.num_layers=10",
+                "--yes",
+            ],
+            env={"INCLUDE_WORKSPACE_FILE": "false"},
+        )
+        assert result.exit_code == 0
+
+        output = result.stdout
+        assert "Training model with the following configuration:" in output
+        # Check that my_model_2's default hidden_size (512) is used
+        assert "Model: Model(hidden_size=512, num_layers=10, activation='relu')" in output
+
 
 class TestDefaultFactory:
     def test_default_factory(self):