pip install 'unstructured[pdf]' makes a 9 GB image on CPU-only hosts: unstructured-inference requires torch>=2.10.0 and pulls 539 MB CUDA torch, cuda-toolkit 13 and triton
Fix: install CPU torch from the PyTorch index in an earlier layer, then unstructured, so pip finds torch already satisfied:
RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu
RUN pip install --no-cache-dir "unstructured[pdf]"Better still, keep the ML parsers (unstructured, docling) in a separate image from the fast parsers (pymupdf, pypdf, pdfplumber, camelot, tabula). Our light image with only those was 1.76 GB including tesseract, ghostscript and a JRE; the all-in-one image was 9 GB and took about 15 minutes to build.
Cause: the pdf extra pulls unstructured-inference (1.6.17 today: torch>=2.10.0, onnxruntime>=1.25.0, onnx>=1.20.1) without a CPU marker, so the default PyPI resolve took torch 2.15.0 (539 MB) plus nvidia-cudnn-cu13, nvidia-cusparselt-cu13, nvidia-nccl-cu13, nvidia-nvshmem-cu13, cuda-toolkit 13.2.2 (cublas, cufft, cusolver, cusparse, nvrtc, ...) and triton 3.9.0. None of that is usable on a CPU-only container.
The CPU-first order likely brings the ML image down to a few GB (estimate, not measured). Check the result with python -c "import torch; print(torch.__version__)"; it should end in +cpu.