-
Notifications
You must be signed in to change notification settings - Fork 356
feat: evaluation implement #16
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
976f20e
add evaluation implement and minial doc
yuki-97 9c1be17
add remap_problem_solution
yuki-97 5399426
set load_format=auto to avoid dummy loading in eval
yuki-97 3e2321f
remove useless keys; move prompt process outside
yuki-97 b60c94d
add MathDataConfig; add remap_dataset_keys; fix rebase
yuki-97 0a21a30
add eval unit test
yuki-97 f0a5b54
remove setting pad_token_id
yuki-97 af39289
remove duplicated keys in MathDataConfig
yuki-97 0b4b103
Merge branch 'main' into yukih/eval
parthchadha fe93ba4
Merge branch 'main' into yukih/eval
parthchadha 1c36f25
Merge branch 'main' into yukih/eval
parthchadha 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Evaluation | ||
|
|
||
| ## Start Evaluation | ||
|
|
||
| ### Start Script | ||
| ```sh | ||
| # To run the evaluation with default config (examples/configs/eval.yaml) | ||
| uv run python examples/run_eval.py | ||
|
|
||
| # Specify a custom config file | ||
| uv run python examples/run_eval.py --config path/to/custom_config.yaml | ||
|
|
||
| # Override specific config values via command line | ||
| uv run python examples/run_eval.py generation.model_name="Qwen/Qwen2.5-Math-7B-Instruct" | ||
| ``` | ||
|
|
||
| ### Example Output | ||
|
|
||
| ``` | ||
| ============================================================ | ||
| model_name='Qwen2.5-Math-1.5B-Instruct' dataset_name='aime_2024' | ||
| score=0.10 (3.0/30) | ||
| ============================================================ | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| An example Evaluation configuration file can be found [here](../../examples/configs/eval.yaml). | ||
|
|
||
| ### Prompt Template Configuration | ||
| Always remember to use the same `prompt_file` and `system_prompt_file` that were used during training. | ||
|
|
||
| For open-source models, we recommend setting `prompt_file=null` and `system_prompt_file=null` to allow them to use their native chat templates. | ||
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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ cluster.md | |
| adding_new_models.md | ||
| guides/sft.md | ||
| guides/grpo.md | ||
| guides/eval.md | ||
| ``` | ||
|
|
||
| ```{toctree} | ||
|
|
||
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,30 @@ | ||
| # Evaluation Configuration | ||
| generation: | ||
| backend: "vllm" # only vllm is supported for evaluation | ||
| max_new_tokens: ${generation.vllm_cfg.max_model_len} | ||
| temperature: 0.0 | ||
| top_p: 1.0 | ||
| top_k: -1 # disable | ||
| num_prompts_per_step: -1 # -1 means pass all prompts at once | ||
| model_name: "Qwen/Qwen2.5-Math-1.5B-Instruct" | ||
| vllm_cfg: | ||
| tensor_parallel_size: 1 | ||
| gpu_memory_utilization: 0.9 | ||
| max_model_len: 2048 | ||
|
|
||
| data: | ||
| max_input_seq_length: ${generation.vllm_cfg.max_model_len} # useless since we directly use prompts in evaluation | ||
| prompt_file: null | ||
| system_prompt_file: null | ||
| dataset_name: "HuggingFaceH4/aime_2024" | ||
| dataset_key: "train" | ||
| problem_key: "problem" | ||
| solution_key: "answer" | ||
|
|
||
| env: | ||
| math: | ||
| num_workers: 8 | ||
|
|
||
| cluster: | ||
| gpus_per_node: 1 | ||
| num_nodes: 1 |
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,145 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # 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. | ||
|
|
||
| import argparse | ||
| import os | ||
| import pprint | ||
| import sys | ||
|
|
||
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
|
||
| from datasets import load_dataset | ||
| from omegaconf import OmegaConf | ||
| from transformers import AutoTokenizer | ||
|
|
||
| from examples.run_grpo_math import math_data_processor | ||
| from nemo_reinforcer.data import MathDataConfig | ||
| from nemo_reinforcer.data.datasets import AllTaskProcessedDataset | ||
| from nemo_reinforcer.data.interfaces import TaskDataSpec | ||
| from nemo_reinforcer.data.llm_message_utils import remap_dataset_keys | ||
| from nemo_reinforcer.distributed.virtual_cluster import init_ray | ||
| from nemo_reinforcer.environments.math_environment import MathEnvironment | ||
| from nemo_reinforcer.evals.eval import MasterConfig, run_env_eval, setup | ||
| from nemo_reinforcer.models.generation.interfaces import GenerationConfig | ||
|
|
||
|
|
||
| def parse_args(): | ||
| """Parse command line arguments.""" | ||
| parser = argparse.ArgumentParser(description="Run Evaluation with configuration") | ||
| parser.add_argument( | ||
| "--config", type=str, default=None, help="Path to YAML config file" | ||
| ) | ||
|
|
||
| # Parse known args for the script | ||
| args, remaining = parser.parse_known_args() | ||
|
|
||
| # Convert remaining args to OmegaConf format | ||
| overrides = OmegaConf.from_dotlist(remaining) | ||
|
|
||
| return args, overrides | ||
|
|
||
|
|
||
| def setup_data( | ||
| data_config: MathDataConfig, generation_config: GenerationConfig, env_configs | ||
| ): | ||
| print("\n▶ Setting up data...") | ||
| math_task_spec = TaskDataSpec( | ||
| task_name="math", | ||
| prompt_file=data_config["prompt_file"], | ||
| system_prompt_file=data_config["system_prompt_file"], | ||
| ) | ||
|
|
||
| # load dataset | ||
| base_dataset = load_dataset(data_config["dataset_name"]) | ||
| if data_config["dataset_key"] is not None: | ||
| base_dataset = base_dataset[data_config["dataset_key"]] | ||
| # remap problem and solution keys | ||
| remapped_dataset = remap_dataset_keys( | ||
| base_dataset, | ||
| mapping_dict={ | ||
| data_config["problem_key"]: "problem", | ||
| data_config["solution_key"]: "expected_answer", | ||
| }, | ||
| ) | ||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained(generation_config["model_name"]) | ||
| if tokenizer.pad_token is None: | ||
| tokenizer.pad_token = tokenizer.eos_token | ||
|
|
||
| math_env = MathEnvironment.options( | ||
| runtime_env={"py_executable": MathEnvironment.DEFAULT_PY_EXECUTABLE} | ||
| ).remote(env_configs["math"]) | ||
|
|
||
| dataset = AllTaskProcessedDataset( | ||
| dataset=remapped_dataset, | ||
| tokenizer=tokenizer, | ||
| default_task_data_spec=math_task_spec, | ||
| task_data_processors=math_data_processor, | ||
| max_seq_length=data_config["max_input_seq_length"], | ||
| ) | ||
|
|
||
| return dataset, math_env, tokenizer | ||
|
|
||
|
|
||
| def main(): | ||
| """Main entry point.""" | ||
| # Parse arguments | ||
| args, overrides = parse_args() | ||
|
|
||
| if not args.config: | ||
| args.config = os.path.join(os.path.dirname(__file__), "configs", "eval.yaml") | ||
|
|
||
| config = OmegaConf.load(args.config) | ||
| print(f"Loaded configuration from: {args.config}") | ||
|
|
||
| if overrides: | ||
| override_conf = OmegaConf.from_cli() | ||
| print(f"Overrides: {override_conf}") | ||
| config = OmegaConf.merge(config, override_conf) | ||
|
|
||
| config: MasterConfig = OmegaConf.to_container(config, resolve=True) | ||
| print("Applied CLI overrides") | ||
|
|
||
| # Print config | ||
| print("Final config:") | ||
| pprint.pprint(config) | ||
|
|
||
| # Init ray | ||
| init_ray() | ||
|
|
||
| # Setup data | ||
| ( | ||
| dataset, | ||
| math_env, | ||
| tokenizer, | ||
| ) = setup_data(config["data"], config["generation"], config["env"]) | ||
|
|
||
| # Setup | ||
| ( | ||
| vllm_generation, | ||
| dataloader, | ||
| master_config, | ||
| ) = setup(config, tokenizer, dataset) | ||
|
|
||
| # Run evaluation | ||
| run_env_eval( | ||
| vllm_generation, | ||
| dataloader, | ||
| math_env, | ||
| master_config, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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.
Uh oh!
There was an error while loading. Please reload this page.