Skip to content

Commit

Permalink
Merge remote-tracking branch 'kanav_sytorch/early_term' into orca_syt…
Browse files Browse the repository at this point in the history
…orch
  • Loading branch information
trajore committed Dec 27, 2023
2 parents 37c6d71 + d03dd74 commit 7376d28
Show file tree
Hide file tree
Showing 321 changed files with 247,873 additions and 83 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,32 @@ SEAL
*.dot
*.csv
*.out
.vscode/
*.out
release/
debug/
datatorch/
client.dat
server.dat
out.folded
out.perf
perf.data
perf.data.old
graph.svg
.venv
*.dat
logs/
temp/
graph.dot
graph.png
venv/
thread_outputs/
CMakeFiles/
Makefile
*.cmake
main
CMakeCache.txt
lib
libsytorch.a
libcryptoTools.a
libLLAMA.a
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "CrypTFlow2/extern/eigen"]
path = SCI/extern/eigen
url = https://gitlab.com/libeigen/eigen
[submodule "ext/sci/extern/SEAL"]
path = ext/sci/extern/SEAL
url = https://github.com/Microsoft/SEAL
105 changes: 105 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
cmake_minimum_required(VERSION 3.16)
project(sytorch)

if(APPLE)

if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()

endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings -Wno-unused-result -maes -Wno-ignored-attributes -march=native -Wno-deprecated-declarations -fopenmp")
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
find_package(Threads REQUIRED)

add_subdirectory(ext/cryptoTools)
add_subdirectory(ext/sci)
add_subdirectory(ext/llama)

add_library(${PROJECT_NAME} STATIC)
target_sources(${PROJECT_NAME}
PRIVATE
src/sytorch/datasets/mnist.cpp
src/sytorch/random.cpp
src/sytorch/train.cpp
src/sytorch/networks.cpp
src/sytorch/backend/cleartext.cpp
)

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_link_libraries (${PROJECT_NAME} Eigen3::Eigen Threads::Threads SCI-FloatML LLAMA cryptoTools)

add_executable(main
main.cpp
)
target_link_libraries (main ${PROJECT_NAME})

add_executable(module
module.cpp
)
target_link_libraries (module ${PROJECT_NAME})

add_executable(vgg16
vgg16.cpp
)
target_link_libraries (vgg16 ${PROJECT_NAME})

add_executable(chexpert
chexpert.cpp
)
target_link_libraries (chexpert ${PROJECT_NAME})

add_executable(resnet18
resnet18.cpp
)
target_link_libraries (resnet18 ${PROJECT_NAME})

add_executable(inference
inference.cpp
)
target_link_libraries (inference ${PROJECT_NAME})

add_executable(resnet18_acc
resnet18_acc.cpp
)
target_link_libraries (resnet18_acc ${PROJECT_NAME})

add_executable(dcftest
dcftest.cpp
)
target_link_libraries (dcftest ${PROJECT_NAME})

add_executable(strtest
strtest.cpp
)
target_link_libraries (strtest ${PROJECT_NAME})

add_executable(orcav2_exp
orcav2_exp.cpp
)
target_link_libraries (orcav2_exp ${PROJECT_NAME})

add_executable(microbenchmark_rt
microbenchmark_rt.cpp
)
target_link_libraries (microbenchmark_rt ${PROJECT_NAME})

add_executable(microbenchmark_rtm
microbenchmark_rtm.cpp
)
target_link_libraries (microbenchmark_rtm ${PROJECT_NAME})
4 changes: 2 additions & 2 deletions OnnxBridge/backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Authors: Saksham Gupta.
Authors: Saksham Gupta,Tanmay Rajore
Copyright:
Copyright (c) 2021 Microsoft Research
Copyright (c) 2023 Microsoft Research
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand Down
2 changes: 1 addition & 1 deletion OnnxBridge/helper/convert_np_to_float_inp.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def convert_np_to_floatpt(path_to_numpy_arr):
args = parse_args()

output_path = convert_np_to_floatpt(args.inp)
print("FLoat point output saved in ", output_path)
print("FLoat point output saved in ", output_path)
2 changes: 1 addition & 1 deletion OnnxBridge/helper/run_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

if __name__ == "__main__":
input_np_arr = np.load(sys.argv[2], allow_pickle=True)
sess = rt.InferenceSession(sys.argv[1])
sess = rt.InferenceSession(sys.argv[1]) #"../onnx_new_files/lenet.onnx"
input_name = sess.get_inputs()[0].name
pred_onx = sess.run(None, {input_name: input_np_arr})[0]
# print("Output:\n", pred_onx.flatten())
Expand Down
1 change: 0 additions & 1 deletion OnnxBridge/utils/optimizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from onnx import shape_inference
from onnx.helper import make_tensor_value_info
from onnxsim import simplify

from utils import logger
from utils.onnx2IR_helper import proto_val_to_dimension_tuple

Expand Down
130 changes: 52 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,52 @@
# EzPC: Easy Secure Multiparty Computation [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/mpc-msri/EzPC/issues)

**Reference Papers:**

[SIGMA: Secure GPT Inference with Function Secret Sharing](https://eprint.iacr.org/2023/1269)
Kanav Gupta, Neha Jawalkar, Ananta Mukherjee, Nishanth Chandran, Divya Gupta, Ashish Panwar, Rahul Sharma

[Orca: FSS-based Secure Training with GPUs](https://eprint.iacr.org/2023/206)
Neha Jawalkar, Kanav Gupta, Arkaprava Basu, Nishanth Chandran, Divya Gupta, Rahul Sharma

[Secure Floating-Point Training](https://eprint.iacr.org/2023/467)
Deevashwer Rathee, Anwesh Bhattacharya, Divya Gupta, Rahul Sharma, Dawn Song
*USENIX Security 2023*

[SecFloat: Accurate Floating-Point meets Secure 2-Party Computation](https://eprint.iacr.org/2022/322)
Deevashwer Rathee, Anwesh Bhattacharya, Rahul Sharma, Divya Gupta, Nishanth Chandran, Aseem Rastogi
*IEEE S&P 2022*

[SIRNN: A Math Library for Secure RNN Inference](https://eprint.iacr.org/2021/459)
Deevashwer Rathee, Mayank Rathee, Rahul Kranti Kiran Goli, Divya Gupta, Rahul Sharma, Nishanth Chandran, Aseem Rastogi
*IEEE S&P 2021*

[CrypTFlow2: Practical 2-Party Secure Inference](https://eprint.iacr.org/2020/1002)
Deevashwer Rathee, Mayank Rathee, Nishant Kumar, Nishanth Chandran, Divya Gupta, Aseem Rastogi, Rahul Sharma
*ACM CCS 2020*

[CrypTFlow: Secure TensorFlow Inference](https://eprint.iacr.org/2019/1049)
Nishant Kumar, Mayank Rathee, Nishanth Chandran, Divya Gupta, Aseem Rastogi, Rahul Sharma
*IEEE S&P 2020*

[EzPC: Programmable, Efficient, and Scalable Secure Two-Party Computation for Machine Learning](https://eprint.iacr.org/2017/1109.pdf)
Nishanth Chandran, Divya Gupta, Aseem Rastogi, Rahul Sharma, Shardul Tripathi
*IEEE EuroS&P 2019*

**Project webpage:** <https://aka.ms/ezpc>

## Introduction
This repository has the following components:

- **EzPC**: a language for secure machine learning.
- **Athos** (part of **CrypTFlow**): an end-to-end compiler from TensorFlow to a variety of semi-honest MPC protocols. Athos leverages EzPC as a low-level intermediate language.
- **SIRNN**: an end-to-end framework for performing inference over quantized RNN models using semi-honest 2-party computation protocols.
- **Beacon**: an end-to-end framework for training feed-forward and convolutional neural networks using specialized 2PC floating-point protocols
- **Porthos** (part of **CrypTFlow**): a semi-honest 3 party computation protocol which is geared towards TensorFlow-like applications.
- **Aramis** (part of **CrypTFlow**): a novel technique that uses hardware with integrity guarantees to convert any semi-honest MPC protocol into an MPC protocol that provides malicious security.
- **SCI** (part of **CrypTFlow2**, **SIRNN**, **SecFloat**, and **Beacon**): a semi-honest 2-party computation library for secure (fixed-point) inference on deep neural networks and secure floating-point computation.

Each one of the above is independent and usable in their own right and more information can be found in the readme of each of the components. But together these combine to make **CrypTFlow** a powerful system for end-to-end secure inference of deep neural networks written in TensorFlow.

With these components in place, we are able to run for the first time secure inference on the [ImageNet dataset]([http://www.image-net.org) with the pre-trained models of the following deep neural nets: ResNet-50, DenseNet-121 and SqueezeNet for ImageNet. For an end-to-end tutorial on running models with CrypTFlow please refer to this [blog post](https://pratik-bhatu.medium.com/privacy-preserving-machine-learning-for-healthcare-using-cryptflow-cc6c379fbab7).

## Setup
For setup instructions, please refer to each of the components' readme.

Alternatively you can use the **setup_env_and_build.sh** script. It installs dependencies and builds each component. It also creates a virtual environment in a *mpc_venv* folder with all the required packages. If you want to do setup with default paths and settings do ``./setup_env_and_build.sh quick``, otherwise if you want to manually choose paths you can use ``./setup_env_and_build.sh``.

Please do ``source mpc_venv/bin/activate`` before using the toolchain.

## Secure AI Validation

To setup the repo with modified SCI build such that only secret shares are revealed at the end of 2PC, run the setup script as ``./setup_env_and_build.sh quick NO_REVEAL_OUTPUT``.
Alternatively, just rebuild SCI. For instructions to build modified SCI, see README for SCI.

To build docker image for Secure AI Validation, use the `Dockerfile_AI_Validation` dockerfile.

```docker build -t ezpc_modified - < path/to/EzPC/Dockerfile_AI_Validation```


### Docker
You can use a pre-built docker image from docker hub using ``docker pull ezpc/ezpc:latest``. We occasionally push stable images to that channel. However, if you want a docker image with the latest code, you can build it yourself using:

```docker build -t ezpc_image - < path/to/EzPC/Dockerfile```

## Wiki
Wiki section of this repository provides coding practices and examples to get started with EzPC.

## Issues/Bugs
For bugs and support, please create an issue on the issues page.
# Sytorch

This GitHub repository contains a script that runs a secure Multi-Party Computation (MPC) model to process an image. The script requires certain arguments to be set in order to run correctly.

## Prerequisites
Before running the script, ensure that you have the following:
- The MPC model file in ONNX format
- The image file to be processed in JPG format
- The preprocess.py file to preprocess the image
- The IP address of the server
- Further server and client IP should be whitelisted so they cam communicate over TCP/IP Protocol.

We require the below packages to run OnnxBridge.
- onnx==1.12.0
- onnxruntime==1.12.1
- onnxsim==0.4.8
- numpy==1.21.0
- protobuf==3.20.1
- torchvision==0.13.1
- idx2numpy==1.2.3

Above dependencies can be installed using the [requirements.txt](OnnxBridge/requirements.txt) file as below:
```bash
pip3 install -r OnnxBridge/requirements.txt
```

## Required Arguments
The script requires the following arguments to be set:
- `MODEL_PATH`: the full path to the ONNX MPC model file
- `IMAGE_PATH`: the full path to the input image file
- `PREPROCESS`: the full path to the preprocess.py file
- `SERVER_IP`: the IP address of the server

If any of these arguments are not set, the script will display an error message and exit.

## Optional Arguments
The script also supports the following optional arguments:
- `-b <backend>`: the MPC backend to use (default: `LLAMA`)
- `-scale <scale>`: the scaling factor for the model input (default: `15`)
- `-bl <bitlength>`: the bitlength to use for the MPC computation (default: `40`)

## Running the Script
To run the script, use the following command:
```bash
./ezpc-cli.sh -m <full-path/model.onnx> -preprocess <full-path/preprocess_image_file> -s <server-ip> -i <full-path/image>
```
The above script only works to generate steps for server and client in form of a bash script,
which can be then run on two VM having Server and Client files respectively.
This script generates :
- server.sh -> For server machine and can be run directly using ```./server.sh```.
- ```server.sh``` also generates ```client_model.zip``` which needs to be sent to client VM in the same folder where ```client.sh``` will be executed.
- client.sh -> For client machine and can be run directly using ```./client.sh```.
Loading

0 comments on commit 7376d28

Please sign in to comment.