interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / docker / Dockerfile.cuda

115 lines · 5436 bytes Raw Blame History
1# =============================================================================
2# MojoLlama — NVIDIA CUDA Dockerfile
3# Multi-stage build:
4# Stage 1 (builder): builds llama-server (CUDA) + AVX2 C kernels
5# Stage 2 (runtime): CUDA runtime + Python 3.11 + mojollama + MAX backend
6# =============================================================================
7# syntax=docker/dockerfile:1
8
9# ── Stage 1: Build llama.cpp (CUDA) + C kernels ─────────────────────────
10FROM nvidia/cuda:12.4.1-devel-ubuntu22.04 AS builder
11
12LABEL stage="builder"
13
14RUN apt-get update && \
15 apt-get install -y --no-install-recommends \
16 build-essential cmake git ca-certificates gcc g++ libomp-dev \
17 && rm -rf /var/lib/apt/lists/*
18
19# ── Build llama-server with CUDA ────────────────────────────────────────
20ARG LLAMACPP_REPO=https://github.com/ggml-org/llama.cpp.git
21ARG LLAMACPP_BRANCH=master
22RUN git clone --depth 1 --branch "${LLAMACPP_BRANCH}" "${LLAMACPP_REPO}" /tmp/llama.cpp
23WORKDIR /tmp/llama.cpp
24RUN mkdir -p build && cd build && \
25 cmake .. -DCMAKE_BUILD_TYPE=Release \
26 -DGGML_CUDA=ON \
27 -DLLAMA_CURL=OFF -DLLAMA_SERVER_VERBOSE=OFF \
28 -DBUILD_SHARED_LIBS=OFF -DLLAMA_CCACHE=OFF \
29 && cmake --build . --target llama-server -- -j"$(nproc)"
30RUN chmod +x /tmp/llama.cpp/convert_hf_to_gguf.py
31
32# ── Build TurboEngine AVX2 C kernels ────────────────────────────────────
33COPY src/mojollama/kernels/ /build/kernels/
34COPY src/mojollama/kernels/legacy-c/turbo_kernels_v2.c /build/kernels/
35WORKDIR /build/kernels
36RUN gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
37 -o quant_kernels_omp.so quant_kernels_omp.c -lm && \
38 gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
39 -o cengine_batch_instr.so cengine_batch_instr.c -lm && \
40 gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
41 -o simd_ops.so simd_ops.c -lm && \
42 gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
43 -o gqa_attention.so gqa_attention.c -lm && \
44 gcc -O3 -mavx2 -mfma -mf16c -shared -fPIC \
45 -o turbo_kernels_v2.so turbo_kernels_v2.c -lm
46
47# ── Stage 2: Runtime image ───────────────────────────────────────────────
48FROM nvidia/cuda:12.4.1-runtime-ubuntu22.04
49
50LABEL org.opencontainers.image.title="MojoLlama CUDA"
51LABEL org.opencontainers.image.description="LLM inference server — NVIDIA CUDA + TurboEngine CPU + MAX backend"
52LABEL org.opencontainers.image.source="https://git.bamse.cloud/a730/MojoLlama"
53LABEL org.opencontainers.image.licenses="Apache-2.0"
54LABEL org.opencontainers.image.version="1.0.0"
55
56ENV PYTHONDONTWRITEBYTECODE=1 \
57 PYTHONUNBUFFERED=1 \
58 PYTHONPATH=/app/src
59
60RUN apt-get update && \
61 apt-get install -y --no-install-recommends \
62 curl ca-certificates libomp-dev python3-pip \
63 && rm -rf /var/lib/apt/lists/*
64
65RUN groupadd -r mojollama && \
66 useradd -r -g mojollama -d /home/mojollama -m -s /sbin/nologin mojollama
67
68# ── Copy llama-server binary ────────────────────────────────────────────
69COPY --from=builder --chown=root:root \
70 /tmp/llama.cpp/build/bin/llama-server \
71 /tmp/llama.cpp/build/bin/llama-server
72COPY --from=builder --chown=root:root \
73 /tmp/llama.cpp/convert_hf_to_gguf.py \
74 /tmp/llama.cpp/convert_hf_to_gguf.py
75RUN chmod 755 /tmp/llama.cpp/build/bin/llama-server /tmp/llama.cpp/convert_hf_to_gguf.py
76
77# ── Copy MojoLlama source first ─────────────────────────────────────────
78WORKDIR /app
79COPY src/mojollama/ /app/src/mojollama/
80
81# ── Overwrite with freshly compiled TurboEngine AVX2 kernels ────────────
82COPY --from=builder --chown=root:root \
83 /build/kernels/quant_kernels_omp.so \
84 /build/kernels/cengine_batch_instr.so \
85 /build/kernels/simd_ops.so \
86 /build/kernels/gqa_attention.so \
87 /build/kernels/turbo_kernels_v2.so \
88 /app/src/mojollama/kernels/
89
90# ── Python deps + MAX backend ───────────────────────────────────────────
91RUN pip install --no-cache-dir gguf numpy transformers requests max
92
93# ── Pre-download TinyLlama for testing ──────────────────────────────────
94RUN mkdir -p /models && \
95 curl -fSL --retry 3 --retry-delay 5 \
96 -o /models/tinyllama-1.1b.Q4_K_M.gguf \
97 "https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf" \
98 || echo "[WARN] TinyLlama download failed"
99
100COPY www/ /app/www/
101COPY docker-entrypoint.sh /app/docker-entrypoint.sh
102RUN chmod 755 /app/docker-entrypoint.sh
103
104RUN mkdir -p /models /home/mojollama/.mojollama && \
105 chown -R mojollama:mojollama /app /models /home/mojollama/.mojollama
106
107HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
108 CMD curl -sf http://localhost:8080/health || exit 1
109
110EXPOSE 8080 8081
111
112USER mojollama
113
114ENTRYPOINT ["/app/docker-entrypoint.sh"]
115CMD []