加密机器学习评估的客户端/服务器框架
项目描述
encrypted-evaluation
一个Python框架,用于构建客户端/服务器应用程序,其中服务器托管用于加密输入评估的模型,然后客户端可以加密其模型输入并将其发送到服务器进行评估,并返回加密结果。
特性
- :fire: 在RESTful API中托管用于加密评估的模型
- :cyclone: 客户端用于向远程API发送用于评估的加密输入
- :zap: CLI实用程序用于加密/解密、生成密钥以及在客户端和服务器之间通信
用法
您可以使用CLI或Python中的编程API使用eeval。
CLI
CLI包含Python安装,并提供有关如何完成的详细说明。我们希望它易于使用。如果您在使用它时遇到困难,请提交问题,让我们知道如何改进。
$ eeval
Usage: eeval [OPTIONS] COMMAND [ARGS]...
Encrypted evaluation with homomorphic encryption
Options:
-v, --verbose verbose level [default: 0]
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or
customize the installation.
--help Show this message and exit.
Commands:
create-context Create a TenSEAL context holding encryption keys and...
decrypt Decrypt a saved tensor
encrypt Encrypt a pickled numpy tensor
eval Evaluate an encrypted input on a remote hosted model
list-models List models available
model-info Get information about a specific model
ping Check if the API at URL is up
serve Start the API server
API
我们展示了一个基本的客户端/服务器应用程序,其中客户端将加密输入发送到服务器以在层(实际上并没有什么用)上进行评估,更高级的使用可以在我们的示例部分中找到。
服务器
这里我们使用了已经实现的线性层模型用于展示目的,否则,您应该通过继承自eeval.server.model.Model
并实现所需方法来实现自己的模型
import eeval.server as server
from eeval import models
# register the LinearLayer model
server.register_model(models.LinearLayer, versions=["0.1"])
server.start(host="localhost", port=8000)
客户端
客户端唯一需要知道的是如何编码和加密其数据,其余部分由eeval.client.Client
处理
from eeval import Client
import tenseal as ts
hostname = "localhost"
port = 8000
client = Client(hostname, port)
# prepare the TenSEAL context
ctx = ts.context(ts.SCHEME_TYPE.CKKS, 8192, -1, [60, 40, 60])
ctx.global_scale = 2 ** 40
ctx.generate_galois_keys()
# we know that the model hosted on the server needs a vector of 16 as input
vec = [0.1] * 16
enc_vec = ts.ckks_vector(ctx, vec)
# print some info about the models hosted on the server
models = client.list_models()
print("============== Models ==============")
print("")
for i, model in enumerate(models):
print(f"[{i + 1}] Model {model['model_name']}:")
print(f"[*] Description: {model['description']}")
print(f"[*] Versions: {model['versions']}")
print(f"[*] Default version: {model['default_version']}")
print("")
print("====================================")
# send the encrypted input and get encrypted output
result = client.evaluate(model_name="LinearLayer", context=ctx, ckks_vector=enc_vec)
print(f"decrypted result from the server: {result.decrypt()}")
安装
$ pip install eeval
示例
TBD
许可
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
本版本没有可用的源代码分发文件。请参阅生成分发存档的教程。
构建分发
eeval-0.1.2-py3-none-any.whl (27.1 kB 查看哈希值)