SecretFlow隐私计算框架
SecretFlow是一个开源的隐私计算框架,旨在简化隐私计算技术的使用,支持多方安全计算(MPC)、同态加密(HE)和可信执行环境(TEE)等技术,使数据科学家和开发者无需了解底层细节即可进行数据分析和机器学习建模。
☀️ 社区地址☀️ https://github.com/secretflow/🌺 文档地址 🌺SecretFlow:https://secretflow.readthedocs.io/SPU:https://spu.readthedocs.io/<div class="lake-content" typography="classic"><h2 id="DgRyg" style="font-size: 24px; line-height: 32px; margin: 21px 0 5px 0"><span class="ne-text">一、“隐语”架构设计全貌</span></h2><h3 id="lvY1b" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text">1.隐语框架设计思想</span></h3><p id="u1c747ede" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">隐私计算是一个新兴的跨学科领域,涉及密码学、机器学习、数据库、硬件等多个领域。根据过去几年的实践经验,我们发现</span></p><ul class="ne-ul" style="margin: 0; padding-left: 23px"><li id="u74de1abd" style="line-height: 1.5"><span class="ne-text">隐私计算技术方向多样,不同场景下有其各自更为合适的技术解决方案</span></li><li id="u3b22f52e" style="line-height: 1.5"><span class="ne-text">隐私计算学习曲线很高,非隐私计算背景的用户使用困难</span></li><li id="u4f0c7141" style="line-height: 1.5"><span class="ne-text">隐私计算涉及领域众多,需要领域专家共同协作</span></li></ul><p id="u04a4afd7" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><p id="u8f6646d4" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><img src="https://img.alicdn.com/imgextra/i1/O1CN01WuPuBm1VJVDAIgzF5_!!6000000002632-2-tps-506-558.png" width="351" id="uc2533e20" class="ne-image"></p><p id="u2b36a5a8" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><p id="u109d0453" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">隐语的设计目标是使得数据科学家和机器学习开发者可以非常容易地使用隐私计算技术进行数据分析和机器学习建模,而无需了解底层技术细节。 </span></p><p id="ud5f3a782" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">为达到这个目标,隐语提供了一层设备抽象,将多方安全计算(MPC)、同态加密(HE)和可信执行环境(TEE)等隐私计算技术抽象为密文设备, 将单方计算抽象为明文设备。</span></p><p id="uf3ee57de" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">基于这层抽象,数据分析和机器学习工作流可以表示为一张计算图,其中节点表示某个设备上的计算,边表示设备之间的数据流动,不同类型设备之间的数据流动会自动进行协议转换。在这一点上,隐语借鉴了主流的深度学习框架,后者将神经网络表示为一张由设备上的算子和设备间的张量流动构成的计算图。</span></p><p id="u6ba6591a" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">隐语框架围绕开放这一核心思想,提供了不同层次的设计抽象,希望为不同类型的开发者都提供良好的开发体验。</span></p><p id="uc5b6acdd" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">在设备层,隐语提供了良好的设备接口和协议接口,支持更多的设备和协议插拔式的接入,我们希望与密码学、可信硬件、硬件加速等领域专家通力合作,不断扩展密态计算的类型和功能,不断提升协议的安全性和计算性能。</span></p><p id="ueb8cdbd8" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">同时,隐语提供了良好的设备接口,第三方隐私计算协议可作为设备插拔式接入。在算法层,为机器学习提供了灵活的编程接口,算法开发者可以很容易定义自己的算法。</span></p><p id="u2ae98569" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text"></span></p><h3 id="LhTCy" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text">2.架构分层总览</span></h3><p id="u33aa8bc1" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">隐语总体架构自底向上一共分为五层:</span></p><p id="ub7bb2c41" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><img src="https://img.alicdn.com/imgextra/i4/O1CN0105IBEt1sba0NlZuup_!!6000000005785-2-tps-1966-1118.png" width="983" id="u95dde4dc" class="ne-image"></p><p id="u6900209f" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><strong><span class="ne-text">资源管理层:</span></strong><span class="ne-text">主要承担了两方面的职责。第一是面向业务交付团队,可以屏蔽不同机构底层基础设施的差异,降低业务交付团队的部署运维成本。另一方面,通过对不同机构的资源进行集中式管理,构建出一个高效协作的数据协同网络。</span></p><p id="u2577a6d6" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><strong><span class="ne-text">明密文计算设备与原语层:</span></strong><span class="ne-text">提供了统一的可编程设备抽象,将多方安全计算(MPC)、同态加密(HE)、可信硬件(TEE)等隐私计算技术抽象为密态设备,将单方本地计算抽象为明文设备。同时,提供了一些不适合作为设备抽象的基础算法,如差分隐私(DP)、安全聚合(Secure Aggregation)等。</span></p><p id="ud24910b7" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><strong><span class="ne-text">明密文混合调度层:</span></strong><span class="ne-text">提供了统一的设备调度抽象,将上层算法描述为一张有向无环图,其中节点表示某个设备上的计算,边表示设备之间的数据流动,即逻辑计算图。逻辑计算图由分布式框架进一步拆分并调度至物理节点。</span></p><p id="udca8ae1e" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><strong><span class="ne-text">AI & BI 隐私算法层:</span></strong><span class="ne-text">这一层的目的是屏蔽掉隐私计算技术细节,但保留隐私计算的概念,其目的是降低隐私计算算法的开发门槛,提升开发效率。有隐私计算算法开发诉求的同学,可以根据自身场景和业务的特点,设计出一些特化的隐私计算算法,来满足自身业务和场景对安全性、计算性能和计算精度的平衡。在这一层上,隐语本身也会提供一些通用的算法能力,比如MPC的LR/XGB/NN,联邦学习算法,SQL能力等。</span></p><p id="u6d9fe243" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><strong><span class="ne-text">用户界面层:</span></strong><span class="ne-text">隐语的目标并不是做一个端到端的产品,而是为了让不同的业务都能够通过快速集成隐语而具备全面的隐私计算能力。因此我们会在最上层去提供一层比较薄的产品API,以及一些SDK,去降低业务方集成隐语的成本。</span></p><p id="u42c3a568" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><br></p><h3 id="X9h2r" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text">3.架构细节拆解</span></h3><h4 id="fMIQW" style="font-size: 16px; line-height: 24px; margin: 10px 0 5px 0"><span class="ne-text">设备与原语层</span></h4><p id="u92856f0c" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">隐语的设备分为物理设备和逻辑设备,其中,物理设备是隐私计算各个参与方的物理机器,逻辑设备则由一个或多个物理设备构成。逻辑设备支持一组 特定的计算算子(Device Ops),有自己特定的数据表示(Device Object)<br /></span><span class="ne-text">。逻辑设备分为明文和密文两种类型,前者执行单方本地计算,后者执行 多方参与的隐私计算。</span></p><p id="uf84ad516" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">逻辑设备的运行时负责内存管理、数据传输、算子调度等职责,运行在一个或多个物理设备上。逻辑设备和物理设备不是一对一的关系,一个物理设备 可能同时属于多个逻辑设备。在同一组物理设备上,可以根据不同的隐私协议和参与组合虚拟出不同的逻辑设备。</span></p><p id="u322bc8f4" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><p id="u9f73a49b" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><img src="https://img.alicdn.com/imgextra/i4/O1CN01dWSRVD1ngYEBCoI3g_!!6000000005119-2-tps-1736-1178.png" width="536" id="ued2c358d" class="ne-image"></p><p id="u3dc30028" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><p id="u64ba7545" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">下表是隐语目前暂定支持的设备列表:</span></p>设备 | 类型 | 运行时 | 算子 | 协议 | 前端 | 状态-- | -- | -- | -- | -- | -- | --PYU | 明文 | Python Interpreter | — | — | Python | ReleaseSPU | 密文 | SPU VM | PSI, XLA HLO | SPDZ-2k, ABY3 | JAX, TensorFlow, PyTorch | AlphaHEU | 密文 | HEU Runtime | Add, XLA HLO | Paillier, OU, TFHE | Numpy, JAX | WIPTEE | 密文 | TEE Runtime | XLA HLO | Intel SGX | JAX, TensorFlow, PyTorch | WIP<h4 id="W9BA6" style="font-size: 16px; line-height: 24px; margin: 10px 0 5px 0"><span class="ne-text">分布式引擎</span></h4><p id="u02d2fb7e" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">用户基于设备构建了一张逻辑计算图,那么我们如何执行这张计算图?由于逻辑设备映射到一个或多个物理设备,因此我们需要将逻辑设备上的算子正确调度到其对应的物理设备,同时处理好这些物理设备间的数据传输关系。毫无疑问,我们需要一个分布式图执行引擎来解决这些问题。</span></p><p id="u3fc66f85" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text"></span></p><p id="uff46348a" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text">那么我们需要一个怎样的分布式图执行引擎?以下是隐语对它的要求</span></p><ul class="ne-ul" style="margin: 0; padding-left: 23px"><li id="ucbc25ece" style="line-height: 1.5"><span class="ne-text">细粒度的异构计算:在一张逻辑计算图中,具有不同粒度的计算任务,既有简单的数据处理(秒级),也有复杂的多方训练(几个小时至几十小时)。 同时,物理节点具有不同的硬件环境,CPU, GPU, TEE, FPGA等。</span></li><li id="ua6a45b0f" style="line-height: 1.5"><span class="ne-text">灵活的计算模型:在水平、垂直场景下,针对数据处理和模型训练等不同工作流,支持多种并行模型,如数据并行、模型并行、混合并行。</span></li><li id="uc9062631" style="line-height: 1.5"><span class="ne-text">动态执行:在联邦学习场景下,不同机构的数据规模、带宽延迟、机器性能可能有较大差异,这导致同步模式的效率受限于最慢的工作节点。因此,我们希望支持 异步训练模式,这要求图执行引擎具有动态执行能力。</span></li></ul><p id="u85f9a5e5" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><p id="u131839cc" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><img src="https://intranetproxy.alipay.com/skylark/lark/0/2022/png/30756417/1656333276180-1934918e-ab30-45d5-8cba-56144661cad7.png" width="615" id="ud0c068d3" class="ne-image"></p><p id="u7c260c8c" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><p id="u957ac914" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text">隐语针对隐私计算场景,已经对框架进行了一些安全加固工作:通过身份认证、代码预装、代码存证等手段对框架做了整体加固。未来,还将探索沙箱隔离、访问控制、静态图等机制以进一步提升安全水位。在环境适配方面,为了适配跨机构网络通信的特点,推进了GCS gRPC通信、域名支持、弱网断线处理等相关功能的开发。</span></p><p id="ud3f424f7" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; line-height: 1.5"><span class="ne-text" style="color: #595959"></span></p><h4 id="Hx8YO" style="font-size: 16px; line-height: 24px; margin: 10px 0 5px 0"><strong><span class="ne-text">AI & BI 隐私算法</span></strong><span class="ne-text"></span></h4><p id="u829ee904" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text">这一层的目的是屏蔽掉隐私计算技术细节,但保留隐私计算的概念,其目的是降低隐私计算算法的开发门槛,提升开发效率。有隐私计算算法开发诉求的同学,可以根据自身场景和业务的特点,设计出一些特化的隐私计算算法,来满足自身业务和场景对安全性、计算性能和计算精度的平衡。在这一层上,隐语本身也会提供一些通用的算法能力,比如MPC的LR/XGB/NN,联邦学习算法,SQL能力等。</span></p><p id="ucae8a6d7" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text"></span></p><p id="u9f7a7984" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text">逻辑设备抽象为算法开发者提供了极大的灵活性,他们可以像积木一样自由组合这些设备,在设备上自定义计算,从而构建自己的隐私计算算法。后文第六部分将通过一个具体的算法来展示隐语框架的通用编程能力。</span></p><h2 id="fdQNy" style="font-size: 24px; line-height: 32px; margin: 21px 0 5px 0"><span class="ne-text">二、“隐语”技术发展路径规划</span></h2><p id="u1f80b998" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><img src="https://intranetproxy.alipay.com/skylark/lark/0/2022/png/30756417/1655977184774-bbb39ab1-d89a-4728-9e65-f43c17b4d268.png" width="974" id="ub895b3fa" class="ne-image"></p><p id="u3d16270a" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><br></p><h2 id="BvgfX" style="font-size: 24px; line-height: 32px; margin: 21px 0 5px 0; text-align: left"><span class="ne-text">三、V0.6版本开源内容</span></h2><p id="ua878683f" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; text-align: center"><span class="ne-text" style="color: rgb(0, 0, 0)"><br /></span><img src="https://intranetproxy.alipay.com/skylark/lark/0/2022/png/30756417/1655968898430-8982fc74-774e-4816-85f1-e8a16d510eb4.png" width="669" id="ufc9e7e98" class="ne-image"></p><p id="u7d67021c" class="ne-p" style="margin: 0; padding: 0; min-height: 24px; text-align: center"><span class="ne-text" style="color: rgb(140, 140, 140); font-size: 13px">图:隐语框架V0.6开源模块</span></p><h3 id="XYiaf" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">1. MPC设备。</span></h3><p id="u91cf175c" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">支持大部分Numpy API,支持自动求导,提供LR和NN相关的demo,支持pade 高精度定点数拟合算法,支持 ABY3、 Cheetah 协议。用户可以采用传统的算法编程模式,在不了解MPC协议的情况下开发出基于MPC协议的AI算法</span></p><h3 id="DKRqR" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">2. HE设备。</span></h3><p id="u0c5d137a" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">支持Paillier同态加密算法,向上层提供Numpy编程接口,用户可以使用Numpy接口做矩阵加法或者明密文矩阵乘法运算。且实现了与MPC密态设备之间的数据可流转。</span></p><h3 id="SA74U" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">3.差分隐私安全原语。</span></h3><p id="u7497567d" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">实现了一些差分隐私噪声机制、安全噪声生成器、隐私开销计算器。</span></p><h3 id="GiMgW" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">4. 明密文混合编程。</span></h3><p id="ub32d00c5" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">支持中心化编程模式,使用@device标记构建明文和密文设备混合计算图,基于计算图进行并行、异步任务调度。</span></p><h3 id="jqQ5r" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">5.数据预处理。</span></h3><p id="uddf43686" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">提供水平场景下的数据标准化、离散化、分箱功能,提供垂直场景下的相关系数矩阵、WOE分箱功能。无缝对接已有的dataframe,提供和sklearn一致的使用体感。</span></p><h3 id="gg2Qf" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">6.AI & BI 隐私算法-多方安全计算。</span></h3><p id="u839326f2" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">提供水平场景下的XGBoost算法、新增垂直场景下的HESS-LR算法,并结合差分隐私增强了对拆分学习的隐私保护。</span></p><h3 id="mnZym" style="font-size: 20; line-height: 28px; margin: 16px 0 5px 0"><span class="ne-text" style="color: rgb(0, 0, 0)">7.AI & BI 隐私算法-联邦学习。</span></h3><p id="u13677940" class="ne-p" style="margin: 0; padding: 0; min-height: 24px"><span class="ne-text" style="color: rgb(0, 0, 0)">提供联邦学习模型构建和包括SecureAggregation,MPC Aggregation, PlaintextAggregation在内的多种安全模式的梯度聚合,用户只需要在模型构建时给出参与方list和聚合方法,之后的数据读取,预处理到模型训练的体验和传统明文编程几乎一致。</span></p></div>✨关注我们✨请移步社区使用issue提交进行官方沟通交流隐语小助手微信号:SecretFlow01隐语邮箱:secretflow-contact@service.alipay.com