Dockerfile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. # syntax=docker/dockerfile:1.7
  2. # GLM-5.3-Flash r27 (jovian-judgement, qualified 2026-09-06) — GB10/Spark build.
  3. #
  4. # Clone-at-pin build, NO staged tarballs: the Dockerfile clones every source
  5. # at the pins in versions.env and gates each one (HEAD commit + tree hash).
  6. # A fresh clone of this repo + `bash build.sh` reproduces this image end to
  7. # end. Source contract: local-inference-lab/rtx6kpro master
  8. # models/glm-5.3-flash/build/glm53-jovian-judgement-community-20260906-r27.source.lock
  9. # (vLLM 63a82f8d / tree f54cd9ca, B12X e8ad299b / f3cd8a9e [includes
  10. # comm.roce RoCEnante, PR #295 + follow-ups — see state doc], LMCache
  11. # 822330db / 008ac3e0, FlashKDA 3b225bf2; merge order documented in vLLM
  12. # issue 651).
  13. #
  14. # Runtime: CUDA 13.2 devel aarch64 base + torch 2.13.0 cu130 + flashinfer
  15. # 0.6.17 — the same pins the r27 tree's requirements/cuda.txt asks for,
  16. # proven on GB10 (deviation from their RTX-PRO-6000 cu133 runtime documented
  17. # in versions.env). GB10 sm_121 fixes baked in (patch_cuda_sm12x.py, eugr
  18. # patch set). LMCache wheel + cuMem interposer built from the locked source
  19. # in-container (engine-driven cache transfers sidecar for vram/native/lmcache
  20. # cache modes).
  21. #
  22. # Build: cd docker-images/glm53-jovian-r27 && TAG=... bash build.sh
  23. ARG CUDA_BASE_IMAGE
  24. ARG CUDA_BASE_DIGEST
  25. ARG UV_VERSION
  26. FROM ${CUDA_BASE_IMAGE}@${CUDA_BASE_DIGEST} AS apt-base
  27. ARG PYPI_INDEX_URL
  28. ARG APT_SOURCE
  29. ENV DEBIAN_FRONTEND=noninteractive \
  30. PIP_BREAK_SYSTEM_PACKAGES=1 \
  31. UV_SYSTEM_PYTHON=1 UV_BREAK_SYSTEM_PACKAGES=1 UV_LINK_MODE=copy
  32. COPY locks/apt-sources.list /tmp/apt-sources-snapshot.list
  33. COPY locks/apt-packages.txt /tmp/apt-packages.txt
  34. COPY locks/python-bootstrap.txt /tmp/python-bootstrap.txt
  35. # APT_SOURCE (versions.env):
  36. # snapshot (default, historical behavior): the pinned point-in-time mirror
  37. # + exact package versions — strictly reproducible, but
  38. # snapshot.ubuntu.com is slow (~30 kB/s) and intermittently 503s
  39. # (12-min apt stall, 2026-09-08).
  40. # current: the live archive.ubuntu.com — fast and reliable; installs the
  41. # pinned package names unversioned. Acceptable: the engine stack is
  42. # pinned by the vLLM/B12X/LMCache source pins, not by apt.
  43. RUN set -eux; \
  44. if [ "${APT_SOURCE:-snapshot}" = "current" ]; then \
  45. printf '%s\n' \
  46. "deb http://ports.ubuntu.com/ubuntu-ports/ noble main restricted universe multiverse" \
  47. "deb http://ports.ubuntu.com/ubuntu-ports/ noble-updates main restricted universe multiverse" \
  48. "deb http://ports.ubuntu.com/ubuntu-ports/ noble-security main restricted universe multiverse" \
  49. > /etc/apt/sources.list; \
  50. PKGS="$(grep -vE '^\s*(#|$)' /tmp/apt-packages.txt | cut -d= -f1)"; \
  51. else \
  52. cp /tmp/apt-sources-snapshot.list /etc/apt/sources.list; \
  53. PKGS="$(grep -vE '^\s*(#|$)' /tmp/apt-packages.txt)"; \
  54. fi; \
  55. rm -f /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; \
  56. apt-get update; \
  57. apt-get install -y --no-install-recommends ${PKGS}; \
  58. rm -rf /var/lib/apt/lists/*; \
  59. python3 -m pip install --no-cache-dir --no-deps \
  60. -r /tmp/python-bootstrap.txt --index-url "${PYPI_INDEX_URL}"
  61. FROM apt-base AS torch-base
  62. ARG PYPI_INDEX_URL
  63. ARG PYTORCH_INDEX_URL
  64. ARG TORCH_VERSION TORCHVISION_VERSION TORCHAUDIO_VERSION
  65. ARG FLASHINFER_VERSION
  66. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  67. uv pip install \
  68. --index-url ${PYPI_INDEX_URL} \
  69. --extra-index-url ${PYTORCH_INDEX_URL} \
  70. --index-strategy unsafe-best-match \
  71. "torch==${TORCH_VERSION}" \
  72. "torchvision==${TORCHVISION_VERSION}" \
  73. "torchaudio==${TORCHAUDIO_VERSION}" \
  74. "flashinfer-python==${FLASHINFER_VERSION}"
  75. # DeepGEMM: cloned in-build (proven to work on the nodes via git; pins are
  76. # gated again in fetch-deps.sh against the vLLM tree's own declaration).
  77. FROM torch-base AS deepgemm-builder
  78. ARG DEEPGEMM_REPO DEEPGEMM_BRANCH DEEPGEMM_REF
  79. RUN set -eux; \
  80. git config --global protocol.version 0; \
  81. git clone --branch ${DEEPGEMM_BRANCH} ${DEEPGEMM_REPO} /deps/deepgemm; \
  82. cd /deps/deepgemm; \
  83. git checkout ${DEEPGEMM_REF}; \
  84. git submodule update --init --depth 1 -- third-party/cutlass third-party/fmt
  85. # ---- vLLM @ r27 integration branch, gated by commit + tree hash ----
  86. FROM torch-base AS vllm-clone
  87. ARG VLLM_REPO VLLM_PIN VLLM_TREE
  88. RUN set -eux; \
  89. git config --global protocol.version 0; \
  90. git init -q /workspace/vllm; \
  91. git -C /workspace/vllm fetch -q --depth 1 ${VLLM_REPO} ${VLLM_PIN}; \
  92. git -C /workspace/vllm checkout -q FETCH_HEAD; \
  93. cd /workspace/vllm; \
  94. test "$(git rev-parse HEAD)" = "${VLLM_PIN}"; \
  95. test "$(git rev-parse HEAD^{tree})" = "${VLLM_TREE}"; \
  96. git config --global --add safe.directory /workspace/vllm
  97. # ---- All build sub-deps, cloned at pins the r27 tree itself declares ----
  98. FROM vllm-clone AS deps-fetched
  99. COPY fetch-deps.sh /tmp/fetch-deps.sh
  100. RUN bash /tmp/fetch-deps.sh
  101. FROM deps-fetched AS vllm-builder
  102. WORKDIR /workspace/vllm
  103. # Hard-declared (do NOT rely on stage-inherited ENVs): the buildkit build
  104. # has no GPU, so torch's device-capability autodetect is unavailable and
  105. # the wheel must be told the target arch explicitly (the r27 slip: kernels
  106. # came out sm120-only -> cudaErrorNoKernelImageForDevice at boot).
  107. ENV TORCH_CUDA_ARCH_LIST=12.1a GIT_PROTOCOL=0
  108. ARG DEEPGEMM_REF
  109. ARG VLLM_PRETEND_VERSION
  110. ARG SOURCE_DATE_EPOCH
  111. ARG BUILD_JOBS
  112. # Empty default overrides (profile `FLASH_KDA_SRC_DIR=`) make the vLLM tree
  113. # fall back to its own pinned FlashKDA + in-tree packed-checkpoints patch
  114. # (required by the r28.1+ flashkda.cmake API gate); the default keeps the
  115. # r27-style shared /deps2 checkout for the older trees.
  116. ARG FLASH_KDA_SRC_DIR=/deps2/FlashKDA
  117. # eugr/spark-vllm-docker build-time patches (main, 2026-09-02): all are
  118. # source-aware/idempotent (skip when the vulnerable pattern is absent), so
  119. # running the full set is safe on the r27 tree. Env gates are opt-in and ON
  120. # for this build (sm_121a + b12x):
  121. # - preserve_sm12x_target: keep 12.1a in CUDA_SUPPORTED_ARCHS (their
  122. # standard CUDA build collapses 12.1a -> 12.0)
  123. # - sm120_cooperative_topk: keep SM90-only (Spark fix)
  124. # - mrv2_speculator_cudagraph_pool / spark_kv_cache_cleanup (UMA snapshot
  125. # flow) / b12x c128a alignment / flashinfer b12x swigluoai / routed
  126. # expert weight shape / topk_softplus_sqrt / others: see each script.
  127. COPY patches-eugr/patch_vllm_*.py /tmp/eugr-patches/
  128. COPY --from=deepgemm-builder /deps/deepgemm /deps/deepgemm
  129. RUN VLLM_PRESERVE_SM12X_TARGET=1 \
  130. VLLM_PATCH_B12X_C128A_ALIGNMENT=1 \
  131. python3 /tmp/eugr-patches/patch_vllm_mrv2_speculator_cudagraph_pool.py . \
  132. && python3 /tmp/eugr-patches/patch_vllm_b12x_c128a_topk_alignment.py . \
  133. && python3 /tmp/eugr-patches/patch_vllm_flashinfer_b12x_swigluoai.py . \
  134. && python3 /tmp/eugr-patches/patch_vllm_topk_softplus_sqrt_control_flow.py . \
  135. && python3 /tmp/eugr-patches/patch_vllm_preserve_sm12x_target.py . \
  136. && python3 /tmp/eugr-patches/patch_vllm_diffusion_tensor_causal.py . \
  137. && python3 /tmp/eugr-patches/patch_vllm_gemma4_mtp_embedding_share.py . \
  138. && python3 /tmp/eugr-patches/patch_vllm_sm120_cooperative_topk.py . \
  139. && python3 /tmp/eugr-patches/patch_vllm_autogptq_symmetric_moe_qzeros.py . \
  140. && python3 /tmp/eugr-patches/patch_vllm_disable_minimax_qk_rmsnorm_ipc.py . \
  141. && python3 /tmp/eugr-patches/patch_vllm_routed_experts_weight_shape.py . \
  142. && python3 /tmp/eugr-patches/patch_vllm_spark_kv_cache_cleanup.py .
  143. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  144. --mount=type=cache,id=ccache,target=/root/.ccache \
  145. --mount=type=cache,id=cargo-registry,target=/root/.cargo/registry \
  146. --mount=type=cache,id=rust-target,target=/workspace/vllm/vllm/target \
  147. git config --global protocol.version 0 \
  148. && uv pip install setuptools-rust setuptools-scm \
  149. && (command -v cargo >/dev/null 2>&1 || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --no-modify-path) \
  150. && export PATH=/root/.cargo/bin:$PATH \
  151. && (command -v protoc >/dev/null 2>&1 || (apt-get update -qq && apt-get install -y --no-install-recommends protobuf-compiler libprotobuf-dev >/dev/null && rm -rf /var/lib/apt/lists/*)) \
  152. && _j="${BUILD_JOBS:-$(nproc)}" \
  153. && export GIT_PROTOCOL=0 MAX_JOBS="${_j}" CMAKE_BUILD_PARALLEL_LEVEL="${_j}" \
  154. VLLM_REQUIRE_RUST_FRONTEND=1 CARGO_BUILD_JOBS="${_j}" \
  155. SETUPTOOLS_SCM_PRETEND_VERSION="${VLLM_PRETEND_VERSION}" \
  156. TRITON_KERNELS_SRC_DIR=/deps2/triton_kernels \
  157. FMHA_SM100_SRC_DIR=/deps2/MSA \
  158. FLASH_MLA_SRC_DIR=/deps2/FlashMLA \
  159. FLASH_KDA_SRC_DIR="${FLASH_KDA_SRC_DIR}" \
  160. VLLM_FLASH_ATTN_SRC_DIR=/deps2/flash-attention \
  161. QUTLASS_SRC_DIR=/deps2/qutlass \
  162. TML_FA4_SRC_DIR=/deps2/tml-fa4 \
  163. VLLM_CUTLASS_SRC_DIR=/deps2/cutlass \
  164. CUTLASS_INCLUDE_DIR_PRE=/deps2/cutlass/include \
  165. && python3 use_existing_torch.py \
  166. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v
  167. # ---- B12X @ r27 integration branch, gated; pure-python CuTe-DSL wheel ----
  168. FROM torch-base AS b12x-clone
  169. ARG B12X_REPO B12X_PIN B12X_TREE
  170. RUN set -eux; \
  171. git config --global protocol.version 0; \
  172. git init -q /workspace/b12x; \
  173. git -C /workspace/b12x fetch -q --depth 1 ${B12X_REPO} ${B12X_PIN}; \
  174. git -C /workspace/b12x checkout -q FETCH_HEAD; \
  175. cd /workspace/b12x; \
  176. test "$(git rev-parse HEAD)" = "${B12X_PIN}"; \
  177. test "$(git rev-parse HEAD^{tree})" = "${B12X_TREE}"; \
  178. git config --global --add safe.directory /workspace/b12x
  179. FROM b12x-clone AS b12x-builder
  180. WORKDIR /workspace/b12x
  181. ARG B12X_PRETEND_VERSION
  182. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  183. SETUPTOOLS_SCM_PRETEND_VERSION_FOR_B12X="${B12X_PRETEND_VERSION}" \
  184. uv build --no-build-isolation --wheel . --out-dir=/wheels -v
  185. # ---- LMCache @ r27 source lock: wheel + cuMem interposer from source ----
  186. FROM torch-base AS lmcache-builder
  187. ARG LMCACHE_REPO LMCACHE_PIN LMCACHE_TREE LMCACHE_VERSION
  188. ARG BUILD_JOBS
  189. RUN set -eux; \
  190. git config --global protocol.version 0; \
  191. git init -q /workspace/lmcache; \
  192. git -C /workspace/lmcache fetch -q --depth 1 ${LMCACHE_REPO} ${LMCACHE_PIN}; \
  193. git -C /workspace/lmcache checkout -q FETCH_HEAD; \
  194. cd /workspace/lmcache; \
  195. test "$(git rev-parse HEAD^{tree})" = "${LMCACHE_TREE}"; \
  196. git config --global --add safe.directory /workspace/lmcache
  197. WORKDIR /workspace/lmcache
  198. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  199. uv pip install "setuptools>=77.0.3,<81.0.0" setuptools_scm wheel packaging ninja \
  200. && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_LMCACHE="${LMCACHE_VERSION}" \
  201. BUILD_WITH_CUDA=1 \
  202. LMCACHE_CUDA_MAJOR=13 \
  203. TORCH_CUDA_ARCH_LIST=12.1a \
  204. ENABLE_CXX11_ABI=1 \
  205. MAX_JOBS="${BUILD_JOBS:-4}" \
  206. NVCC_THREADS=auto \
  207. python3 -m pip wheel --no-build-isolation --no-deps --wheel-dir /lmcache-artifacts . \
  208. && make -C csrc/cumem_ipc_interposer CUDA_HOME=/usr/local/cuda \
  209. && install -Dm755 csrc/cumem_ipc_interposer/liblmcache_cumem_shareable.so \
  210. /lmcache-artifacts/liblmcache_cumem_shareable.so \
  211. && cd /lmcache-artifacts && sha256sum *.whl liblmcache_cumem_shareable.so > SHA256SUMS
  212. # ---- Runner: flattened GB10 serving image ----
  213. FROM torch-base AS runner
  214. ARG PYPI_INDEX_URL
  215. ARG LMCACHE_VERSION
  216. COPY checksums/tiktoken.sha256 /tmp/tiktoken.sha256
  217. COPY patch_cuda_sm12x.py /tmp/patch_cuda_sm12x.py
  218. COPY lmcache-runtime-requirements.txt /tmp/lmcache-runtime-requirements.txt
  219. WORKDIR /workspace
  220. RUN mkdir -p tiktoken_encodings \
  221. && wget -O tiktoken_encodings/o200k_base.tiktoken https://openaipublic.blob.core.windows.net/encodings/o200k_base.tiktoken \
  222. && wget -O tiktoken_encodings/cl100k_base.tiktoken https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken \
  223. && cd tiktoken_encodings && sha256sum -c /tmp/tiktoken.sha256
  224. ENV TIKTOKEN_ENCODINGS_BASE=/workspace/tiktoken_encodings
  225. RUN --mount=type=bind,from=vllm-builder,source=/wheels,target=/vllm-wheels \
  226. --mount=type=bind,from=b12x-builder,source=/wheels,target=/b12x-wheels \
  227. --mount=type=bind,from=lmcache-builder,source=/lmcache-artifacts,target=/lmcache-artifacts \
  228. --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  229. pip install --no-cache-dir --no-build-isolation /vllm-wheels/*.whl \
  230. && pip install --no-cache-dir --no-deps -r /tmp/lmcache-runtime-requirements.txt \
  231. && pip install --no-cache-dir --no-deps --force-reinstall /b12x-wheels/*.whl \
  232. && pip install --no-cache-dir --no-deps --force-reinstall /lmcache-artifacts/*.whl \
  233. && install -Dm755 /lmcache-artifacts/liblmcache_cumem_shareable.so \
  234. /opt/lmcache/lib/liblmcache_cumem_shareable.so \
  235. && install -m 644 /tmp/lmcache-runtime-requirements.txt /opt/lmcache/ \
  236. && python3 /tmp/patch_cuda_sm12x.py \
  237. && find /usr/local/lib/python3.12/dist-packages/vllm /opt/lmcache \
  238. -name "__pycache__" -type d -prune -exec rm -rf {} + 2>/dev/null || true
  239. # b12x loader allocation patch (discord, 2026-09-07): pinned_wc -> managed
  240. # in b12x/integration/vllm/loader.py — two occurrences (the weight_pool call
  241. # and the matching audit label). Reported prefill 1350 -> ~2000 tok/s. No
  242. # recompiles; hard-gated: any pinned_wc left behind fails the build.
  243. RUN set -eux; \
  244. F=/usr/local/lib/python3.12/dist-packages/b12x/integration/vllm/loader.py; \
  245. sed -i 's/allocation="pinned_wc"/allocation="managed"/; \
  246. s/"allocation": "pinned_wc"/"allocation": "managed"/' "$F"; \
  247. test "$(grep -c 'allocation="managed"' "$F")" = "1"; \
  248. grep -Fq '"allocation": "managed"' "$F"; \
  249. ! grep -q 'pinned_wc' "$F"
  250. # Build gate: the r27 stack must import with the GB10 patches in place and
  251. # carry the qualified package trees (marker spot-checks from the source lock).
  252. RUN set -eux; \
  253. python3 -c "import vllm; print('vllm', vllm.__version__)"; \
  254. python3 -c "from importlib.metadata import version; print('b12x', version('b12x'))"; \
  255. python3 -c "from importlib.metadata import version as v; \
  256. assert v('lmcache') == '${LMCACHE_VERSION}', v('lmcache'); print('lmcache', v('lmcache'))"; \
  257. python3 -c "import lmcache, lmcache.cuda_ops, lmcache.lmcache_native, lmcache.lmcache_fs; print('lmcache modules ok')"; \
  258. python3 -c "import vllm._flashkda_C; print('flashkda_C ok')"; \
  259. python3 -c "from vllm.config.attention import AttentionBackendEnum as E; \
  260. assert E.B12X.value and 'b12x' in E.B12X.value.lower(); print('B12X enum ok')"; \
  261. grep -q "AttentionBackendEnum.B12X," /usr/local/lib/python3.12/dist-packages/vllm/platforms/cuda.py; \
  262. grep -Fq 'def apply_top_k_top_p_probs' /usr/local/lib/python3.12/dist-packages/vllm/v1/sample/ops/topk_topp_sampler.py; \
  263. grep -Fq 'B12X_PCIE_ONESHOT_PDL' /usr/local/lib/python3.12/dist-packages/b12x/comm/pcie/_oneshot_cute.py; \
  264. grep -Fq 'self._transfer_workspace_slot_count = self._commit_workers' /usr/local/lib/python3.12/dist-packages/lmcache/v1/multiprocess/transfer_context/async_engine_driven.py; \
  265. test -s /opt/lmcache/lib/liblmcache_cumem_shareable.so
  266. ENV LMCACHE_EXPECTED_SOURCE_ROOT=/usr/local/lib/python3.12/site-packages/lmcache
  267. ENTRYPOINT []
  268. CMD ["bash"]