Views
No views yet
| Model | Params / M | Rel. Latency ↑ | Short-Form WER ↓ | Long-Form WER ↓ |
|---|---|---|---|---|
| large-v3 | 1550 | 1.0 | 8.4 | 11.0 |
| distil-large-v3 | 756 | 6.3 | 9.7 | 10.8 |
| distil-large-v2 | 756 | 5.8 | 10.1 | 11.6 |
| distil-medium.en | 394 | 6.8 | 11.1 | 12.4 |
| distil-small.en | 166 | 5.6 | 12.1 | 12.8 |
1pip install --upgrade pip
2pip install --upgrade transformers accelerate datasets[audio]AutoModelForSpeechSeq2Seq and AutoProcessor classes.float16 precision and make sure that loading time takes as little time as possible by passing low_cpu_mem_usage=True.
In addition, we want to make sure that the model is loaded in safetensors format by passing use_safetensors=True:1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3
4device = "cuda:0" if torch.cuda.is_available() else "cpu"
5torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
6
7model_id = "distil-whisper/distil-large-v3"
8
9model = AutoModelForSpeechSeq2Seq.from_pretrained(
10 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
11)
12model.to(device)
13
14processor = AutoProcessor.from_pretrained(model_id)pipeline.
Note that if you would like to have more control over the generation process, you can directly make use of model + processor API as shown below.1pipe = pipeline(
2 "automatic-speech-recognition",
3 model=model,
4 tokenizer=processor.tokenizer,
5 feature_extractor=processor.feature_extractor,
6 max_new_tokens=128,
7 torch_dtype=torch_dtype,
8 device=device,
9)1from datasets import load_dataset
2
3dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
4sample = dataset[0]["audio"]1result = pipe(sample)
2print(result["text"])1result = pipe("audio.mp3")
2print(result["text"])model.generate, including num_beams for beam-search, return_timestamps
for segment-level timestamps, and prompt_ids for prompting. See the docstrings
for more details.1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3from datasets import Audio, load_dataset
4
5
6device = "cuda:0" if torch.cuda.is_available() else "cpu"
7torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
8
9model_id = "distil-whisper/distil-large-v3"
10
11model = AutoModelForSpeechSeq2Seq.from_pretrained(
12 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
13)
14model.to(device)
15
16processor = AutoProcessor.from_pretrained(model_id)
17
18dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
19dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
20sample = dataset[0]["audio"]
21
22input_features = processor(
23 sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt"
24).input_features
25
26input_features = input_features.to(device, dtype=torch_dtype)
27
28gen_kwargs = {
29 "max_new_tokens": 128,
30 "num_beams": 1,
31 "return_timestamps": False,
32}
33
34pred_ids = model.generate(input_features, **gen_kwargs)
35pred_text = processor.batch_decode(pred_ids, skip_special_tokens=True, decode_with_timestamps=gen_kwargs["return_timestamps"])
36
37print(pred_text)1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3
4device = "cuda:0" if torch.cuda.is_available() else "cpu"
5torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
6
7model_id = "distil-whisper/distil-large-v3"
8
9model = AutoModelForSpeechSeq2Seq.from_pretrained(
10 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
11)
12model.to(device)
13
14processor = AutoProcessor.from_pretrained(model_id)pipeline.
Note that if you would like to have more control over the generation process, you can directly make use of model.generate(...) API as shown below.1pipe = pipeline(
2 "automatic-speech-recognition",
3 model=model,
4 tokenizer=processor.tokenizer,
5 feature_extractor=processor.feature_extractor,
6 max_new_tokens=128,
7 torch_dtype=torch_dtype,
8 device=device,
9)1from datasets import load_dataset
2
3dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
4sample = dataset[0]["audio"]1result = pipe(sample)
2print(result["text"])1result = pipe("audio.mp3")
2print(result["text"])1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3from datasets import Audio, load_dataset
4
5
6device = "cuda:0" if torch.cuda.is_available() else "cpu"
7torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
8
9model_id = "distil-whisper/distil-large-v3"
10
11model = AutoModelForSpeechSeq2Seq.from_pretrained(
12 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
13)
14model.to(device)
15
16processor = AutoProcessor.from_pretrained(model_id)
17
18dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
19dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
20sample = dataset[0]["audio"]
21
22inputs = processor(
23 sample["array"],
24 sampling_rate=sample["sampling_rate"],
25 return_tensors="pt",
26 truncation=False,
27 padding="longest",
28 return_attention_mask=True,
29)
30inputs = inputs.to(device, dtype=torch_dtype)
31
32gen_kwargs = {
33 "max_new_tokens": 448,
34 "num_beams": 1,
35 "condition_on_prev_tokens": False,
36 "compression_ratio_threshold": 1.35, # zlib compression ratio threshold (in token space)
37 "temperature": (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
38 "logprob_threshold": -1.0,
39 "no_speech_threshold": 0.6,
40 "return_timestamps": True,
41}
42
43pred_ids = model.generate(**inputs, **gen_kwargs)
44pred_text = processor.batch_decode(pred_ids, skip_special_tokens=True, decode_with_timestamps=False)
45
46print(pred_text)1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
3
4device = "cuda:0" if torch.cuda.is_available() else "cpu"
5torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
6
7model_id = "distil-whisper/distil-large-v3"
8
9model = AutoModelForSpeechSeq2Seq.from_pretrained(
10 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
11)
12model.to(device)
13
14processor = AutoProcessor.from_pretrained(model_id)chunk_length_s parameter to the pipeline. For distil-large-v3, a chunk length of 25-seconds
is optimal. To activate batching, pass the argument batch_size:1pipe = pipeline(
2 "automatic-speech-recognition",
3 model=model,
4 tokenizer=processor.tokenizer,
5 feature_extractor=processor.feature_extractor,
6 max_new_tokens=128,
7 chunk_length_s=25,
8 batch_size=16,
9 torch_dtype=torch_dtype,
10 device=device,
11)max_new_tokens controls the maximum number of generated tokens per-chunk. In the typical speech setting,
we have no more than 3 words spoken per-second. Therefore, for a 30-second input, we have at most 90 words (approx 128 tokens).
We set the maximum number of generated tokens per-chunk to 128 to truncate any possible hallucinations that occur at the
end of the segment. These tokens get removed at the chunk borders using the long-form chunking transcription algorithm,
so it is more efficient to truncate them directly during generation to avoid redundant generation steps in the decoder.1from datasets import load_dataset
2
3dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
4sample = dataset[0]["audio"]1result = pipe(sample)
2print(result["text"])openai/whisper-large-v3.
As well as the assistant (a.k.a student) distil-whisper/distil-large-v3.1from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
2import torch
3
4device = "cuda:0" if torch.cuda.is_available() else "cpu"
5torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
6
7model_id = "openai/whisper-large-v3"
8
9model = AutoModelForSpeechSeq2Seq.from_pretrained(
10 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
11)
12model.to(device)
13
14processor = AutoProcessor.from_pretrained(model_id)1from transformers import AutoModelForCausalLM
2assistant_model_id = "distil-whisper/distil-large-v2"
3
4assistant_model = AutoModelForCausalLM.from_pretrained(
5 assistant_model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
6)
7assistant_model.to(device)generate_kwarg
with the key "assistant_model"
so that speculative decoding is enabled:1pipe = pipeline(
2 "automatic-speech-recognition",
3 model=model,
4 tokenizer=processor.tokenizer,
5 feature_extractor=processor.feature_extractor,
6 max_new_tokens=128,
7 generate_kwargs={"assistant_model": assistant_model},
8 torch_dtype=torch_dtype,
9 device=device,
10)1from datasets import load_dataset
2
3dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
4sample = dataset[0]["audio"]
5
6result = pipe(sample)
7print(result["text"])pip install flash-attn --no-build-isolationuse_flash_attention_2=True to from_pretrained to enable Flash Attention 2:1- model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
2+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True, use_flash_attention_2=True)pip install --upgrade optimum1model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
2+ model = model.to_bettertransformer()| Library | distil-small.en | distil-medium.en | distil-large-v2 |
|---|---|---|---|
| OpenAI Whisper | link | link | link |
| Whisper cpp | link | link | link |
| Transformers js | link | link | link |
| Candle (Rust) | link | link | link |





@misc{gandhi2023distilwhisper,
title={Distil-Whisper: Robust Knowledge Distillation via Large-Scale Pseudo Labelling},
author={Sanchit Gandhi and Patrick von Platen and Alexander M. Rush},
year={2023},
eprint={2311.00430},
archivePrefix={arXiv},
primaryClass={cs.CL}
}@misc{radford2022robust,
title={Robust Speech Recognition via Large-Scale Weak Supervision},
author={Alec Radford and Jong Wook Kim and Tao Xu and Greg Brockman and Christine McLeavey and Ilya Sutskever},
year={2022},
eprint={2212.04356},
archivePrefix={arXiv},
primaryClass={eess.AS}
}