Repository navigation
fix(cli): fail fast when gym eval run --split has no matching dataset
#2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from omegaconf import DictConfig | ||
|
|
||
| from nemo_gym.cli.eval import _validate_prepared_split_file_exists, _validate_split_datasets_declared | ||
| from nemo_gym.config_types import ConfigError, ResponsesAPIAgentServerInstanceConfig | ||
|
|
||
|
|
||
| def _make_agent_instance_config(name: str, dataset_specs: list) -> ResponsesAPIAgentServerInstanceConfig: | ||
| server_type_config_dict = { | ||
| "responses_api_agents": { | ||
| "simple_agent": { | ||
| "host": "127.0.0.1", | ||
| "port": 12345, | ||
| "entrypoint": "app.py", | ||
| "datasets": [ | ||
| { | ||
| "name": d["name"], | ||
| "type": d["type"], | ||
| "jsonl_fpath": d.get("jsonl_fpath", f"path/{d['name']}.jsonl"), | ||
| "license": None if d["type"] == "example" else "Apache 2.0", | ||
| } | ||
| for d in dataset_specs | ||
| ], | ||
| "resources_server": { | ||
| "type": "resources_servers", | ||
| "name": f"{name}_resources_server", | ||
| }, | ||
| "model_server": { | ||
| "type": "responses_api_models", | ||
| "name": "policy_model", | ||
| }, | ||
| } | ||
| } | ||
| } | ||
| return ResponsesAPIAgentServerInstanceConfig( | ||
| name=name, | ||
| server_type_config_dict=DictConfig(server_type_config_dict), | ||
| responses_api_agents=server_type_config_dict["responses_api_agents"], | ||
| ) | ||
|
|
||
|
|
||
| class TestValidateSplitDatasetsDeclared: | ||
| def test_passes_when_a_dataset_of_the_split_type_is_declared(self) -> None: | ||
| configs = [_make_agent_instance_config("my_agent", [{"name": "train_data", "type": "train"}])] | ||
| _validate_split_datasets_declared("train", configs) | ||
|
|
||
| def test_fails_fast_when_only_example_data_is_declared(self) -> None: | ||
| configs = [ | ||
| _make_agent_instance_config( | ||
| "example_agent", | ||
| [{"name": "example", "type": "example", "jsonl_fpath": "resources_servers/x/data/example.jsonl"}], | ||
| ) | ||
| ] | ||
| with pytest.raises(ConfigError) as exc_info: | ||
| _validate_split_datasets_declared("train", configs) | ||
| message = str(exc_info.value) | ||
| # The error must name the requested split, list what is declared, and give the | ||
| # copy-pasteable --no-serve recipe for the example file. | ||
| assert "No dataset of type `train`" in message | ||
| assert "example_agent: example (type: example)" in message | ||
| assert "--no-serve --input resources_servers/x/data/example.jsonl" in message | ||
|
|
||
| def test_fails_when_no_datasets_are_declared_at_all(self) -> None: | ||
| configs = [_make_agent_instance_config("bare_agent", [])] | ||
| with pytest.raises(ConfigError, match=r"- \(none\)"): | ||
| _validate_split_datasets_declared("validation", configs) | ||
|
|
||
| def test_mismatched_split_lists_declared_types(self) -> None: | ||
| configs = [_make_agent_instance_config("val_agent", [{"name": "val_data", "type": "validation"}])] | ||
| with pytest.raises(ConfigError, match=r"val_agent: val_data \(type: validation\)"): | ||
| _validate_split_datasets_declared("train", configs) | ||
|
|
||
|
|
||
| class TestValidatePreparedSplitFileExists: | ||
| def test_passes_when_the_file_exists(self, tmp_path: Path) -> None: | ||
| fpath = tmp_path / "train.jsonl" | ||
| fpath.write_text("{}\n") | ||
| _validate_prepared_split_file_exists(fpath, "train", tmp_path) | ||
|
|
||
| def test_fails_with_the_split_and_the_files_actually_prepared(self, tmp_path: Path) -> None: | ||
| (tmp_path / "validation.jsonl").write_text("{}\n") | ||
| with pytest.raises(ConfigError, match=r"split `train`.*\['validation.jsonl'\]"): | ||
| _validate_prepared_split_file_exists(tmp_path / "train.jsonl", "train", tmp_path) | ||
|
|
||
| def test_fails_with_none_when_the_output_dir_is_missing(self, tmp_path: Path) -> None: | ||
| missing_dir = tmp_path / "does_not_exist" | ||
| with pytest.raises(ConfigError, match=r"none"): | ||
| _validate_prepared_split_file_exists(missing_dir / "train.jsonl", "train", missing_dir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we run
_validate_split_datasets_declared()before theshould_skip_data_processingbranch? As written, whenreuse_existing_data_preparation=trueand the expected split file already exists, the declaration check is skipped. That appears to allow a stale prepared file to run even when the current loaded configuration no longer declares that split. Is that intentional? If reuse is expected to bypass this validation, should the new documentation qualify its statement that a matching dataset “must be declared”?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll fix that