From 05bf24144b45de5012f7ee2e023e2152a06876ed Mon Sep 17 00:00:00 2001 From: Ekaterina Aidova Date: Mon, 3 Feb 2025 17:38:23 +0400 Subject: [PATCH] offline experience fixes (#2711) --- .../bark-text-to-audio/bark-text-to-audio.ipynb | 2 +- .../blip-visual-language-processing.ipynb | 1 + notebooks/depth-anything/depth-anything.ipynb | 16 ++++++++-------- .../instruct-pix2pix-image-editing.ipynb | 3 ++- .../llm-agent-react-langchain.ipynb | 5 +++++ .../multimodal-rag-llamaindex.ipynb | 5 +++++ .../optical-character-recognition.ipynb | 12 ++++++------ .../paddle-ocr-webcam/pre_post_processing.py | 2 +- .../softvc-voice-conversion.ipynb | 2 +- .../whisper-asr-genai/whisper-asr-genai.ipynb | 7 +++++-- .../whisper-subtitles-generation.ipynb | 2 +- .../yolov10-optimization.ipynb | 2 +- .../yolov11-keypoint-detection.ipynb | 3 ++- .../yolov8-object-detection.ipynb | 2 +- .../yolov9-optimization.ipynb | 2 +- 15 files changed, 41 insertions(+), 25 deletions(-) diff --git a/notebooks/bark-text-to-audio/bark-text-to-audio.ipynb b/notebooks/bark-text-to-audio/bark-text-to-audio.ipynb index 59edfbf754c..d6f66f7eeb6 100644 --- a/notebooks/bark-text-to-audio/bark-text-to-audio.ipynb +++ b/notebooks/bark-text-to-audio/bark-text-to-audio.ipynb @@ -142,7 +142,7 @@ "source": [ "text_use_small = True\n", "\n", - "text_encoder = load_model(model_type=\"text\", use_gpu=False, use_small=text_use_small, force_reload=False)\n", + "text_encoder = load_model(model_type=\"text\", use_gpu=False, use_small=text_use_small, force_reload=False, weights_only=False)\n", "\n", "text_encoder_model = text_encoder[\"model\"]\n", "tokenizer = text_encoder[\"tokenizer\"]" diff --git a/notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb b/notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb index cc6c47992cb..4ef3e28f8f9 100644 --- a/notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb +++ b/notebooks/blip-visual-language-processing/blip-visual-language-processing.ipynb @@ -1644,6 +1644,7 @@ "\n", "comp_text_encoder = core.compile_model(TEXT_ENCODER_OV, device.value)\n", "comp_text_decoder_with_past = core.compile_model(TEXT_DECODER_OV, device.value)\n", + "comp_vision_model = core.compile_model(VISION_MODEL_OV, device.value)\n", "fp_text_decoder.forward = partial(text_decoder_forward, ov_text_decoder_with_past=comp_text_decoder_with_past)\n", "fp16_model = OVBlipModel(model.config, model.decoder_start_token_id, comp_vision_model, comp_text_encoder, fp_text_decoder)" ] diff --git a/notebooks/depth-anything/depth-anything.ipynb b/notebooks/depth-anything/depth-anything.ipynb index 46c05edda74..61ea03dcf36 100644 --- a/notebooks/depth-anything/depth-anything.ipynb +++ b/notebooks/depth-anything/depth-anything.ipynb @@ -69,13 +69,7 @@ " r = requests.get(\n", " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/cmd_helper.py\",\n", " )\n", - " open(\"cmd_helper.py\", \"w\").write(r.text)\n", - "\n", - "if not Path(\"notebook_utils.py\").exists():\n", - " r = requests.get(\n", - " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", - " )\n", - " open(\"notebook_utils.py\", \"w\").write(r.text)" + " open(\"cmd_helper.py\", \"w\").write(r.text)" ] }, { @@ -109,7 +103,13 @@ "if platform.system() == \"Darwin\":\n", " %pip install -q \"numpy<2.0.0\"\n", "if platform.python_version_tuple()[1] in [\"8\", \"9\"]:\n", - " %pip install -q \"gradio-imageslider<=0.0.17\" \"typing-extensions>=4.9.0\"" + " %pip install -q \"gradio-imageslider<=0.0.17\" \"typing-extensions>=4.9.0\"\n", + "\n", + "if not Path(\"notebook_utils.py\").exists():\n", + " r = requests.get(\n", + " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", + " )\n", + " open(\"notebook_utils.py\", \"w\").write(r.text)" ] }, { diff --git a/notebooks/instruct-pix2pix-image-editing/instruct-pix2pix-image-editing.ipynb b/notebooks/instruct-pix2pix-image-editing/instruct-pix2pix-image-editing.ipynb index 2bee53d26b7..32a5d4d24d9 100644 --- a/notebooks/instruct-pix2pix-image-editing/instruct-pix2pix-image-editing.ipynb +++ b/notebooks/instruct-pix2pix-image-editing/instruct-pix2pix-image-editing.ipynb @@ -1080,12 +1080,13 @@ "source": [ "import io\n", "import requests\n", + "from diffusers.utils import load_image\n", "\n", "default_image_path = Path(\"default_image.png\")\n", "default_url = \"https://user-images.githubusercontent.com/29454499/223343459-4ac944f0-502e-4acf-9813-8e9f0abc8a16.jpg\"\n", "\n", "if not default_image_path.exists():\n", - " img = PIL.Image.open(io.BytesIO(requests.get(default_url, stream=True).raw))\n", + " img = load_image(default_url)\n", " img.save(default_image_path)\n", "\n", "default_image = PIL.Image.open(default_image_path)\n", diff --git a/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb b/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb index dbc40e94b6c..f6f945aed46 100644 --- a/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb +++ b/notebooks/llm-agent-react/llm-agent-react-langchain.ipynb @@ -486,6 +486,11 @@ "import openvino.properties.hint as hints\n", "import openvino.properties.streams as streams\n", "\n", + "import torch\n", + "\n", + "if hasattr(torch, \"mps\") and torch.mps.is_available:\n", + " torch.mps.is_available = lambda: False\n", + "\n", "\n", "class StopSequenceCriteria(StoppingCriteria):\n", " \"\"\"\n", diff --git a/notebooks/multimodal-rag/multimodal-rag-llamaindex.ipynb b/notebooks/multimodal-rag/multimodal-rag-llamaindex.ipynb index 2d5c4ed4700..0c502140628 100644 --- a/notebooks/multimodal-rag/multimodal-rag-llamaindex.ipynb +++ b/notebooks/multimodal-rag/multimodal-rag-llamaindex.ipynb @@ -605,6 +605,11 @@ "metadata": {}, "outputs": [], "source": [ + "import torch\n", + "\n", + "if hasattr(torch, \"mps\") and torch.mps.is_available:\n", + " torch.mps.is_available = lambda: False\n", + "\n", "from llama_index.core.indices import MultiModalVectorStoreIndex\n", "from llama_index.vector_stores.qdrant import QdrantVectorStore\n", "from llama_index.core import StorageContext, Settings\n", diff --git a/notebooks/optical-character-recognition/optical-character-recognition.ipynb b/notebooks/optical-character-recognition/optical-character-recognition.ipynb index 75eda70afbe..983a1562eb1 100644 --- a/notebooks/optical-character-recognition/optical-character-recognition.ipynb +++ b/notebooks/optical-character-recognition/optical-character-recognition.ipynb @@ -94,7 +94,7 @@ " )\n", "\n", " open(\"notebook_utils.py\", \"w\").write(r.text)\n", - "from notebook_utils import load_image, device_widget\n", + "from notebook_utils import download_file, device_widget\n", "\n", "# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n", "from notebook_utils import collect_telemetry\n", @@ -290,14 +290,14 @@ } ], "source": [ - "# The `image_file` variable can point to a URL or a local image.\n", - "image_url = \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/intel_rnb.jpg\"\n", - "\n", "image_path = Path(\"intel_rnb.jpg\")\n", "\n", "if not image_path.exists():\n", - " image = load_image(image_url)\n", - " cv2.imwrite(str(image_path), image)\n", + " download_file(\n", + " url=\"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/image/intel_rnb.jpg\",\n", + " filename=image_path.name,\n", + " directory=image_path.parent,\n", + " )\n", "else:\n", " image = cv2.imread(str(image_path))\n", "\n", diff --git a/notebooks/paddle-ocr-webcam/pre_post_processing.py b/notebooks/paddle-ocr-webcam/pre_post_processing.py index 7e77d73d089..8b3d754df38 100644 --- a/notebooks/paddle-ocr-webcam/pre_post_processing.py +++ b/notebooks/paddle-ocr-webcam/pre_post_processing.py @@ -461,7 +461,7 @@ def draw_ocr_box_txt(image, boxes, txts, scores=None, drop_score=0.5, font_path= try: char_size = font.getbox(c) y_idx = -1 - except AttributeError: + except Exception: char_size = font.getsize(c) y_idx = 1 diff --git a/notebooks/softvc-voice-conversion/softvc-voice-conversion.ipynb b/notebooks/softvc-voice-conversion/softvc-voice-conversion.ipynb index be7f6b2a72e..9a9c23fc3b4 100644 --- a/notebooks/softvc-voice-conversion/softvc-voice-conversion.ipynb +++ b/notebooks/softvc-voice-conversion/softvc-voice-conversion.ipynb @@ -108,7 +108,7 @@ "\n", "%pip install -q \"openvino>=2023.2.0\"\n", "clone_repo(\"https://github.com/svc-develop-team/so-vits-svc\", revision=\"4.1-Stable\", add_to_sys_path=False)\n", - "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu tqdm librosa \"torch>=2.1.0\" \"torchaudio>=2.1.0\" faiss-cpu \"gradio>=4.19\" \"numpy>=1.23.5\" praat-parselmouth" + "%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu tqdm librosa \"torch>=2.1.0,<2.6.0\" \"torchaudio>=2.1.0,<2.6.0\" faiss-cpu \"gradio>=4.19\" \"numpy>=1.23.5\" praat-parselmouth" ] }, { diff --git a/notebooks/whisper-asr-genai/whisper-asr-genai.ipynb b/notebooks/whisper-asr-genai/whisper-asr-genai.ipynb index ba9920fdfc6..43ee8ae76f6 100644 --- a/notebooks/whisper-asr-genai/whisper-asr-genai.ipynb +++ b/notebooks/whisper-asr-genai/whisper-asr-genai.ipynb @@ -243,6 +243,7 @@ "source": [ "from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, pipeline\n", "from transformers.utils import logging\n", + "import torch\n", "\n", "processor = AutoProcessor.from_pretrained(model_id.value)\n", "\n", @@ -253,7 +254,7 @@ " model=pt_model,\n", " tokenizer=processor.tokenizer,\n", " feature_extractor=processor.feature_extractor,\n", - " device=\"cpu\",\n", + " device=torch.device(\"cpu\"),\n", ")" ] }, @@ -1017,7 +1018,9 @@ " model=ov_model,\n", " chunk_length_s=30,\n", " tokenizer=ov_processor.tokenizer,\n", - " feature_extractor=ov_processor.feature_extractor)\n", + " feature_extractor=ov_processor.feature_extractor,\n", + " device=torch.device(\"cpu\")\n", + " )\n", " try:\n", " calibration_dataset = dataset = load_dataset(\"openslr/librispeech_asr\", \"clean\", split=\"validation\", streaming=True, trust_remote_code=True)\n", " for sample in tqdm(islice(calibration_dataset, calibration_dataset_size), desc=\"Collecting calibration data\",\n", diff --git a/notebooks/whisper-subtitles-generation/whisper-subtitles-generation.ipynb b/notebooks/whisper-subtitles-generation/whisper-subtitles-generation.ipynb index f0c6af3a0d1..755d2b4c311 100644 --- a/notebooks/whisper-subtitles-generation/whisper-subtitles-generation.ipynb +++ b/notebooks/whisper-subtitles-generation/whisper-subtitles-generation.ipynb @@ -763,7 +763,7 @@ " model=ov_model,\n", " chunk_length_s=30,\n", " tokenizer=processor.tokenizer,\n", - " feature_extractor=processor.feature_extractor)\n", + " feature_extractor=processor.feature_extractor, devide=torch.device(\"cpu\"))\n", " try:\n", " calibration_dataset = dataset = load_dataset(\"openslr/librispeech_asr\", \"clean\", split=\"validation\", streaming=True, trust_remote_code=True)\n", " for sample in tqdm(islice(calibration_dataset, calibration_dataset_size), desc=\"Collecting calibration data\",\n", diff --git a/notebooks/yolov10-optimization/yolov10-optimization.ipynb b/notebooks/yolov10-optimization/yolov10-optimization.ipynb index e71e6821883..cff0909b806 100644 --- a/notebooks/yolov10-optimization/yolov10-optimization.ipynb +++ b/notebooks/yolov10-optimization/yolov10-optimization.ipynb @@ -86,7 +86,7 @@ "%pip install -q \"nncf>=2.11.0\"\n", "%pip install -Uq \"openvino>=2024.3.0\"\n", "%pip install -q \"git+https://github.com/THU-MIG/yolov10.git\" --extra-index-url https://download.pytorch.org/whl/cpu\n", - "%pip install -q \"torch>=2.1\" \"torchvision>=0.16\" tqdm opencv-python \"gradio>=4.19\" \"matplotlib>=3.9\" --extra-index-url https://download.pytorch.org/whl/cpu" + "%pip install -q \"torch>=2.1,<2.6\" \"torchvision>=0.16\" tqdm opencv-python \"gradio>=4.19\" \"matplotlib>=3.9\" --extra-index-url https://download.pytorch.org/whl/cpu" ] }, { diff --git a/notebooks/yolov11-optimization/yolov11-keypoint-detection.ipynb b/notebooks/yolov11-optimization/yolov11-keypoint-detection.ipynb index d53a21862d2..9fbde2decbc 100644 --- a/notebooks/yolov11-optimization/yolov11-keypoint-detection.ipynb +++ b/notebooks/yolov11-optimization/yolov11-keypoint-detection.ipynb @@ -117,12 +117,13 @@ "# Fetch `notebook_utils` module\n", "import requests\n", "\n", - "if Path(\"notebook_utils.py\").exists():\n", + "if not Path(\"notebook_utils.py\").exists():\n", " r = requests.get(\n", " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", " )\n", "\n", " open(\"notebook_utils.py\", \"w\").write(r.text)\n", + "\n", "from notebook_utils import download_file, VideoPlayer, device_widget\n", "\n", "# Read more about telemetry collection at https://github.com/openvinotoolkit/openvino_notebooks?tab=readme-ov-file#-telemetry\n", diff --git a/notebooks/yolov8-optimization/yolov8-object-detection.ipynb b/notebooks/yolov8-optimization/yolov8-object-detection.ipynb index 1bcd46d016e..e7fa6ff2aec 100644 --- a/notebooks/yolov8-optimization/yolov8-object-detection.ipynb +++ b/notebooks/yolov8-optimization/yolov8-object-detection.ipynb @@ -132,7 +132,7 @@ "# Fetch `notebook_utils` module\n", "import requests\n", "\n", - "if not Path(\"notebook_utils.py\").exists()\n", + "if not Path(\"notebook_utils.py\").exists():\n", " r = requests.get(\n", " url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n", " )\n", diff --git a/notebooks/yolov9-optimization/yolov9-optimization.ipynb b/notebooks/yolov9-optimization/yolov9-optimization.ipynb index 627613a76e6..ef960316d8c 100644 --- a/notebooks/yolov9-optimization/yolov9-optimization.ipynb +++ b/notebooks/yolov9-optimization/yolov9-optimization.ipynb @@ -63,7 +63,7 @@ "metadata": {}, "outputs": [], "source": [ - "%pip install -q \"openvino>=2023.3.0\" \"nncf>=2.8.1\" \"opencv-python\" \"matplotlib>=3.4\" \"seaborn\" \"pandas\" \"scikit-learn\" \"torch\" \"torchvision\" \"tqdm\" --extra-index-url https://download.pytorch.org/whl/cpu" + "%pip install -q \"openvino>=2023.3.0\" \"nncf>=2.8.1\" \"opencv-python\" \"matplotlib>=3.4\" \"seaborn\" \"pandas\" \"scikit-learn\" \"torch<2.6.0\" \"torchvision\" \"tqdm\" --extra-index-url https://download.pytorch.org/whl/cpu" ] }, {