Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/Dockerfile # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 ──────────────────────────────────────── 13 FROM debian:bookworm-`20250408` AS builder 14 15 LABEL org.opencontainers.image.title="MojoLlama" 16 LABEL org.opencontainers.image.description="High-throughput CPU LLM inference engine — GGUF native, MoE-optimized" 17 LABEL org.opencontainers.image.version="0.5.0" 18 LABEL org.opencontainers.image.licenses="MIT" 19 20 SHELL ["/bin/bash", "-c"] 21 22 # ── Build dependencies ── 23 RUN 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 ── 41 RUN 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) ── 46 RUN 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 ── 62 COPY kernels/ /build/kernels/ 63 WORKDIR /build/kernels 64 RUN 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 ── 74 COPY engine/ /build/engine/ 75 WORKDIR /build/engine 76 RUN make clean && make && strip mojo_engine && cp mojo_engine /usr/local/bin/mojo_engine 77 78 # ── Build Mojo modules ── 79 COPY model/ /build/model/ 80 COPY gguf/ /build/gguf/ 81 COPY graph/ /build/graph/ 82 COPY inference/ /build/inference/ 83 COPY runtime/ /build/runtime/ 84 COPY kernels/*.mojo /build/kernels/ 85 WORKDIR /build 86 RUN 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 ───────────────────────────────────────── 91 FROM debian:bookworm-`20250408`-slim AS runtime 92 93 SHELL ["/bin/bash", "-c"] 94 95 # ── Runtime dependencies ── 96 RUN 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 ── 106 RUN python3 -m venv /opt/venv 107 ENV PATH="/opt/venv/bin:$PATH" 108 ENV VIRTUAL_ENV="/opt/venv" 109 110 # ── Install Python dependencies ── 111 RUN 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 ── 124 COPY --from=builder /build/kernels/*.so /opt/mojollama/kernels/ 125 COPY --from=builder /usr/local/bin/llama-cli /usr/local/bin/ 126 COPY --from=builder /usr/local/bin/llama-server /usr/local/bin/ 127 COPY --from=builder /usr/local/bin/llama-bench /usr/local/bin/ 128 COPY --from=builder /usr/local/bin/mojo_engine /usr/local/bin/ 129 COPY --from=builder /usr/local/lib/mojollama/ /usr/local/lib/mojollama/ 130 131 # ── Copy MojoLlama source ── 132 COPY . /opt/mojollama/src/ 133 WORKDIR /opt/mojollama 134 135 # Create symlinks for C kernels so engine can find them 136 RUN ln -sf /opt/mojollama/kernels /opt/mojollama/src/mojollama/kernels && \ 137 mkdir -p /opt/mojollama/models 138 139 # Install mojollama as a pip package 140 RUN pip install --no-cache-dir -e /opt/mojollama/src/ 141 142 # ── Wrapper: auto-tune on first model load ── 143 COPY docker-entrypoint.sh /usr/local/bin/ 144 RUN chmod +x /usr/local/bin/docker-entrypoint.sh 145 146 # ── Expose ports ── 147 EXPOSE 8080 8081 148 149 # ── Health check ── 150 HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \ 151 CMD curl -sf http://localhost:${PORT:-8080}/health || exit 1 152 153 # ── Entry point ── 154 ENTRYPOINT ["docker-entrypoint.sh"] 155 CMD ["--help"]