-
Notifications
You must be signed in to change notification settings - Fork 194
Eval kit support #1239
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
Eval kit support #1239
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0cd07e
Adds two new generation modules for running NeMo Skills benchmarks via
Jorjeous 7c75e63
Update nemo_skills/inference/mcore_skills.py
Jorjeous bab1245
fix metrics_type routing and deterministic task names
Jorjeous 021ece6
make eval_kit always self-contained
Jorjeous 37476ac
fix ruff lint and formatting
Jorjeous c4651ea
narrow exception catch in _resolve_generation_task_class
Jorjeous a0f5f54
adressed coderabiit comments
Jorjeous ed1c5a5
adressed coderabbit comments round 2
Jorjeous e247ef3
Merge branch 'main' into eval-kit
Jorjeous c4f4b72
Added quick run instructions
Jorjeous 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,45 @@ | ||
| # 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. | ||
|
|
||
| # VLMEvalKit integration module. | ||
| # Benchmarks are referenced as eval_kit.<VLMEvalKit_dataset_name>, e.g. eval_kit.MMBench_DEV_EN | ||
| # The sub-benchmark name after eval_kit. is dynamically resolved and passed to VLMEvalKit. | ||
|
|
||
| GENERATION_MODULE = "nemo_skills.inference.eval.eval_kit" | ||
| METRICS_TYPE = "eval_kit" | ||
| GENERATION_ARGS = "" | ||
| NUM_SAMPLES = 0 # VLMEvalKit inference is deterministic; no random seeds | ||
|
|
||
| # No JSONL input file; VLMEvalKit manages its own data via build_dataset() | ||
| SKIP_INPUT_FILE = True | ||
|
|
||
| # Note: SELF_CONTAINED_TASK is NOT set here because it depends on model_type. | ||
| # For mcore mode (Megatron in-process), the pipeline sets self_contained_task=True | ||
| # at runtime based on ++model_type=mcore in extra_arguments. | ||
| # For vllm mode, the standard NeMo Skills server/client flow is used. | ||
|
|
||
|
|
||
| def get_extra_generation_args(benchmark): | ||
| """Return extra generation args for the given benchmark name. | ||
|
|
||
| Extracts the VLMEvalKit dataset name from the dotted benchmark name | ||
| (e.g. eval_kit.MMBench_DEV_EN -> ++vlm_dataset=MMBench_DEV_EN). | ||
| """ | ||
| if "." not in benchmark: | ||
| raise ValueError( | ||
| f"eval_kit benchmark must be in 'eval_kit.<dataset_name>' format, got '{benchmark}'. " | ||
| f"Example: eval_kit.MMBench_DEV_EN, eval_kit.LibriSpeech_test_clean" | ||
| ) | ||
| sub = benchmark.split(".", 1)[1] | ||
| return f" ++vlm_dataset={sub} " |
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,95 @@ | ||
| # 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 json | ||
| from pathlib import Path | ||
|
|
||
| from nemo_skills.evaluation.metrics.base import BaseMetrics | ||
|
|
||
|
|
||
| class EvalKitMetrics(BaseMetrics): | ||
| """Metrics class for VLMEvalKit benchmarks. | ||
|
|
||
| VLMEvalKit computes its own aggregate metrics during evaluation. | ||
| This class reads pre-computed aggregates from eval_kit_metrics.json | ||
| (written by EvalKitGenerationTask) rather than computing per-sample metrics. | ||
| The per-sample JSONL is still read by ComputeMetrics for the update() loop, | ||
| but we only count entries here -- the real metrics come from the JSON file. | ||
|
|
||
| Note: ComputeMetrics only calls setup() on the "_all_" calculator. When | ||
| the data contains ``subset_for_metrics``, additional per-subset calculator | ||
| instances are created but never receive a setup() call. We use a | ||
| class-level ``_shared_metrics_file`` so that those subset instances can | ||
| still locate the eval_kit_metrics.json discovered by the "_all_" instance. | ||
| """ | ||
|
|
||
| # Shared across all instances so subset calculators can find the file | ||
| # even though only the "_all_" calculator receives setup(). | ||
| _shared_metrics_file: Path | None = None | ||
|
|
||
| def __init__(self, **kwargs): | ||
| super().__init__(compute_no_answer=False) | ||
| self.eval_kit_metrics_file = None | ||
|
Jorjeous marked this conversation as resolved.
|
||
|
|
||
| def setup(self, input_files): | ||
| """Find the eval_kit_metrics.json in the same directory as the input files.""" | ||
| if input_files: | ||
| # input_files are like ['/path/to/eval-results/eval_kit.MMBench_DEV_EN/output.jsonl'] | ||
| metrics_dir = Path(input_files[0]).parent | ||
| candidate = metrics_dir / "eval_kit_metrics.json" | ||
| if candidate.exists(): | ||
| self.eval_kit_metrics_file = candidate | ||
| EvalKitMetrics._shared_metrics_file = candidate | ||
| else: | ||
| # Reset stale shared path so a previous run's file isn't reused. | ||
| EvalKitMetrics._shared_metrics_file = None | ||
|
|
||
|
Jorjeous marked this conversation as resolved.
|
||
| def update(self, predictions): | ||
| """Count entries but don't compute per-sample metrics.""" | ||
| self.total += 1 | ||
|
|
||
| def get_metrics(self): | ||
| """Return pre-computed VLMEvalKit aggregate metrics.""" | ||
| metrics_dict = {} | ||
|
|
||
| # Load pre-computed metrics from VLMEvalKit. | ||
| # Fall back to the class-level shared file for subset calculators | ||
| # that never received a setup() call. | ||
| eval_kit_results = {} | ||
| effective_file = self.eval_kit_metrics_file or EvalKitMetrics._shared_metrics_file | ||
| if effective_file and effective_file.exists(): | ||
| with open(effective_file, "rt", encoding="utf-8") as f: | ||
| eval_kit_results = json.load(f) | ||
|
|
||
| # Build the metrics in NeMo Skills format | ||
| agg_dict = {"num_entries": self.total} | ||
|
|
||
| # Flatten VLMEvalKit results into the metrics dict | ||
| for key, value in eval_kit_results.items(): | ||
| if isinstance(value, dict): | ||
| # Nested results (e.g., per-category scores) | ||
| for sub_key, sub_value in value.items(): | ||
| if isinstance(sub_value, (int, float)): | ||
| agg_dict[f"{key}_{sub_key}"] = sub_value | ||
| elif isinstance(value, (int, float)): | ||
| agg_dict[key] = value | ||
|
|
||
| metrics_dict["greedy"] = agg_dict | ||
| return metrics_dict | ||
|
|
||
| def metrics_to_print(self): | ||
| return None | ||
|
|
||
| def evaluations_to_print(self): | ||
| return ["greedy"] | ||
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.