|
17 | 17 | import json |
18 | 18 | import os |
19 | 19 | import shlex |
| 20 | +import sys |
20 | 21 | from glob import glob |
21 | 22 | from os import makedirs |
22 | 23 | from os.path import exists |
|
33 | 34 | from devtools import pprint |
34 | 35 | from omegaconf import DictConfig, OmegaConf |
35 | 36 | from pydantic import Field |
| 37 | +from rich.markup import escape |
36 | 38 | from rich.table import Table |
37 | 39 | from tqdm.auto import tqdm |
38 | 40 |
|
@@ -799,6 +801,34 @@ def dump_config(): # pragma: no cover |
799 | 801 | print(OmegaConf.to_yaml(global_config_dict, resolve=True)) |
800 | 802 |
|
801 | 803 |
|
| 804 | +def validate(): |
| 805 | + """ |
| 806 | + Validate a NeMo Gym configuration without starting any servers. |
| 807 | +
|
| 808 | + Runs the full config parse and validation pipeline — config_paths loading, key resolution, |
| 809 | + cross-reference checks, and per-server validation — with no Ray initialization and no server |
| 810 | + subprocesses. Exits 0 if the configuration is valid, 1 otherwise. Intended as a fast pre-flight |
| 811 | + check before a run or a cluster submission. |
| 812 | +
|
| 813 | + Examples: |
| 814 | +
|
| 815 | + ```bash |
| 816 | + gym env validate --config <config1> --config <config2> |
| 817 | + ``` |
| 818 | + """ |
| 819 | + try: |
| 820 | + global_config_dict = get_global_config_dict() |
| 821 | + # Mirrors `run`/`dump_config`: handles the +h=true help path and final config validation. |
| 822 | + BaseNeMoGymCLIConfig.model_validate(global_config_dict) |
| 823 | + except Exception as e: |
| 824 | + # escape() so '[...]' in the message (e.g. config_paths examples) isn't eaten as rich markup. |
| 825 | + rich.print(f"[red]✗ Config validation failed:[/red] {escape(f'{type(e).__name__}: {e}')}") |
| 826 | + sys.exit(1) |
| 827 | + |
| 828 | + server_instances = [k for k in global_config_dict.keys() if k not in NEMO_GYM_RESERVED_TOP_LEVEL_KEYS] |
| 829 | + rich.print(f"[green]✓ Config is valid[/green] — {len(server_instances)} server instance(s) configured.") |
| 830 | + |
| 831 | + |
802 | 832 | def status(): # pragma: no cover |
803 | 833 | global_config_dict = get_global_config_dict() |
804 | 834 | BaseNeMoGymCLIConfig.model_validate(global_config_dict) |
|
0 commit comments