Update pytorch demo with copy_bom

This commit is contained in:
jianfengjiang 2021-09-26 11:18:51 +08:00 committed by Zongmin.Gu
parent 7290cfa561
commit 3f78b09df7
4 changed files with 28 additions and 17 deletions

@ -346,7 +346,7 @@ jobs:
# FIXME: PyTorch can't exit normally in SIM mode
- name: Kill the container
run: |
sleep 180;
sleep 240;
cat "$GITHUB_WORKSPACE/log";
if grep -q Done "$GITHUB_WORKSPACE/log"; then
docker stop pytorch_test

@ -8,4 +8,4 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# 2. Install python and dependencies to specified position
[ -d Miniconda3-latest-Linux-x86_64.sh ] || wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
[ -d miniconda ] || bash ./Miniconda3-latest-Linux-x86_64.sh -b -p $script_dir/miniconda
$script_dir/miniconda/bin/conda create --prefix $script_dir/occlum_instance/image/opt/python-occlum -y python=3.7 pytorch numpy torchvision -c pytorch
$script_dir/miniconda/bin/conda create --prefix $script_dir/python-occlum -y python=3.7 pytorch numpy torchvision -c pytorch

@ -0,0 +1,17 @@
includes:
- base.yaml
targets:
- target: /bin
createlinks:
- src: /opt/python-occlum/bin/python3
linkname: python3
# python packages
- target: /opt
copy:
- dirs:
- ../python-occlum
# python code
- target: /
copy:
- files:
- ../demo.py

@ -7,26 +7,20 @@ NC='\033[0m'
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
python_dir="$script_dir/occlum_instance/image/opt/python-occlum"
cd occlum_instance && rm -rf image
copy_bom -f ../pytorch.yaml --root image --include-dir /opt/occlum/etc/template
if [ ! -d $python_dir ];then
echo "Error: cannot stat '$python_dir' directory"
exit 1
fi
cd occlum_instance
# Copy files into Occlum Workspace and build
if [ ! -L "image/bin/python3" ];then
ln -s /opt/python-occlum/bin/python3 image/bin/python3
cp -f /opt/occlum/glibc/lib/libdl.so.2 image/opt/occlum/glibc/lib/
cp -f /opt/occlum/glibc/lib/libutil.so.1 image/opt/occlum/glibc/lib/
cp -f /opt/occlum/glibc/lib/librt.so.1 image/opt/occlum/glibc/lib/
cp -f ../demo.py image
new_json="$(jq '.resource_limits.user_space_size = "6000MB" |
.resource_limits.kernel_space_heap_size = "256MB" |
.process.default_mmap_size = "4000MB" |
.env.default += ["PYTHONHOME=/opt/python-occlum"]' Occlum.json)" && \
echo "${new_json}" > Occlum.json
occlum build
fi
new_json="$(jq '.resource_limits.user_space_size = "6000MB" |
.resource_limits.kernel_space_heap_size = "256MB" |
.process.default_mmap_size = "4000MB" |
.env.default += ["PYTHONHOME=/opt/python-occlum"]' Occlum.json)" && \
echo "${new_json}" > Occlum.json
occlum build
# Run the python demo
echo -e "${BLUE}occlum run /bin/python3 demo.py${NC}"