Skip to content

Commit

Permalink
distil whisper fix quantization (#2674)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova authored Jan 20, 2025
1 parent e4f0cb6 commit 894d859
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions notebooks/distil-whisper-asr/distil-whisper-asr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@
"### Quantize Distil-Whisper encoder and decoder models\n",
"[back to top ⬆️](#Table-of-contents:)\n",
"\n",
"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."
"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."
]
},
{
Expand Down Expand Up @@ -1154,7 +1154,7 @@
" # Smooth Quant algorithm reduces activation quantization error; optimal alpha value was obtained through grid search\n",
" advanced_parameters=nncf.AdvancedQuantizationParameters(smooth_quant_alpha=0.95)\n",
" )\n",
" ov.save_model(quantized_decoder_with_past, quantized_model_path / \"openvino_decoder_model.xml\")\n",
" ov.save_model(quantized_decoder, quantized_model_path / \"openvino_decoder_model.xml\")\n",
" del quantized_decoder\n",
" del decoder_calibration_data\n",
" gc.collect()\n",
Expand Down
6 changes: 5 additions & 1 deletion notebooks/outetts-text-to-speech/ov_outetts_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
try:
from outetts.version.v1.interface import InterfaceHF
from outetts.version.v1.prompt_processor import PromptProcessor
from outetts.version.v1.model import HFModel

try:
from outetts.version.v1.model import HFModel
except ImportError:
from outetts.models.hf_model import HFModel
from outetts.wav_tokenizer.audio_codec import AudioCodec

updated_version = True
Expand Down
2 changes: 2 additions & 0 deletions notebooks/phi-3-vision/phi-3-vision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"metadata": {},
"outputs": [],
"source": [
"import platform\n",
"\n",
"%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",
"%pip install --pre -qU \"openvino>=2024.6.0\" \"openvino-tokenizers>=2024.6.0\" --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly\n",
"%pip install -q -U \"nncf>=2.14.0\"\n",
Expand Down
4 changes: 3 additions & 1 deletion notebooks/sparsity-optimization/sparsity-optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
},
"outputs": [],
"source": [
"import torch\n",
"\n",
"# The following model has been quantized, sparsified using Optimum-Intel 1.7 which is enabled by OpenVINO and NNCF\n",
"# for reproducibility, refer https://huggingface.co/OpenVINO/bert-base-uncased-sst2-int8-unstructured80\n",
"model_id = \"OpenVINO/bert-base-uncased-sst2-int8-unstructured80\"\n",
Expand All @@ -133,7 +135,7 @@
"tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
"\n",
"# Let's take the model for a spin!\n",
"sentiment_classifier = pipeline(\"text-classification\", model=ov_model, tokenizer=tokenizer)\n",
"sentiment_classifier = pipeline(\"text-classification\", model=ov_model, tokenizer=tokenizer, device=torch.device(\"cpu\"))\n",
"\n",
"text = \"He's a dreadful magician.\"\n",
"outputs = sentiment_classifier(text)\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/stable-audio/stable-audio.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"source": [
"import platform\n",
"\n",
"%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",
"%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",
"%pip install -q --no-deps \"stable-audio-tools\"\n",
"%pip install -q \"nncf>=2.12.0\"\n",
"if platform.system() == \"Darwin\":\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@
" ).shuffle(seed=42)\n",
"\n",
" transformer_config = dict(pipe.transformer.config)\n",
" del transformer_config[\"model\"]\n",
" if \"model\" in transformer_config:\n",
" del transformer_config[\"model\"]\n",
" wrapped_unet = UNetWrapper(pipe.transformer.model, transformer_config)\n",
" pipe.transformer = wrapped_unet\n",
" # Run inference for data collection\n",
Expand Down
7 changes: 6 additions & 1 deletion notebooks/whisper-asr-genai/whisper-asr-genai.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,15 @@
"%pip install -q \"torch>=2.3\" \"torchvision>=0.18.1\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q -U \"transformers>=4.45\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"git+https://github.com/huggingface/optimum-intel.git\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install --pre -q -U \"openvino>=2024.5.0\" \"openvino-tokenizers>=2024.5.0\" \"openvino-genai>=2024.5.0\"\n",
"%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",
"%pip install -q datasets \"gradio>=4.0\" \"soundfile>=0.12\" \"librosa\" \"python-ffmpeg<=1.0.16\"\n",
"%pip install -q \"nncf>=2.14.0\" \"jiwer\" \"typing_extensions>=4.9\"\n",
"if platform.system() == \"Darwin\":\n",
" %pip install -q \"numpy<2.0\"\n",
"\n",
"from transformers.utils.import_utils import is_tf_available\n",
"\n",
"if is_tf_available():\n",
" %pip install -q \"numpy<2.0\""
]
},
Expand Down

0 comments on commit 894d859

Please sign in to comment.