char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
5d8ccdf9d
char/aliceai-t5-moe
1# ============================================================================== 2# ARGUMENTS 3# ============================================================================== 4 5# Define the CANN base image for easier version updates later 6ARG CHIP_TYPE=910b 7ARG CANN_BASE_IMAGE=quay.io/ascend/cann:8.5.0-${ CHIP_TYPE } -openeuler24.03-py3.11 8ARG BUILD_DATE=N/A 9ARG APP_VERSION=N/A 10ARG APP_REVISION=N/A 11 12# ============================================================================== 13# BUILD STAGE 14# Compile all binary files and libraries 15# ============================================================================== 16ARG NODE_VERSION=24 17 18FROM docker.io/node: $ NODE_VERSION AS web 19 20ARG APP_VERSION 21 22WORKDIR /app/tools/ui 23 24COPY tools/ui/package.json tools/ui/package-lock.json ./ 25RUN npm ci 26 27COPY tools/ui/ ./ 28RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build 29 30FROM ${ CANN_BASE_IMAGE } AS build 31 32# -- Install build dependencies -- 33RUN yum install -y gcc g++ cmake make git openssl-devel python3 python3-pip && \ 34 yum clean all && \ 35 rm -rf /var/cache/yum 36 37# -- Set the working directory -- 38WORKDIR /app 39 40# -- Copy project files -- 41COPY . . 42 43COPY --from=web /app/tools/ui/dist tools/ui/dist 44 45# -- Set CANN environment variables (required for compilation) -- 46# Using ENV instead of `source` allows environment variables to persist across the entire image layer 47ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest 48ENV LD_LIBRARY_PATH=${ ASCEND_TOOLKIT_HOME } /lib64:${ LD_LIBRARY_PATH } 49ENV PATH=${ ASCEND_TOOLKIT_HOME } /bin:${ PATH } 50ENV ASCEND_OPP_PATH=${ ASCEND_TOOLKIT_HOME } /opp 51ENV LD_LIBRARY_PATH=${ ASCEND_TOOLKIT_HOME } /runtime/lib64/stub:$ LD_LIBRARY_PATH 52# ... You can add other environment variables from the original file as needed ... 53# For brevity, only core variables are listed here. You can paste the original ENV list here. 54 55# -- Build llama.cpp -- 56# Use the passed CHIP_TYPE argument and add general build options 57ARG CHIP_TYPE 58RUN source /usr/local/Ascend/ascend-toolkit/set_env.sh --force \ 59 && \ 60 cmake -B build \ 61 -DGGML_CANN=ON \ 62 -DCMAKE_BUILD_TYPE=Release \ 63 -DSOC_TYPE=ascend${CHIP_TYPE} \ 64 -DUSE_ACL_GRAPH=ON \ 65 . && \ 66 cmake --build build --config Release -j$(nproc) 67 68# -- Organize build artifacts for copying in later stages -- 69# Create a lib directory to store all .so files 70RUN mkdir -p /app/lib && \ 71 find build -name "*.so*" -exec cp -P {} /app/lib \; 72 73# Create a full directory to store all executables and Python scripts 74RUN mkdir -p /app/full && \ 75 cp build/bin/* /app/full/ && \ 76 cp *.py /app/full/ && \ 77 cp -r conversion /app/full/ && \ 78 cp -r gguf-py /app/full/ && \ 79 cp -r requirements /app/full/ && \ 80 cp requirements.txt /app/full/ 81# If you have a tools.sh script, make sure it is copied here 82# cp .devops/tools.sh /app/full/tools.sh 83 84# ============================================================================== 85# BASE STAGE 86# Create a minimal base image with CANN runtime and common libraries 87# ============================================================================== 88FROM ${ CANN_BASE_IMAGE } AS base 89 90ARG BUILD_DATE=N/A 91ARG APP_VERSION=N/A 92ARG APP_REVISION=N/A 93ARG IMAGE_URL=https://github.com/ggml-org/llama.cpp 94ARG IMAGE_SOURCE=https://github.com/ggml-org/llama.cpp 95LABEL org.opencontainers.image.created=$ BUILD_DATE \ 96 org.opencontainers.image.version=$ APP_VERSION \ 97 org.opencontainers.image.revision=$ APP_REVISION \ 98 org.opencontainers.image.title="llama.cpp" \ 99 org.opencontainers.image.description="LLM inference in C/C++" \ 100 org.opencontainers.image.url=$ IMAGE_URL \ 101 org.opencontainers.image.source=$ IMAGE_SOURCE 102 103# -- Install runtime dependencies -- 104RUN yum install -y libgomp curl && \ 105 yum clean all && \ 106 rm -rf /var/cache/yum 107 108# -- Set CANN environment variables (required for runtime) -- 109ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest 110ENV LD_LIBRARY_PATH=/app:${ ASCEND_TOOLKIT_HOME } /lib64:${ LD_LIBRARY_PATH } 111ENV PATH=${ ASCEND_TOOLKIT_HOME } /bin:${ PATH } 112ENV ASCEND_OPP_PATH=${ ASCEND_TOOLKIT_HOME } /opp 113# ... You can add other environment variables from the original file as needed ... 114 115WORKDIR /app 116 117# Copy compiled .so files from the build stage 118COPY --from=build /app/lib/ /app 119 120# ============================================================================== 121# FINAL STAGES (TARGETS) 122# ============================================================================== 123 124### Target: full 125# Complete image with all tools, Python bindings, and dependencies 126# ============================================================================== 127FROM baseAS full 128 129COPY --from=build /app/full /app 130 131# Install Python dependencies 132RUN yum install -y git python3 python3-pip && \ 133 pip3 install --no-cache-dir --upgrade pip setuptools wheel && \ 134 pip3 install --no-cache-dir -r requirements.txt && \ 135 yum clean all && \ 136 rm -rf /var/cache/yum 137 138# You need to provide a tools.sh script as the entrypoint 139ENTRYPOINT ["/app/tools.sh" ] 140# If there is no tools.sh, you can set the default to start the server 141# ENTRYPOINT ["/app/llama-server"] 142 143### Target: light 144# Lightweight image containing only llama-cli and llama-completion 145# ============================================================================== 146FROM baseAS light 147 148COPY --from=build /app/full/llama /app/full/llama-cli /app/full/llama-completion /app 149 150ENTRYPOINT ["/app/llama-cli" ] 151 152### Target: server 153# Dedicated server image containing only llama-server 154# ============================================================================== 155FROM baseAS server 156 157ENV LLAMA_ARG_HOST=0.0.0.0 158 159COPY --from=build /app/full/llama /app/full/llama-server /app 160 161HEALTHCHECK --interval=5mCMD ["curl" ,"-f" ,"http://localhost:8080/health" ] 162 163ENTRYPOINT ["/app/llama-server" ]