Dockerfile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # syntax=docker/dockerfile:1.7
  2. # ==========================================================================
  3. # GLM-5.2 NF3-Hybrid — DGX Spark (aarch64/sm_121a)
  4. #
  5. # Builds vLLM (local-inference-lab/eldritch-enlightenment) + b12x
  6. # + FlashInfer from source, then overlays the NF3 Triton kernels.
  7. #
  8. # Usage:
  9. # docker build \
  10. # --build-arg VLLM_SRC=/path/to/vllm \
  11. # --build-arg B12X_SRC=/path/to/b12x \
  12. # --build-arg NCCL_SRC=/path/to/nccl \
  13. # -t vllm-nf3-hybrid:probe .
  14. #
  15. # On dgx4.lan:
  16. # VLLM_SRC=/home/kilork/projects/github.com/vllm-eldritch
  17. # B12X_SRC=/home/kilork/projects/github.com/b12x-nf3
  18. # NCCL_SRC=/home/kilork/projects/github.com/nccl-canonical
  19. # ==========================================================================
  20. ARG CUDA_VERSION=13.2.0
  21. ARG UBUNTU_VERSION=24.04
  22. ARG GPU_ARCH=12.1a
  23. FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
  24. ARG GPU_ARCH
  25. ARG DEBIAN_FRONTEND=noninteractive
  26. ENV DEBIAN_FRONTEND=noninteractive \
  27. PIP_BREAK_SYSTEM_PACKAGES=1 \
  28. TORCH_CUDA_ARCH_LIST=${GPU_ARCH} \
  29. CUTE_DSL_ARCH=sm_121a \
  30. FLASHINFER_CUDA_ARCH_LIST=${GPU_ARCH} \
  31. MAX_JOBS=$(nproc) \
  32. CMAKE_BUILD_PARALLEL_LEVEL=$(nproc)
  33. # ── System packages ─────────────────────────────────────────────────
  34. RUN apt-get update && apt-get install -y --no-install-recommends \
  35. build-essential ninja-build cmake curl git wget \
  36. python3-dev python3-pip python3-venv ccache \
  37. libibverbs-dev libibverbs1 rdma-core \
  38. libcudnn9-cuda-13 libcudnn9-dev-cuda-13 \
  39. rapidjson-dev libxml2-dev \
  40. && rm -rf /var/lib/apt/lists/*
  41. # ── Python build essentials ─────────────────────────────────────────
  42. RUN pip install --no-cache-dir uv pybind11 setuptools-scm wheel
  43. # ── PyTorch 2.12.0+cu132 (aarch64) ──────────────────────────────────
  44. RUN pip install --no-cache-dir --no-deps torch==2.12.0 \
  45. && pip install --no-cache-dir --no-deps torchvision==0.22.0
  46. # ── NCCL ────────────────────────────────────────────────────────────
  47. COPY nccl /opt/nccl
  48. WORKDIR /opt/nccl
  49. RUN make -j$(nproc) src.build \
  50. CUDA_HOME=/usr/local/cuda \
  51. NVCC_GENCODE="-gencode=arch=compute_121,code=sm_121" \
  52. && make install PREFIX=/usr/local && ldconfig
  53. # ── b12x ────────────────────────────────────────────────────────────
  54. COPY b12x /opt/b12x
  55. WORKDIR /opt/b12x
  56. RUN pip install --no-cache-dir -e . --no-build-isolation \
  57. -C setup.args="--cuda-arch=${GPU_ARCH}"
  58. # ── FlashInfer ──────────────────────────────────────────────────────
  59. RUN git clone --recursive https://github.com/flashinfer-ai/flashinfer.git /opt/flashinfer \
  60. && cd /opt/flashinfer \
  61. && git checkout 25dd814e03791e370f96c3148242f0dc8de504ac \
  62. && git submodule update --init --recursive
  63. WORKDIR /opt/flashinfer
  64. RUN uv build --no-build-isolation --wheel . --out-dir=/wheels -v \
  65. && cd flashinfer-cubin \
  66. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v \
  67. && cd ../flashinfer-jit-cache \
  68. && uv build --no-build-isolation --wheel . --out-dir=/wheels -v \
  69. && pip install --no-cache-dir /wheels/*.whl
  70. # ── vLLM (eldritch-enlightenment) ───────────────────────────────────
  71. COPY vllm /opt/vllm
  72. WORKDIR /opt/vllm
  73. RUN git checkout 45c1582e9b80ba83e71c3a6458e71da4736fbdc4 2>/dev/null || true \
  74. && git submodule update --init --recursive 2>/dev/null || true
  75. # Build vLLM wheel
  76. RUN --mount=type=cache,id=uv-cache,target=/root/.cache/uv \
  77. uv build --no-build-isolation --wheel . --out-dir=/wheels -v \
  78. && pip install --no-cache-dir /wheels/vllm*.whl
  79. # ── NF3 hybrid overlay ─────────────────────────────────────────────
  80. COPY overlay/hybrid_loader.py /usr/local/lib/python3.12/dist-packages/hybrid_loader.py
  81. COPY overlay/nf3_kernel.py /usr/local/lib/python3.12/dist-packages/nf3_kernel.py
  82. COPY overlay/nvfp4_kernel.py /usr/local/lib/python3.12/dist-packages/nvfp4_kernel.py
  83. COPY overlay/nf3_replan.py /usr/local/lib/python3.12/dist-packages/nf3_replan.py
  84. COPY overlay/mxfp8_tier.json /usr/local/lib/python3.12/dist-packages/mxfp8_tier.json
  85. # .pth hook: hybrid_loader fires when any Python process imports from vllm
  86. RUN python3 -c "import sys; open('/usr/local/lib/python3.12/dist-packages/hybrid_loader.pth','w').write('import hybrid_loader\n')"
  87. # ── Verify ──────────────────────────────────────────────────────────
  88. RUN python3 -c "import hybrid_loader; print('hybrid_loader OK'); import nf3_kernel; print('nf3_kernel OK'); import nvfp4_kernel; print('nvfp4_kernel OK'); import nf3_replan; print('nf3_replan OK'); import flashinfer; print(f'flashinfer OK: {flashinfer.__version__}'); import torch; print(f'PyTorch OK: {torch.__version__}, CUDA: {torch.version.cuda}'); import b12x; print(f'b12x OK: {b12x.__version__}'); import vllm; print(f'vLLM OK: {vllm.__version__}')"
  89. ENTRYPOINT ["vllm", "serve"]