Skip to content

Commit ae146e9

Browse files
Make it possible to disable (via build) avx support (old cpus)
1 parent c70e361 commit ae146e9

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

compose/local/django/Dockerfile

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ RUN apt-get update && \
3030
# Instalar ninja-build y cmake
3131
RUN 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+
RUN if [ "${ENABLE_OPTIMIZATIONS}" = "true" ]; then \
36+
export CFLAGS="-mfma -mavx2"; \
37+
export CXXFLAGS="-mfma -mavx2"; \
38+
export CMAKE_ARGS="-DGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS"; \
39+
fi
3740

3841
# Actualizar pip, setuptools y wheel antes de instalar dependencias
3942
RUN python -m pip install --upgrade pip setuptools wheel
@@ -42,13 +45,12 @@ RUN python -m pip install --upgrade pip setuptools wheel
4245
COPY ./requirements .
4346

4447
# Update pip
45-
#RUN python -m pip install --upgrade pip
48+
RUN python -m pip install --upgrade pip
4649

4750
# Create Python Dependency and Sub-Dependency Wheels.
4851
RUN pip wheel --wheel-dir /usr/src/app/wheels \
4952
-r ${BUILD_ENVIRONMENT}.txt
5053

51-
5254
# Python 'run' stage
5355
FROM python AS python-run-stage
5456

@@ -59,6 +61,12 @@ ENV PYTHONUNBUFFERED 1
5961
ENV PYTHONDONTWRITEBYTECODE 1
6062
ENV BUILD_ENV ${BUILD_ENVIRONMENT}
6163

64+
# Disable AVX support for llama-cpp-python if needed
65+
ARG DISABLE_AVX=false
66+
67+
# Set the version of llama-cpp-python
68+
ARG LLAMA_VERSION=0.3.14
69+
6270
WORKDIR ${APP_HOME}
6371

6472
# Install required system dependencies
@@ -75,10 +83,17 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
7583
# copy python dependency wheels from python-build-stage
7684
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
7785

78-
# use wheels to install python dependencies
79-
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
86+
# Use wheels to install python dependencies (excluding llama-cpp-python)
87+
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ $(find /wheels/ -name "*.whl" ! -name "llama_cpp_python*") \
8088
&& rm -rf /wheels/
8189

90+
# Install llama-cpp-python with specific CMAKE flags for Kubernetes nodes with our without AVX support
91+
RUN if [ "${DISABLE_AVX}" = "true" ]; then \
92+
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; \
93+
else \
94+
pip install llama-cpp-python==${LLAMA_VERSION} --force-reinstall --no-cache-dir; \
95+
fi
96+
8297
COPY ./compose/production/django/entrypoint /entrypoint
8398
RUN sed -i 's/\r$//g' /entrypoint
8499
RUN chmod +x /entrypoint
@@ -87,7 +102,6 @@ COPY ./compose/local/django/start /start
87102
RUN sed -i 's/\r$//g' /start
88103
RUN chmod +x /start
89104

90-
91105
COPY ./compose/local/django/celery/worker/start /start-celeryworker
92106
RUN sed -i 's/\r$//g' /start-celeryworker
93107
RUN chmod +x /start-celeryworker
@@ -100,7 +114,6 @@ COPY ./compose/local/django/celery/flower/start /start-flower
100114
RUN sed -i 's/\r$//g' /start-flower
101115
RUN chmod +x /start-flower
102116

103-
104117
# copy application code to WORKDIR
105118
COPY . ${APP_HOME}
106119

compose/production/django/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ WORKDIR ${APP_HOME}
4747
RUN addgroup --system django \
4848
&& adduser --system --ingroup django django
4949

50-
5150
# Install required system dependencies
5251
RUN apt-get update && apt-get install --no-install-recommends -y \
5352
# psycopg2 dependencies
@@ -62,34 +61,36 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
6261
# copy python dependency wheels from python-build-stage
6362
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
6463

65-
# use wheels to install python dependencies
66-
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
67-
&& rm -rf /wheels/
64+
# use wheels to install python dependencies (excluding llama-cpp-python)
65+
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ $(find /wheels/ -name "*.whl" ! -name "llama_cpp_python*") && rm -rf /wheels/
6866

67+
# Install llama-cpp-python with specific CMAKE flags for Kubernetes nodes without AVX support
68+
RUN if [ "${DISABLE_AVX}" = "true" ]; then \
69+
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; \
70+
else \
71+
pip install llama-cpp-python==${LLAMA_VERSION} --force-reinstall --no-cache-dir; \
72+
fi
6973

7074
COPY --chown=django:django ./compose/production/django/entrypoint /entrypoint
7175
RUN sed -i 's/\r$//g' /entrypoint
7276
RUN chmod +x /entrypoint
7377

74-
7578
COPY --chown=django:django ./compose/production/django/start /start
7679
RUN sed -i 's/\r$//g' /start
7780
RUN chmod +x /start
81+
7882
COPY --chown=django:django ./compose/production/django/celery/worker/start /start-celeryworker
7983
RUN sed -i 's/\r$//g' /start-celeryworker
8084
RUN chmod +x /start-celeryworker
8185

82-
8386
COPY --chown=django:django ./compose/production/django/celery/beat/start /start-celerybeat
8487
RUN sed -i 's/\r$//g' /start-celerybeat
8588
RUN chmod +x /start-celerybeat
8689

87-
8890
COPY ./compose/production/django/celery/flower/start /start-flower
8991
RUN sed -i 's/\r$//g' /start-flower
9092
RUN chmod +x /start-flower
9193

92-
9394
# copy application code to WORKDIR
9495
COPY --chown=django:django . ${APP_HOME}
9596

0 commit comments

Comments
 (0)