Skip to content

Commit

Permalink
remove checking vs existing for pytorch quantization (openvinotoolkit…
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova authored Mar 7, 2024
1 parent 623715b commit f935d5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -20,7 +19,8 @@
"> **NOTE**: This notebook requires that a C++ compiler is accessible on the default binary search path of the OS you are running the notebook.\n",
"\n",
"\n",
"#### Table of contents:\n\n",
"#### Table of contents:\n",
"\n",
"- [Preparations](#Preparations)\n",
" - [Imports](#Imports)\n",
" - [Settings](#Settings)\n",
Expand All @@ -38,7 +38,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -53,57 +52,11 @@
"outputs": [],
"source": [
"# Install openvino package\n",
"%pip install -q \"openvino>=2023.1.0\" torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"nncf>=2.6.0\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": true,
"tags": []
},
"outputs": [],
"source": [
"# On Windows, this script adds the directory that contains cl.exe to the PATH to enable PyTorch to find the\n",
"# required C++ tools. This code assumes that Visual Studio 2019 is installed in the default\n",
"# directory. If you have a different C++ compiler, add the correct path to os.environ[\"PATH\"]\n",
"# directly.\n",
"\n",
"# Adding the path to os.environ[\"LIB\"] is not always required - it depends on the system configuration.\n",
"\n",
"import sys\n",
"\n",
"if sys.platform == \"win32\":\n",
" import distutils.command.build_ext\n",
" import os\n",
" from pathlib import Path\n",
"\n",
" VS_INSTALL_DIR = r\"C:/Program Files (x86)/Microsoft Visual Studio\"\n",
" cl_paths = sorted(list(Path(VS_INSTALL_DIR).glob(\"**/Hostx86/x64/cl.exe\")))\n",
" if len(cl_paths) == 0:\n",
" raise ValueError(\n",
" \"Cannot find Visual Studio. This notebook requires C++. If you installed \"\n",
" \"a C++ compiler, please add the directory that contains cl.exe to \"\n",
" \"`os.environ['PATH']`\"\n",
" )\n",
" else:\n",
" # If multiple versions of MSVC are installed, get the most recent one.\n",
" cl_path = cl_paths[-1]\n",
" vs_dir = str(cl_path.parent)\n",
" os.environ[\"PATH\"] += f\"{os.pathsep}{vs_dir}\"\n",
" # The code for finding the library dirs is from\n",
" # https://stackoverflow.com/questions/47423246/get-pythons-lib-path\n",
" d = distutils.core.Distribution()\n",
" b = distutils.command.build_ext.build_ext(d)\n",
" b.finalize_options()\n",
" os.environ[\"LIB\"] = os.pathsep.join(b.library_dirs)\n",
" print(f\"Added {vs_dir} to PATH\")"
"%pip install -q \"openvino>=2024.0.0\" torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"nncf>=2.9.0\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -146,7 +99,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -206,7 +158,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -264,7 +215,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -340,7 +290,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -404,7 +353,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -441,7 +389,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -507,7 +454,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -518,7 +464,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -557,7 +502,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -569,7 +513,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -596,7 +539,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -639,7 +581,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -674,15 +615,13 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"It should be noted that the inference time for the quantized PyTorch model is longer than that of the original model, as fake quantizers are added to the model by NNCF. However, the model's performance will significantly improve when it is in the OpenVINO Intermediate Representation (IR) format."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -759,7 +698,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -806,7 +744,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -881,7 +818,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -972,7 +908,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1018,7 +953,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1032,7 +967,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.8.10"
},
"openvino_notebooks": {
"imageUrl": "",
Expand All @@ -1055,43 +990,12 @@
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
"5ba51a4155a94f2f9b2021414519d2fd": {
"model_module": "@jupyter-widgets/base",
"model_module_version": "2.0.0",
"model_name": "LayoutModel",
"state": {}
},
"88897c3f697f4cef82e9b7c3e0064fa4": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "DescriptionStyleModel",
"state": {
"description_width": ""
}
},
"e4be0e28604d4474ba58bb32a06e4514": {
"model_module": "@jupyter-widgets/controls",
"model_module_version": "2.0.0",
"model_name": "DropdownModel",
"state": {
"_options_labels": [
"CPU",
"GPU",
"AUTO"
],
"description": "Device:",
"index": 2,
"layout": "IPY_MODEL_5ba51a4155a94f2f9b2021414519d2fd",
"style": "IPY_MODEL_88897c3f697f4cef82e9b7c3e0064fa4"
}
}
},
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Loading

0 comments on commit f935d5c

Please sign in to comment.