Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
openvino-dev-samples committed Dec 2, 2024
2 parents 104c08f + 60d0cde commit ea13834
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 191 deletions.
9 changes: 2 additions & 7 deletions .ci/skipped_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,6 @@
skips:
- python:
- '3.9'
- notebook: notebooks/minicpm-v-multimodal-chatbot/minicpm-v-multimodal-chatbot.ipynb
skips:
- os:
- macos-13
- ubuntu-20.04
- ubuntu-22.04
- windows-2019
- notebook: notebooks/stable-audio/stable-audio.ipynb
skips:
- os:
Expand Down Expand Up @@ -552,6 +545,8 @@
skips:
- os:
- macos-13
- python:
- '3.9'
- notebook: notebooks/mobileclip-video-search/mobileclip-video-search.ipynb
skips:
- os:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@
" \"transformers>=4.30.2\",\n",
" \"controlnet-aux>=0.0.6\",\n",
" \"gradio>=3.36\",\n",
" \"datasets>=2.14.6\",\n",
" \"nncf>=2.7.0\",\n",
" \"opencv-python\",\n",
" \"--extra-index-url\",\n",
" \"https://download.pytorch.org/whl/cpu\",\n",
")\n",
"pip_install(\"openvino>=2023.1.0\", \"datasets>=2.14.6\", \"nncf>=2.7.0\", \"opencv-python\")"
"pip_install(\"openvino>=2023.1.0\")"
]
},
{
Expand Down
9 changes: 8 additions & 1 deletion notebooks/efficient-sam/efficient-sam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -q \"openvino>=2023.3.0\" \"nncf>=2.7.0\" opencv-python \"gradio>=4.13\" \"matplotlib>=3.4\" torch torchvision tqdm --extra-index-url https://download.pytorch.org/whl/cpu"
"import platform\n",
"\n",
"%pip install -q \"openvino>=2024.5.0\" \"nncf>=2.14.0\"\n",
"%pip install -q \"torch>=2.2.0\" \"torchaudio>=2.2.0\" \"torchvision>=0.17.0\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q opencv-python \"gradio>=4.13\" \"matplotlib>=3.4\" tqdm\n",
"\n",
"if platform.system() == \"Darwin\":\n",
" %pip install -q \"numpy<2.0.0\""
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"from pathlib import Path\n",
"import requests\n",
"\n",
"%pip install -q \"torch>=2.1.0\" \"torchvision\" \"torchaudio\" --index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"torch>=2.3.0\" \"torchvision\" \"torchaudio\" --index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"git+https://github.com/huggingface/optimum-intel.git\" --index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"nncf>=2.14.0\" \"sentencepiece\" \"tokenizers>=0.12.1\" \"transformers>=4.45.0\" \"gradio>=4.36\"\n",
"%pip install -q -U \"openvino-tokenizers>=2024.5.0\" \"openvino>=2024.5.0\" \"openvino-genai>=2024.5.0\"|\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@
"cell_type": "code",
"execution_count": 3,
"id": "82e846bb",
"metadata": {},
"metadata": {
"test_replace": {
"openbmb/MiniCPM-V-2_6": "katuni4ka/tiny-random-minicpmv-2_6"
}
},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -169,7 +173,7 @@
"model_dir = Path(model_id.split(\"/\")[-1] + \"-ov\")\n",
"\n",
"if not model_dir.exists():\n",
" optimum_cli(model_id, model_dir, additional_args={\"trust-remote-code\": \"\", \"weight-format\": \"fp16\"})\n",
" optimum_cli(model_id, model_dir, additional_args={\"trust-remote-code\": \"\", \"weight-format\": \"fp16\", \"task\": \"image-text-to-text\"})\n",
" compress_lm_weights(model_dir)"
]
},
Expand Down Expand Up @@ -204,22 +208,22 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"id": "626fef57",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "84bba5eaf8cc4b7e97a5e5d3768146e3",
"model_id": "2362638a795340e6b3effb0805848768",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Dropdown(description='Device:', index=1, options=('CPU', 'AUTO'), value='AUTO')"
]
},
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -434,21 +438,7 @@
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"41592555658f4eb69616c541894b88f0": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"658a0c15a9cb47078c9c8647bff53d1e": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {}
},
"84bba5eaf8cc4b7e97a5e5d3768146e3": {
"2362638a795340e6b3effb0805848768": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "DropdownModel",
Expand All @@ -459,9 +449,23 @@
],
"description": "Device:",
"index": 1,
"layout": "IPY_MODEL_658a0c15a9cb47078c9c8647bff53d1e",
"style": "IPY_MODEL_41592555658f4eb69616c541894b88f0"
"layout": "IPY_MODEL_d737bcde20ac4ba38ecf0902eec67998",
"style": "IPY_MODEL_49b230bc877e422788033f49884843a2"
}
},
"49b230bc877e422788033f49884843a2": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"d737bcde20ac4ba38ecf0902eec67998": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {}
}
},
"version_major": 2,
Expand Down
215 changes: 75 additions & 140 deletions notebooks/outetts-text-to-speech/outetts-text-to-speech.ipynb

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions notebooks/outetts-text-to-speech/ov_outetts_helper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from outetts.v0_1.interface import InterfaceHF
from outetts.v0_1.audio_codec import AudioCodec
from outetts.v0_1.prompt_processor import PromptProcessor
from outetts.v0_1.model import HFModel
import torch
from optimum.intel.openvino import OVModelForCausalLM

