Closed Niclouge closed 1 year ago
在运行程序时,端口监听情况如下:
嗨,@Niclouge辛苦把代码贴的全一些?我复现是没有问题的 代码 请参考:
import spu
import sys
import time
import logging
from sklearn.metrics import roc_auc_score
import secretflow as sf
from secretflow.data import FedNdarray, PartitionWay
from secretflow.device.driver import reveal
from secretflow.ml.boost.sgb_v import Sgb
from sklearn.metrics import roc_auc_score
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
parties = {
'alice': {
'address': 'xxx:9494'
},
'bob': {
'address': 'xxx:9495'
}
}
cluster_config ={
'parties': parties,
'self_party': sys.argv[1]
}
alice_ip = 'xxx仅是ip'
bob_ip = 'xxx仅是ip'
ip_party_map = {bob_ip:'bob', alice_ip:'alice'}
_system_config = {'lineage_pinning_enabled':False}
sf.shutdown()
# init cluster
sf.init(address='local', cluster_config=cluster_config, _system_config = _system_config, object_store_memory = 5 * 1024 * 1024 * 1024)
# SPU settings
cluster_def = {
'nodes': [
{'party': 'alice', 'id': 'local:0', 'address': 'xxx:9594'},
{'party': 'bob', 'id': 'local:1', 'address': 'xxx:9595'},
],
'runtime_config': {
# SEMI2K support 2/3 PC, ABY3 only support 3PC, CHEETAH only support 2PC.
# pls pay attention to size of nodes above. nodes size need match to PC setting.
'protocol': spu.spu_pb2.SEMI2K,
'field': spu.spu_pb2.FM128,
},
}
# HEU settings
heu_config = {
'sk_keeper': {'party': 'alice'},
'evaluators': [{'party': 'bob'}],
'mode': 'PHEU',
'he_parameters': {
# ou is a fast encryption schema that is as secure as paillier.
'schema': 'ou',
'key_pair': {
'generate': {
# bit size should be 2048 to provide sufficient security.
'bit_size': 2048,
},
},
},
'encoding': {
'cleartext_type': 'DT_I32',
'encoder': "IntegerEncoder",
'encoder_args': {"scale": 1},
}
}
alice = sf.PYU('alice')
bob = sf.PYU('bob')
heu = sf.HEU(heu_config, cluster_def['runtime_config']['field'])
from sklearn.datasets import load_breast_cancer
ds = load_breast_cancer()
x, y = ds['data'], ds['target']
v_data = FedNdarray(
{
alice: (alice(lambda: x[:, :15])()),
bob: (bob(lambda: x[:, 15:])()),
},
partition_way=PartitionWay.VERTICAL,
)
label_data = FedNdarray(
{alice: (alice(lambda: y)())},
partition_way=PartitionWay.VERTICAL,
)
params = {
'num_boost_round': 5,
'max_depth': 5,
# about 13 bin numbers
'sketch_eps': 0.08,
# use 'linear' if want to do regression
# for classification, currently only supports binary classfication
'objective': 'logistic',
'reg_lambda': 0.3,
'subsample': 0.9,
'colsample_by_tree': 0.9,
}
sgb = Sgb(heu)
model = sgb.train(params, v_data, label_data)
yhat = model.predict(v_data)
yhat = reveal(yhat)
print(f"auc: {roc_auc_score(y, yhat)}")
我已经找到问题,原来SPU的配置还会和下面的HEU配置挂钩, 在HEU中的sk-keeper必须和PYU命名一致
Issue Type
Bug
Source
binary
Secretflow Version
secretflow 0.8.1b1
OS Platform and Distribution
ubuntu 20.04
Python version
3.8.16
Bazel version
No response
GCC/Compiler version
No response
What happend and What you expected to happen.
Reproduction code to reproduce the issue.