Skip to content

Commit

Permalink
reuse device widget (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Aug 26, 2024
1 parent eb75851 commit 350672e
Show file tree
Hide file tree
Showing 67 changed files with 266 additions and 802 deletions.
2 changes: 1 addition & 1 deletion .ci/patch_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
EXCLUDED_NOTEBOOKS = ["data-preparation-ct-scan.ipynb", "pytorch-monai-training.ipynb"]

DEVICE_WIDGET = "device = widgets.Dropdown("
DEVICE_WIDGET_NEW = "device = device_widget("
DEVICE_WIDGET_NEW = "device_widget("


def disable_gradio_debug(nb, notebook_path):
Expand Down
9 changes: 1 addition & 8 deletions notebooks/3D-pose-estimation-webcam/3D-pose-estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,7 @@
"metadata": {},
"outputs": [],
"source": [
"core = ov.Core()\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = utils.device_widget()\n",
"\n",
"device"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
")\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"\n",
"from notebook_utils import download_file"
"from notebook_utils import download_file, device_widget"
]
},
{
Expand Down Expand Up @@ -338,14 +338,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = device_widget()\n",
"\n",
"device"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,7 @@
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"\n",
"core = ov.Core()\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = utils.device_widget()\n",
"\n",
"device"
]
Expand Down
10 changes: 1 addition & 9 deletions notebooks/async-api/async-api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"core = ov.Core()\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"CPU\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = utils.device_widget(default=\"CPU\")\n",
"\n",
"device"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
" url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\",\n",
")\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"from notebook_utils import download_file\n",
"from notebook_utils import download_file, device_widget, quantization_widget\n",
"\n",
"# get model and processor\n",
"processor = BlipProcessor.from_pretrained(\"Salesforce/blip-vqa-base\")\n",
Expand Down Expand Up @@ -571,14 +571,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = device_widget()\n",
"\n",
"device"
]
Expand Down Expand Up @@ -781,11 +774,7 @@
}
],
"source": [
"to_quantize = widgets.Checkbox(\n",
" value=True,\n",
" description=\"Quantization\",\n",
" disabled=False,\n",
")\n",
"to_quantize = quantization_widget()\n",
"\n",
"to_quantize"
]
Expand Down Expand Up @@ -1723,6 +1712,8 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"use_quantized_model = widgets.Checkbox(\n",
" description=\"Use quantized model\",\n",
" value=int8_model is not None,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"# Fetch `notebook_utils` module\n",
"r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/utils/notebook_utils.py\")\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"from notebook_utils import download_file\n",
"from notebook_utils import download_file, device_widget\n",
"\n",
"if not Path(\"./custom_segmentation.py\").exists():\n",
" download_file(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/ct-segmentation-quantize/custom_segmentation.py\")\n",
Expand Down Expand Up @@ -775,15 +775,7 @@
"# By default, benchmark on MULTI:CPU,GPU if a GPU is available, otherwise on CPU.\n",
"device_list = [\"MULTI:CPU,GPU\" if \"GPU\" in core.available_devices else \"AUTO\"]\n",
"\n",
"import ipywidgets as widgets\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + device_list,\n",
" value=device_list[0],\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"\n",
"device = device_widget(device_list[0], added=device_list)\n",
"device"
]
},
Expand Down
23 changes: 7 additions & 16 deletions notebooks/depth-anything/depth-anything-v2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
")\n",
"\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"from notebook_utils import download_file\n",
"from notebook_utils import download_file, device_widget, quantization_widget\n",
"\n",
"download_file(\n",
" \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/3f779fc1-c1b2-4dec-915a-64dae510a2bb\",\n",
Expand Down Expand Up @@ -383,16 +383,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"core = ov.Core()\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = device_widget()\n",
"\n",
"device"
]
Expand All @@ -404,6 +395,8 @@
"metadata": {},
"outputs": [],
"source": [
"core = ov.Core()\n",
"\n",
"compiled_model = core.compile_model(OV_DEPTH_ANYTHING_PATH, device.value)"
]
},
Expand Down Expand Up @@ -878,11 +871,7 @@
}
],
"source": [
"to_quantize = widgets.Checkbox(\n",
" value=True,\n",
" description=\"Quantization\",\n",
" disabled=False,\n",
")\n",
"to_quantize = quantization_widget()\n",
"\n",
"to_quantize"
]
Expand Down Expand Up @@ -1426,6 +1415,8 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"quantized_model_present = OV_DEPTH_ANYTHING_INT8_PATH.exists()\n",
"\n",
"use_quantized_model = widgets.Checkbox(\n",
Expand Down
23 changes: 6 additions & 17 deletions notebooks/depth-anything/depth-anything.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
")\n",
"\n",
"open(\"notebook_utils.py\", \"w\").write(r.text)\n",
"from notebook_utils import download_file\n",
"from notebook_utils import download_file, device_widget, quantization_widget\n",
"\n",
"download_file(\n",
" \"https://github.com/openvinotoolkit/openvino_notebooks/assets/29454499/3f779fc1-c1b2-4dec-915a-64dae510a2bb\",\n",
Expand Down Expand Up @@ -395,17 +395,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"core = ov.Core()\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"\n",
"device = device_widget()\n",
"device"
]
},
Expand All @@ -416,6 +406,7 @@
"metadata": {},
"outputs": [],
"source": [
"core = ov.Core()\n",
"compiled_model = core.compile_model(OV_DEPTH_ANYTHING_PATH, device.value)"
]
},
Expand Down Expand Up @@ -849,11 +840,7 @@
}
],
"source": [
"to_quantize = widgets.Checkbox(\n",
" value=True,\n",
" description=\"Quantization\",\n",
" disabled=False,\n",
")\n",
"to_quantize = quantization_widget()\n",
"\n",
"to_quantize"
]
Expand Down Expand Up @@ -1210,6 +1197,8 @@
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets\n",
"\n",
"quantized_model_present = OV_DEPTH_ANYTHING_INT8_PATH.exists()\n",
"\n",
"use_quantized_model = widgets.Checkbox(\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@
"import openvino as ov"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7325aad7",
"metadata": {},
"outputs": [],
"source": [
"# Fetch `notebook_utils` module\n",
"import requests\n",
"\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",
"from notebook_utils import download_file, device_widget"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -215,14 +233,7 @@
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = device_widget()\n",
"\n",
"device"
]
Expand Down Expand Up @@ -357,16 +368,6 @@
"metadata": {},
"outputs": [],
"source": [
"# Fetch `notebook_utils` module\n",
"import requests\n",
"\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",
"from notebook_utils import download_file\n",
"\n",
"# Download the text from the openvino_notebooks storage\n",
"vocab_file_path = download_file(\n",
" \"https://storage.openvinotoolkit.org/repositories/openvino_notebooks/data/data/text/food_reviews.txt\",\n",
Expand Down
39 changes: 20 additions & 19 deletions notebooks/efficient-sam/efficient-sam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@
"%cd $repo_dir"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ca5e78a",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\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, device_widget, quantization_widget # noqa: F401"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down Expand Up @@ -475,12 +493,7 @@
}
],
"source": [
"device = widgets.Dropdown(\n",
" options=core.available_devices + [\"AUTO\"],\n",
" value=\"AUTO\",\n",
" description=\"Device:\",\n",
" disabled=False,\n",
")\n",
"device = device_widget()\n",
"\n",
"device"
]
Expand Down Expand Up @@ -609,11 +622,7 @@
}
],
"source": [
"to_quantize = widgets.Checkbox(\n",
" value=True,\n",
" description=\"Quantization\",\n",
" disabled=False,\n",
")\n",
"to_quantize = quantization_widget()\n",
"\n",
"to_quantize"
]
Expand Down Expand Up @@ -667,14 +676,6 @@
"\n",
"from zipfile import ZipFile\n",
"\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\n",
"\n",
"DATA_URL = \"https://ultralytics.com/assets/coco128.zip\"\n",
"OUT_DIR = Path('.')\n",
"\n",
Expand Down
Loading

0 comments on commit 350672e

Please sign in to comment.