try:
from outetts.version.v1.interface import InterfaceHF
from outetts.version.v1.prompt_processor import PromptProcessor
from outetts.version.v1.model import HFModel
from outetts.wav_tokenizer.audio_codec import AudioCodec
updated_version = True
except ImportError:
from outetts.v0_1.interface import InterfaceHF
from outetts.v0_1.audio_codec import AudioCodec
from outetts.v0_1.prompt_processor import PromptProcessor
from outetts.v0_1.model import HFModel
updated_version = False


class OVHFModel(HFModel):
def __init__(self, model_path, device):
Expand All @@ -20,5 +29,9 @@ def __init__(
) -> None:
self.device = torch.device("cpu")
self.audio_codec = AudioCodec(self.device)
self.prompt_processor = PromptProcessor(model_path)
self.prompt_processor = PromptProcessor(model_path) if not updated_version else PromptProcessor(model_path, ["en"])
self.model = OVHFModel(model_path, device)
self.language = "en"
self.verbose = False
self.languages = ["en"]
self._device = torch.device("cpu")
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
"\n",
"os.environ[\"GIT_CLONE_PROTECTION_ACTIVE\"] = \"false\"\n",
"\n",
"%pip uninstall -q -y torch torchvision torchaudio\n",
"%pip install -q \"openvino>=2024.2.0\"\n",
"%pip install -q git+https://github.com/huggingface/parler-tts.git \"gradio>=4.19\" transformers \"torch>=2.2\" --extra-index-url https://download.pytorch.org/whl/cpu"
"%pip install -q git+https://github.com/huggingface/parler-tts.git \"gradio>=4.19\" transformers \"torch>=2.2\" \"torchaudio\" --extra-index-url https://download.pytorch.org/whl/cpu"
]
},
{
Expand Down
38 changes: 28 additions & 10 deletions notebooks/speculative-sampling/speculative-sampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "553148f5",
"metadata": {},
"outputs": [
Expand All @@ -207,7 +207,23 @@
"pipe = ov_genai.LLMPipeline(target_model_path, device.value)\n",
"\n",
"config = ov_genai.GenerationConfig()\n",
"config.max_new_tokens = 100\n",
"config.max_new_tokens = 330\n",
"prompt = '''<s>\n",
"\n",
"def prime_fib(n: int):\n",
" \"\"\"\n",
" prime_fib returns n-th number that is a Fibonacci number and it's also prime.\n",
" >>> prime_fib(1)\n",
" 2\n",
" >>> prime_fib(2)\n",
" 3\n",
" >>> prime_fib(3)\n",
" 5\n",
" >>> prime_fib(4)\n",
" 13\n",
" >>> prime_fib(5)\n",
" 89\n",
" \"\"\"'''\n",
"\n",
"\n",
"def streamer(subword):\n",
Expand All @@ -218,13 +234,13 @@
"\n",
"\n",
"start_time = time.perf_counter()\n",
"pipe.generate([\"Sun is yellow because\"], config, streamer=streamer)\n",
"pipe.generate(prompt, config, streamer=streamer)\n",
"end_time = time.perf_counter()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "c40d9901-ceb2-4c4c-a686-303590292ab3",
"metadata": {},
"outputs": [
Expand All @@ -241,7 +257,7 @@
"\n",
"print(f\"Generation time: {end_time - start_time:.2f}s\")\n",
"del pipe\n",
"gc.collect();"
"gc.collect()"
]
},
{
Expand All @@ -263,7 +279,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "9fde1b3c",
"metadata": {},
"outputs": [
Expand All @@ -278,17 +294,19 @@
"source": [
"scheduler_config = ov_genai.SchedulerConfig()\n",
"# cache params\n",
"scheduler_config.cache_size = 2\n",
"scheduler_config.cache_size = 0\n",
"scheduler_config.num_kv_blocks = 2048 // 8\n",
"scheduler_config.max_num_batched_tokens = 2048\n",
"\n",
"draft_model = ov_genai.draft_model(draft_model_path, device.value)\n",
"\n",
"pipe = ov_genai.LLMPipeline(target_model_path, device.value, draft_model=draft_model, scheduler_config=scheduler_config)\n",
"\n",
"config = ov_genai.GenerationConfig()\n",
"config.max_new_tokens = 100\n",
"config.num_assistant_tokens = 3\n",
"config.max_new_tokens = 330\n",
"config.num_assistant_tokens = 5\n",
"start_time = time.perf_counter()\n",
"result = pipe.generate([\"Sun is yellow because\"], config, streamer=streamer)\n",
"result = pipe.generate(prompt, config, streamer=streamer)\n",
"end_time = time.perf_counter()"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,27 @@
"outputs": [],
"source": [
"import platform\n",
"import importlib.metadata\n",
"import importlib.util\n",
"\n",
"%pip install -q \"nncf>=2.14.0\"\n",
"%pip install -q -U \"openvino>=2024.5.0\" \"openvino-tokenizers>=2024.5.0\" \"openvino-genai>=2024.5.0\"\n",
"%pip install -q \"python-ffmpeg<=1.0.16\" \"ffmpeg\" \"moviepy\" \"transformers>=4.45\" \"git+https://github.com/huggingface/optimum-intel.git\" \"torch>=2.1\" --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q -U \"yt_dlp>=2024.8.6\" soundfile librosa jiwer\n",
"%pip install -q -U \"yt_dlp>=2024.8.6\" soundfile librosa jiwer packaging\n",
"%pip install -q \"gradio>=4.19\" \"typing_extensions>=4.9\"\n",
"\n",
"if platform.system() == \"Darwin\":\n",
" %pip install -q \"numpy<2.0\""
" %pip install -q \"numpy<2.0\"\n",
"\n",
"\n",
"from packaging import version\n",
"\n",
"if (\n",
" importlib.util.find_spec(\"tensorflow\") is not None\n",
" and version.parse(importlib.metadata.version(\"tensorflow\")) < version.parse(\"2.18.0\")\n",
" and version.parse(importlib.metadata.version(\"numpy\")) >= version.parse(\"2.0.0\")\n",
"):\n",
" %pip uninstall -q -y tensorflow"
]
},
{
Expand Down Expand Up @@ -379,7 +391,10 @@
"metadata": {},
"outputs": [],
"source": [
"from moviepy.editor import VideoFileClip\n",
"try:\n",
" from moviepy import VideoFileClip\n",
"except ImportError:\n",
" from moviepy.editor import VideoFileClip\n",
"from transformers.pipelines.audio_utils import ffmpeg_read\n",
"\n",
"\n",
Expand Down

0 comments on commit ea13834

Please sign in to comment.