-
Notifications
You must be signed in to change notification settings - Fork 155
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
Draft
Jorjeous
wants to merge
2
commits into
main
Choose a base branch
from
eval-kit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Eval kit support #1239
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # 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 "." in benchmark: | ||
| sub = benchmark.split(".", 1)[1] | ||
| return f" ++vlm_dataset={sub} " | ||
| return "" |
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
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,93 @@ | ||
| # 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 collections import defaultdict | ||
| 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 | ||
|
|
||
| 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 | ||
|
|
||
| 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.
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.
Silent import suppression will produce a confusing error when
compute-evalis actually requested.If the dependency is missing and a user requests the
"compute-eval"evaluator, they'll see"Evaluator class not found for type: compute-eval"(fromget_evaluator_class) instead of a clear message about the missing import. Consider deferring the error to the point of use so it's actionable.Suggested approach
Then in
get_evaluator_class(or at registration lookup time), surface_compute_eval_import_errorwheneval_type == "compute-eval"and the class isNone.As per coding guidelines, "Do not catch exceptions when they are not normally expected to be raised; let code fail with clear errors instead of silently misbehaving."
📝 Committable suggestion
🤖 Prompt for AI Agents