11###############################################################
2- # Stage 1 Base builder image with common tooling
3- ###############################################################
4- FROM registry.access.redhat.com/ubi9/python-312@sha256:cb818db6c1dc82c70aeaa1139e33f3371f47b97b60ae6f9f23381319746f6f1d as packages-build
5-
6- USER root
7- WORKDIR /app
8-
9- ENV PATH="$HOME/.cargo/bin:$PATH"
10- ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
11- ARG TARGETARCH
12-
13- # Install dependencies
14- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
15- dnf install -y \
16- make libtool wget patch ninja-build cmake xz bzip2-devel libffi-devel zlib-devel openssl-devel libevent-devel \
17- python3.12 python3.12-devel python3.12-pip clang \
18- gcc-toolset-14-gcc gcc-toolset-14-gcc-c++ gcc-toolset-14-gcc-gfortran skopeo && \
19- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
20- dnf clean all && \
21- pip install --upgrade setuptools-rust pip 'cmake<4' setuptools wheel maturin ; \
22- fi
23-
24- COPY requirements* /app/
25-
26- # Create a dummy file to trigger build dependency
27- RUN touch /tmp/control
28-
29- ###############################################################
30- # Stage 2 to build OpenBLAS
31- ###############################################################
32-
33- FROM packages-build AS openblas-builder
34- ENV OPENBLAS_VERSION=0.3.30
35- ARG TARGETARCH
36-
37- WORKDIR /app
38-
39- # Creating a directory for OpenBlas
40- RUN mkdir /tmp/openblas
41-
42- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
43- source /opt/rh/gcc-toolset-14/enable && \
44- wget https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION}/OpenBLAS-${OPENBLAS_VERSION}.zip && \
45- unzip OpenBLAS-${OPENBLAS_VERSION}.zip -d /tmp/ && mv -T /tmp/OpenBLAS-${OPENBLAS_VERSION} /tmp/openblas && \
46- cd /tmp/openblas && \
47- make -j$(nproc) TARGET=POWER9 BINARY=64 USE_OPENMP=1 USE_THREAD=1 NUM_THREADS=120 DYNAMIC_ARCH=1 INTERFACE64=0 ; \
48- fi
49-
50- ###############################################################
51- # Stage 3 to build pyTorch
52- ###############################################################
53-
54- FROM packages-build AS torch-builder
55- USER root
56-
57- WORKDIR /app
58-
59- ARG MAX_JOBS
60- ARG _GLIBCXX_USE_CXX11_ABI=1
61- ARG TARGETARCH
62-
63- RUN mkdir -p /torchwheels
64-
65- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
66- export TORCH_VERSION=$(sed -n "s/^torch==//p" /app/requirements-torch.in) && \
67- source /opt/rh/gcc-toolset-14/enable && \
68- git clone --recursive https://github.com/pytorch/pytorch.git -b v${TORCH_VERSION} && \
69- cd pytorch && pip install -r requirements.txt && \
70- rm -f dist/torch*+git*whl && \
71- # Set MAX_JOBS to 2 or 4 to prevent OOM
72- # MAX_JOBS=4 \
73- USE_NCCL=0 \
74- BUILD_TEST=0 \
75- PYTORCH_BUILD_VERSION=${TORCH_VERSION} \
76- PYTORCH_BUILD_NUMBER=1 \
77- pip wheel . --no-build-isolation --wheel-dir /torchwheels/ \
78- ; fi
79-
80- ###############################################################
81- # Stage 4 to build Tiktoken
82- ###############################################################
83-
84- FROM packages-build as tiktoken-builder
85- ARG TARGETARCH
86- WORKDIR /app
87-
88- RUN mkdir -p /tiktokenwheels
89-
90- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
91- export TIKTOKEN_VERSION=$(sed -n "s/^tiktoken==//p" /app/requirements.txt) && \
92- source /opt/rh/gcc-toolset-14/enable && \
93- git clone https://github.com/openai/tiktoken.git && \
94- cd tiktoken && \
95- git checkout ${TIKTOKEN_VERSION} && \
96- pip wheel . --wheel-dir /tiktokenwheels ; \
97- fi
98-
99- ###############################################################
100- # Stage 5 to build onnxruntime
101- ###############################################################
102- FROM packages-build AS onnxruntime-builder
103- ARG TARGETARCH
104- USER root
105-
106- WORKDIR /app
107-
108- ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib:/app/.openblas/lib
109-
110- # copy built OpenBLAS sources
111- COPY --from=openblas-builder /tmp/openblas/ /build/openblas
112-
113- # Install OpenBLAS
114- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
115- PREFIX=/app/.openblas make -C /build/openblas install && \
116- ln -sf /app/.openblas/lib/libopenblasp-r0.3.30.so /app/.openblas/lib/libopenblasp.so.0 ; \
117- fi
118-
119- COPY scripts/build_onnxruntime.sh /build/build_onnxruntime.sh
120-
121- RUN mkdir -p /onnxruntime_wheels
122-
123- # Build onnxruntime
124- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
125- export ONNXRUNTIME_VERSION=$(sed -n "s/^onnxruntime==//p" /app/requirements.txt) && \
126- sh /build/build_onnxruntime.sh ; \
127- fi
128-
129- ###############################################################
130- # Stage 6 Install hf_xet from source ppc64le
131- ###############################################################
132- FROM packages-build AS hf-xet-builder
133- ARG TARGETARCH
134- USER root
135-
136- WORKDIR /app
137- RUN mkdir -p /hf_xet_wheels
138-
139- RUN if [ "$TARGETARCH" = "ppc64le" ]; then \
140- export HF_XET_VERSION=$(sed -n "s/^hf-xet==//p" /app/requirements.txt) && \
141- git clone https://github.com/huggingface/xet-core.git && \
142- cd xet-core/hf_xet && git checkout v${HF_XET_VERSION} && \
143- sed -i '/python-source = "python"/d' pyproject.toml && \
144- maturin build --release --out /hf_xet_wheels ; \
145- fi
146-
147- ###############################################################
148- # Stage 7 Install all the dependencies
2+ # Stage 1 Install all the dependencies
1493###############################################################
1504
1515FROM registry.access.redhat.com/ubi9/python-312@sha256:cb818db6c1dc82c70aeaa1139e33f3371f47b97b60ae6f9f23381319746f6f1d as build
@@ -155,11 +9,6 @@ WORKDIR /app
1559
15610ARG TARGETARCH
15711ARG GUARDRAILS_PROFILE=opensource
158- ENV LD_LIBRARY_PATH=/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib:/app/.openblas/lib
159- ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/app/.openblas/lib/pkgconfig
160- ENV PATH="$HOME/.cargo/bin:/app/.venv/bin:$PATH"
161- ENV BLIS_ARCH=generic
162- ENV GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
16312
16413COPY requirements.txt requirements-torch.txt pyproject.toml README.md ./
16514COPY nemoguardrails/ ./nemoguardrails/
@@ -168,8 +17,6 @@ COPY examples/bots/ ./examples/bots/
16817
16918RUN chmod +x ./scripts/entrypoint.sh
17019
171- RUN python3 -m pip install --no-cache-dir pyyaml
172-
17320RUN python3 ./scripts/filter_guardrails.py ./scripts/provider-list.yaml $GUARDRAILS_PROFILE
17421
17522ENV HF_HOME=/app/.cache/huggingface \
@@ -180,35 +27,6 @@ ENV HF_HOME=/app/.cache/huggingface \
18027
18128RUN python3 -m venv /app/.venv
18229
183- # Copy OpenBLAS
184- COPY --from=openblas-builder /tmp/openblas/ /tmp/openblas
185-
186- # Dummy file to trigger build dependency
187- COPY --from=torch-builder /tmp/control /dev/null
188- COPY --from=tiktoken-builder /tmp/control /dev/null
189- COPY --from=onnxruntime-builder /tmp/control /dev/null
190- COPY --from=hf-xet-builder /tmp/control /dev/null
191-
192- RUN --mount=type=cache,from=torch-builder,source=/torchwheels/,target=/tmp/torchwheels/,ro \
193- --mount=type=cache,from=tiktoken-builder,source=/tiktokenwheels/,target=/tmp/tiktokenwheels/,ro \
194- --mount=type=cache,from=onnxruntime-builder,source=/onnxruntime_wheels/,target=/tmp/onnxruntime_wheels/,ro \
195- --mount=type=cache,from=hf-xet-builder,source=/hf_xet_wheels/,target=/tmp/hf_xet_wheels/,ro \
196- if [ "$TARGETARCH" = "ppc64le" ]; then \
197- /app/.venv/bin/pip install \
198- /tmp/torchwheels/*.whl \
199- /tmp/tiktokenwheels/*.whl \
200- /tmp/onnxruntime_wheels/*.whl \
201- /tmp/hf_xet_wheels/*.whl && \
202- PREFIX=/app/.openblas make -C /tmp/openblas install && rm -rf /tmp/openblas ; \
203- fi
204-
205- # Temporary workaround for ppc64le with the pinned pandas version. Remove after upgrading pandas with v3.x
206- RUN if [ "$TARGETARCH" == "ppc64le" ]; then \
207- export PANDAS_VERSION=$(sed -n "s/^pandas==//p" /app/requirements.txt) && \
208- /app/.venv/bin/pip install --no-cache-dir "meson<1.10" meson-python ninja cython numpy versioneer[toml] packaging && \
209- /app/.venv/bin/pip install --no-cache-dir --no-build-isolation pandas==${PANDAS_VERSION} ; \
210- fi
211-
21230RUN /app/.venv/bin/pip install --no-cache-dir -r requirements.txt && \
21331 /app/.venv/bin/pip install --no-cache-dir --no-deps . && \
21432 rm -rf /root/.cache/pip /tmp/* /var/tmp/*
@@ -227,7 +45,7 @@ RUN set -ex && \
22745 rm -rf /app/.cache/huggingface/xet /root/.cache /tmp/* /var/tmp/*
22846
22947###############################################################
230- # Stage 8 Final Build
48+ # Stage 2 Final Build
23149###############################################################
23250
23351FROM registry.access.redhat.com/ubi9/python-312:latest as runtime
0 commit comments