Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fern/versions/latest/pages/reference/cli-commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ gym env init --resources-server my_server

Resolve the configs, flags, and overrides into a final merged config and print it. Useful for debugging configuration. Secrets are hidden.

Unlike `gym env validate`, `resolve` substitutes no dummy model, so a model config's `policy_*` values must be supplied for its interpolations to resolve.

| Option | Description |
| --- | --- |
| `--config PATH` | Config file to load. Repeatable. |
Expand All @@ -411,7 +413,10 @@ Resolve the configs, flags, and overrides into a final merged config and print i
gym env resolve \
--config resources_servers/example_single_tool_call/configs/example_single_tool_call.yaml \
--config responses_api_models/openai_model/configs/openai_model.yaml \
++responses_create_params.temperature=0.6
++responses_create_params.temperature=0.6 \
++policy_base_url=https://api.openai.com/v1 \
++policy_api_key=sk-example \
++policy_model_name=gpt-4o-mini
```

### `gym env validate`
Expand Down
4 changes: 4 additions & 0 deletions nemo_gym/config_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class ConfigMissingValuesError(ConfigError, ValueError):
"""One or more required config values are still unset (OmegaConf '???') after merging."""


class ConfigInterpolationError(ConfigError, ValueError):
"""An `${...}` interpolation references a key that is not present in the merged config."""


class ServerRefNotFoundError(ConfigError, ValueError):
"""A server cross-reference points to an instance that is not defined in the merged config."""

Expand Down
22 changes: 21 additions & 1 deletion nemo_gym/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import re
import sys
from argparse import ArgumentParser
from collections import defaultdict
Expand All @@ -31,6 +32,7 @@
import wandb
import wandb.util
from omegaconf import MISSING, DictConfig, ListConfig, OmegaConf, open_dict
from omegaconf.errors import InterpolationResolutionError
from openai import __version__ as openai_version
from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError
from ray import __version__ as ray_version
Expand All @@ -40,6 +42,7 @@
from nemo_gym.config_types import (
AlmostServerError,
ConfigError,
ConfigInterpolationError,
ConfigMissingValuesError,
ConfigPathNotFoundError,
InheritPathNotFoundError,
Expand Down Expand Up @@ -828,7 +831,24 @@ def set_global_config_dict(
global_config_dict_parser_cls: Type[GlobalConfigDictParser] = GlobalConfigDictParser,
) -> None:
global _GLOBAL_CONFIG_DICT
global_config_dict = global_config_dict_parser_cls().parse(global_config_dict_parser_config)
try:
global_config_dict = global_config_dict_parser_cls().parse(global_config_dict_parser_config)
except InterpolationResolutionError as e:
# Same class of user error as an unset '???' (see raise_on_missing_values), so report it the same
# way instead of letting omegaconf's traceback reach the top level. Covers both a missing `${key}`
# (InterpolationKeyError) and a failing resolver such as `${oc.env:VAR}`, which carries its own
# message and so is passed through as-is.
match = re.search(r"Interpolation key '([^']+)' not found", str(e))
if not match:
raise ConfigInterpolationError(str(e)) from e
key = match.group(1)
raise ConfigInterpolationError(
f"""Config value '{e.full_key}' references '{key}', which is not set after merging.

Provide it via a CLI override, in env.yaml, or in a config you pass via config_paths.
For example, on the command line:
++{key}=<value>"""
) from e

_GLOBAL_CONFIG_DICT = global_config_dict

Expand Down
Loading