Dockerfile 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # syntax=docker/dockerfile:1.7
  2. # GLM-5.2 NF3-Hybrid — self-contained build for DGX Spark (aarch64/sm_121a)
  3. #
  4. # All build inputs pinned in versions.env and locks/. No external repo needed
  5. # beyond the package registries and git repos each stage clones.
  6. #
  7. # Build: cd docker-images/glm52-nf3-hybrid && bash build.sh
  8. ARG CUDA_BASE_IMAGE
  9. ARG CUDA_BASE_DIGEST
  10. FROM ${CUDA_BASE_IMAGE}@${CUDA_BASE_DIGEST} AS apt-base
  11. ARG UV_VERSION
  12. ARG PYTORCH_INDEX_URL
  13. ARG PYPI_INDEX_URL
  14. ARG TORCH_CUDA_ARCH_LIST=12.1a
  15. ENV DEBIAN_FRONTEND=noninteractive \
  16. PIP_BREAK_SYSTEM_PACKAGES=1 \
  17. UV_SYSTEM_PYTHON=1 UV_BREAK_SYSTEM_PACKAGES=1 UV_LINK_MODE=copy \
  18. TORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST} \
  19. TRITON_PTXAS_PATH=/usr/local/cuda/bin/ptxas
  20. COPY locks/apt-sources.list /tmp/apt-sources.list
  21. COPY locks/apt-packages.txt /tmp/apt-packages.txt
  22. COPY locks/python-bootstrap.txt /tmp/python-bootstrap.txt
  23. COPY locks/python-build.txt /tmp/python-build.txt
  24. RUN rm -f /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources \
  25. && cp /tmp/apt-sources.list /etc/apt/sources.list \
  26. && apt-get update \
  27. && grep -vE '^\s*(#|$)' /tmp/apt-packages.txt \
  28. | xargs apt-get install -y --no-install-recommends \
  29. && rm -rf /var/lib/apt/lists/* \
  30. && python3 -m pip install --no-cache-dir --require-hashes --no-deps \
  31. -r /tmp/python-bootstrap.txt --index-url ${PYPI_INDEX_URL}
  32. FROM apt-base AS torch-base
  33. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  34. uv pip install --require-hashes -r /tmp/python-build.txt \
  35. --index-url ${PYPI_INDEX_URL} --extra-index-url ${PYTORCH_INDEX_URL} \
  36. --index-strategy unsafe-best-match
  37. FROM torch-base AS base
  38. ARG TORCH_VERSION TORCHVISION_VERSION TORCHAUDIO_VERSION TRITON_VERSION
  39. ARG NCCL_REPO NCCL_REF
  40. RUN git clone --depth 1 -b ${NCCL_REF} ${NCCL_REPO} /opt/nccl \
  41. && cd /opt/nccl \
  42. && make -j $(nproc) src.build \
  43. NVCC_GENCODE="-gencode=arch=compute_121,code=sm_121" \
  44. && make install PREFIX=/usr/local && ldconfig
  45. FROM base AS flashinfer-builder
  46. ARG FLASHINFER_REPO FLASHINFER_REF
  47. ARG FLASHINFER_CUDA_ARCH_LIST=12.1a
  48. ARG SOURCE_DATE_EPOCH BUILD_JOBS
  49. ENV FLASHINFER_CUDA_ARCH_LIST=${FLASHINFER_CUDA_ARCH_LIST}
  50. RUN git clone --recursive ${FLASHINFER_REPO} /workspace/flashinfer \
  51. && cd /workspace/flashinfer \
  52. && git checkout ${FLASHINFER_REF} \
  53. && git submodule update --init --recursive
  54. WORKDIR /workspace/flashinfer
  55. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  56. --mount=type=cache,id=ccache,target=/root/.ccache \
  57. _j="${BUILD_JOBS:-$(nproc)}" \
  58. && export MAX_JOBS="${_j}" CMAKE_BUILD_PARALLEL_LEVEL="${_j}" \
  59. && sed -i '/^license-files/d' pyproject.toml \
  60. && sed -i 's|^license = .*|license = {text = "Apache-2.0"}|' pyproject.toml \
  61. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v \
  62. && cd flashinfer-cubin \
  63. && sed -i '/^license-files/d' pyproject.toml \
  64. && sed -i 's|^license = .*|license = {text = "Apache-2.0"}|' pyproject.toml \
  65. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v \
  66. && cd ../flashinfer-jit-cache \
  67. && sed -i '/^license-files/d' pyproject.toml \
  68. && sed -i 's|^license = .*|license = {text = "Apache-2.0"}|' pyproject.toml \
  69. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v
  70. FROM base AS vllm-builder
  71. ARG VLLM_REPO VLLM_REF VLLM_COMMIT
  72. ARG SOURCE_DATE_EPOCH BUILD_JOBS
  73. RUN git clone --recursive ${VLLM_REPO} /workspace/vllm \
  74. && cd /workspace/vllm \
  75. && git checkout ${VLLM_REF} \
  76. && git submodule update --init --recursive
  77. COPY patches/ /patches/
  78. RUN cd /workspace/vllm \
  79. && for p in /patches/*.patch; do [ -f "$p" ] && patch -p1 --forward < "$p" || true; done
  80. WORKDIR /workspace/vllm
  81. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  82. --mount=type=cache,id=ccache,target=/root/.ccache \
  83. _j="${BUILD_JOBS:-$(nproc)}" \
  84. && export MAX_JOBS="${_j}" CMAKE_BUILD_PARALLEL_LEVEL="${_j}" \
  85. && python3 use_existing_torch.py \
  86. && sed -i '/^license-files/d' pyproject.toml \
  87. && sed -i 's|^license = .*|license = {text = "Apache-2.0"}|' pyproject.toml \
  88. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v
  89. FROM base AS b12x-builder
  90. ARG B12X_REPO B12X_REF B12X_COMMIT
  91. ARG TORCH_CUDA_ARCH_LIST=12.1a
  92. ENV TORCH_CUDA_ARCH_LIST=${TORCH_CUDA_ARCH_LIST} CUTE_DSL_ARCH=sm_121a
  93. RUN git clone --recursive ${B12X_REPO} /opt/b12x \
  94. && cd /opt/b12x \
  95. && git checkout ${B12X_REF} \
  96. && pip install --no-cache-dir -e . --no-build-isolation \
  97. -C setup.args="--cuda-arch=${TORCH_CUDA_ARCH_LIST}"
  98. FROM base AS runner
  99. ARG TORCH_CUDA_ARCH_LIST=12.1a
  100. ARG PYTORCH_INDEX_URL PYPI_INDEX_URL
  101. ARG CUTLASS_DSL_VERSION
  102. COPY locks/python-runtime.txt /tmp/python-runtime.txt
  103. WORKDIR /workspace
  104. COPY checksums/tiktoken.sha256 /tmp/tiktoken.sha256
  105. RUN mkdir -p tiktoken_encodings \
  106. && wget -O tiktoken_encodings/o200k_base.tiktoken https://openaipublic.blob.core.windows.net/encodings/o200k_base.tiktoken \
  107. && wget -O tiktoken_encodings/cl100k_base.tiktoken https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken \
  108. && cd tiktoken_encodings && sha256sum -c /tmp/tiktoken.sha256
  109. ENV TIKTOKEN_ENCODINGS_BASE=/workspace/tiktoken_encodings
  110. RUN apt-get update && apt-get install -y --no-install-recommends libboost-dev libaio-dev \
  111. && rm -rf /var/lib/apt/lists/*
  112. # Install all wheels
  113. RUN --mount=type=bind,from=flashinfer-builder,source=/wheels,target=/fi-wheels \
  114. --mount=type=bind,from=vllm-builder,source=/wheels,target=/vllm-wheels \
  115. --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  116. uv pip install --require-hashes -r /tmp/python-runtime.txt \
  117. --index-url ${PYPI_INDEX_URL} --extra-index-url ${PYTORCH_INDEX_URL} \
  118. --index-strategy unsafe-best-match \
  119. && pip install --no-cache-dir /fi-wheels/*.whl /vllm-wheels/*.whl
  120. # b12x: symlink full source tree (must include integration/ attention/ etc.)
  121. COPY --from=b12x-builder /opt/b12x/ /opt/b12x/
  122. RUN rm -rf /usr/local/lib/python3.12/dist-packages/b12x* \
  123. && ln -sf /opt/b12x/b12x /usr/local/lib/python3.12/dist-packages/b12x \
  124. && pip install --no-cache-dir -e /opt/b12x --no-build-isolation --no-deps \
  125. -C setup.args="--cuda-arch=${TORCH_CUDA_ARCH_LIST}"
  126. RUN pip install --no-cache-dir \
  127. nvidia-cutlass-dsl==${CUTLASS_DSL_VERSION} \
  128. nvidia-cutlass-dsl-libs-cu13==${CUTLASS_DSL_VERSION}
  129. # NCCL symlink for torch
  130. RUN rm -f /usr/local/lib/python3.12/dist-packages/nvidia/nccl/lib/libnccl.so.2 \
  131. && ln -s /usr/local/lib/libnccl.so.2 \
  132. /usr/local/lib/python3.12/dist-packages/nvidia/nccl/lib/libnccl.so.2
  133. # NF3 hybrid overlay
  134. COPY overlay/hybrid_loader.py /usr/local/lib/python3.12/dist-packages/hybrid_loader.py
  135. COPY overlay/hybrid.pth /usr/local/lib/python3.12/dist-packages/hybrid.pth
  136. COPY overlay/nf3_kernel.py /usr/local/lib/python3.12/dist-packages/nf3_kernel.py
  137. COPY overlay/nvfp4_kernel.py /usr/local/lib/python3.12/dist-packages/nvfp4_kernel.py
  138. COPY overlay/nf3_replan.py /usr/local/lib/python3.12/dist-packages/nf3_replan.py
  139. COPY overlay/mxfp8_tier.json /usr/local/lib/python3.12/dist-packages/mxfp8_tier.json
  140. COPY overlay/b12x/moe/fused/w4a16/prepare.py /usr/local/lib/python3.12/dist-packages/b12x/moe/fused/w4a16/prepare.py
  141. COPY overlay/b12x/moe/fused/w4a16/host.py /usr/local/lib/python3.12/dist-packages/b12x/moe/fused/w4a16/host.py
  142. COPY overlay/b12x/cute/fp4.py /usr/local/lib/python3.12/dist-packages/b12x/cute/fp4.py
  143. COPY overlay/vllm/v1/attention/backends/mla/indexer.py \
  144. /usr/local/lib/python3.12/dist-packages/vllm/v1/attention/backends/mla/indexer.py
  145. ENTRYPOINT []
  146. CMD ["bash"]