Skip to content

Commit fd75a6a

Browse files
Merge pull request #19 from pitangainnovare/feat/avx-disable-option
Inclui possibilidade de desativar instruções AVX
2 parents 9bb3984 + 9ddac59 commit fd75a6a

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

compose/local/django/Dockerfile

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ 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+
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
3941
RUN python -m pip install --upgrade pip setuptools wheel
@@ -42,13 +44,12 @@ RUN python -m pip install --upgrade pip setuptools wheel
4244
COPY ./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.
4850
RUN pip wheel --wheel-dir /usr/src/app/wheels \
4951
-r ${BUILD_ENVIRONMENT}.txt
5052

51-
5253
# Python 'run' stage
5354
FROM python AS python-run-stage
5455

@@ -59,6 +60,12 @@ ENV PYTHONUNBUFFERED 1
5960
ENV PYTHONDONTWRITEBYTECODE 1
6061
ENV 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+
6269
WORKDIR ${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
7683
COPY --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+
8296
COPY ./compose/production/django/entrypoint /entrypoint
8397
RUN sed -i 's/\r$//g' /entrypoint
8498
RUN chmod +x /entrypoint
@@ -87,7 +101,6 @@ COPY ./compose/local/django/start /start
87101
RUN sed -i 's/\r$//g' /start
88102
RUN chmod +x /start
89103

90-
91104
COPY ./compose/local/django/celery/worker/start /start-celeryworker
92105
RUN sed -i 's/\r$//g' /start-celeryworker
93106
RUN chmod +x /start-celeryworker
@@ -100,7 +113,6 @@ COPY ./compose/local/django/celery/flower/start /start-flower
100113
RUN sed -i 's/\r$//g' /start-flower
101114
RUN chmod +x /start-flower
102115

103-
104116
# copy application code to WORKDIR
105117
COPY . ${APP_HOME}
106118

compose/production/django/Dockerfile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ RUN python -m pip install --upgrade pip
2626
RUN pip wheel --wheel-dir /usr/src/app/wheels \
2727
-r ${BUILD_ENVIRONMENT}.txt
2828

29-
3029
# Python 'run' stage
3130
FROM python as python-run-stage
3231

@@ -37,12 +36,17 @@ ENV PYTHONUNBUFFERED 1
3736
ENV PYTHONDONTWRITEBYTECODE 1
3837
ENV BUILD_ENV ${BUILD_ENVIRONMENT}
3938

39+
# Install llama-cpp-python with specific CMAKE flags for Kubernetes nodes without AVX support
40+
ARG DISABLE_AVX=true
41+
42+
# Set the version of llama-cpp-python
43+
ARG LLAMA_VERSION=0.3.14
44+
4045
WORKDIR ${APP_HOME}
4146

4247
RUN addgroup --system django \
4348
&& adduser --system --ingroup django django
4449

45-
4650
# Install required system dependencies
4751
RUN apt-get update && apt-get install --no-install-recommends -y \
4852
# psycopg2 dependencies
@@ -57,34 +61,36 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
5761
# copy python dependency wheels from python-build-stage
5862
COPY --from=python-build-stage /usr/src/app/wheels /wheels/
5963

60-
# use wheels to install python dependencies
61-
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
62-
&& 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/
6366

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
6473

6574
COPY --chown=django:django ./compose/production/django/entrypoint /entrypoint
6675
RUN sed -i 's/\r$//g' /entrypoint
6776
RUN chmod +x /entrypoint
6877

69-
7078
COPY --chown=django:django ./compose/production/django/start /start
7179
RUN sed -i 's/\r$//g' /start
7280
RUN chmod +x /start
81+
7382
COPY --chown=django:django ./compose/production/django/celery/worker/start /start-celeryworker
7483
RUN sed -i 's/\r$//g' /start-celeryworker
7584
RUN chmod +x /start-celeryworker
7685

77-
7886
COPY --chown=django:django ./compose/production/django/celery/beat/start /start-celerybeat
7987
RUN sed -i 's/\r$//g' /start-celerybeat
8088
RUN chmod +x /start-celerybeat
8189

82-
8390
COPY ./compose/production/django/celery/flower/start /start-flower
8491
RUN sed -i 's/\r$//g' /start-flower
8592
RUN chmod +x /start-flower
8693

87-
8894
# copy application code to WORKDIR
8995
COPY --chown=django:django . ${APP_HOME}
9096

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ whitenoise==6.6.0 # https://github.com/evansd/whitenoise
4040
# Llama
4141
# ------------------------------------------------------------------------------
4242
huggingface-hub==0.26.1
43-
llama-cpp-python==0.3.1
43+
llama-cpp-python==0.3.14

0 commit comments

Comments
 (0)