Skip to content

Commit e787b1e

Browse files
committed
fix: PDF ingestion fails on Linux due to CUDA torchvision mismatch
The desktop CI workflow only pre-installed CPU-only torch but not torchvision. When docling pulled in torchvision from PyPI, it got the CUDA variant whose _C.so links against libtorch_cuda.so/libc10_cuda.so which don't exist in CPU-only torch, causing every PDF page to fail. - Add torch/torchvision as explicit deps pinned to PyTorch CPU index via [tool.uv.sources] in pyproject.toml (works for all builds) - Add torch/torchvision to PACKAGES_WITH_BINARIES in PyInstaller spec so their .so files land where LD_LIBRARY_PATH is set on Linux - Remove redundant CPU PyTorch install step from CI workflow - Switch Dockerfile from uv pip install to uv sync (uses lockfile)
1 parent 1533d84 commit e787b1e

5 files changed

Lines changed: 216 additions & 287 deletions

File tree

.github/workflows/desktop-publish.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ jobs:
5858
- name: Setup uv
5959
uses: astral-sh/setup-uv@v4
6060

61-
- name: Install CPU-only PyTorch (Linux)
62-
if: matrix.platform == 'ubuntu-22.04'
63-
run: uv pip install torch --index-url https://download.pytorch.org/whl/cpu --system
64-
6561
- name: Install backend dependencies
6662
run: uv pip install -e "backend/.[build,libs]" --system
6763

Dockerfile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,16 @@ RUN apk update && apk add --no-cache \
2929

3030
WORKDIR /app
3131

32-
COPY backend/pyproject.toml backend/README.md ./backend/
32+
# Copy lockfile, pyproject.toml, and minimal source for uv sync
33+
COPY backend/pyproject.toml backend/uv.lock backend/README.md ./backend/
3334
COPY backend/syft_space/__init__.py ./backend/syft_space/
3435

3536
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
3637

37-
# 1. Install base deps (fast, frequently cached)
38-
RUN uv venv /app/.venv --python python${PYTHON_VERSION} && \
39-
uv pip install --python /app/.venv/bin/python -e "./backend"
40-
41-
# 2. Install CPU-only PyTorch (avoids 4GB+ CUDA packages)
42-
RUN uv pip install --python /app/.venv/bin/python \
43-
torch torchvision --index-url https://download.pytorch.org/whl/cpu
44-
45-
# 3. Install heavy optional deps (docling will use existing torch)
46-
RUN uv pip install --python /app/.venv/bin/python -e "./backend[libs]"
38+
# Install all deps (including libs) from lockfile.
39+
# CPU-only torch/torchvision is enforced by [tool.uv.sources] in pyproject.toml.
40+
ENV UV_PROJECT_ENVIRONMENT=/app/.venv
41+
RUN cd backend && uv sync --extra libs --no-install-project
4742

4843
# ============================================================================
4944
# Stage 2: Production
@@ -75,6 +70,9 @@ COPY --from=backend-builder /app/.venv /app/.venv
7570
# Copy backend source
7671
COPY backend/ ./backend/
7772

73+
# Install the project itself (source-only, deps already in venv)
74+
RUN /app/.venv/bin/pip install --no-deps -e ./backend
75+
7876
# Copy pre-built frontend (must run: cd frontend && bun run build)
7977
COPY frontend/dist ./frontend/dist
8078

backend/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ libs = [
6464
"docling>=2.75.0",
6565
"docling-core>=2.65.2",
6666
"chromadb>=0.5.0",
67+
"torch>=2.10.0",
68+
"torchvision>=0.25.0",
6769
]
6870

6971
# All development dependencies (includes test, lint, pre-commit)
@@ -125,5 +127,12 @@ skips = [
125127
where = ["."] # Find packages in current directory (backend/)
126128
include = ["syft_space*"] # Include syft_space and sub-packages
127129

130+
[[tool.uv.index]]
131+
name = "pytorch-cpu"
132+
url = "https://download.pytorch.org/whl/cpu"
133+
explicit = true
134+
128135
[tool.uv.sources]
129136
syft-accounting-sdk = { git = "https://github.com/OpenMined/accounting-sdk.git", rev = "main" }
137+
torch = { index = "pytorch-cpu" }
138+
torchvision = { index = "pytorch-cpu" }

backend/syft-space-backend.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ PACKAGES_WITH_BINARIES = [
4141
'chromadb',
4242
'chromadb_rust_bindings',
4343
'docling_parse',
44+
'torch',
45+
'torchvision',
4446
]
4547

4648
a = Analysis(

0 commit comments

Comments
 (0)