@@ -30,10 +30,12 @@ RUN apt-get update && \
3030# Instalar ninja-build y cmake
3131RUN apt-get install -y ninja-build cmake
3232
33- # Configurar variables de entorno para compilar con BLAS y SIMD
34- ENV CFLAGS="-mfma -mavx2" \
35- CXXFLAGS="-mfma -mavx2" \
36- CMAKE_ARGS="-DGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS"
33+ # Configurar variables de entorno para compilar con BLAS y SIMD condicionalmente
34+ ARG ENABLE_OPTIMIZATIONS=true
35+ ARG ENABLE_OPTIMIZATIONS=true
36+ ENV CFLAGS="${ENABLE_OPTIMIZATIONS:+-mfma -mavx2}" \
37+ CXXFLAGS="${ENABLE_OPTIMIZATIONS:+-mfma -mavx2}" \
38+ CMAKE_ARGS="${ENABLE_OPTIMIZATIONS:+-DGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS}"
3739
3840# Actualizar pip, setuptools y wheel antes de instalar dependencias
3941RUN python -m pip install --upgrade pip setuptools wheel
@@ -42,13 +44,12 @@ RUN python -m pip install --upgrade pip setuptools wheel
4244COPY ./requirements .
4345
4446# Update pip
45- # RUN python -m pip install --upgrade pip
47+ RUN python -m pip install --upgrade pip
4648
4749# Create Python Dependency and Sub-Dependency Wheels.
4850RUN pip wheel --wheel-dir /usr/src/app/wheels \
4951 -r ${BUILD_ENVIRONMENT}.txt
5052
51-
5253# Python 'run' stage
5354FROM python AS python-run-stage
5455
@@ -59,6 +60,12 @@ ENV PYTHONUNBUFFERED 1
5960ENV PYTHONDONTWRITEBYTECODE 1
6061ENV BUILD_ENV ${BUILD_ENVIRONMENT}
6162
63+ # Disable AVX support for llama-cpp-python if needed
64+ ARG DISABLE_AVX=false
65+
66+ # Set the version of llama-cpp-python
67+ ARG LLAMA_VERSION=0.3.14
68+
6269WORKDIR ${APP_HOME}
6370
6471# Install required system dependencies
@@ -75,10 +82,17 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
7582# copy python dependency wheels from python-build-stage
7683COPY --from=python-build-stage /usr/src/app/wheels /wheels/
7784
78- # use wheels to install python dependencies
79- RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
85+ # Use wheels to install python dependencies (excluding llama-cpp-python)
86+ RUN pip install --no-cache-dir --no-index --find-links=/wheels/ $(find /wheels/ -name "*.whl" ! -name "llama_cpp_python*" ) \
8087 && rm -rf /wheels/
8188
89+ # Install llama-cpp-python with specific CMAKE flags for Kubernetes nodes with or without AVX support
90+ RUN if [ "${DISABLE_AVX}" = "true" ]; then \
91+ CMAKE_ARGS='-DLLAMA_AVX=OFF -DLLAMA_AVX2=OFF -DLLAMA_FMA=OFF -DLLAMA_F16C=OFF -DLLAMA_OPENMP=ON' pip install llama-cpp-python==${LLAMA_VERSION} --force-reinstall --no-cache-dir; \
92+ else \
93+ pip install llama-cpp-python==${LLAMA_VERSION} --force-reinstall --no-cache-dir; \
94+ fi
95+
8296COPY ./compose/production/django/entrypoint /entrypoint
8397RUN sed -i 's/\r $//g' /entrypoint
8498RUN chmod +x /entrypoint
@@ -87,7 +101,6 @@ COPY ./compose/local/django/start /start
87101RUN sed -i 's/\r $//g' /start
88102RUN chmod +x /start
89103
90-
91104COPY ./compose/local/django/celery/worker/start /start-celeryworker
92105RUN sed -i 's/\r $//g' /start-celeryworker
93106RUN chmod +x /start-celeryworker
@@ -100,7 +113,6 @@ COPY ./compose/local/django/celery/flower/start /start-flower
100113RUN sed -i 's/\r $//g' /start-flower
101114RUN chmod +x /start-flower
102115
103-
104116# copy application code to WORKDIR
105117COPY . ${APP_HOME}
106118
0 commit comments