Skip to content

Commit 772c4f0

Browse files
Merge pull request #2946 from VWS-Python/adamtheturtle/cpu-only-torch
Use CPU-only torch for Docker builds to reduce image size
2 parents 7550c05 + 9f484ea commit 772c4f0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies = [
4444
"responses>=0.25.3",
4545
"torch>=2.5.1",
4646
"torchmetrics>=1.5.1",
47+
"torchvision>=0.20.1",
4748
"tzdata; sys_platform=='win32'",
4849
"vws-auth-tools>=2024.7.12",
4950
"werkzeug>=3.1.2",
@@ -138,6 +139,11 @@ fallback_version = "0.0.0"
138139
# Code to match this is in ``conf.py``.
139140
version_scheme = "post-release"
140141

142+
[tool.uv]
143+
sources.torch = { index = "pytorch-cpu" }
144+
sources.torchvision = { index = "pytorch-cpu" }
145+
index = [ { name = "pytorch-cpu", url = "https://download.pytorch.org/whl/cpu", explicit = true } ]
146+
141147
[tool.ruff]
142148
line-length = 79
143149
lint.select = [
@@ -312,6 +318,9 @@ per_rule_ignores.DEP002 = [
312318
# tzdata is needed on Windows for zoneinfo to work.
313319
# See https://docs.python.org/3/library/zoneinfo.html#data-sources.
314320
"tzdata",
321+
# torchvision is used transitively via piq, but must be a direct dependency
322+
# so that tool.uv.sources can route it to the CPU-only PyTorch index.
323+
"torchvision",
315324
]
316325

317326
[tool.pyproject-fmt]

src/mock_vws/_flask_server/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ COPY --chown=myuser:myuser . /app
1212
# See https://pythonspeed.com/articles/activate-virtualenv-dockerfile/
1313
# For why we use this method of activating the virtual environment.
1414
ENV VIRTUAL_ENV=/app/docker_venvs/.venv
15-
RUN python3 -m venv $VIRTUAL_ENV
15+
ENV UV_PROJECT_ENVIRONMENT=/app/docker_venvs/.venv
1616
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
1717

1818
WORKDIR /app
19-
RUN pip install --no-cache-dir uv==0.10.4 && \
20-
uv pip install --no-cache-dir --upgrade --editable .
19+
RUN python3 -m venv $VIRTUAL_ENV && \
20+
pip install --no-cache-dir uv==0.10.4 && \
21+
uv sync --no-cache
2122
EXPOSE 5000
2223
ENTRYPOINT ["python"]
2324
HEALTHCHECK --interval=1s --timeout=10s --start-period=5s --retries=3 CMD ["python", "/app/src/mock_vws/_flask_server/healthcheck.py"]

0 commit comments

Comments
 (0)