Skip to content

Commit 3400b3f

Browse files
ppc64le(jupyter/trustyai): create multiarch build for ppc64le (opendatahub-io#2465)
Signed-off-by: Md. Shafi Hussain <[email protected]>
1 parent 1fee387 commit 3400b3f

File tree

5 files changed

+297
-110
lines changed

5 files changed

+297
-110
lines changed

.tekton/odh-workbench-jupyter-trustyai-cpu-py312-ubi9-pull-request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ spec:
3636
- name: build-platforms
3737
value:
3838
- linux/x86_64
39+
- linux/ppc64le
3940
- name: dockerfile
4041
value: jupyter/trustyai/ubi9-python-3.12/Dockerfile.cpu
4142
- name: path-context

jupyter/trustyai/ubi9-python-3.12/Dockerfile.cpu

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ RUN curl -Lo mongodb-cli-mongocli-v${MONGOCLI_VERSION}.zip https://github.com/mo
1515
RUN unzip ./mongodb-cli-mongocli-v${MONGOCLI_VERSION}.zip
1616
RUN cd ./mongodb-cli-mongocli-v${MONGOCLI_VERSION}/ && \
1717
CGO_ENABLED=1 GOOS=linux go build -a -tags strictfipsruntime -o /tmp/mongocli ./cmd/mongocli/
18+
####################
19+
# wheel-cache-base #
20+
####################
21+
FROM ${BASE_IMAGE} AS whl-cache
22+
23+
USER root
24+
ENV HOME=/root
25+
WORKDIR /root
26+
27+
ARG TRUSTYAI_SOURCE_CODE=jupyter/trustyai/ubi9-python-3.12
28+
29+
COPY ${TRUSTYAI_SOURCE_CODE}/pylock.toml .
30+
COPY ${TRUSTYAI_SOURCE_CODE}/devel_env_setup.sh .
31+
32+
RUN --mount=type=cache,target=/root/.cache/uv \
33+
pip install --no-cache uv && \
34+
# the devel script is ppc64le specific - sets up build-time dependencies
35+
source ./devel_env_setup.sh && \
36+
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
37+
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
38+
UV_LINK_MODE=copy uv pip install --strict --no-deps --refresh --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml
1839

1940
####################
2041
# cpu-base #
@@ -117,6 +138,8 @@ FROM jupyter-datascience AS jupyter-trustyai
117138
ARG DATASCIENCE_SOURCE_CODE=jupyter/datascience/ubi9-python-3.12
118139
ARG TRUSTYAI_SOURCE_CODE=jupyter/trustyai/ubi9-python-3.12
119140

141+
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
142+
120143
LABEL name="odh-notebook-jupyter-trustyai-ubi9-python-3.12" \
121144
summary="Jupyter trustyai notebook image for ODH notebooks" \
122145
description="Jupyter trustyai notebook image with base Python 3.12 builder image based on UBI9 for ODH notebooks" \
@@ -134,16 +157,39 @@ RUN INSTALL_PKGS="java-17-openjdk" && \
134157
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
135158
dnf -y clean all --enablerepo='*'
136159

137-
USER 1001
138-
139160
# Install Python packages and Jupyterlab extensions from requirements.txt
140161
COPY ${TRUSTYAI_SOURCE_CODE}/pylock.toml ./
141162

142-
RUN echo "Installing softwares and packages" && \
143-
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
144-
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
145-
uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml && \
146-
# setup path for runtime configuration
163+
# install openblas for ppc64le
164+
RUN --mount=type=cache,from=whl-cache,source=/root/OpenBLAS/,target=/OpenBlas/,rw \
165+
bash -c ' \
166+
if [[ $(uname -m) == "ppc64le" ]]; then \
167+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm; \
168+
dnf install -y libraqm libimagequant; \
169+
PREFIX=/usr/ make install -C /OpenBlas; \
170+
fi '
171+
172+
# Install packages and cleanup
173+
# install packages as USER 0 (this will allow us to consume uv cache)
174+
RUN --mount=type=cache,from=whl-cache,source=/wheelsdir/,target=/wheelsdir/,rw \
175+
--mount=type=cache,target=/root/.cache/uv \
176+
bash -c ' \
177+
if [[ $(uname -m) == "ppc64le" ]]; then \
178+
UV_LINK_MODE=copy uv pip install /wheelsdir/*.whl accelerate --cache-dir /root/.cache/uv; \
179+
fi '
180+
RUN --mount=type=cache,target=/root/.cache/uv \
181+
echo "Installing softwares and packages" && \
182+
# we can ensure wheels are consumed from the cache only by restricting internet access for uv install with '--offline' flag
183+
UV_LINK_MODE=copy uv pip install --cache-dir /root/.cache/uv --requirements=./pylock.toml && \
184+
# Note: debugpy wheel availabe on pypi (in uv cache) is none-any but bundles amd64.so files
185+
# Build debugpy from source instead
186+
UV_LINK_MODE=copy uv pip install --no-cache git+https://github.com/microsoft/debugpy.git@v$(grep -A1 '\"debugpy\"' ./pylock.toml | grep -Eo '\b[0-9\.]+\b') && \
187+
# change ownership to default user (all packages were installed as root and has root:root ownership \
188+
chown -R 1001:0 /opt/app-root/
189+
190+
USER 1001
191+
192+
RUN # setup path for runtime configuration \
147193
mkdir /opt/app-root/runtimes && \
148194
# Remove default Elyra runtime-images \
149195
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
set -eoux pipefail
3+
4+
#####################################################################################################
5+
# This script is expected to be run on ppc64le hosts as `root` #
6+
# It installs the required build-time dependencies for python wheels #
7+
# OpenBlas is built from source (instead of distro provided) with recommended flags for performance #
8+
#####################################################################################################
9+
WHEELS_DIR=/wheelsdir
10+
mkdir -p ${WHEELS_DIR}
11+
if [[ $(uname -m) == "ppc64le" ]]; then
12+
CURDIR=$(pwd)
13+
14+
# install development packages
15+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
16+
dnf install -y fribidi-devel gcc-toolset-13 lcms2-devel libimagequant-devel \
17+
libraqm-devel openjpeg2-devel tcl-devel tk-devel unixODBC-devel
18+
19+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
20+
21+
source /opt/rh/gcc-toolset-13/enable
22+
source $HOME/.cargo/env
23+
24+
uv pip install cmake
25+
26+
export MAX_JOBS=${MAX_JOBS:-$(nproc)}
27+
export OPENBLAS_VERSION=${OPENBLAS_VERSION:-0.3.30}
28+
29+
# Install OpenBlas
30+
# IMPORTANT: Ensure Openblas is installed in the final image
31+
cd /root
32+
curl -L https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION}/OpenBLAS-${OPENBLAS_VERSION}.tar.gz | tar xz
33+
# rename directory for mounting (without knowing version numbers) in multistage builds
34+
mv OpenBLAS-${OPENBLAS_VERSION}/ OpenBLAS/
35+
cd OpenBLAS/
36+
make -j${MAX_JOBS} TARGET=POWER9 BINARY=64 USE_OPENMP=1 USE_THREAD=1 NUM_THREADS=120 DYNAMIC_ARCH=1 INTERFACE64=0
37+
make install
38+
cd ..
39+
40+
# set path for openblas
41+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/OpenBLAS/lib/:/usr/local/lib64:/usr/local/lib
42+
export PKG_CONFIG_PATH=$(find / -type d -name "pkgconfig" 2>/dev/null | tr '\n' ':')
43+
export CMAKE_ARGS="-DPython3_EXECUTABLE=python"
44+
export CMAKE_POLICY_VERSION_MINIMUM=3.5
45+
46+
TMP=$(mktemp -d)
47+
48+
# Torch
49+
cd ${CURDIR}
50+
TORCH_VERSION=$(grep -A1 '"torch"' pylock.toml | grep -Eo '\b[0-9\.]+\b')
51+
cd ${TMP}
52+
git clone --recursive https://github.com/pytorch/pytorch.git -b v${TORCH_VERSION}
53+
cd pytorch
54+
uv pip install -r requirements.txt
55+
python setup.py develop
56+
rm -f dist/torch*+git*whl
57+
MAX_JOBS=${MAX_JOBS:-$(nproc)} \
58+
PYTORCH_BUILD_VERSION=${TORCH_VERSION} PYTORCH_BUILD_NUMBER=1 uv build --wheel --out-dir ${WHEELS_DIR}
59+
60+
cd ${CURDIR}
61+
# Pyarrow
62+
PYARROW_VERSION=$(grep -A1 '"pyarrow"' pylock.toml | grep -Eo '\b[0-9\.]+\b')
63+
cd ${TMP}
64+
git clone --recursive https://github.com/apache/arrow.git -b apache-arrow-${PYARROW_VERSION}
65+
cd arrow/cpp
66+
mkdir build && cd build && \
67+
cmake -DCMAKE_BUILD_TYPE=release \
68+
-DCMAKE_INSTALL_PREFIX=/usr/local \
69+
-DARROW_PYTHON=ON \
70+
-DARROW_BUILD_TESTS=OFF \
71+
-DARROW_JEMALLOC=ON \
72+
-DARROW_BUILD_STATIC="OFF" \
73+
-DARROW_PARQUET=ON \
74+
.. && \
75+
make install -j ${MAX_JOBS:-$(nproc)} && \
76+
cd ../../python/ && \
77+
uv pip install -v -r requirements-wheel-build.txt && \
78+
PYARROW_PARALLEL=${PYARROW_PARALLEL:-$(nproc)} \
79+
python setup.py build_ext \
80+
--build-type=release --bundle-arrow-cpp \
81+
bdist_wheel --dist-dir ${WHEELS_DIR}
82+
83+
ls -ltr ${WHEELS_DIR}
84+
85+
cd ${CURDIR}
86+
uv pip install --refresh ${WHEELS_DIR}/*.whl accelerate==$(grep -A1 '"accelerate"' pylock.toml | grep -Eo '\b[0-9\.]+\b')
87+
88+
uv pip list
89+
cd ${CURDIR}
90+
else
91+
# only for mounting on non-ppc64le
92+
mkdir -p /root/OpenBLAS/
93+
fi

0 commit comments

Comments
 (0)