Skip to content
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

Add support for huggingface ASR datasets #749

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Ahmedsaed
Copy link
Contributor

@Ahmedsaed Ahmedsaed commented Aug 15, 2024

What does this PR do? Please describe:
This PR builds upon #740 by incorporating the refactoring changes here and adding new commits that enable support for defining other datasets via configuration.

Example:

fairseq2 hg asr /tmp/fairseq2 --config max_samples=2 dataset_config.split=test dataset_config.dataset_path=google/fleurs dataset_config.
dataset_name=en_us dataset_config.target_column=['transcription'] # override default preset
[08/15/24 03:55:44] INFO     fairseq2.recipes.hg.evaluator - Running evaluation on 1 device(s).                                                                                  
[08/15/24 03:57:55] INFO     fairseq2.recipes.hg.evaluator - Eval Metrics - BLEU: 0 | Elapsed Time: 130s | Wall Time: 131s | brevity_penalty: 1.0 | length_ratio: 1.0 |          
                             precisions: [0.375, 0.15789473684210525, 0.05555555555555555, 0.0] | reference_length: 40 | translation_length: 40                                  
                    INFO     fairseq2.recipes.hg.evaluator - Evaluation complete in 131 seconds                                                                                  

This evaluates wav2vec2 model on google/fleurs dataset by just overriding the relevant configs.

Does your PR introduce any breaking changes? If yes, please list them:
None.

Check list:

  • Was the content of this PR discussed and approved via a GitHub issue? (no need for typos or documentation improvements)
  • Did you read the contributor guideline?
  • Did you make sure that your PR does only one thing instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests?
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (no need for typos, documentation, or minor internal changes)

@Ahmedsaed Ahmedsaed requested a review from cbalioglu as a code owner August 15, 2024 04:32
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 15, 2024
src/fairseq2/recipes/hg/asr_eval.py Show resolved Hide resolved
src/fairseq2/recipes/hg/asr_eval.py Outdated Show resolved Hide resolved
src/fairseq2/recipes/hg/asr_eval.py Outdated Show resolved Hide resolved
src/fairseq2/recipes/hg/asr_eval.py Outdated Show resolved Hide resolved
del inputs
del targets
del outputs
torch.cuda.empty_cache()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this explicit empty_cache() call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the data from previous batches were not freed which lead to the evaluator crashing OOM after a some batches.

Quoting #740 (comment)

I noticed that running the evaluation with max_samples > 20 on a 15GB VRAM setup was causing a CUDA out-of-memory error. To address this, I made improvements to better manage and free up memory. With these updates, you can now run the evaluation on the entire dataset, provided the batch_size fits within the available memory. I successfully tested this on the whole test split (approximately 2939 examples) using whisper-tiny and wav2vec2_asr_base_10h with max_num_elements=10.
...

Edit: max_num_elements can also be increased significantly by defining max_audio_len as some audio samples were quite long and the whole batch gets padded to the longest sequence causing some batches to require a lot more memory than expected.

src/fairseq2/recipes/hg/asr_eval.py Outdated Show resolved Hide resolved
@@ -82,97 +125,133 @@ class AsrEvalConfig:
"""The data type of the model."""


asr_eval_presets = ConfigRegistry[AsrEvalConfig]()
@dataclass
class EvalSeqBatch:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not using Seq2SeqBatch here like the native ASR evaluator here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Seq2SeqBatch class expects targets to be tensors, which is useful for training. However, during evaluation, encoding the target only to decode it again without utilizing the tensors seems redundant.

Is there a better approach? another fairseq2 data-structure to use?

src/fairseq2/recipes/hg/asr_eval.py Show resolved Hide resolved
@Ahmedsaed Ahmedsaed changed the title Add support for other datasets through hg recipes Add support for huggingface ASR datasets Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants