Installation#
The simplest way to try SecretFlow is to use offical docker image which ships with SecretFlow binary.
Or you could install SecretFlow via Python Package Index.
For advanced users, you could install SecretFlow from source.
After installation, don’t forget to have a quick try to check if SecretFlow is good to go.
Environment#
Python:3.8
pip: >= 19.3
OS: CentOS 7, Ubuntu 18.04
CPU/Memory: recommended minimum requirement is 8C16G.
Option 1: from pypi#
For users who want to try SecretFlow, you can install the current release.
Note that it requires python version == 3.8, you can create a virtual environment with conda if not satisfied.
conda create -n sf python=3.8
conda activate sf
After that, please use pip to install SecretFlow.
pip install -U secretflow
Option 2: from docker#
You can also use SecretFlow Docker image to give SecretFlow a quick try.
The latest version can be obtained from secretflow tags.
export version={SecretFlow version}
for example
export version=0.6.13b1
then run the image.
docker run -it secretflow/secretflow-anolis8:${version}
Option 3: from source#
Download code and set up Python virtual environment.
git clone https://github.com/secretflow/secretflow.git
cd secretflow
conda create -n secretflow python=3.8
conda activate secretflow
Install SecretFlow
python setup.py bdist_wheel
pip install dist/*.whl
Option 4: from WSL#
SecretFlow does not support Windows directly now, however, a Windows user can use secretFlow by WSL(Windows Subsystem for Linux).
Install WSL2 in Windows
You are supposed to follow the guide_zh or guide_en to install WSL(Windows Subsystem for Linux) in your Windows and make sure that the version of WSL is 2.
As for the distribution of GNU/Linux, Ubuntu is recommended.
Install Anaconda in WSL
Just follow the installation of anaconda in GNU/Linux to install anaconda in your WSL.
Install secretflow
create conda environment
conda create -n sf python=3.8
activate the environment
conda activate sf
use pip to install SecretFlow.
pip install -U secretflow
GPUs support#
NVIDIA’s CUDA and cuDNN are typically used to accelerate the training and testing of Tensoflow and PyTorch deep learning models. Tensoflow and PyTorch are both deep learning backends for SecretFlow.
JAX is the frontend highly recommended by the SecretFlow team. JAX can compile and run your NumPy code on accelerators, such as GPUs and TPUs.Now we supply GPUs supports to JAX in SecretFlow.
if you want to use GPU acceleration in SecretFlow, you can follow these steps:
Make sure your NVIDIA driver is available and meet the version requirements as JAX recommend.
The version requirements:
the driver must be version >= 525.60.13 for CUDA 12 and >= 450.80.02 for CUDA 11 on Linux.
Run NVIDIA System Management Interface (nvidia-smi) to make sure your NVIDIA driver is available and meet the version requirements.
nvidia-smi
Follow the NVIDIA official guide to setup NVIDIA Container Toolkit on your distributions.
Use a dockerfile file to construct an image
Download code
git clone https://github.com/secretflow/secretflow.git
cd secretflow/docker
Construct an image
docker build -f sf-gpu.Dockerfile -t secretflow-gpu .
Run an container
docker container run -it --gpus all secretflow-gpu bash
--gpus all: This parameter is essential.
After the container is running, you can use the jupyter notebook GPU Check to check the callability of JAX, Tensorflow and PyTorch for NVIDIA GPUs inside the container.
A quick try#
Try your first SecretFlow program.
>>> import secretflow as sf
>>> sf.init(['alice', 'bob', 'carol'], address='local')
>>> dev = sf.PYU('alice')
>>> import numpy as np
>>> data = dev(np.random.rand)(3, 4)
>>> data
<secretflow.device.device.pyu.PYUObject object at 0x7fdec24a15b0>