Views
No views yet
| Configuration | Explanation |
|---|---|
BASELINE | a reference functionally equivalent to the original model |
BASIC | all linear algebraic operands quantized to MXINT8-64 |
pip install dmx_compressor1import torch
2from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
3from datasets import load_dataset
4from dmx.compressor.modeling import DmxModel
5
6
7device = "cuda:0" if torch.cuda.is_available() else "cpu"
8torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
9
10model_id = "d-matrix/whisper-medium"
11
12model = AutoModelForSpeechSeq2Seq.from_pretrained(
13 model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
14)
15model.to(device)
16
17processor = AutoProcessor.from_pretrained(model_id)
18
19pipe = pipeline(
20 "automatic-speech-recognition",
21 model=model,
22 tokenizer=processor.tokenizer,
23 feature_extractor=processor.feature_extractor,
24 torch_dtype=torch_dtype,
25 device=device,
26)
27
28dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
29sample = dataset[0]["audio"]
30shorter_audio = sample["array"][:1000]
31
32pipe.model = DmxModel.from_torch(pipe.model)
33
34result = pipe(shorter_audio)
35print(result["text"])