Views
No views yet
1from vllm.assets.audio import AudioAsset
2from vllm import LLM, SamplingParams
3
4# prepare model
5llm = LLM(
6 model="neuralmagic/whisper-medium-FP8-Dynamic",
7 max_model_len=448,
8 max_num_seqs=400,
9 limit_mm_per_prompt={"audio": 1},
10)
11
12# prepare inputs
13inputs = { # Test explicit encoder/decoder prompt
14 "encoder_prompt": {
15 "prompt": "",
16 "multi_modal_data": {
17 "audio": AudioAsset("winning_call").audio_and_sample_rate,
18 },
19 },
20 "decoder_prompt": "<|startoftranscript|>",
21}
22
23# generate response
24print("========== SAMPLE GENERATION ==============")
25outputs = llm.generate(inputs, SamplingParams(temperature=0.0, max_tokens=64))
26print(f"PROMPT : {outputs[0].prompt}")
27print(f"RESPONSE: {outputs[0].outputs[0].text}")
28print("==========================================")1python quantize.py \
2 --model_path openai/whisper-medium \
3 --quant_path output_dir/whisper-medium-FP8-Dynamic1import argparse
2import torch
3import os
4from datasets import load_dataset
5from transformers import WhisperProcessor
6from llmcompressor import oneshot
7from llmcompressor.modifiers.quantization import QuantizationModifier
8from llmcompressor.transformers.tracing import TraceableWhisperForConditionalGeneration
9from compressed_tensors.quantization import QuantizationType
10
11# --- Args ---
12parser = argparse.ArgumentParser()
13parser.add_argument('--model_path', type=str, required=True)
14parser.add_argument('--quant_path', type=str, required=True)
15parser.add_argument('--observer', type=str, default="minmax")
16args = parser.parse_args()
17
18# --- Load Model ---
19model = TraceableWhisperForConditionalGeneration.from_pretrained(
20 args.model_path,
21 device_map="auto",
22 torch_dtype="auto",
23)
24model.config.forced_decoder_ids = None
25processor = WhisperProcessor.from_pretrained(args.model_path)
26
27# --- Recipe (FP8 Dynamic) ---
28recipe = [
29 QuantizationModifier(
30 targets="Linear",
31 scheme="FP8_DYNAMIC",
32 sequential_targets=["WhisperEncoderLayer", "WhisperDecoderLayer"],
33 ignore=["re:.*lm_head"],
34 )
35]
36
37# --- Run oneshot ---
38oneshot(
39 model=model,
40 recipe=recipe,
41 trust_remote_code_model=True,
42)
43
44# --- Save ---
45os.makedirs(args.quant_path, exist_ok=True)
46model.save_pretrained(args.quant_path, save_compressed=True)
47processor.save_pretrained(args.quant_path)
48
49lmms-eval \
--model=whisper_vllm \
--model_args="pretrained=neuralmagic-ent/whisper-medium-FP8-Dynamic" \
--batch_size 64 \
--output_path <output_file_path> \
--tasks librispeechlmms-eval \
--model=whisper_vllm \
--model_args="pretrained=neuralmagic-ent/whisper-medium-FP8-Dynamic" \
--batch_size 64 \
--output_path <output_file_path> \
--tasks fleurs| Benchmark | Split | BF16 | w8a8 | Recovery (%) |
|---|---|---|---|---|
| LibriSpeech (WER) | test-clean | 2.8269 | 2.8155 | 100.40% |
| test-other | 6.4445 | 6.4124 | 100.50% | |
| Fleurs (X→en, WER) | cmn_hans_cn | 13.3371 | 13.0153 | 102.47% |
| en | 4.6004 | 4.5386 | 101.36% | |
| yue_hant_hk | 9.8107 | 10.2004 | 96.18% |