Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Stop shipping a CUDA stack in the crawler image

Daoud Clarke6cd93e663e36
diff --git a/Dockerfile.crawler b/Dockerfile.crawler
index 5ff05b0..ed72ba4 100644
--- a/Dockerfile.crawler
+++ b/Dockerfile.crawler
@@ -1,13 +1,7 @@
-FROM python:3.11.12-bookworm AS base
-
-ENV PYTHONFAULTHANDLER=1 \
- PYTHONHASHSEED=random \
- PYTHONUNBUFFERED=1
+FROM python:3.11.12-bookworm AS builder
WORKDIR /app
-FROM base AS builder
-
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
@@ -42,7 +36,22 @@ RUN SODIR=/venv/lib/python3.11/site-packages/mwmbl_rank && \
cp /app/mwmbl_rank/target/release/deps/libxgboost.so "$SODIR/" && \
patchelf --set-rpath '$ORIGIN' "$SODIR"/mwmbl_rank.cpython-311-*.so
-FROM base AS final
+# The final stage ships to crawler volunteers, so it runs on the slim base: it needs
+# no compilers, git or headers, only the interpreter and the prebuilt /venv. That is
+# ~330MB less to download than the full python:3.11.12-bookworm image.
+FROM python:3.11.12-slim-bookworm AS final
+
+ENV PYTHONFAULTHANDLER=1 \
+ PYTHONHASHSEED=random \
+ PYTHONUNBUFFERED=1
+
+WORKDIR /app
+
+# libgomp1 is the OpenMP runtime that the bundled libxgboost.so links against. The
+# full base image happens to carry it; the slim one does not.
+RUN apt-get update && \
+ apt-get install -y --no-install-recommends libgomp1 && \
+ rm -rf /var/lib/apt/lists/*
# Copy only the required /venv directory from the builder image that contains mwmbl and its dependencies
COPY --from=builder /venv /venv
diff --git a/pyproject.toml b/pyproject.toml
index 7c33d56..e5f82a3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -34,7 +34,14 @@ dependencies = [
"numpy==1.23.2",
"objgraph>=3.6.1",
"psutil>=6.0.0",
- "xgboost>=2.1.0",
+ # xgboost's Linux wheels bundle a CUDA-enabled libxgboost.so and pull in
+ # nvidia-nccl-cu12, together ~600MB installed. Since 3.1.3 that applies to
+ # arm64 as well, which is what doubled the crawler image. Nothing here trains
+ # or predicts on a GPU - serving goes through the Rust extension's own
+ # libxgboost - so take the CPU-only build wherever it is published (Linux and
+ # Windows). The macOS wheel has no CUDA in it to begin with.
+ "xgboost-cpu>=2.1.0; sys_platform != 'darwin'",
+ "xgboost>=2.1.0; sys_platform == 'darwin'",
"pydistinct>=0.6.4",
"django-ninja-jwt>=5.3.3",
"sentry-sdk>=2.13.0",
@@ -86,6 +93,13 @@ dev = [
"pre-commit>=4.6.2",
]
+[tool.uv]
+# pydistinct declares xgboost as a dependency but never imports it - its four modules
+# use numpy, scipy and statsmodels only. On Linux that stale requirement is enough to
+# drag the CUDA wheel and nvidia-nccl-cu12 back in, undoing the xgboost-cpu switch
+# above, so confine every xgboost request to macOS where the wheel is CPU-only anyway.
+override-dependencies = ["xgboost>=2.1.0; sys_platform == 'darwin'"]
+
[tool.maturin]
python-source = "."
module-name = "mwmbl_rank"
diff --git a/uv.lock b/uv.lock
index 35f63a4..013a246 100644
--- a/uv.lock
+++ b/uv.lock
@@ -2,6 +2,9 @@ version = 1
revision = 3
requires-python = "==3.11.*"
+[manifest]
+overrides = [{ name = "xgboost", marker = "sys_platform == 'darwin'", specifier = ">=2.1.0" }]
+
[[package]]
name = "annotated-types"
version = "0.7.0"
@@ -837,7 +840,8 @@ dependencies = [
{ name = "tokenizers" },
{ name = "uvicorn" },
{ name = "wasmtime" },
- { name = "xgboost" },
+ { name = "xgboost", marker = "sys_platform == 'darwin'" },
+ { name = "xgboost-cpu", marker = "sys_platform != 'darwin'" },
{ name = "zstandard" },
]
@@ -917,7 +921,8 @@ requires-dist = [
{ name = "uvicorn", specifier = ">=0.16.0" },
{ name = "warcio", marker = "extra == 'indexer'", specifier = "==1.7.4" },
{ name = "wasmtime", specifier = ">=24.0.0" },
- { name = "xgboost", specifier = ">=2.1.0" },
+ { name = "xgboost", marker = "sys_platform == 'darwin'", specifier = ">=2.1.0" },
+ { name = "xgboost-cpu", marker = "sys_platform != 'darwin'", specifier = ">=2.1.0" },
{ name = "zstandard", specifier = ">=0.16.0" },
]
provides-extras = ["indexer"]
@@ -961,15 +966,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/f5/85/3b622959cc922874aee72fc5c9db87c3e3779c7404d0370faab80450a3f3/numpy-1.23.2-cp311-cp311-win_amd64.whl", hash = "sha256:8ecb818231afe5f0f568c81f12ce50f2b828ff2b27487520d85eb44c71313b9e", size = 14630485, upload-time = "2022-08-14T00:18:15.379Z" },
]
-[[package]]
-name = "nvidia-nccl-cu12"
-version = "2.29.7"
-source = { registry = "https://pypi.org/simple" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/20/cc/f48875411d1f176bce58e6343fd5d4131fc1db5420719ff25944bdc006c6/nvidia_nccl_cu12-2.29.7-py3-none-manylinux_2_18_aarch64.whl", hash = "sha256:0cf032ee22b560447daf0456108a75e32bd74a4de6c6b64725637a359fa48cd8", size = 293563644, upload-time = "2026-03-03T05:34:46.166Z" },
- { url = "https://files.pythonhosted.org/packages/31/1e/9e366f36efc550f07d6737f199e3f6bffafdf28795d007f10a77dd274f5c/nvidia_nccl_cu12-2.29.7-py3-none-manylinux_2_18_x86_64.whl", hash = "sha256:ecd0a012051abc20c1aa87328841efa8cade3ced65803046e38c2f03c0891fea", size = 293633942, upload-time = "2026-03-03T05:37:05.625Z" },
-]
-
[[package]]
name = "oauthlib"
version = "3.3.1"
@@ -1272,7 +1268,7 @@ dependencies = [
{ name = "numpy" },
{ name = "scipy" },
{ name = "statsmodels" },
- { name = "xgboost" },
+ { name = "xgboost", marker = "sys_platform == 'darwin'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/aa/db/3611006a3e72c2249a8fe66dfd2ef88bb9cb33b81bb195ed0fc1329fdd23/pydistinct-0.6.4.tar.gz", hash = "sha256:ccd66ce4cdeefc20debe9e40a529de1d51f7175247a3216148d64fd29d3fe693", size = 17096, upload-time = "2020-03-25T09:56:43.774Z" }
wheels = [
@@ -1913,16 +1909,28 @@ version = "3.2.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "numpy" },
- { name = "nvidia-nccl-cu12", marker = "sys_platform == 'linux'" },
{ name = "scipy" },
]
sdist = { url = "https://files.pythonhosted.org/packages/91/bb/1eb0242409d22db725d7a88088e6cfd6556829fb0736f9ff69aa9f1e9455/xgboost-3.2.0.tar.gz", hash = "sha256:99b0e9a2a64896cdaf509c5e46372d336c692406646d20f2af505003c0c5d70d", size = 1263936, upload-time = "2026-02-10T11:03:05.542Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/2d/49/6e4cdd877c24adf56cb3586bc96d93d4dcd780b5ea1efb32e1ee0de08bae/xgboost-3.2.0-py3-none-macosx_10_15_x86_64.whl", hash = "sha256:2f661966d3e322536d9c448090a870fcba1e32ee5760c10b7c46bac7a342079a", size = 2507014, upload-time = "2026-02-10T10:50:57.44Z" },
{ url = "https://files.pythonhosted.org/packages/93/f1/c09ef1add609453aa3ba5bafcd0d1c1a805c1263c0b60138ec968f8ec296/xgboost-3.2.0-py3-none-macosx_12_0_arm64.whl", hash = "sha256:eabbd40d474b8dbf6cb3536325f9150b9e6f0db32d18de9914fb3227d0bef5b7", size = 2328527, upload-time = "2026-02-10T10:51:17.502Z" },
- { url = "https://files.pythonhosted.org/packages/96/9f/d9914a7b8df842832850b1a18e5f47aaa071c217cdd1da2ae9deb291018b/xgboost-3.2.0-py3-none-manylinux_2_28_aarch64.whl", hash = "sha256:852eabc6d3b3702a59bf78dbfdcd1cb9c4d3a3b6e5ed1f8781d8b9512354fdd2", size = 131100954, upload-time = "2026-02-10T11:02:42.704Z" },
- { url = "https://files.pythonhosted.org/packages/79/98/679de17c2caa4fd3b0b4386ecf7377301702cb0afb22930a07c142fcb1d8/xgboost-3.2.0-py3-none-manylinux_2_28_x86_64.whl", hash = "sha256:99b4a6bbcb47212fec5cf5fbe12347215f073c08967431b0122cfbd1ee70312c", size = 131748579, upload-time = "2026-02-10T10:54:40.424Z" },
- { url = "https://files.pythonhosted.org/packages/1f/3d/1661dd114a914a67e3f7ab66fa1382e7599c2a8c340f314ad30a3e2b4d08/xgboost-3.2.0-py3-none-win_amd64.whl", hash = "sha256:0d169736fd836fc13646c7ab787167b3a8110351c2c6bc770c755ee1618f0442", size = 101681668, upload-time = "2026-02-10T10:59:31.202Z" },
+]
+
+[[package]]
+name = "xgboost-cpu"
+version = "3.2.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "numpy" },
+ { name = "scipy" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/1c/43/89437af879315468860b0ef566647113102be898f28fc094b667166d6fe3/xgboost_cpu-3.2.0.tar.gz", hash = "sha256:27f1b1642815c23ee73065d5702ad24c1c1649d63e4e2f498dc7e6a961012281", size = 1264279, upload-time = "2026-02-10T10:34:51.922Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/16/3d/b996f80a52e6a4f7c5ed1851bfc1f4e8dae2dc7670ef8b0ca283b3006e3b/xgboost_cpu-3.2.0-py3-none-manylinux_2_28_aarch64.whl", hash = "sha256:896b9e2bc52ec0921edf92ddd1cebedf47032e94992b7aca0293524d380ce6e9", size = 5213428, upload-time = "2026-02-10T10:32:30.609Z" },
+ { url = "https://files.pythonhosted.org/packages/ba/1d/c05e982a2220e1a208f5ca8792265cefb43e860e8796bff3245cc94fc2ce/xgboost_cpu-3.2.0-py3-none-manylinux_2_28_x86_64.whl", hash = "sha256:9c10b1653e1a689bf4094a328144cf3633c9be0e5217a76fbdc2fde6abcb2950", size = 5595924, upload-time = "2026-02-10T10:33:04.692Z" },
+ { url = "https://files.pythonhosted.org/packages/cc/b6/3981ecd0f11992203254bb5a94002a6b07ada12d0e660f01f6e742d15795/xgboost_cpu-3.2.0-py3-none-win_amd64.whl", hash = "sha256:bfe72e42f73d2c6870a1a8b75324d56ae86ddad9abd4dccefeb36f2c3196dd48", size = 2149094, upload-time = "2026-02-10T10:34:25.086Z" },
+ { url = "https://files.pythonhosted.org/packages/1b/0a/595eff7c5603f6ba49b7ce1501bafed8ce3039ed2dcaadd61748d1be9ecd/xgboost_cpu-3.2.0-py3-none-win_arm64.whl", hash = "sha256:78fc90c09d7a1a1603ebb3a1c341689096797160c35a996d6a096b03e20caab4", size = 2087619, upload-time = "2026-02-10T10:33:32.664Z" },
]
[[package]]