|
| 1 | +# What this notebook does |
| 2 | + |
| 3 | +This notebook shows how to do inference with Automatic Device Selection (AUTO) in OpenVINO and gives a high-level overview of how AUTO chooses the most suitable execution device based on model and hardware availability. |
| 4 | + |
| 5 | +It demonstrates how to compile a model with AUTO, compare first inference latency (model compilation time + first inference time) between GPU and AUTO, and show the difference between THROUGHPUT and LATENCY performance hints. |
| 6 | + |
| 7 | +This notebook provides a practical, engineering-focused introduction to deploying one application across heterogeneous systems (CPU/GPU/NPU) with minimal device-specific branching. It includes explicit device discovery, deterministic fallback behavior, idempotent model preparation/loading, and repeatable runtime measurements for first-inference and steady-state execution. |
| 8 | + |
| 9 | +# Hardware & device support |
| 10 | + |
| 11 | +This notebook supports the following devices: |
| 12 | + |
| 13 | +- CPU — **supported (fallback)** |
| 14 | +- GPU — **supported if available** |
| 15 | +- NPU — **supported if available** |
| 16 | +- AUTO — **primary execution mode** |
| 17 | + |
| 18 | +# Setup |
| 19 | + |
| 20 | +Make sure that **uv** is installed. |
| 21 | + |
| 22 | +## Windows |
| 23 | +irm https://astral.sh/uv/install.ps1 | iex |
| 24 | + |
| 25 | +## macOS / Linux |
| 26 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
| 27 | + |
| 28 | +Verify installation: |
| 29 | +uv --version |
| 30 | + |
| 31 | +From the auto-device notebook folder: |
| 32 | + |
| 33 | +uv sync |
| 34 | + |
| 35 | +uv run jupyter lab auto-device.ipynb |
| 36 | + |
| 37 | +The sample image is included with the notebook. An internet connection is required only on the first run to download the pretrained ResNet-50 weights and create model/resnet50.xml. |
| 38 | + |
| 39 | +# Expected output |
| 40 | + |
| 41 | +When the notebook runs successfully, you should see: |
| 42 | + |
| 43 | +- **Device discovery and selection output**, e.g. |
| 44 | + `Available devices: ['CPU', 'GPU.0']` |
| 45 | + `Selected device: GPU` |
| 46 | + |
| 47 | +- **Idempotent model preparation logs**, e.g. |
| 48 | + `IR model saved to model/resnet50.xml` on first run, then |
| 49 | + `Read IR model from model/resnet50.xml` on subsequent runs. |
| 50 | + |
| 51 | +- **Compilation and first-inference timing output**, e.g. |
| 52 | + `Time to load model on GPU device and get first inference: 0.15 seconds.` |
| 53 | + |
| 54 | +- **Performance-hint measurements**, with throughput/latency metrics printed over multiple intervals. |
| 55 | + |
| 56 | +For systems without accelerator devices, CPU fallback output is expected and valid. |
| 57 | + |
| 58 | +# Tested-on |
| 59 | + |
| 60 | +| OS | Python | OpenVINO | Device(s) | Status | |
| 61 | +|----|--------|----------|-----------|--------| |
| 62 | +| Windows 11 | 3.12 | 2026.2 | CPU, GPU | Pass | |
| 63 | + |
| 64 | +# Troubleshooting |
| 65 | + |
| 66 | +### AUTO always selects CPU |
| 67 | +**Cause:** GPU/NPU plugin not available, unsupported hardware, or driver/runtime mismatch. |
| 68 | +**Fix:** Verify `ov.Core().available_devices`, then update Intel GPU/NPU drivers and confirm execution inside the correct uv environment. |
| 69 | + |
| 70 | +### First inference is much slower than later runs |
| 71 | +**Cause:** Model compilation and backend warm-up overhead during first execution. |
| 72 | +**Fix:** Compare first-run timing to repeated runs; use multiple iterations for steady-state performance analysis. |
| 73 | + |
| 74 | +### Notebook import errors (openvino/torchvision/notebook utils) |
| 75 | +**Cause:** Environment not synced or wrong interpreter selected. |
| 76 | +**Fix:** Run `uv sync` in this directory and launch with `uv run jupyter lab auto-device.ipynb`. |
| 77 | + |
| 78 | +### AUTO behavior differs across machines |
| 79 | +**Cause:** Different available hardware backends or plugin versions. |
| 80 | +**Fix:** Log `core.available_devices` at startup and keep OpenVINO/runtime stack consistent across systems. |
| 81 | + |
| 82 | +# References |
| 83 | + |
| 84 | +- Upstream OpenVINO auto-device notebook: |
| 85 | + https://github.com/openvinotoolkit/openvino_notebooks/blob/latest/notebooks/auto-device/auto-device.ipynb |
| 86 | + |
| 87 | +- OpenVINO AUTO device documentation: |
| 88 | + https://docs.openvino.ai/2024/openvino-workflow/running-inference/inference-devices-and-modes/auto-device-selection.html |
| 89 | + |
| 90 | +- OpenVINO performance hints: |
| 91 | + https://docs.openvino.ai/2024/openvino-workflow/running-inference/performance-hints.html |
0 commit comments