Skip to content

Commit d088912

Browse files
fix(pii): assert torch CUDA state after every pip install
The check sat directly after the torch install, but requirements-gliner.txt and requirements-dev.txt are installed afterwards and resolve against PyPI with no torch pin, so a future gliner bump could swap the wheel that torch_index selected without tripping the assert. Neither file changes torch today (verified: torch is 2.11.0+cu128 both before and after the gliner install), so this guards the invariant rather than fixing a live regression. Moving it below the last pip install makes it certify the torch that actually ships. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QHNEWVrh7k89m8Wtqzhs18
1 parent 5030616 commit d088912

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

docker/pii.Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ RUN --mount=type=cache,target=/root/.cache/pip \
6767
esac && \
6868
pip install torch==${TORCH_VERSION} --index-url "${torch_index}"
6969

70-
# A CPU-only wheel on amd64 silently degrades to the "torch.cuda.is_available()
71-
# is False" crash only once GLiNER loads on a GPU host, so assert at build time.
72-
RUN python -c "import torch; \
73-
have = torch.version.cuda is not None; \
74-
want = '${TARGETARCH}' == 'amd64'; \
75-
assert have == want, f'{torch.__version__}: cuda build={have}, expected={want}'"
76-
7770
COPY apps/pii/requirements-gliner.txt ./requirements-gliner.txt
7871
RUN --mount=type=cache,target=/root/.cache/pip \
7972
pip install -r requirements-gliner.txt
@@ -106,6 +99,15 @@ COPY apps/pii/requirements-dev.txt ./requirements-dev.txt
10699
RUN --mount=type=cache,target=/root/.cache/pip \
107100
pip install -r requirements-dev.txt
108101

102+
# Runs after every pip install, because the requirements above resolve against
103+
# PyPI and could swap the wheel torch_index chose. A cpu-only torch on amd64
104+
# otherwise surfaces only as "torch.cuda.is_available() is False" once GLiNER
105+
# loads on a GPU host.
106+
RUN python -c "import torch; \
107+
have = torch.version.cuda is not None; \
108+
want = '${TARGETARCH}' == 'amd64'; \
109+
assert have == want, f'{torch.__version__}: cuda build={have}, expected={want}'"
110+
109111
RUN groupadd -g 1001 pii && \
110112
useradd -u 1001 -g pii pii && \
111113
chown -R pii:pii /app

0 commit comments

Comments
 (0)