Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates properties #2403

Merged
merged 14 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .ci/skipped_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,8 @@
- python:
- '3.8'
- os:
- macos-12
- macos-12
- notebook: notebooks/llm-agent-react/llm-agent-react-langchain.ipynb
skips:
- python:
- '3.8'
1 change: 1 addition & 0 deletions .ci/spellcheck/.pyspelling.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ perceptron
Patil
PEFT
perceiver
PerformanceMode
performant
PersonaGPT
PGI
Expand Down
16 changes: 11 additions & 5 deletions notebooks/auto-device/auto-device.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"import platform\n",
"\n",
"# Install required packages\n",
"%pip install -q \"openvino>=2023.1.0\" Pillow torch torchvision tqdm --extra-index-url https://download.pytorch.org/whl/cpu\n",
"%pip install -q \"openvino>=2023.1.0\" \"numpy<2\" Pillow torch torchvision tqdm --extra-index-url https://download.pytorch.org/whl/cpu\n",
"\n",
"if platform.system() != \"Windows\":\n",
" %pip install -q \"matplotlib>=3.4\"\n",
Expand Down Expand Up @@ -187,8 +187,11 @@
}
],
"source": [
"import openvino.properties.log as log\n",
"\n",
"\n",
"# Set LOG_LEVEL to LOG_INFO.\n",
"core.set_property(\"AUTO\", {\"LOG_LEVEL\": \"LOG_INFO\"})\n",
"core.set_property(\"AUTO\", {log.level(): log.Level.INFO})\n",
"\n",
"# Load the model onto the target device.\n",
"compiled_model = core.compile_model(ov_model)\n",
Expand Down Expand Up @@ -249,7 +252,7 @@
],
"source": [
"# Set LOG_LEVEL to LOG_NONE.\n",
"core.set_property(\"AUTO\", {\"LOG_LEVEL\": \"LOG_NONE\"})\n",
"core.set_property(\"AUTO\", {log.level(): log.Level.NO})\n",
"\n",
"compiled_model = core.compile_model(model=ov_model, device_name=\"AUTO\")\n",
"\n",
Expand Down Expand Up @@ -611,12 +614,15 @@
}
],
"source": [
"import openvino.properties.hint as hints\n",
"\n",
"\n",
"THROUGHPUT_hint_context = InferContext(metrics_update_interval, metrics_update_num)\n",
"\n",
"print(\"Compiling Model for AUTO device with THROUGHPUT hint\")\n",
"sys.stdout.flush()\n",
"\n",
"compiled_model = core.compile_model(model=ov_model, config={\"PERFORMANCE_HINT\": \"THROUGHPUT\"})\n",
"compiled_model = core.compile_model(model=ov_model, config={hints.performance_mode(): hints.PerformanceMode.THROUGHPUT})\n",
"\n",
"infer_queue = ov.AsyncInferQueue(compiled_model, 0) # Setting to 0 will query optimal number by default.\n",
"infer_queue.set_callback(completion_callback)\n",
Expand Down Expand Up @@ -680,7 +686,7 @@
"print(\"Compiling Model for AUTO Device with LATENCY hint\")\n",
"sys.stdout.flush()\n",
"\n",
"compiled_model = core.compile_model(model=ov_model, config={\"PERFORMANCE_HINT\": \"LATENCY\"})\n",
"compiled_model = core.compile_model(model=ov_model, config={hints.performance_mode(): hints.PerformanceMode.LATENCY})\n",
"\n",
"# Setting to 0 will query optimal number by default.\n",
"infer_queue = ov.AsyncInferQueue(compiled_model, 0)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"source": [
"# Install requirements\n",
"%pip install -q \"openvino>=2023.1.0\"\n",
"%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu transformers \"torch>=2.1\" \"gradio>=4.19\""
"%pip install -q --extra-index-url https://download.pytorch.org/whl/cpu transformers \"numpy<2\" \"torch>=2.1\" \"gradio>=4.19\""
]
},
{
Expand Down Expand Up @@ -759,14 +759,15 @@
"outputs": [],
"source": [
"from typing import Dict, Any\n",
"import openvino.properties.hint as hints\n",
"\n",
"\n",
"image_model = core.read_model(image_model_path)\n",
"\n",
"image_model = core.compile_model(\n",
" model=image_model,\n",
" device_name=device.value,\n",
" config={\"PERFORMANCE_HINT\": \"THROUGHPUT\"},\n",
" config={hints.performance_mode(): hints.PerformanceMode.THROUGHPUT},\n",
")"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,13 @@
"source": [
"from typing import Any\n",
"\n",
"import openvino.properties.hint as hints\n",
"\n",
"\n",
"compiled_throughput_hint = core.compile_model(\n",
" ov_model,\n",
" device_name=device.value,\n",
" config={\"PERFORMANCE_HINT\": \"THROUGHPUT\"},\n",
" config={hints.performance_mode(): hints.PerformanceMode.THROUGHPUT},\n",
")"
]
},
Expand Down Expand Up @@ -1323,7 +1325,10 @@
}
],
"source": [
"cpu_name = core.get_property(\"CPU\", \"FULL_DEVICE_NAME\")\n",
"import openvino.properties as props\n",
"\n",
"\n",
"cpu_name = core.get_property(\"CPU\", props.device.full_name)\n",
"\n",
"plot = sns.barplot(benchmark_dataframe, errorbar=\"sd\")\n",
"plot.set(ylabel=\"Sentences Per Second\", title=f\"Sentence Embeddings Benchmark\\n{cpu_name}\")\n",
Expand Down
5 changes: 3 additions & 2 deletions notebooks/ct-segmentation-quantize/async_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import cv2

import openvino.properties as props
from custom_segmentation import Model


Expand Down Expand Up @@ -169,15 +170,15 @@ def __init__(self, ie, model, plugin_config, device="CPU", max_num_requests=0):
cache_path.mkdir(exist_ok=True)
# Enable model caching for GPU devices
if "GPU" in device and "GPU" in ie.available_devices:
ie.set_property(device_name="GPU", properties={"CACHE_DIR": str(cache_path)})
ie.set_property(device_name="GPU", properties={props.cache_dir(): str(cache_path)})

self.model = model
self.logger = logging.getLogger()

self.logger.info("Loading network to {} plugin...".format(device))
self.exec_net = ie.compile_model(self.model.net, device, plugin_config)
if max_num_requests == 0:
max_num_requests = self.exec_net.get_property("OPTIMAL_NUMBER_OF_INFER_REQUESTS") + 1
max_num_requests = self.exec_net.get_property(props.optimal_number_of_infer_requests) + 1
self.requests = [self.exec_net.create_infer_request() for _ in range(max_num_requests)]
self.empty_requests = deque(self.requests)
self.completed_request_results = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,15 @@
],
"source": [
"from pathlib import Path\n",
"\n",
"from transformers import AutoTokenizer\n",
"from optimum.intel.openvino import OVModelForCausalLM\n",
"\n",
"import openvino.properties as props\n",
"import openvino.properties.hint as hints\n",
"import openvino.properties.streams as streams\n",
"\n",
"\n",
"if model_to_run.value == \"INT4\":\n",
" model_dir = int4_model_dir\n",
"elif model_to_run.value == \"INT8\":\n",
Expand All @@ -579,7 +585,7 @@
"\n",
"current_device = device.value\n",
"\n",
"ov_config = {\"PERFORMANCE_HINT\": \"LATENCY\", \"NUM_STREAMS\": \"1\", \"CACHE_DIR\": \"\"}\n",
"ov_config = {hints.performance_mode(): hints.PerformanceMode.LATENCY, streams.num(): \"1\", props.cache_dir(): \"\"}\n",
"\n",
"ov_model = OVModelForCausalLM.from_pretrained(model_dir, device=current_device, ov_config=ov_config)"
]
Expand Down
1 change: 0 additions & 1 deletion notebooks/florence2/gradio_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def plot_bbox(image, data):


