[UX] Enable nested configs in config yaml files (#33193)

This commit is contained in:
Michael Goin
2026-01-28 16:54:25 -05:00
committed by GitHub
parent ab597c869a
commit ca1969186d
2 changed files with 70 additions and 7 deletions
+26 -7
View File
@@ -444,16 +444,30 @@ class FlexibleArgumentParser(ArgumentParser):
def load_config_file(self, file_path: str) -> list[str]:
"""Loads a yaml file and returns the key value pairs as a
flattened list with argparse like pattern
flattened list with argparse like pattern.
Supports both flat configs and nested YAML structures.
Flat config example:
```yaml
port: 12323
tensor-parallel-size: 4
```
returns:
processed_args: list[str] = [
'--port': '12323',
'--tensor-parallel-size': '4'
]
['--port', '12323', '--tensor-parallel-size', '4']
Nested config example:
```yaml
compilation-config:
pass_config:
fuse_allreduce_rms: true
speculative-config:
model: "nvidia/gpt-oss-120b-Eagle3-v2"
num_speculative_tokens: 3
```
returns:
['--compilation-config', '{"pass_config": {"fuse_allreduce_rms": true}}',
'--speculative-config', '{"model": "nvidia/gpt-oss-120b-Eagle3-v2", ...}']
"""
extension: str = file_path.split(".")[-1]
if extension not in ("yaml", "yml"):
@@ -461,10 +475,10 @@ class FlexibleArgumentParser(ArgumentParser):
f"Config file must be of a yaml/yml type. {extension} supplied"
)
# only expecting a flat dictionary of atomic types
# Supports both flat configs and nested dicts
processed_args: list[str] = []
config: dict[str, int | str] = {}
config: dict[str, Any] = {}
try:
with open(file_path) as config_file:
config = yaml.safe_load(config_file)
@@ -484,6 +498,11 @@ class FlexibleArgumentParser(ArgumentParser):
processed_args.append("--" + key)
for item in value:
processed_args.append(str(item))
elif isinstance(value, dict):
# Convert nested dicts to JSON strings so they can be parsed
# by the existing JSON argument parsing machinery.
processed_args.append("--" + key)
processed_args.append(json.dumps(value))
else:
processed_args.append("--" + key)
processed_args.append(str(value))