Skip to content

Commit f3d9d39

Browse files
authored
update dockerfile to use native python env (#2886)
1 parent 560f9fe commit f3d9d39

File tree

5 files changed

+86
-68
lines changed

5 files changed

+86
-68
lines changed

docker/Dockerfile.compile

+12-25
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ RUN if [ -f /etc/apt/apt.conf.d/proxy.conf ]; then rm /etc/apt/apt.conf.d/proxy.
1313
RUN apt update && \
1414
apt full-upgrade -y && \
1515
DEBIAN_FRONTEND=noninteractive apt install --no-install-recommends -y \
16-
sudo \
1716
ca-certificates \
1817
git \
1918
curl \
@@ -22,32 +21,27 @@ RUN apt update && \
2221
numactl \
2322
gcc-12 \
2423
g++-12 \
24+
python3 \
25+
python3-dev \
26+
python3-pip \
2527
make
2628
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 && \
2729
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100 && \
2830
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 100 && \
29-
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100
31+
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100 && \
32+
update-alternatives --install /usr/bin/python python /usr/bin/python3 100
3033
RUN apt clean && \
3134
rm -rf /var/lib/apt/lists/* && \
3235
if [ -f /etc/apt/apt.conf.d/proxy.conf ]; then rm /etc/apt/apt.conf.d/proxy.conf; fi
3336

34-
RUN useradd -m ubuntu && \
35-
echo 'ubuntu ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
36-
USER ubuntu
37-
WORKDIR /home/ubuntu
38-
39-
RUN curl -fsSL -v -o miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
40-
bash miniconda.sh -b -p ./miniconda3 && \
41-
rm miniconda.sh && \
42-
echo "source ~/miniconda3/bin/activate" >> ./.bashrc
37+
WORKDIR /root
38+
ENV PATH=/root/.local/bin:${PATH}
4339

4440
FROM base AS dev
45-
COPY --chown=ubuntu:ubuntu . ./intel-extension-for-pytorch
41+
COPY . ./intel-extension-for-pytorch
4642
RUN cp ./intel-extension-for-pytorch/scripts/compile_bundle.sh ./ && \
4743
sed -i "s/VER_IPEX=.*/VER_IPEX=/" compile_bundle.sh
48-
RUN . ./miniconda3/bin/activate && \
49-
conda create -y -n compile_py310 python=3.10 && conda activate compile_py310 && \
50-
bash compile_bundle.sh && \
44+
RUN CC=gcc CXX=g++ bash compile_bundle.sh && \
5145
cd intel-extension-for-pytorch && \
5246
python -m pip install pyyaml && \
5347
VER_TORCH=$(python tools/yaml_utils.py -f dependency_version.yml -d pytorch -k version) && \
@@ -58,18 +52,11 @@ RUN . ./miniconda3/bin/activate && \
5852
echo ${VER_TORCH} | grep "dev" > /dev/null; TORCH_DEV=$?; URL_NIGHTLY=""; if [ ${TORCH_DEV} -eq 0 ]; then URL_NIGHTLY="nightly/"; fi; echo "#!/bin/bash\npython -m pip install torch==${VER_TORCH} torchvision==${VER_TORCHVISION} torchaudio==${VER_TORCHAUDIO} --index-url https://download.pytorch.org/whl/${URL_NIGHTLY}cpu" > torch_install.sh
5953

6054
FROM base AS deploy
61-
COPY --from=dev --chown=ubuntu:ubuntu /home/ubuntu/intel-extension-for-pytorch/dist ./wheels
62-
COPY --from=dev --chown=ubuntu:ubuntu /home/ubuntu/intel-extension-for-pytorch/tools/get_libstdcpp_lib.sh .
63-
COPY --from=dev --chown=ubuntu:ubuntu /home/ubuntu/torch_install.sh .
64-
RUN . ./miniconda3/bin/activate && \
65-
conda create -y -n py310 python=3.10 && conda activate py310 && \
66-
bash ./torch_install.sh && rm ./torch_install.sh && \
55+
COPY --from=dev /root/intel-extension-for-pytorch/dist ./wheels
56+
COPY --from=dev /root/torch_install.sh .
57+
RUN bash ./torch_install.sh && rm ./torch_install.sh && \
6758
python -m pip install ./wheels/*.whl && \
6859
python -m pip install intel-openmp && \
69-
conda install -y jemalloc gperftools -c conda-forge && \
7060
python -m pip cache purge && \
71-
conda clean -a -y && \
7261
rm -rf ./wheels && \
73-
echo "conda activate py310" >> ./.bashrc && \
74-
ldpreload=$(bash get_libstdcpp_lib.sh) && echo "export LD_PRELOAD=${ldpreload}" >> ./.bashrc && rm get_libstdcpp_lib.sh && \
7562
echo "echo \"**Note:** For better performance, please consider to launch workloads with command 'ipexrun'.\"" >> ./.bashrc

examples/cpu/inference/python/llm/Dockerfile

+37-30
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,62 @@ RUN if [ -f /etc/apt/apt.conf.d/proxy.conf ]; then rm /etc/apt/apt.conf.d/proxy.
1313
RUN apt update && \
1414
apt full-upgrade -y && \
1515
DEBIAN_FRONTEND=noninteractive apt install --no-install-recommends -y \
16-
sudo \
1716
ca-certificates \
1817
git \
1918
curl \
2019
wget \
2120
vim \
21+
python3 \
22+
python3-dev \
23+
python3-pip \
2224
numactl \
2325
gcc-12 \
2426
g++-12 \
25-
make
27+
make \
28+
cmake
2629
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 && \
2730
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100 && \
2831
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 100 && \
29-
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100
30-
RUN apt clean && \
31-
rm -rf /var/lib/apt/lists/* && \
32-
if [ -f /etc/apt/apt.conf.d/proxy.conf ]; then rm /etc/apt/apt.conf.d/proxy.conf; fi
32+
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100 && \
33+
update-alternatives --install /usr/bin/python python /usr/bin/python3 100
3334

34-
RUN useradd -m ubuntu && \
35-
echo 'ubuntu ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
36-
USER ubuntu
37-
WORKDIR /home/ubuntu
38-
39-
RUN curl -fsSL -v -o miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
40-
bash miniconda.sh -b -p ./miniconda3 && \
41-
rm miniconda.sh && \
42-
echo "source ~/miniconda3/bin/activate" >> ./.bashrc
35+
WORKDIR /root
36+
ENV PATH=/root/.local/bin:${PATH}
4337

4438
# --build-arg COMPILE=ON to compile from source
4539
FROM base AS dev
4640
ARG COMPILE
47-
COPY --chown=ubuntu:ubuntu . ./intel-extension-for-pytorch
48-
RUN . ./miniconda3/bin/activate && \
49-
conda create -y -n compile_py310 python=3.10 && conda activate compile_py310 && \
50-
cd intel-extension-for-pytorch/examples/cpu/inference/python/llm && \
51-
if [ -z ${COMPILE} ]; then bash tools/env_setup.sh 6; else bash tools/env_setup.sh 2; fi
41+
COPY . ./intel-extension-for-pytorch
42+
RUN cd intel-extension-for-pytorch/examples/cpu/inference/python/llm && \
43+
export CC=gcc && export CXX=g++ && \
44+
if [ -z ${COMPILE} ]; then bash tools/env_setup.sh 6; else bash tools/env_setup.sh 2; fi && \
45+
unset CC && unset CXX
5246

5347
FROM base AS deploy
54-
COPY --from=dev --chown=ubuntu:ubuntu /home/ubuntu/intel-extension-for-pytorch/examples/cpu/inference/python/llm ./llm
55-
RUN rm ./llm/tools/get_libstdcpp_lib.sh
56-
COPY --from=dev --chown=ubuntu:ubuntu /home/ubuntu/intel-extension-for-pytorch/examples/cpu/inference/python/llm/tools/get_libstdcpp_lib.sh ./llm/tools/get_libstdcpp_lib.sh
57-
RUN . ./miniconda3/bin/activate && \
58-
conda create -y -n py310 python=3.10 && conda activate py310 && \
59-
echo "conda activate py310" >> ./.bashrc && \
48+
RUN apt update && \
49+
DEBIAN_FRONTEND=noninteractive apt install --no-install-recommends -y \
50+
google-perftools \
51+
openssh-server \
52+
net-tools && \
53+
apt clean && \
54+
rm -rf /var/lib/apt/lists/* && \
55+
if [ -f /etc/apt/apt.conf.d/proxy.conf ]; then rm /etc/apt/apt.conf.d/proxy.conf; fi
56+
COPY --from=dev /root/intel-extension-for-pytorch/examples/cpu/inference/python/llm ./llm
57+
COPY --from=dev /root/intel-extension-for-pytorch/tools/get_libstdcpp_lib.sh ./llm/tools
58+
RUN cd /usr/lib/x86_64-linux-gnu/ && ln -s libtcmalloc.so.4 libtcmalloc.so && cd && \
6059
echo "echo \"**Note:** For better performance, please consider to launch workloads with command 'ipexrun'.\"" >> ./.bashrc && \
6160
cd ./llm && \
6261
bash tools/env_setup.sh 1 && \
6362
python -m pip cache purge && \
64-
conda clean -a -y && \
65-
sudo mv ./oneCCL_release /opt/oneCCL && \
66-
sudo chown -R root:root /opt/oneCCL && \
67-
sed -i "s|ONECCL_PATH=.*|ONECCL_PATH=/opt/oneCCL|" ./tools/env_activate.sh
63+
mv ./oneCCL_release /opt/oneCCL && \
64+
chown -R root:root /opt/oneCCL && \
65+
sed -i "s|ONECCL_PATH=.*|ONECCL_PATH=/opt/oneCCL|" ./tools/env_activate.sh && \
66+
LN=$(grep "Conda environment is not available." -n ./tools/env_activate.sh | cut -d ":" -f 1) && sed -i "${LN}s|.*| export LD_PRELOAD=\${LD_PRELOAD}:/usr/lib/x86_64-linux-gnu/libtcmalloc.so:/usr/local/lib/libiomp5.so|" ./tools/env_activate.sh
67+
ARG PORT_SSH=22
68+
RUN mkdir /var/run/sshd && \
69+
sed -i "s/#Port.*/Port ${PORT_SSH}/" /etc/ssh/sshd_config && \
70+
echo "service ssh start" >> /root/.bashrc && \
71+
ssh-keygen -b 4096 -f /root/.ssh/id_rsa -N "" && \
72+
mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys && \
73+
echo "Host *\n Port ${PORT_SSH}\n IdentityFile /root/.ssh/id_rsa\n StrictHostKeyChecking no" > /root/.ssh/config
74+
EXPOSE ${PORT_SSH}

examples/cpu/inference/python/llm/tools/env_activate.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if [ $? -eq 0 ]; then
1616
# Tcmalloc is a recommended malloc implementation that emphasizes fragmentation avoidance and scalable concurrency support.
1717
export LD_PRELOAD=${LD_PRELOAD}:${CONDA_PREFIX}/lib/libtcmalloc.so
1818
else
19-
echo "Conda environment is not available. You need to set environment variable LD_PRELOAD to dynamic libraries of Intel OpenMP and TcMalloc manually."
19+
echo "Conda environment is not available. You need to set environment variable LD_PRELOAD to dynamic libraries of Intel OpenMP and TcMalloc manually if they are not in library search paths."
2020
fi
2121

2222
ONECCL_PATH=${BASEFOLDER}/../oneCCL_release

examples/cpu/inference/python/llm/tools/env_setup.sh

+25-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ ! -f ${WHEELFOLDER}/lm_eval*.whl ] ||
3232
fi
3333

