From b728887ef1574f500d294c6bab4bae8710dcc8f1 Mon Sep 17 00:00:00 2001 From: MrPandir Date: Mon, 19 Feb 2024 18:36:04 +0100 Subject: [PATCH] fix: installing pytorch in docker cpu only --- docker/Dockerfile | 10 +++++++--- pyproject.toml | 9 ++++++++- requirements-dev.lock | 7 +++++-- requirements.lock | 7 +++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 0fd94c5..3a51920 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,14 +7,18 @@ LABEL org.opencontainers.image.description="This is a simple server that uses Si LABEL org.opencontainers.image.vendor="TwirApp" FROM base as dependencies-installer +WORKDIR /app SHELL ["/bin/bash", "-c"] RUN apt-get -y update && apt-get -y install curl && \ apt-get autoremove && apt-get clean +# disabling uv is a temporary solution until this is fixed: +# https://github.com/astral-sh/uv/issues/1497 +# And also until rye updates uv to the latest versions, at the time of writing rye is using version 0.1.0 RUN curl -sSf https://rye-up.com/get | NO_AUTO_INSTALL=1 RYE_INSTALL_OPTION="--yes" RYE_TOOLCHAIN=/usr/local/bin/python3 bash && \ - bash -c "source $HOME/.rye/env && rye pin 3.12.2" + bash -c "source $HOME/.rye/env && rye pin 3.12.2 && rye config --set-bool behavior.use-uv=false" ENV PATH=/root/.rye/shims:$PATH -COPY pyproject.toml requirements.lock /app/ -RUN --mount=type=cache,target=/root/.cache rye sync --pyproject /app/pyproject.toml --no-dev --no-lock +COPY pyproject.toml ./ +RUN --mount=type=cache,target=/root/.cache rye sync --no-dev --features torch-cpu FROM base as models-installer RUN apt-get -y update && apt-get -y install curl diff --git a/pyproject.toml b/pyproject.toml index 1a94e03..86dc4f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,12 +8,18 @@ authors = [ dependencies = [ "uvicorn>=0.27.1", "litestar>=2.6.1", - "torch==2.2.0+cpu", "numpy>=1.26.4", "python-dotenv>=1.0.1", ] requires-python = ">=3.9" +[project.optional-dependencies] +torch-cpu = ["torch==2.2.0+cpu"] +torch = ["torch==2.2.0"] + +[tool.setuptools] +packages = [] + [tool.rye] managed = true dev-dependencies = [] @@ -29,6 +35,7 @@ excluded-dependencies = [ "networkx", "sympy", ] +lock-with-sources = true [[tool.rye.sources]] name = "pytorch" diff --git a/requirements-dev.lock b/requirements-dev.lock index af974a2..2d3d7ba 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -3,9 +3,12 @@ # # last locked with the following flags: # pre: false -# features: [] +# features: ["torch"] # all-features: false -# with-sources: false +# with-sources: true + +--extra-index-url https://download.pytorch.org/whl/cpu +--index-url https://pypi.org/simple/ -e file:. anyio==4.2.0 diff --git a/requirements.lock b/requirements.lock index af974a2..2d3d7ba 100644 --- a/requirements.lock +++ b/requirements.lock @@ -3,9 +3,12 @@ # # last locked with the following flags: # pre: false -# features: [] +# features: ["torch"] # all-features: false -# with-sources: false +# with-sources: true + +--extra-index-url https://download.pytorch.org/whl/cpu +--index-url https://pypi.org/simple/ -e file:. anyio==4.2.0