Skip to content

Commit

Permalink
fix: installing pytorch in docker cpu only
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPandir committed Feb 19, 2024
1 parent 3e17198 commit b728887
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
10 changes: 7 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -29,6 +35,7 @@ excluded-dependencies = [
"networkx",
"sympy",
]
lock-with-sources = true

[[tool.rye.sources]]
name = "pytorch"
Expand Down
7 changes: 5 additions & 2 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b728887

Please sign in to comment.