3434
# Check existance of required Linux commands
35-
for CMD in conda gcc g++; do
35+
for CMD in gcc g++; do
3636
command -v ${CMD} > /dev/null || (echo "Error: Command \"${CMD}\" is required."; exit 1;)
3737
done
3838

@@ -131,12 +131,21 @@ if [ $((${MODE} & 0x02)) -ne 0 ]; then
131131
echo " Found GCC version $(gcc -dumpfullversion)"
132132
echo " Installing gcc and g++ 12.3 with conda"
133133
echo ""
134-
conda install -y sysroot_linux-64
135-
conda install -y gcc==12.3 gxx==12.3 cxx-compiler -c conda-forge
136-
if [ -z ${CONDA_BUILD_SYSROOT} ]; then
137-
source ${CONDA_PREFIX}/etc/conda/activate.d/activate-gcc_linux-64.sh
138-
source ${CONDA_PREFIX}/etc/conda/activate.d/activate-gxx_linux-64.sh
139-
source ${CONDA_PREFIX}/etc/conda/activate.d/activate-binutils_linux-64.sh
134+
set +e
135+
command -v conda > /dev/null
136+
EXIST_CONDA=$?
137+
set -e
138+
if [ ${EXIST_CONDA} -gt 0 ]; then
139+
echo "[Error] Command \"conda\" is not available."
140+
exit 5
141+
else
142+
conda install -y sysroot_linux-64
143+
conda install -y gcc==12.3 gxx==12.3 cxx-compiler -c conda-forge
144+
if [ -z ${CONDA_BUILD_SYSROOT} ]; then
145+
source ${CONDA_PREFIX}/etc/conda/activate.d/activate-gcc_linux-64.sh
146+
source ${CONDA_PREFIX}/etc/conda/activate.d/activate-gxx_linux-64.sh
147+
source ${CONDA_PREFIX}/etc/conda/activate.d/activate-binutils_linux-64.sh
148+
fi
140149
fi
141150
fi
142151

