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 / src / mojollama / Dockerfile

155 lines · 5418 bytes Raw Blame History
1# ============================================================
2# MojoLlama Dockerfile — Multi-stage build
3# ============================================================
4# Produces a single image with:
5# - MojoLlama engine (Python + C kernels + Mojo/MAX)
6# - llama.cpp as fallback backend
7# - Studio web UI (Flask)
8# - Quantization engine
9# - OpenAI-compatible API server
10# ============================================================
11
12# ── Stage 1: Builder ────────────────────────────────────────
13FROM debian:bookworm-20250408 AS builder
14
15LABEL org.opencontainers.image.title="MojoLlama"
16LABEL org.opencontainers.image.description="High-throughput CPU LLM inference engine — GGUF native, MoE-optimized"
17LABEL org.opencontainers.image.version="0.5.0"
18LABEL org.opencontainers.image.licenses="MIT"
19
20SHELL ["/bin/bash", "-c"]
21
22# ── Build dependencies ──
23RUN apt-get update && apt-get install -y --no-install-recommends \
24 build-essential \
25 cmake \
26 gcc \
27 g++ \
28 make \
29 git \
30 curl \
31 wget \
32 ca-certificates \
33 pkg-config \
34 libomp-dev \
35 python3 \
36 python3-pip \
37 python3-venv \
38 && rm -rf /var/lib/apt/lists/*
39
40# ── Install MAX / Mojo SDK ──
41RUN curl -fsSL https://get.modular.com | bash -s -- --install-version 26.3.0 \
42 && pip install max-mojo-libs==26.3.0 max-mojo-mogg-libs==26.3.0 \
43 && rm -rf ~/.cache/pip
44
45# ── Build llama.cpp (fallback backend) ──
46RUN git clone --depth=1 --branch b4729 https://github.com/ggml-org/llama.cpp /tmp/llama.cpp \
47 && cd /tmp/llama.cpp \
48 && cmake -B build \
49 -DCMAKE_BUILD_TYPE=Release \
50 -DLLAMA_NATIVE=OFF \
51 -DLLAMA_AVX2=ON \
52 -DLLAMA_FMA=ON \
53 -DLLAMA_F16C=ON \
54 -DLLAMA_OPENMP=ON \
55 -DLLAMA_CURL=OFF \
56 && cmake --build build --config Release -j$(nproc) --target llama-cli llama-server llama-bench \
57 && strip build/bin/llama-cli build/bin/llama-server build/bin/llama-bench \
58 && cp build/bin/llama-* /usr/local/bin/ \
59 && rm -rf /tmp/llama.cpp
60
61# ── Build MojoLlama C kernels ──
62COPY kernels/ /build/kernels/
63WORKDIR /build/kernels
64RUN gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
65 -o quant_kernels_omp.so quant_kernels_omp.c -lm \
66 && gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
67 -o cengine_batch_instr.so cengine_batch_instr.c -lm \
68 && gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
69 -o simd_ops.so simd_ops.c -lm \
70 && gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \
71 -o gqa_attention.so gqa_attention.c -lm
72
73# ── Build Mojo engine ──
74COPY engine/ /build/engine/
75WORKDIR /build/engine
76RUN make clean && make && strip mojo_engine && cp mojo_engine /usr/local/bin/mojo_engine
77
78# ── Build Mojo modules ──
79COPY model/ /build/model/
80COPY gguf/ /build/gguf/
81COPY graph/ /build/graph/
82COPY inference/ /build/inference/
83COPY runtime/ /build/runtime/
84COPY kernels/*.mojo /build/kernels/
85WORKDIR /build
86RUN max build --release -o /usr/local/lib/mojollama/mojo_engine_infer mojollama_infer.mojo \
87 && max build --release -o /usr/local/lib/mojollama/mojo_gguf_reader gguf/reader.mojo \
88 || echo "Mojo build skipped (optional)"
89
90# ── Stage 2: Runtime ─────────────────────────────────────────
91FROM debian:bookworm-20250408-slim AS runtime
92
93SHELL ["/bin/bash", "-c"]
94
95# ── Runtime dependencies ──
96RUN apt-get update && apt-get install -y --no-install-recommends \
97 python3 \
98 python3-pip \
99 python3-venv \
100 libomp-dev \
101 ca-certificates \
102 curl \
103 && rm -rf /var/lib/apt/lists/*
104
105# ── Python environment ──
106RUN python3 -m venv /opt/venv
107ENV PATH="/opt/venv/bin:$PATH"
108ENV VIRTUAL_ENV="/opt/venv"
109
110# ── Install Python dependencies ──
111RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
112 pip install --no-cache-dir \
113 numpy<2 \
114 gguf \
115 flask \
116 fastapi \
117 uvicorn \
118 pydantic \
119 sse-starlette \
120 huggingface_hub \
121 jinja2
122
123# ── Copy built artifacts from builder ──
124COPY --from=builder /build/kernels/*.so /opt/mojollama/kernels/
125COPY --from=builder /usr/local/bin/llama-cli /usr/local/bin/
126COPY --from=builder /usr/local/bin/llama-server /usr/local/bin/
127COPY --from=builder /usr/local/bin/llama-bench /usr/local/bin/
128COPY --from=builder /usr/local/bin/mojo_engine /usr/local/bin/
129COPY --from=builder /usr/local/lib/mojollama/ /usr/local/lib/mojollama/
130
131# ── Copy MojoLlama source ──
132COPY . /opt/mojollama/src/
133WORKDIR /opt/mojollama
134
135# Create symlinks for C kernels so engine can find them
136RUN ln -sf /opt/mojollama/kernels /opt/mojollama/src/mojollama/kernels && \
137 mkdir -p /opt/mojollama/models
138
139# Install mojollama as a pip package
140RUN pip install --no-cache-dir -e /opt/mojollama/src/
141
142# ── Wrapper: auto-tune on first model load ──
143COPY docker-entrypoint.sh /usr/local/bin/
144RUN chmod +x /usr/local/bin/docker-entrypoint.sh
145
146# ── Expose ports ──
147EXPOSE 8080 8081
148
149# ── Health check ──
150HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
151 CMD curl -sf http://localhost:${PORT:-8080}/health || exit 1
152
153# ── Entry point ──
154ENTRYPOINT ["docker-entrypoint.sh"]
155CMD ["--help"]