SecretFlow 如何安装和初步使用

隐语安装环境:

       - Python>=3.8

       - Ubuntu18+

        - 硬件资源:>=8核16G

隐语安装包:

        - secretflow-lite

隐语推荐安装方式:

        - docker

隐语部署模式:

1) 仿真模式:验证效果

- 单机仿真:

       import secretflow as sf

       sf.init(parties=['alice', 'bob'], address='local')

- 集群仿真 

一个机器执行:

ray start --head --node-ip-address="ip" --port="port" --resources='{"alice": 16}' --include-dashboard=False --disable-usage-stats 

另一个机器执行:

 注意:ip:port 为主节点的 node-ip-address 和 port

ray start --address="ip:port" --resources='{"bob": 16}' --disable-usage-stats

启动Secretflow, 仅仅PYU:

>>> import secretflow as sf
# Replace with the `node-ip-address` and `port` of head node.
>>> sf.init(parties=['alice', 'bob'], address='112.134.32.5:8888')
>>> alice = sf.PYU('alice')
>>> bob = sf.PYU('bob')
>>> alice(lambda x : x)(2)
<secretflow.device.device.pyu.PYUObject object at 0x9fe932a1a645>
>>> bob(lambda x : x)(2)
<secretflow.device.device.pyu.PYUObject object at 0x9fe6fef03252>

 启动SPU:

import spu
import secretflow as sf

# Use ray head adress please.
sf.init(parties=['alice', 'bob'], address='Ray head node address')

cluster_def={
    'nodes': [
        {
            'party': 'alice',
            # Please choose an unused port.
            'address': 'ip:port of alice',
            'listen_addr': '0.0.0.0:port'
        },
        {
            'party': 'bob',
            # Please choose an unused port.
            'address': 'ip:port of bob',
            'listen_addr': '0.0.0.0:port'
        },
    ],
    'runtime_config': {
        'protocol': spu.spu_pb2.SEMI2K,
        'field': spu.spu_pb2.FM128,
        'sigmoid_mode': spu.spu_pb2.RuntimeConfig.SIGMOID_REAL,
    }
}

spu = sf.SPU(cluster_def=cluster_def)

注意:

  1. 请使用主节点的 node-ip-address 和 port 填充 sf.init 的 address 参数。
  2. alice 的 address 请填写可以被bob访通的地址,并且选择一个 未被占用的端口 ,注意不要和Ray端口冲突。
  3. alice 的 listen_addr 可以和alice address里的端口一样。
  4. bob 的 address 请填写可以被alice访通的地址,并且选择一个 未被占用的端口 ,注意不要和Ray端口冲突。
  5. bob 的 listen_addr 可以和bob address里的端口一样。

2) 生产模式:安全增强

Alice的启动Ray网络: 

ray start --head --node-ip-address="ip" --port="port" --include-dashboard=False --disable-usage-stats

配置为:

cluster_config ={
    'parties': {
        'alice': {
            # replace with alice's real address.
            'address': 'ip:port of alice',
            'listen_addr': '0.0.0.0:port'
        },
        'bob': {
            # replace with bob's real address.
            'address': 'ip:port of bob',
            'listen_addr': '0.0.0.0:port'
        },
    },
    'self_party': 'alice'
}

sf.init(address='alice ray head node address', cluster_config=cluster_config)

# your code to run.

Bob启动Ray网络:

ray start --head --node-ip-address="ip" --port="port" --include-dashboard=False --disable-usage-stats

配置为:

cluster_config ={
    'parties': {
        'alice': {
            # replace with alice's real address.
            'address': 'ip:port of alice',
            'listen_addr': '0.0.0.0:port'
        },
        'bob': {
            # replace with bob's real address.
            'address': 'ip:port of bob',
            'listen_addr': '0.0.0.0:port'
        },
    },
    'self_party': 'bob'
}

sf.init(address='bob ray head node address', cluster_config=cluster_config)

# your code to run.

如何启动SPU: 同仿真模式

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
SecretFlow是一个用于保护机密信息的Python库。它提供了下载工具源码和配置Python虚拟环境的步骤,可以通过克隆GitHub仓库、创建虚拟环境和激活虚拟环境来获取SecretFlow的源码。在SecretFlow的官方文档中,你可以找到更详细的教程和说明。在使用SecretFlow时,你可以使用secretflow.init函数以独立模式运行它,并传入一些参数,如'alice', 'bob', 'carol'作为参与者和8个CPU核心的数量。通过这种方式,SecretFlow可以在集群模式下运行,以更高效地保护你的机密信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [SecretFlow:一款功能强大的隐私保护数据分析和机器学习统一框架](https://blog.csdn.net/qq_69775412/article/details/127191864)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [SecretFlow隐语-简介](https://blog.csdn.net/lucklilili/article/details/126409906)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值