@@ -206,7 +215,15 @@ if [ $((${MODE} & 0x02)) -ne 0 ]; then
206215
cd intel-extension-for-pytorch/examples/cpu/inference/python/llm
207216
fi
208217
if [ $((${MODE} & 0x01)) -ne 0 ]; then
209-
conda install -y gperftools -c conda-forge
218+
set +e
219+
command -v conda > /dev/null
220+
EXIST_CONDA=$?
221+
set -e
222+
if [ ${EXIST_CONDA} -gt 0 ]; then
223+
echo "[WARNING] Command \"conda\" is not available. Please install tcmalloc manually."
224+
else
225+
conda install -y gperftools -c conda-forge
226+
fi
210227
bash ${AUX_INSTALL_SCRIPT}
211228
python -m pip install ${WHEELFOLDER}/*.whl
212229
rm -rf ${WHEELFOLDER}

scripts/compile_bundle.sh

+11-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if [ $# -gt 0 ]; then
2323
fi
2424

2525
# Check existance of required Linux commands
26-
for CMD in conda git nproc; do
26+
for CMD in git nproc; do
2727
command -v ${CMD} > /dev/null || (echo "Error: Command \"${CMD}\" not found." ; exit 1)
2828
done
2929

@@ -97,8 +97,11 @@ function ver_compare() {
9797
fi
9898
echo ${RET}
9999
}
100-
GCC_CONDA=0
101100
set +e
101+
command -v conda > /dev/null
102+
EXIST_CONDA=$?
103+
104+
GCC_CONDA=0
102105
command -v gcc > /dev/null
103106
EXIST_CC=$?
104107
command -v g++ > /dev/null
@@ -121,7 +124,7 @@ else
121124
GCC_CONDA=1
122125
else
123126
DIR_GCC=$(which gcc)
124-
if [[ ${DIR_GCC} =~ ${CONDA_PREFIX} ]]; then
127+
if [ ! -z ${CONDA_PREFIX} ] && [[ ${DIR_GCC} =~ ${CONDA_PREFIX} ]]; then
125128
GCC_CONDA=2
126129
fi
127130
fi
@@ -216,6 +219,10 @@ ABI=$(python -c "import torch; print(int(torch._C._GLIBCXX_USE_CXX11_ABI))")
216219

217220
# Compile individual component
218221
if [ ${GCC_CONDA} -eq 1 ]; then
222+
if [ ${EXIST_CONDA} -gt 0 ]; then
223+
echo "Command \"conda\" not found. Exit."
224+
exit 2
225+
fi
219226
conda install -y sysroot_linux-64
220227
conda install -y gcc==12.3 gxx==12.3 cxx-compiler -c conda-forge
221228
fi
@@ -240,7 +247,7 @@ fi
240247
set +e
241248
command -v make > /dev/null
242249
if [ $? -gt 0 ]; then
243-
conda install -y make -c conda-forge
250+
python -m pip install make
244251
fi
245252
set -e
246253

0 commit comments

Comments
 (0)