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/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 / Dockerfile` 111 lines · 5119 bytes Raw Blame History 1 # ============================================================================= 2 # MojoLlama — Universal Dockerfile 3 # Multi-stage build: 4 # Stage 1 (builder): builds llama-server (llama.cpp) + AVX2 C kernels 5 # Stage 2 (runtime): Python 3.11 + mojollama code + all binaries 6 # ============================================================================= 7 # syntax=docker/dockerfile:1 8 9 ARG GPU_BACKEND=cpu 10 11 # ── Stage 1: Build llama.cpp + C kernels ────────────────────────────────── 12 FROM ubuntu:22.04 AS builder 13 14 LABEL stage="builder" 15 16 RUN apt-get update && \ 17 apt-get install -y --no-install-recommends \ 18 build-essential cmake git ca-certificates gcc g++ libomp-dev \ 19 && rm -rf /var/lib/apt/lists/* 20 21 # ── Build llama-server ────────────────────────────────────────────────── 22 ARG LLAMACPP_REPO=https://github.com/ggml-org/llama.cpp.git 23 ARG LLAMACPP_BRANCH=master 24 RUN git clone --depth 1 --branch "${LLAMACPP_BRANCH}" "${LLAMACPP_REPO}" /tmp/llama.cpp 25 WORKDIR /tmp/llama.cpp 26 RUN mkdir -p build && cd build && \ 27 cmake .. -DCMAKE_BUILD_TYPE=Release \ 28 -DLLAMA_CURL=OFF -DLLAMA_SERVER_VERBOSE=OFF \ 29 -DBUILD_SHARED_LIBS=OFF -DLLAMA_CCACHE=OFF \ 30 && cmake --build . --target llama-server -- -j"$(nproc)" 31 RUN chmod +x /tmp/llama.cpp/convert_hf_to_gguf.py 32 33 # ── Build TurboEngine AVX2 C kernels ──────────────────────────────────── 34 COPY src/mojollama/kernels/ /build/kernels/ 35 COPY src/mojollama/kernels/legacy-c/turbo_kernels_v2.c /build/kernels/ 36 WORKDIR /build/kernels 37 RUN gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \ 38 -o quant_kernels_omp.so quant_kernels_omp.c -lm && \ 39 gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \ 40 -o cengine_batch_instr.so cengine_batch_instr.c -lm && \ 41 gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \ 42 -o simd_ops.so simd_ops.c -lm && \ 43 gcc -O3 -mavx2 -mfma -mf16c -fopenmp -shared -fPIC \ 44 -o gqa_attention.so gqa_attention.c -lm && \ 45 gcc -O3 -mavx2 -mfma -mf16c -shared -fPIC \ 46 -o turbo_kernels_v2.so turbo_kernels_v2.c -lm 47 48 # ── Stage 2: Runtime image ─────────────────────────────────────────────── 49 FROM python:3.11-slim 50 51 LABEL org.opencontainers.image.title="MojoLlama" 52 LABEL org.opencontainers.image.description="Universal LLM inference server — TurboEngine CPU + llama.cpp GPU backends" 53 LABEL org.opencontainers.image.source="https://git.bamse.cloud/a730/MojoLlama" 54 LABEL org.opencontainers.image.licenses="Apache-2.0" 55 LABEL org.opencontainers.image.version="1.0.0" 56 57 ENV PYTHONDONTWRITEBYTECODE=1 \ 58 PYTHONUNBUFFERED=1 \ 59 PYTHONPATH=/app/src 60 61 RUN apt-get update && \ 62 apt-get install -y --no-install-recommends \ 63 curl ca-certificates libomp-dev libgomp1 \ 64 && rm -rf /var/lib/apt/lists/* 65 66 RUN groupadd -r mojollama && \ 67 useradd -r -g mojollama -d /home/mojollama -m -s /sbin/nologin mojollama 68 69 # ── Copy llama-server binary ──────────────────────────────────────────── 70 COPY --from=builder --chown=root:root \ 71 /tmp/llama.cpp/build/bin/llama-server \ 72 /tmp/llama.cpp/build/bin/llama-server 73 COPY --from=builder --chown=root:root \ 74 /tmp/llama.cpp/convert_hf_to_gguf.py \ 75 /tmp/llama.cpp/convert_hf_to_gguf.py 76 RUN chmod 755 /tmp/llama.cpp/build/bin/llama-server /tmp/llama.cpp/convert_hf_to_gguf.py 77 78 # ── Copy MojoLlama source + Python files first ───────────────────────── 79 WORKDIR /app 80 COPY src/mojollama/ /app/src/mojollama/ 81 82 # ── Overwrite with freshly compiled TurboEngine AVX2 kernels (.so files) ── 83 # Must come AFTER COPY src/mojollama/ so that stale checked-in .so files 84 # in the source tree are overwritten by the freshly built ones. 85 COPY --from=builder --chown=root:root \ 86 /build/kernels/quant_kernels_omp.so \ 87 /build/kernels/cengine_batch_instr.so \ 88 /build/kernels/simd_ops.so \ 89 /build/kernels/gqa_attention.so \ 90 /build/kernels/turbo_kernels_v2.so \ 91 /app/src/mojollama/kernels/ 92 93 # ── Python deps ───────────────────────────────────────────────────────── 94 RUN pip install --no-cache-dir gguf numpy transformers requests huggingface_hub 95 96 COPY www/ /app/www/ 97 COPY docker-entrypoint.sh /app/docker-entrypoint.sh 98 RUN chmod 755 /app/docker-entrypoint.sh 99 100 RUN mkdir -p /models /home/mojollama/.mojollama && \ 101 chown -R mojollama:mojollama /app /models /home/mojollama/.mojollama 102 103 HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \ 104 CMD curl -sf http://localhost:${PORT:-8080}/health || exit 1 105 106 EXPOSE 8080 8081 107 108 USER mojollama 109 110 ENTRYPOINT ["/app/docker-entrypoint.sh"] 111 CMD []