okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mmq-default-off: build the engine without llama.cpp's MMQ kernels by default (-DSTRATA_MMQ=ON keeps the old path; linux-aarch64 unchanged)5649b9e52

main
7.4 KiB105 linesraw
1# Strata, built FROM SOURCE (NVIDIA CUDA 13). The engine is compiled here, packaged as an engine component package and then
2# installed into the same runtime image as the ready-made ones (docker/Dockerfile): same Terminal, same entrypoint, same /data volume.
3#
4# Most people want the ready-made images instead (nothing compiled): docs/DOCKER.md.
5#
6#   docker build -t strata:src .                                        # RTX 20/30/40/50 (compiles for each, ~25 min)
7#   docker build -t strata:src --build-arg CUDA_ARCHITECTURES=86 .      # one card only (faster); 86 = RTX 30, 89 = RTX 40, 120 = RTX 50
8#   docker build -t strata:src-cuda12 --build-arg CUDA_IMAGE=nvidia/cuda:12.9.1-devel-ubuntu24.04 \
9#              --build-arg CUDA_ARCHITECTURES="60;61;70;75;80;86;89" --build-arg BUILD_VISION=0 .   # GTX 10 / P100 / V100 (driver 575+)
10#   docker run --rm --gpus all -p 127.0.0.1:8080:8080 --ulimit memlock=-1 --shm-size 2g --stop-timeout 120 \
11#              -v strata-data:/data -e MODEL=IQ3_XXS -e API_KEY=change-me-please-123 strata:src
12#
13# docker build has no GPU, so the CUDA architectures are given here instead of read from nvidia-smi. The engine is a fat binary with
14# a machine-code part per listed architecture (plus PTX for the newest, which later cards can JIT), and the runtime picks the one
15# matching your card. Narrow CUDA_ARCHITECTURES to your card for a faster build. Native code for the CPU that builds the image is NOT
16# used (STRATA_PORTABLE=ON), so the image runs on any x86-64 CPU with AVX2.
17#
18# Plain legacy-builder features only (no heredocs, no --mount). AMD (HIP) and Intel (SYCL) source builds: docs/AMD_HIP.md, docs/INTEL.md.
19
20ARG CUDA_IMAGE=nvidia/cuda:13.0.0-devel-ubuntu24.04
21ARG RUNTIME_BASE=ubuntu:24.04
22
23# ---- 1. compile the engine and make its component package
24FROM ${CUDA_IMAGE} AS engine-build
25ENV DEBIAN_FRONTEND=noninteractive PYTHONUNBUFFERED=1 PATH=/venv/bin:$PATH
26RUN apt-get update && apt-get install -y --no-install-recommends \
27        build-essential ca-certificates git libgomp1 libatomic1 python3 python3-pip python3-venv unzip \
28    && rm -rf /var/lib/apt/lists/*
29WORKDIR /src
30COPY . .
31ARG CUDA_ARCHITECTURES="75;80;86;89;120"
32ARG BUILD_VISION=1
33ARG ENGINE_VERSION=
34RUN python3 -m venv /venv && /venv/bin/pip install --no-cache-dir -r requirements.txt -r requirements-build.txt
35# ggml comes from the vendored third_party/strata-ggml and strata-vision from third_party/strata-llama (llama, mtmd, ggml at the pin): nothing is downloaded
36RUN set -e; \
37    real=""; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' '  '); do real="$real;${a}-real"; done; real=${real#;}; \
38    last=$(echo "$CUDA_ARCHITECTURES" | tr ';,' '  ' | awk '{print $NF}'); \
39    sm60=OFF; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' '  '); do if [ "$a" -lt 75 ]; then sm60=ON; fi; done; \
40    /venv/bin/cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \
41        -DSTRATA_EXPERIMENTAL_SM60=$sm60 \
42        -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON \
43        "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual"; \
44    . packaging/engine_targets.sh; targets=$(engine_targets /venv/bin/cmake build); \
45    /venv/bin/cmake --build build --target $targets -j "$(nproc)"; \
46    if [ "$BUILD_VISION" = "1" ]; then \
47      /venv/bin/cmake -G Ninja -S tools/vision -B build-vision -DCMAKE_BUILD_TYPE=Release \
48          -DSTRATA_VISION_CUDA=ON -DSTRATA_PORTABLE=ON -DGGML_CUDA_NCCL=OFF "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual"; \
49      /venv/bin/cmake --build build-vision --target strata-vision -j "$(nproc)"; \
50    fi
51RUN set -e; \
52    mkdir -p /stage /engine; \
53    cp build/strata /stage/; \
54    [ -f build/libstrata_kq.so ] && cp build/libstrata_kq.so /stage/ || true; \
55    [ -f build-vision/bin/strata-vision ] && cp build-vision/bin/strata-vision /stage/ || true; \
56    ver="${ENGINE_VERSION:-$(sed -n 's/^[[:space:]]*project([^)]*VERSION[[:space:]]*\([0-9][0-9.]*\).*/\1/p' CMakeLists.txt | head -1)}"; \
57    cudafull=$(nvcc --version | sed -n 's/.*release \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1); cudamajor=${cudafull%%.*}; \
58    if [ "$cudamajor" = 13 ]; then mindriver=580.65; else mindriver=575.51; fi; \
59    vision_archs=""; [ -f /stage/strata-vision ] && vision_archs=", \"vision_archs\": \"$CUDA_ARCHITECTURES\""; \
60    echo "{\"version\": \"$ver\", \"source\": \"docker build\", \"archs\": \"$CUDA_ARCHITECTURES\", \"cuda\": \"$cudafull\", \"portable\": true${vision_archs}}" > /stage/BUILD.json; \
61    python3 packaging/collect_libs.py --binary build/strata --search /usr/local/cuda/lib64 --out /stage --also 'libcublasLt.so*'; \
62    archs=""; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' '  '); do archs="$archs --arch sm_$a"; done; \
63    last=$(echo "$CUDA_ARCHITECTURES" | tr ';,' '  ' | awk '{print $NF}'); \
64    python3 packaging/package_engine.py --src /stage --backend cuda --version "$ver" --out /engine $archs --arch "compute_$last" \
65        --min-driver nvidia=$mindriver --variant cuda$cudamajor --platform linux-x86_64 --build-id "docker-source-${ver}-cuda${cudafull}" --include SYSTEM-LIBS.txt --include 'libstrata_kq*' \
66        --include strata-vision; \
67    for d in /engine/*/; do python3 packaging/package_engine.py --verify "$d"; python3 packaging/binary_deps.py "$d"; done
68
69# ---- 2. the Terminal (the release archive, built here)
70FROM ${RUNTIME_BASE} AS terminal
71ARG STRATA_COMMIT=
72ENV STRATA_BUILD_COMMIT=${STRATA_COMMIT}
73ENV DEBIAN_FRONTEND=noninteractive
74RUN apt-get update && apt-get install -y --no-install-recommends python3 ca-certificates git && rm -rf /var/lib/apt/lists/*
75COPY . /src/
76RUN python3 /src/packaging/package_terminal.py --out /out --cache /cache \
77 && mkdir -p /opt/strata \
78 && tar -xzf /out/strata-terminal-*-linux-x86_64.tar.gz -C /opt/strata \
79 && mv /opt/strata/strata-terminal-* /opt/strata/terminal \
80 && /opt/strata/terminal/bin/strata --version
81# gguf-py (the model preparation tools) is part of the Terminal archive (third_party/strata-gguf-py), so the first start fetches nothing from
82# GitHub and the image needs no llama.cpp: check that it is there
83RUN test -f /opt/strata/terminal/third_party/strata-gguf-py/gguf/__init__.py
84
85# ---- 3. the runtime image (the same as docker/Dockerfile's, FLAVOR=cuda)
86FROM ${RUNTIME_BASE}
87ARG STRATA_VERSION=dev
88ENV DEBIAN_FRONTEND=noninteractive
89RUN apt-get update && apt-get install -y --no-install-recommends tini ca-certificates libgomp1 libatomic1 libnuma1 zlib1g \
90    && rm -rf /var/lib/apt/lists/* /var/cache/apt/*
91COPY --from=terminal /opt/strata/terminal /opt/strata/terminal
92COPY --from=engine-build /engine/ /opt/strata/components/engine/
93COPY docker/entrypoint.sh docker/healthcheck.sh /opt/strata/
94COPY docker/strata-wrapper.sh /usr/local/bin/strata
95RUN chmod 0755 /opt/strata/entrypoint.sh /opt/strata/healthcheck.sh /usr/local/bin/strata
96ENV STRATA_COMPONENTS_DIR=/opt/strata/components STRATA_INSTALL_DIR=/data/install XDG_STATE_HOME=/data/state \
97    XDG_CONFIG_HOME=/data/config HOME=/data/home PORT=8080 LANG=C.UTF-8 PYTHONUNBUFFERED=1 PYTHONNOUSERSITE=1 STRATA_IN_DOCKER=1 \
98    NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=compute,utility
99VOLUME ["/data"]
100EXPOSE 8080
101LABEL org.opencontainers.image.title="Strata" com.strata.flavor="cuda" com.strata.build="from-source" org.opencontainers.image.version="${STRATA_VERSION}"
102HEALTHCHECK --interval=30s --timeout=8s --start-period=2h --retries=3 CMD ["/opt/strata/healthcheck.sh"]
103STOPSIGNAL SIGTERM
104ENTRYPOINT ["/usr/bin/tini", "--", "/opt/strata/entrypoint.sh"]
105CMD ["run"]