Skip to content

Commit 894d859

Browse files
authored
distil whisper fix quantization (#2674)
1 parent e4f0cb6 commit 894d859

File tree

7 files changed

+21
-7
lines changed

7 files changed

+21
-7
lines changed

notebooks/distil-whisper-asr/distil-whisper-asr.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@
10151015
"### Quantize Distil-Whisper encoder and decoder models\n",
10161016
"[back to top ⬆️](#Table-of-contents:)\n",
10171017
"\n",
1018-
"Below we run the `quantize` function which calls `nncf.quantize` on Distil-Whisper encoder and decoder-with-past models. We don't quantize first-step-decoder because its share in whole inference time is negligible."
1018+
"Below we run the `quantize` function which calls `nncf.quantize` on Distil-Whisper encoder and decoder models. We don't quantize first-step-decoder because its share in whole inference time is negligible."
10191019
]
10201020
},
10211021
{
@@ -1154,7 +1154,7 @@
11541154
" # Smooth Quant algorithm reduces activation quantization error; optimal alpha value was obtained through grid search\n",
11551155
" advanced_parameters=nncf.AdvancedQuantizationParameters(smooth_quant_alpha=0.95)\n",
11561156
" )\n",
1157-
" ov.save_model(quantized_decoder_with_past, quantized_model_path / \"openvino_decoder_model.xml\")\n",
1157+
" ov.save_model(quantized_decoder, quantized_model_path / \"openvino_decoder_model.xml\")\n",
11581158
" del quantized_decoder\n",
11591159
" del decoder_calibration_data\n",
11601160
" gc.collect()\n",

notebooks/outetts-text-to-speech/ov_outetts_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
try:
66
from outetts.version.v1.interface import InterfaceHF
77
from outetts.version.v1.prompt_processor import PromptProcessor
8-
from outetts.version.v1.model import HFModel
8+
9+
try:
10+
from outetts.version.v1.model import HFModel
11+
except ImportError:
12+
from outetts.models.hf_model import HFModel
913
from outetts.wav_tokenizer.audio_codec import AudioCodec
1014

1115
updated_version = True

notebooks/phi-3-vision/phi-3-vision.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
54+
"import platform\n",
55+
"\n",
5456
"%pip install -q -U \"torch>=2.1\" \"torchvision\" \"transformers>=4.45\" \"protobuf>=3.20\" \"gradio>=4.26\" \"Pillow\" \"accelerate\" \"tqdm\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
5557
"%pip install --pre -qU \"openvino>=2024.6.0\" \"openvino-tokenizers>=2024.6.0\" --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly\n",
5658
"%pip install -q -U \"nncf>=2.14.0\"\n",

notebooks/sparsity-optimization/sparsity-optimization.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
},
125125
"outputs": [],
126126
"source": [
127+
"import torch\n",
128+
"\n",
127129
"# The following model has been quantized, sparsified using Optimum-Intel 1.7 which is enabled by OpenVINO and NNCF\n",
128130
"# for reproducibility, refer https://huggingface.co/OpenVINO/bert-base-uncased-sst2-int8-unstructured80\n",
129131
"model_id = \"OpenVINO/bert-base-uncased-sst2-int8-unstructured80\"\n",
@@ -133,7 +135,7 @@
133135
"tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
134136
"\n",
135137
"# Let's take the model for a spin!\n",
136-
"sentiment_classifier = pipeline(\"text-classification\", model=ov_model, tokenizer=tokenizer)\n",
138+
"sentiment_classifier = pipeline(\"text-classification\", model=ov_model, tokenizer=tokenizer, device=torch.device(\"cpu\"))\n",
137139
"\n",
138140
"text = \"He's a dreadful magician.\"\n",
139141
"outputs = sentiment_classifier(text)\n",

notebooks/stable-audio/stable-audio.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"source": [
6565
"import platform\n",
6666
"\n",
67-
"%pip install -q \"torch>=2.2\" torchaudio einops einops-exts huggingface-hub k-diffusion pytorch_lightning alias-free-torch ema-pytorch transformers>=4.45 \"gradio>=4.19 --extra-index-url https://download.pytorch.org/whl/cpu\n",
67+
"%pip install -q \"torch>=2.2\" \"torchaudio\" \"einops\" \"einops-exts\" \"huggingface-hub\" \"k-diffusion\" \"pytorch_lightning\" \"alias-free-torch\" \"ema-pytorch\" \"transformers>=4.45\" \"gradio>=4.19\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
6868
"%pip install -q --no-deps \"stable-audio-tools\"\n",
6969
"%pip install -q \"nncf>=2.12.0\"\n",
7070
"if platform.system() == \"Darwin\":\n",

notebooks/stable-diffusion-v3/stable-diffusion-v3-torch-fx.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@
450450
" ).shuffle(seed=42)\n",
451451
"\n",
452452
" transformer_config = dict(pipe.transformer.config)\n",
453-
" del transformer_config[\"model\"]\n",
453+
" if \"model\" in transformer_config:\n",
454+
" del transformer_config[\"model\"]\n",
454455
" wrapped_unet = UNetWrapper(pipe.transformer.model, transformer_config)\n",
455456
" pipe.transformer = wrapped_unet\n",
456457
" # Run inference for data collection\n",

notebooks/whisper-asr-genai/whisper-asr-genai.ipynb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@
7777
"%pip install -q \"torch>=2.3\" \"torchvision>=0.18.1\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
7878
"%pip install -q -U \"transformers>=4.45\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
7979
"%pip install -q \"git+https://github.com/huggingface/optimum-intel.git\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
80-
"%pip install --pre -q -U \"openvino>=2024.5.0\" \"openvino-tokenizers>=2024.5.0\" \"openvino-genai>=2024.5.0\"\n",
80+
"%pip install --pre -q -U \"openvino>=2024.5.0\" \"openvino-tokenizers>=2024.5.0\" \"openvino-genai>=2024.5.0\" --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly\n",
8181
"%pip install -q datasets \"gradio>=4.0\" \"soundfile>=0.12\" \"librosa\" \"python-ffmpeg<=1.0.16\"\n",
8282
"%pip install -q \"nncf>=2.14.0\" \"jiwer\" \"typing_extensions>=4.9\"\n",
8383
"if platform.system() == \"Darwin\":\n",
84+
" %pip install -q \"numpy<2.0\"\n",
85+
"\n",
86+
"from transformers.utils.import_utils import is_tf_available\n",
87+
"\n",
88+
"if is_tf_available():\n",
8489
" %pip install -q \"numpy<2.0\""
8590
]
8691
},

0 commit comments

Comments
 (0)