Dockerfile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. # syntax=docker/dockerfile:1.7
  2. # karmic-kraken (local-inference-lab vLLM fork, dev/karmic-kraken) — 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. Current tip: vLLM 636afde9 (2026-10-08), which takes B12X from
  8. # FlashInfer 0.7.1 (the standalone b12x repo is archived — no separate wheel).
  9. #
  10. # Runtime: CUDA 13.4.2 devel aarch64 base + torch 2.13.0 cu130 + flashinfer
  11. # 0.7.1 (carries B12X as flashinfer/experimental/b12x + the top-level `b12x`
  12. # import package). GB10 sm_121 fixes baked in (patch_cuda_sm12x.py, eugr
  13. # patch set).
  14. #
  15. # Build: cd docker-images/karmic-kraken && TAG=... bash build.sh
  16. ARG CUDA_BASE_IMAGE
  17. ARG CUDA_BASE_DIGEST
  18. ARG UV_VERSION
  19. FROM ${CUDA_BASE_IMAGE}@${CUDA_BASE_DIGEST} AS apt-base
  20. ARG PYPI_INDEX_URL
  21. ARG APT_SOURCE
  22. ENV DEBIAN_FRONTEND=noninteractive \
  23. PIP_BREAK_SYSTEM_PACKAGES=1 \
  24. UV_SYSTEM_PYTHON=1 UV_BREAK_SYSTEM_PACKAGES=1 UV_LINK_MODE=copy
  25. COPY locks/apt-sources.list /tmp/apt-sources-snapshot.list
  26. COPY locks/apt-packages.txt /tmp/apt-packages.txt
  27. COPY locks/python-bootstrap.txt /tmp/python-bootstrap.txt
  28. COPY locks/deps.lock /tmp/deps.lock
  29. # APT_SOURCE (versions.env):
  30. # snapshot (default, historical behavior): the pinned point-in-time mirror
  31. # + exact package versions — strictly reproducible, but
  32. # snapshot.ubuntu.com is slow (~30 kB/s) and intermittently 503s
  33. # (12-min apt stall, 2026-09-08).
  34. # current: the live archive.ubuntu.com — fast and reliable; installs the
  35. # pinned package names unversioned. Acceptable: the engine stack is
  36. # pinned by the vLLM/B12X/LMCache source pins, not by apt.
  37. RUN set -eux; \
  38. if [ "${APT_SOURCE:-snapshot}" = "current" ]; then \
  39. printf '%s\n' \
  40. "deb http://ports.ubuntu.com/ubuntu-ports/ noble main restricted universe multiverse" \
  41. "deb http://ports.ubuntu.com/ubuntu-ports/ noble-updates main restricted universe multiverse" \
  42. "deb http://ports.ubuntu.com/ubuntu-ports/ noble-security main restricted universe multiverse" \
  43. > /etc/apt/sources.list; \
  44. PKGS="$(grep -vE '^\s*(#|$)' /tmp/apt-packages.txt | cut -d= -f1)"; \
  45. else \
  46. cp /tmp/apt-sources-snapshot.list /etc/apt/sources.list; \
  47. PKGS="$(grep -vE '^\s*(#|$)' /tmp/apt-packages.txt)"; \
  48. fi; \
  49. rm -f /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; \
  50. apt-get update; \
  51. apt-get install -y --no-install-recommends ${PKGS}; \
  52. rm -rf /var/lib/apt/lists/*; \
  53. python3 -m pip install --no-cache-dir --no-deps \
  54. -r /tmp/python-bootstrap.txt --index-url "${PYPI_INDEX_URL}"
  55. FROM apt-base AS torch-base
  56. ARG PYPI_INDEX_URL
  57. ARG PYTORCH_INDEX_URL
  58. ARG TORCH_VERSION TORCHVISION_VERSION TORCHAUDIO_VERSION
  59. ARG FLASHINFER_VERSION
  60. ARG B12X_VERSION
  61. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  62. uv pip install \
  63. --index-url ${PYPI_INDEX_URL} \
  64. --extra-index-url ${PYTORCH_INDEX_URL} \
  65. --index-strategy unsafe-best-match \
  66. "torch==${TORCH_VERSION}" \
  67. "torchvision==${TORCHVISION_VERSION}" \
  68. "torchaudio==${TORCHAUDIO_VERSION}" \
  69. "flashinfer-python==${FLASHINFER_VERSION}" \
  70. "b12x==${B12X_VERSION}"
  71. # DeepGEMM: cloned in-build (proven to work on the nodes via git; pins are
  72. # gated again in fetch-deps.sh against the vLLM tree's own declaration).
  73. FROM torch-base AS deepgemm-builder
  74. ARG DEEPGEMM_REPO DEEPGEMM_BRANCH DEEPGEMM_REF
  75. RUN set -eux; \
  76. git config --global protocol.version 0; \
  77. git clone --branch ${DEEPGEMM_BRANCH} ${DEEPGEMM_REPO} /deps/deepgemm; \
  78. cd /deps/deepgemm; \
  79. git checkout ${DEEPGEMM_REF}; \
  80. git submodule update --init --depth 1 -- third-party/cutlass third-party/fmt
  81. # ---- vLLM @ r27 integration branch, gated by commit + tree hash ----
  82. FROM torch-base AS vllm-clone
  83. ARG VLLM_REPO VLLM_PIN VLLM_BRANCH
  84. RUN set -eux; \
  85. git config --global protocol.version 0; \
  86. git init -q /workspace/vllm; \
  87. git -C /workspace/vllm fetch -q --depth 1 ${VLLM_REPO} ${VLLM_PIN}; \
  88. git -C /workspace/vllm checkout -q FETCH_HEAD; \
  89. cd /workspace/vllm; \
  90. test "$(git rev-parse HEAD)" = "${VLLM_PIN}"; \
  91. echo "vllm at $(git rev-parse HEAD) (branch ${VLLM_BRANCH})"; \
  92. git config --global --add safe.directory /workspace/vllm
  93. # ---- All build sub-deps, cloned at pins the r27 tree itself declares ----
  94. # REGEN_LOCK=1: fetch-deps.sh rewrites /tmp/deps.lock from the staged state
  95. # (pin cuts) instead of verifying against it — export the stage to harvest
  96. # the new lock, then commit it.
  97. FROM vllm-clone AS deps-fetched
  98. ARG REGEN_LOCK=""
  99. COPY fetch-deps.sh /tmp/fetch-deps.sh
  100. RUN if [ -n "$REGEN_LOCK" ]; then bash /tmp/fetch-deps.sh --regen-lock /tmp/deps.lock; else bash /tmp/fetch-deps.sh; fi
  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=
  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. # The vllm tip pins flashinfer-python==0.7.1 (final) in requirements/cuda.txt,
  144. # which does NOT exist on PyPI (only 0.7.1rc5). Relax to the installed rc5 so
  145. # the wheel's dep metadata is satisfiable (flashinfer 0.7.1rc5 is in torch-base);
  146. # otherwise `pip install` of the wheel fails to resolve the dep and vllm is absent.
  147. RUN set -eux; \
  148. sed -i 's/flashinfer-python==0.7.1/flashinfer-python==0.7.1rc5/' /workspace/vllm/requirements/cuda.txt; \
  149. grep 'flashinfer-python' /workspace/vllm/requirements/cuda.txt
  150. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  151. --mount=type=cache,id=ccache,target=/root/.ccache \
  152. --mount=type=cache,id=cargo-registry,target=/root/.cargo/registry \
  153. --mount=type=cache,id=rust-target,target=/workspace/vllm/vllm/target \
  154. git config --global protocol.version 0 \
  155. && uv pip install setuptools-rust setuptools-scm \
  156. && (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) \
  157. && export PATH=/root/.cargo/bin:$PATH \
  158. && (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/*)) \
  159. && _j="${BUILD_JOBS:-$(nproc)}" \
  160. && export GIT_PROTOCOL=0 MAX_JOBS="${_j}" CMAKE_BUILD_PARALLEL_LEVEL="${_j}" \
  161. VLLM_REQUIRE_RUST_FRONTEND=1 CARGO_BUILD_JOBS="${_j}" \
  162. SETUPTOOLS_SCM_PRETEND_VERSION="${VLLM_PRETEND_VERSION}" \
  163. TRITON_KERNELS_SRC_DIR=/deps2/triton_kernels \
  164. FMHA_SM100_SRC_DIR=/deps2/MSA \
  165. FLASH_MLA_SRC_DIR=/deps2/FlashMLA \
  166. FLASH_KDA_SRC_DIR="${FLASH_KDA_SRC_DIR}" \
  167. VLLM_FLASH_ATTN_SRC_DIR=/deps2/flash-attention \
  168. QUTLASS_SRC_DIR=/deps2/qutlass \
  169. TML_FA4_SRC_DIR=/deps2/tml-fa4 \
  170. VLLM_CUTLASS_SRC_DIR=/deps2/cutlass \
  171. CUTLASS_INCLUDE_DIR_PRE=/deps2/cutlass/include \
  172. && python3 use_existing_torch.py \
  173. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v
  174. # ---- B12X: now ships inside flashinfer-python 0.7.1 (installed in torch-base) ----
  175. # The standalone lukealonso/b12x repo is archived; its code continues in
  176. # FlashInfer, whose wheel installs the top-level `b12x` package that vLLM
  177. # imports. No separate b12x wheel is built or installed (a standalone b12x
  178. # package must not sit next to flashinfer 0.7.1 — same namespace).
  179. # ---- Runner: flattened GB10 serving image ----
  180. FROM torch-base AS runner
  181. ARG PYPI_INDEX_URL
  182. COPY checksums/tiktoken.sha256 /tmp/tiktoken.sha256
  183. COPY patch_cuda_sm12x.py /tmp/patch_cuda_sm12x.py
  184. # GLM-5.3 chat template (from the kindling stack): the karmic recipe serves
  185. # GLM-5.3-Flash with --chat-template /usr/local/share/glm53-chat-template.jinja;
  186. # bake it in so the karmic image matches the kindling one (fair A/B).
  187. COPY glm53-chat-template.jinja /usr/local/share/glm53-chat-template.jinja
  188. WORKDIR /workspace
  189. RUN mkdir -p tiktoken_encodings \
  190. && wget -O tiktoken_encodings/o200k_base.tiktoken https://openaipublic.blob.core.windows.net/encodings/o200k_base.tiktoken \
  191. && wget -O tiktoken_encodings/cl100k_base.tiktoken https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken \
  192. && cd tiktoken_encodings && sha256sum -c /tmp/tiktoken.sha256
  193. ENV TIKTOKEN_ENCODINGS_BASE=/workspace/tiktoken_encodings
  194. RUN --mount=type=bind,from=vllm-builder,source=/wheels,target=/vllm-wheels \
  195. --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  196. set -eux; \
  197. echo '=== /vllm-wheels contents ==='; ls -la /vllm-wheels/; \
  198. pip install --no-cache-dir --no-build-isolation /vllm-wheels/*.whl; \
  199. python3 -c "import vllm; print('vllm installed OK:', vllm.__version__)" \
  200. && python3 /tmp/patch_cuda_sm12x.py \
  201. && find /usr/local/lib/python3.12/dist-packages/vllm \
  202. -name "__pycache__" -type d -prune -exec rm -rf {} + 2>/dev/null || true
  203. # b12x loader allocation patch (discord, 2026-09-07): pinned_wc -> managed in
  204. # b12x/integration/vllm/loader.py. Legacy-only: with FlashInfer 0.7.1's bundled
  205. # b12x (auto-allocation, no pinned_wc) the file is ABSENT, so the patch is N/A.
  206. # Tolerant of all three cases: pinned_wc present (patch it), file present but
  207. # clean (skip), file absent (new flashinfer-bundled b12x — N/A).
  208. RUN set -eux; \
  209. F=/usr/local/lib/python3.12/dist-packages/b12x/integration/vllm/loader.py; \
  210. if [ -f "$F" ] && grep -q 'pinned_wc' "$F" 2>/dev/null; then \
  211. sed -i 's/allocation="pinned_wc"/allocation="managed"/; \
  212. s/"allocation": "pinned_wc"/"allocation": "managed"/' "$F"; \
  213. test "$(grep -c 'allocation="managed"' "$F")" = "1"; \
  214. grep -Fq '"allocation": "managed"' "$F"; \
  215. ! grep -q 'pinned_wc' "$F"; \
  216. elif [ -f "$F" ]; then \
  217. echo "b12x loader carries no pinned_wc (new auto-allocation b12x) — patch skipped"; \
  218. else \
  219. echo "b12x loader file absent (b12x ships inside flashinfer 0.7.1 with auto-allocation) — patch N/A"; \
  220. fi
  221. # Build gate: the r27 stack must import with the GB10 patches in place and
  222. # carry the qualified package trees (marker spot-checks from the source lock).
  223. RUN set -eux; \
  224. python3 -c "import vllm; print('vllm', vllm.__version__)"; \
  225. python3 -c "import b12x; print('b12x', getattr(b12x,'__version__','(bundled in flashinfer 0.7.1)'))"; \
  226. python3 -c "import vllm._flashkda_C; print('flashkda_C ok')"; \
  227. python3 -c "from vllm.config.attention import AttentionBackendEnum as E; \
  228. assert E.B12X.value and 'b12x' in E.B12X.value.lower(); print('B12X enum ok')"; \
  229. grep -q "AttentionBackendEnum.B12X," /usr/local/lib/python3.12/dist-packages/vllm/platforms/cuda.py; \
  230. grep -Fq 'def apply_top_k_top_p_probs' /usr/local/lib/python3.12/dist-packages/vllm/v1/sample/ops/topk_topp_sampler.py; \
  231. if [ -f /usr/local/lib/python3.12/dist-packages/b12x/comm/pcie/_oneshot_cute.py ]; then \
  232. grep -Fq '_PREPARED_ONESHOT_LAUNCHERS' /usr/local/lib/python3.12/dist-packages/b12x/comm/pcie/_oneshot_cute.py; \
  233. else \
  234. echo "b12x oneshot marker file absent (new flashinfer-bundled layout) — spot-check skipped"; \
  235. fi
  236. ENTRYPOINT []
  237. CMD ["bash"]