mpc-msri / EzPC

MIT License
401 stars 122 forks source link

Automatically generate C++ code for ResNet-32 using EzPC compiler. #153

Closed zwxandy closed 1 year ago

zwxandy commented 1 year ago

Hi, I have a question when I use "EzPC/SCI". As you say, the models in "networks" folder are automatically generated using the EzPC compiler. Now I want to modify the original ResNet architecture (on CIFAR-10 dataset) and then generate its C++ code using EzPC compiler, can I achieve this? Or how can I achieve this? I have a look at "EzPC/SIRNN" which has an instruction of generating C++ code, and we need to use "SeeDot" to quantize the model first. However, It seems that "SeeDot" only supports ['bonsai' or 'protonn' or 'fastgrnn' or 'rnnpool'] algorithms in the code. So, I am a little confused about generating C++ code for ResNet (on CIFAR-10) using EzPC compiler. I would appreciate it very much if you could help me with this question. Thank you!

xingpz2008 commented 1 year ago

I think the following might be helpful.

The input of EzPC module is an .ezpc file, which is protocol-independent. In this repo, author provides Athos, which converts pythonic model (TensorFlow, ONNX-supported Freamworks) to models compatible with EzPC module, with fixed-point encoded input and parameters. After the conversion, the ezpc compiler implement specific protocols (e.g. CryptFlow2, SIRNN, Secfloat) and generate binary executable used by parties. As such, you may refer to Athos parts to see if it helps.

zwxandy commented 1 year ago

I think the following might be helpful.

The input of EzPC module is an .ezpc file, which is protocol-independent. In this repo, author provides Athos, which converts pythonic model (TensorFlow, ONNX-supported Freamworks) to models compatible with EzPC module, with fixed-point encoded input and parameters. After the conversion, the ezpc compiler implement specific protocols (e.g. CryptFlow2, SIRNN, Secfloat) and generate binary executable used by parties. As such, you may refer to Athos parts to see if it helps.

Thanks a lot! In recent days, I really have tried the method you've said above. As a result, I successfully convert different TensorFlow (TF) models into C++ models (even other TF models written by myself) with the help of "EzPC/Athos".

As far as I know, this conversion in "EzPC/Athos" can be set to "SCI-OT/SCI-HE" mode, i.e., different protocols (I set to "SCI-OT"). I follow the instruction in both "EzPC/Athos" and "EzPC/SIRNN", and I get their generated C++ codes. However, I find the C++ code generated by "EzPC/Athos" seems different from the example given in "EzPC/SIRNN". Because SIRNN allows us to adjust the bit-width in each module like MatMul (named "truncate_and_reduce"), but the code generated by "EzPC/Athos" seems not as convenient as the code generated by "EzPC/SIRNN". Specifically, when implementing MatMul, "EzPC/Athos" invokes the protocol in library_fixed_uniform.cpp while "EzPC/SIRNN" invokes the protocol in library_fixed.cpp instead.

I wonder how can I use "ezpc" compiler to implement "SIRNN" protocol as you said, or how can I compile the model using the protocols in library_fixed.cpp. Thank you again!

xingpz2008 commented 1 year ago

Perhaps you can try the following command:

python secureCodegen.py --predict_dir ${EZPC_DIR}/sirnn --ezpc_dir ${EZPC_DIR} --results_dir FastGRNN/Google-30/ 

This command was mentioned in README.md of /EzPC/SIRNN. The input should be an .ezpc file generated by Athos (SeeDot)

zwxandy commented 1 year ago

Perhaps you can try the following command:

python secureCodegen.py --predict_dir ${EZPC_DIR}/sirnn --ezpc_dir ${EZPC_DIR} --results_dir FastGRNN/Google-30/ 

This command was mentioned in README.md of /EzPC/SIRNN. The input should be an .ezpc file generated by Athos (SeeDot)

OK, thanks! I will have a try.

drunkenlegend commented 1 year ago

Marking this issue closed, as no activity. Feel free to reopen in case of anymore queries.