Felipe97/llama-cpp-compiled
01.1k
1# ==============================================================================2# ARGUMENTS3# ==============================================================================4 5# Define the CANN base image for easier version updates later6ARG CHIP_TYPE=910b7ARG CANN_BASE_IMAGE=quay.io/ascend/cann:8.5.0-${CHIP_TYPE}-openeuler24.03-py3.118ARG BUILD_DATE=N/A9ARG APP_VERSION=N/A10ARG APP_REVISION=N/A11 12# ==============================================================================13# BUILD STAGE14# Compile all binary files and libraries15# ==============================================================================16ARG NODE_VERSION=2417 18FROM docker.io/node:$NODE_VERSION AS web19 20ARG APP_VERSION21 22WORKDIR /app/tools/ui23 24COPY tools/ui/package.json tools/ui/package-lock.json ./25RUN npm ci26 27COPY tools/ui/ ./28RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build29 30FROM ${CANN_BASE_IMAGE} AS build31 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/yum36 37# -- Set the working directory --38WORKDIR /app39 40# -- Copy project files --41COPY . .42 43COPY --from=web /app/tools/ui/dist tools/ui/dist44 45# -- Set CANN environment variables (required for compilation) --46# Using ENV instead of `source` allows environment variables to persist across the entire image layer47ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest48ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${LD_LIBRARY_PATH}49ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${PATH}50ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp51ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/runtime/lib64/stub:$LD_LIBRARY_PATH52# ... 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 options57ARG CHIP_TYPE58RUN 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 files70RUN 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 scripts74RUN 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 here82 # cp .devops/tools.sh /app/full/tools.sh83 84# ==============================================================================85# BASE STAGE86# Create a minimal base image with CANN runtime and common libraries87# ==============================================================================88FROM ${CANN_BASE_IMAGE} AS base89 90ARG BUILD_DATE=N/A91ARG APP_VERSION=N/A92ARG APP_REVISION=N/A93ARG IMAGE_URL=https://github.com/ggml-org/llama.cpp94ARG IMAGE_SOURCE=https://github.com/ggml-org/llama.cpp95LABEL 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_SOURCE102 103# -- Install runtime dependencies --104RUN yum install -y libgomp curl && \105 yum clean all && \106 rm -rf /var/cache/yum107 108# -- Set CANN environment variables (required for runtime) --109ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest110ENV 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}/opp113# ... You can add other environment variables from the original file as needed ...114 115WORKDIR /app116 117# Copy compiled .so files from the build stage118COPY --from=build /app/lib/ /app119 120# ==============================================================================121# FINAL STAGES (TARGETS)122# ==============================================================================123 124### Target: full125# Complete image with all tools, Python bindings, and dependencies126# ==============================================================================127FROM base AS full128 129COPY --from=build /app/full /app130 131# Install Python dependencies132RUN 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/yum137 138# You need to provide a tools.sh script as the entrypoint139ENTRYPOINT ["/app/tools.sh"]140# If there is no tools.sh, you can set the default to start the server141# ENTRYPOINT ["/app/llama-server"]142 143### Target: light144# Lightweight image containing only llama-cli and llama-completion145# ==============================================================================146FROM base AS light147 148COPY --from=build /app/full/llama /app/full/llama-cli /app/full/llama-completion /app149 150ENTRYPOINT [ "/app/llama-cli" ]151 152### Target: server153# Dedicated server image containing only llama-server154# ==============================================================================155FROM base AS server156 157ENV LLAMA_ARG_HOST=0.0.0.0158 159COPY --from=build /app/full/llama /app/full/llama-server /app160 161HEALTHCHECK --interval=5m CMD [ "curl", "-f", "http://localhost:8080/health" ]162 163ENTRYPOINT [ "/app/llama-server" ]164 