def draw_polygons(image, prediction, fill_mask=False):

draw = ImageDraw.Draw(image)
scale = 1
for polygons, label in zip(prediction["polygons"], prediction["labels"]):
Expand Down
1 change: 0 additions & 1 deletion notebooks/florence2/ov_florence2_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def __init__(self, model_dir, device, ov_config=None) -> None:
self.language_model = OVFlorence2LangModel(model_dir, self.config.text_config, device, ov_config)

def generate(self, input_ids, inputs_embeds=None, pixel_values=None, **kwargs):

if inputs_embeds is None:
# 1. Extra the input embeddings
if input_ids is not None:
Expand Down
32 changes: 20 additions & 12 deletions notebooks/gpu-device/gpu-device.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,12 @@
}
],
"source": [
"import openvino.properties as props\n",
"\n",
"\n",
"device = \"GPU\"\n",
"\n",
"core.get_property(device, \"FULL_DEVICE_NAME\")"
"core.get_property(device, props.device.full_name)"
]
},
{
Expand All @@ -267,7 +270,7 @@
"id": "aac3129a-129f-49aa-aba0-71ae1e892ada",
"metadata": {},
"source": [
"Each device also has a specific property called `SUPPORTED_PROPERTIES`, that enables viewing all the available properties in the device. We can check the value for each property by simply looping through the dictionary returned by `core.get_property(\"GPU\", \"SUPPORTED_PROPERTIES\")` and then querying for that property."
"Each device also has a specific property called `SUPPORTED_PROPERTIES`, that enables viewing all the available properties in the device. We can check the value for each property by simply looping through the dictionary returned by `core.get_property(\"GPU\", props.supported_properties)` and then querying for that property."
]
},
{
Expand Down Expand Up @@ -321,7 +324,7 @@
],
"source": [
"print(f\"{device} SUPPORTED_PROPERTIES:\\n\")\n",
"supported_properties = core.get_property(device, \"SUPPORTED_PROPERTIES\")\n",
"supported_properties = core.get_property(device, props.supported_properties)\n",
"indent = len(max(supported_properties, key=len))\n",
"\n",
"for property_key in supported_properties:\n",
Expand Down Expand Up @@ -677,7 +680,7 @@
"core = ov.Core()\n",
"\n",
"# Set cache folder\n",
"core.set_property({\"CACHE_DIR\": cache_folder})\n",
"core.set_property({props.cache_dir(): cache_folder})\n",
"\n",
"# Compile the model as before\n",
"model = core.read_model(model=model_path)\n",
Expand Down Expand Up @@ -717,7 +720,7 @@
"source": [
"start = time.time()\n",
"core = ov.Core()\n",
"core.set_property({\"CACHE_DIR\": \"cache\"})\n",
"core.set_property({props.cache_dir(): \"cache\"})\n",
"model = core.read_model(model=model_path)\n",
"compiled_model = core.compile_model(model, device)\n",
"print(f\"Cache enabled - compile time: {time.time() - start}s\")\n",
Expand Down Expand Up @@ -765,7 +768,7 @@
"id": "7077b662-22f3-4c52-9c80-e5ac1309c482",
"metadata": {},
"source": [
"To use the \"LATENCY\" performance hint, add `{\"PERFORMANCE_HINT\": \"LATENCY\"}` when compiling the model as shown below. For GPUs, this automatically minimizes the batch size and number of parallel streams such that all of the compute resources can focus on completing a single inference as fast as possible."
"To use the \"LATENCY\" performance hint, add `{hints.performance_mode(): hints.PerformanceMode.LATENCY}` when compiling the model as shown below. For GPUs, this automatically minimizes the batch size and number of parallel streams such that all of the compute resources can focus on completing a single inference as fast as possible."
]
},
{
Expand All @@ -780,7 +783,10 @@
},
"outputs": [],
"source": [
"compiled_model = core.compile_model(model, device, {\"PERFORMANCE_HINT\": \"LATENCY\"})"
"import openvino.properties.hint as hints\n",
"\n",
"\n",
"compiled_model = core.compile_model(model, device, {hints.performance_mode(): hints.PerformanceMode.LATENCY})"
]
},
{
Expand All @@ -789,7 +795,7 @@
"id": "06589f38-ce35-457f-8395-a4a3f6327ea0",
"metadata": {},
"source": [
"To use the \"THROUGHPUT\" performance hint, add `{\"PERFORMANCE_HINT\": \"THROUGHPUT\"}` when compiling the model. For GPUs, this creates multiple processing streams to efficiently utilize all the execution cores and optimizes the batch size to fill the available memory."
"To use the \"THROUGHPUT\" performance hint, add `{hints.performance_mode(): hints.PerformanceMode.THROUGHPUT}` when compiling the model. For GPUs, this creates multiple processing streams to efficiently utilize all the execution cores and optimizes the batch size to fill the available memory."
]
},
{
Expand All @@ -804,7 +810,7 @@
},
"outputs": [],
"source": [
"compiled_model = core.compile_model(model, device, {\"PERFORMANCE_HINT\": \"THROUGHPUT\"})"
"compiled_model = core.compile_model(model, device, {hints.performance_mode(): hints.PerformanceMode.THROUGHPUT})"
]
},
{
Expand Down Expand Up @@ -836,7 +842,9 @@
"Note that we always need to explicitly specify the device list for MULTI to work, otherwise MULTI does not know which devices are available for inference. However, this is not the only way to use multiple devices in OpenVINO. There is another performance hint called \"CUMULATIVE_THROUGHPUT\" that works similar to MULTI, except it uses the devices automatically selected by AUTO. This way, we do not need to manually specify devices to use. Below is an example showing how to use \"CUMULATIVE_THROUGHPUT\", equivalent to the MULTI one:\n",
"\n",
"`\n",
"compiled_model = core.compile_model(model=model, device_name=\"AUTO\", config={\"PERFORMANCE_HINT\": \"CUMULATIVE_THROUGHPUT\"})\n",
"\n",
"\n",
"compiled_model = core.compile_model(model=model, device_name=\"AUTO\", config={hints.performance_mode(): hints.PerformanceMode.CUMULATIVE_THROUGHPUT})\n",
"`\n",
"\n",
"> **Important**: **The “THROUGHPUT”, “MULTI”, and “CUMULATIVE_THROUGHPUT” modes are only applicable to asynchronous inferencing pipelines. The example at the end of this article shows how to set up an asynchronous pipeline that takes advantage of parallelism to increase throughput.** To learn more, see [Asynchronous Inferencing](https://docs.openvino.ai/2024/documentation/openvino-extensibility/openvino-plugin-library/asynch-inference-request.html) in OpenVINO as well as the [Asynchronous Inference notebook](../async-api/async-api.ipynb)."
Expand Down Expand Up @@ -1584,7 +1592,7 @@
"# Read model and compile it on GPU in THROUGHPUT mode\n",
"model = core.read_model(model=model_path)\n",
"device_name = \"GPU\"\n",
"compiled_model = core.compile_model(model=model, device_name=device_name, config={\"PERFORMANCE_HINT\": \"THROUGHPUT\"})\n",
"compiled_model = core.compile_model(model=model, device_name=device_name, config={hints.performance_mode(): hints.PerformanceMode.THROUGHPUT})\n",
"\n",
"# Get the input and output nodes\n",
"input_layer = compiled_model.input(0)\n",
Expand Down Expand Up @@ -1996,7 +2004,7 @@
" )\n",
" cv2.putText(\n",
" frame,\n",
" f\"hint {compiled_model.get_property('PERFORMANCE_HINT')}\",\n",
" f\"hint {compiled_model.get_property(hints.performance_mode)}\",\n",
" (5, 60),\n",
" cv2.FONT_ITALIC,\n",
" 0.6,\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,6 @@
"outputs": [],
"source": [
"def draw_mask(mask, draw, random_color=False):\n",
"\n",
" if random_color:\n",
" color = (\n",
" np.random.randint(0, 255),\n",
Expand Down
Loading
Loading