Skip to content

Commit

Permalink
fix(deps): update machine-learning (#10740)
Browse files Browse the repository at this point in the history
* fix(deps): update machine-learning

* update openvino options, cuda

* update openvino build

* fix indentation

* update minimum nvidia driver

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: mertalev <[email protected]>
  • Loading branch information
renovate[bot] and mertalev authored Jul 21, 2024
1 parent 8b773a2 commit b53bd8c
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 284 deletions.
2 changes: 2 additions & 0 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ services:
dockerfile: Dockerfile
args:
- DEVICE=cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference
ports:
- 3003:3003
volumes:
- model-cache:/cache
env_file:
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/features/ml-hardware-acceleration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ You do not need to redo any machine learning jobs after enabling hardware accele

- The GPU must have compute capability 5.2 or greater.
- The server must have the official NVIDIA driver installed.
- The installed driver must be >= 535 (it must support CUDA 12.2).
- The installed driver must be >= 545 (it must support CUDA 12.3.2).
- On Linux (except for WSL2), you also need to have [NVIDIA Container Toolkit][nvct] installed.

#### OpenVINO
Expand Down
24 changes: 13 additions & 11 deletions machine-learning/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ ARG DEVICE=cpu

FROM python:3.11-bookworm@sha256:7bec1574675e7fd9e3a540a03cd7d6811c59ca261bd300cd665369d8f435298a as builder-cpu

FROM openvino/ubuntu22_runtime:2023.3.0@sha256:176646df619032ea6c10faf842867119c393e7497b7f88b5e307e932a0fd5aa8 as builder-openvino
USER root
RUN apt-get update && apt-get install -y --no-install-recommends python3-dev
FROM builder-cpu as builder-openvino

FROM builder-cpu as builder-cuda

Expand Down Expand Up @@ -38,13 +36,15 @@ RUN poetry install --sync --no-interaction --no-ansi --no-root --with ${DEVICE}

FROM python:3.11-slim-bookworm@sha256:17ec9dc2367aa748559d0212f34665ec4df801129de32db705ea34654b5bc77a as prod-cpu

FROM openvino/ubuntu22_runtime:2023.3.0@sha256:176646df619032ea6c10faf842867119c393e7497b7f88b5e307e932a0fd5aa8 as prod-openvino
USER root
# TODO: remove this once the image has the fix for https://github.com/intel/compute-runtime/issues/710
ENV NEOReadDebugKeys=1 \
OverrideGpuAddressSpace=48
FROM prod-cpu as prod-openvino

FROM nvidia/cuda:12.2.2-cudnn8-runtime-ubuntu22.04@sha256:2d913b09e6be8387e1a10976933642c73c840c0b735f0bf3c28d97fc9bc422e0 as prod-cuda
COPY scripts/configure-apt.sh ./
RUN ./configure-apt.sh && \
apt-get update && \
apt-get install -t unstable --no-install-recommends -yqq intel-opencl-icd && \
rm configure-apt.sh

FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04@sha256:fa44193567d1908f7ca1f3abf8623ce9c63bc8cba7bcfdb32702eb04d326f7a8 as prod-cuda

COPY --from=builder-cuda /usr/local/bin/python3 /usr/local/bin/python3
COPY --from=builder-cuda /usr/local/lib/python3.11 /usr/local/lib/python3.11
Expand All @@ -71,13 +71,15 @@ COPY --from=builder-armnn \
/opt/armnn/

FROM prod-${DEVICE} as prod
ARG DEVICE

RUN apt-get update && \
apt-get install -y --no-install-recommends tini libmimalloc2.0 && \
apt-get install -y --no-install-recommends tini $(if ! [ "$DEVICE" = "openvino" ]; then echo "libmimalloc2.0"; fi) && \
apt-get autoremove -yqq && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app
ARG DEVICE
ENV TRANSFORMERS_CACHE=/cache \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
Expand Down
4 changes: 2 additions & 2 deletions machine-learning/app/models/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def pil_to_cv2(image: Image.Image) -> NDArray[np.uint8]:
def decode_pil(image_bytes: bytes | IO[bytes] | Image.Image) -> Image.Image:
if isinstance(image_bytes, Image.Image):
return image_bytes
image = Image.open(BytesIO(image_bytes) if isinstance(image_bytes, bytes) else image_bytes)
image.load() # type: ignore
image: Image.Image = Image.open(BytesIO(image_bytes) if isinstance(image_bytes, bytes) else image_bytes)
image.load()
if not image.mode == "RGB":
image = image.convert("RGB")
return image
Expand Down
16 changes: 10 additions & 6 deletions machine-learning/app/sessions/ort.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,21 @@ def provider_options(self, provider_options: list[dict[str, Any]]) -> None:

@property
def _provider_options_default(self) -> list[dict[str, Any]]:
options = []
provider_options = []
for provider in self.providers:
match provider:
case "CPUExecutionProvider" | "CUDAExecutionProvider":
option = {"arena_extend_strategy": "kSameAsRequested"}
options = {"arena_extend_strategy": "kSameAsRequested"}
case "OpenVINOExecutionProvider":
option = {"device_type": "GPU_FP32", "cache_dir": (self.model_path.parent / "openvino").as_posix()}
options = {
"device_type": "GPU",
"precision": "FP32",
"cache_dir": (self.model_path.parent / "openvino").as_posix(),
}
case _:
option = {}
options.append(option)
return options
options = {}
provider_options.append(options)
return provider_options

@property
def sess_options(self) -> ort.SessionOptions:
Expand Down
2 changes: 1 addition & 1 deletion machine-learning/app/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_sets_default_provider_options(self, ov_device_ids: list[str]) -> None:
session = OrtSession(model_path, providers=["OpenVINOExecutionProvider", "CPUExecutionProvider"])

assert session.provider_options == [
{"device_type": "GPU_FP32", "cache_dir": "/cache/ViT-B-32__openai/openvino"},
{"device_type": "GPU", "precision": "FP32", "cache_dir": "/cache/ViT-B-32__openai/openvino"},
{"arena_extend_strategy": "kSameAsRequested"},
]

Expand Down
Loading

0 comments on commit b53bd8c

Please sign in to comment.