Repository navigation
[benchmarking] Adds audio curation benchmark to nightly #1360
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
Changes from all commits
89bc074
9b64594
34564d4
7ef2bf9
0692fbb
82383a0
3ec5b30
ed1b95e
59de0d9
53ef91d
af646d8
eba1928
cc2bf93
026d79c
fc61726
8a7f0b2
6e90da1
69b1d06
58741c4
323c346
58eaf11
3324e2f
6b461e8
a991a07
43f1bfc
bc50782
6a34d85
58bb3a5
be5d93b
12931e8
33ebc5a
a1c89be
c6d6589
02ba779
6a03d08
98e3a56
6e5cd40
3e556f7
dfb5834
fa311ed
cda714d
3f3d5ac
8f84e03
957f2e6
3ed1e14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,141 @@ | ||||||||||||||||||||||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The copyright year is 2026, but should be 2025.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The copyright year is set to 2026, which appears to be incorrect. Should be 2025 to match other files in the repository.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copyright year should be 2025, not 2026. All other files in the repository use 2025.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Copyright year should be 2025, not 2026
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Copyright year should be 2025 to match other files in this PR (
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: copyright year should be 2025 to match other files in the repository
Suggested change
|
||||||||||||||||||||||
| # | ||||||||||||||||||||||
| # 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. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # ruff: noqa: S101 # Allow asserts in this script | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import argparse | ||||||||||||||||||||||
| import sys | ||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| from loguru import logger | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| from nemo_curator.backends.xenna import XennaExecutor | ||||||||||||||||||||||
| from nemo_curator.pipeline import Pipeline | ||||||||||||||||||||||
| from nemo_curator.stages.audio.common import GetAudioDurationStage, PreserveByValueStage | ||||||||||||||||||||||
| from nemo_curator.stages.audio.datasets.fleurs.create_initial_manifest import CreateInitialManifestFleursStage | ||||||||||||||||||||||
| from nemo_curator.stages.audio.inference.asr_nemo import InferenceAsrNemoStage | ||||||||||||||||||||||
| from nemo_curator.stages.audio.io.convert import AudioToDocumentStage | ||||||||||||||||||||||
| from nemo_curator.stages.audio.metrics.get_wer import GetPairwiseWerStage | ||||||||||||||||||||||
| from nemo_curator.stages.resources import Resources | ||||||||||||||||||||||
| from nemo_curator.stages.text.io.writer import JsonlWriter | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Import benchmarking utils which are currently only available directly from the Curator source tree. | ||||||||||||||||||||||
| # __file__ is expected to be <curator repo>/benchmarking/scripts/audio_fleurs_benchmark.py | ||||||||||||||||||||||
| _repo_dir = Path(__file__).resolve().parent.parent.parent | ||||||||||||||||||||||
| sys.path.insert(0, str(_repo_dir)) | ||||||||||||||||||||||
| from benchmarking.runner.utils import write_benchmark_results # noqa: E402 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def run_audio_fleurs_benchmark(args: argparse.Namespace) -> dict[str, Any]: | ||||||||||||||||||||||
| results_dir = args.benchmark_results_path / "results" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Ensure the results dir does not exist so that it will be created. | ||||||||||||||||||||||
| # This ensures no preexisting files are present which would otherwise be treated as additional results. | ||||||||||||||||||||||
| if results_dir.exists(): | ||||||||||||||||||||||
| msg = f"Result directory {results_dir} already exists." | ||||||||||||||||||||||
| raise ValueError(msg) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| executor = XennaExecutor() | ||||||||||||||||||||||
| pipeline = Pipeline(name="audio_inference", description="Inference audio and filter by WER threshold.") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Add stages | ||||||||||||||||||||||
| # Add the composite stage that combines reading and downloading | ||||||||||||||||||||||
| pipeline.add_stage( | ||||||||||||||||||||||
| CreateInitialManifestFleursStage( | ||||||||||||||||||||||
| lang=args.lang, | ||||||||||||||||||||||
| split=args.split, | ||||||||||||||||||||||
| raw_data_dir=args.scratch_output_path / "armenian/fleurs", | ||||||||||||||||||||||
| ).with_(batch_size=4) | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| pipeline.add_stage(InferenceAsrNemoStage(model_name=args.model_name).with_(resources=Resources(gpus=args.gpus))) | ||||||||||||||||||||||
| pipeline.add_stage( | ||||||||||||||||||||||
| GetPairwiseWerStage( | ||||||||||||||||||||||
| text_key="text", | ||||||||||||||||||||||
| pred_text_key="pred_text", | ||||||||||||||||||||||
| wer_key="wer", | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| pipeline.add_stage( | ||||||||||||||||||||||
| GetAudioDurationStage( | ||||||||||||||||||||||
| audio_filepath_key="audio_filepath", | ||||||||||||||||||||||
| duration_key="duration", | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| pipeline.add_stage( | ||||||||||||||||||||||
| PreserveByValueStage( | ||||||||||||||||||||||
| input_value_key="wer", | ||||||||||||||||||||||
| target_value=args.wer_threshold, | ||||||||||||||||||||||
| operator="le", | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| pipeline.add_stage(AudioToDocumentStage().with_(batch_size=1)) | ||||||||||||||||||||||
| pipeline.add_stage( | ||||||||||||||||||||||
| JsonlWriter( | ||||||||||||||||||||||
| path=results_dir, | ||||||||||||||||||||||
| write_kwargs={"force_ascii": False}, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| results = pipeline.run(executor) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| # Populate the metrics dictionary with metrics to include in the report for this benchmark. | ||||||||||||||||||||||
| # This also allows the framework to perform user-defined checks on the metrics to ensure perf requirements are met. | ||||||||||||||||||||||
| "metrics": { | ||||||||||||||||||||||
| "is_success": True, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| "tasks": results, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
rlratzel marked this conversation as resolved.
Resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def main() -> int: | ||||||||||||||||||||||
| parser = argparse.ArgumentParser(description="Audio Fleurs benchmark") | ||||||||||||||||||||||
| parser.add_argument("--benchmark-results-path", required=True, help="Path to benchmark results") | ||||||||||||||||||||||
| parser.add_argument("--scratch-output-path", required=True, help="Path to scratch output directory") | ||||||||||||||||||||||
| parser.add_argument("--model-name", default="nvidia/stt_hy_fastconformer_hybrid_large_pc", help="ASR model name") | ||||||||||||||||||||||
| parser.add_argument("--lang", default="hy_am", help="Language code") | ||||||||||||||||||||||
| parser.add_argument("--split", default="dev", help="Dataset split to use") | ||||||||||||||||||||||
| parser.add_argument("--wer-threshold", type=float, default=5.5, help="WER threshold for filtering") | ||||||||||||||||||||||
| parser.add_argument("--gpus", type=int, default=1, help="Number of GPUs to use") | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Consider using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||
| args = parser.parse_args() | ||||||||||||||||||||||
| logger.info("=== Audio Fleurs Benchmark Starting ===") | ||||||||||||||||||||||
| logger.info(f"Arguments: {vars(args)}") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| success_code = 1 # assume failure until benchmark succeeds | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # This dictionary will contain benchmark metadata and results, written to files for the benchmark framework to read. | ||||||||||||||||||||||
| # The dictionary must contain objects which can be serialized to JSON or pickle files. | ||||||||||||||||||||||
| result_dict = { | ||||||||||||||||||||||
| "params": vars(args).copy(), | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||||||||||
| "metrics": { | ||||||||||||||||||||||
| "is_success": False, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| "tasks": [], | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| # Now that the args have been saved as JSON-serializable strings for the result_dict, convert paths to Path | ||||||||||||||||||||||
| # objects for use in the benchmark script. | ||||||||||||||||||||||
| args.benchmark_results_path = Path(args.benchmark_results_path) | ||||||||||||||||||||||
| args.scratch_output_path = Path(args.scratch_output_path) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| result_dict.update(run_audio_fleurs_benchmark(args)) | ||||||||||||||||||||||
| success_code = 0 if result_dict["metrics"]["is_success"] else 1 | ||||||||||||||||||||||
| finally: | ||||||||||||||||||||||
| write_benchmark_results(result_dict, args.benchmark_results_path) | ||||||||||||||||||||||
| return success_code | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||
| raise SystemExit(main()) | ||||||||||||||||||||||
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.
The copyright year is set to 2026, which is in the future. This should be 2025 to match the other files in this PR (entry.py, session.py, utils.py all use 2025).