occlum/demos/pytorch
pu1p a1777330b0 doc(demos/PyTorch): fix wrong message in README
Step 2 and 3 should be executed inside the container, not on host.
The demo's dir is ` /root/demos/pytorch`,
not ` /root/occlum/demos/pytorch`
2021-12-22 08:16:27 +08:00
..
.gitignore Fix the script of running Python demo 2021-07-13 19:31:28 +08:00
demo.py Add pytorch demo 2021-06-08 19:07:58 +08:00
install_python_with_conda.sh Update pytorch demo with copy_bom 2021-09-26 21:06:59 +08:00
pytorch.yaml Update pytorch demo with copy_bom 2021-09-26 21:06:59 +08:00
README.md doc(demos/PyTorch): fix wrong message in README 2021-12-22 08:16:27 +08:00
run_pytorch_on_occlum.sh Increase the pytorch demo TCS number to 64 2021-10-22 16:42:48 +08:00

Use PyTorch with Python and Occlum

This project demonstrates how Occlum enables unmodified PyTorch programs running in SGX enclaves, on the basis of unmodified Python.

Sample Code: Linear model

Use the nn package to define our model as a sequence of layers. nn.Sequential is a Module which contains other Modules, and applies them in sequence to produce its output. Each Linear Module computes output from input using a linear function, and holds internal Tensors for its weight and bias.

How to Run

This tutorial is written under the assumption that you have Docker installed and use Occlum in a Docker container.

Occlum is compatible with glibc-supported Python, we employ miniconda as python installation tool. You can import PyTorch packages using conda. Here, miniconda is automatically installed by install_python_with_conda.sh script, the required python and PyTorch packages for this project are also loaded by this script. Here, we take occlum/occlum:0.23.0-ubuntu18.04 as example.

Step 1 (on the host): Start an Occlum container

docker pull occlum/occlum:0.23.0-ubuntu18.04
docker run -it --name=pythonDemo --device /dev/sgx/enclave occlum/occlum:0.23.0-ubuntu18.04 bash

Step 2 (in the Occlum container): Download miniconda and install python to prefix position.

cd /root/demos/pytorch
bash ./install_python_with_conda.sh

Step 3 (in the Occlum container): Run the sample code on Occlum

cd /root/demos/pytorch
bash ./run_pytorch_on_occlum.sh