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

Added Whisper from Huggingface. #1769

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions torchbenchmark/models/hf_Whisper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from torchbenchmark.util.framework.huggingface.model_factory import HuggingFaceModel
from torchbenchmark.tasks import SPEECH
import torch

class Model(HuggingFaceModel):
task = SPEECH.RECOGNITION
# https://cdn.openai.com/papers/whisper.pdf Says for large-v2 they trained on 1024 batch sizes, with 16 GPUs
DEFAULT_EVAL_BSIZE = 64
DEFAULT_Train_BSIZE = 64
Copy link
Contributor

Choose a reason for hiding this comment

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

If training is not implemented, please remove this line.


def __init__(self, test, device, jit=False, batch_size=None, extra_args=[]):
super().__init__(name="hf_Whisper", test=test, device=device, jit=jit, batch_size=batch_size, extra_args=extra_args)
self.feature_size = 80
self.sequence_length = 3000
input_features = torch.randn(size=(self.batch_size, self.feature_size, self.sequence_length),device=self.device)
self.example_inputs = {"input_features": input_features.to(self.device)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are wrapping the model in a different way, we need to implement customized get_module() here, similar to the upstream code: https://github.com/MaanavD/benchmark/blob/116df9cb937b6921d16eba34fc504776bb40a6ee/torchbenchmark/util/framework/huggingface/model_factory.py#L110

The reason we need get_module() is because this API is being used by our downstream benchmarking script: https://github.com/pytorch/pytorch/blob/main/benchmarks/dynamo/torchbench.py#L358
and it requires model(*example_input) runs successfully.


xuzhao9 marked this conversation as resolved.
Show resolved Hide resolved
def eval(self):
super().eval()
def train(self):
raise NotImplementedError("Training is not implemented.")
13 changes: 13 additions & 0 deletions torchbenchmark/models/hf_Whisper/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import subprocess
import sys
import os
from torchbenchmark.util.framework.huggingface.patch_hf import patch_transformers, cache_model

def pip_install_requirements():
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt'])

if __name__ == '__main__':
pip_install_requirements()
patch_transformers()
model_name = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
cache_model(model_name)
10 changes: 10 additions & 0 deletions torchbenchmark/models/hf_Whisper/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
devices:
NVIDIA A100-SXM4-40GB:
eval_batch_size: 8
eval_benchmark: false
eval_deterministic: false
eval_nograd: true
not_implemented:
- jit: true
train_benchmark: false
train_deterministic: false
1 change: 1 addition & 0 deletions torchbenchmark/models/hf_Whisper/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
numba
3 changes: 2 additions & 1 deletion torchbenchmark/util/framework/huggingface/model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from torchbenchmark.util.model import BenchmarkModel
from torchbenchmark.tasks import NLP
import transformers
from transformers import AutoConfig, ReformerConfig, BertConfig, GenerationConfig
from transformers import AutoConfig, ReformerConfig, BertConfig, GenerationConfig, WhisperConfig
from typing import Tuple

class_models = {
Expand All @@ -27,6 +27,7 @@
'hf_Bert': (512, 512, 'BertConfig()', 'AutoModelForMaskedLM'),
# see https://huggingface.co/bert-large-cased
'hf_Bert_large': (512, 512, 'BertConfig(hidden_size=1024, num_hidden_layers=24, num_attention_heads=16)', 'AutoModelForMaskedLM'),
'hf_Whisper': (1024, 1024, 'WhisperConfig()', 'AutoModelForAudioClassification'),
}

cpu_input_slice = {
Expand Down
2 changes: 1 addition & 1 deletion torchbenchmark/util/framework/huggingface/patch_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys
from .model_factory import class_models
from transformers import AutoConfig, ReformerConfig, BigBirdConfig, BertConfig
from transformers import AutoConfig, ReformerConfig, BigBirdConfig, BertConfig, WhisperConfig

PATCH_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "patches")

Expand Down
Loading