Skip to content

Commit

Permalink
use encrypt_tensor api for phe encryptor(#4659)
Browse files Browse the repository at this point in the history
edit fate_test examples(#5008)
replace Intersection with PSI in examples

Signed-off-by: Yu Wu <yolandawu131@gmail.com>
  • Loading branch information
nemirorox committed Aug 9, 2023
1 parent 329387d commit 2db064d
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 113 deletions.
18 changes: 9 additions & 9 deletions examples/benchmark_quality/linr/fate-linr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import argparse

from fate_client.pipeline import FateFlowPipeline
from fate_client.pipeline.components.fate import CoordinatedLinR, Intersection
from fate_client.pipeline.components.fate import CoordinatedLinR, PSI
from fate_client.pipeline.components.fate import Evaluation
from fate_client.pipeline.interface import DataWarehouseChannel
from fate_client.pipeline.utils import test_utils
Expand All @@ -43,11 +43,11 @@ def main(config="../../config.yaml", param="./linr_config.yaml", namespace=""):

pipeline = FateFlowPipeline().set_roles(guest=guest, host=host, arbiter=arbiter)

intersect_0 = Intersection("intersect_0", method="raw")
intersect_0.guest.component_setting(input_data=DataWarehouseChannel(name=guest_train_data["name"],
namespace=guest_train_data["namespace"]))
intersect_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name=host_train_data["name"],
namespace=host_train_data["namespace"]))
psi_0 = PSI("psi_0")
psi_0.guest.component_setting(input_data=DataWarehouseChannel(name=guest_train_data["name"],
namespace=guest_train_data["namespace"]))
psi_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name=host_train_data["name"],
namespace=host_train_data["namespace"]))

linr_param = {
}
Expand All @@ -63,10 +63,10 @@ def main(config="../../config.yaml", param="./linr_config.yaml", namespace=""):
}
linr_param.update(config_param)
linr_0 = CoordinatedLinR("linr_0",
train_data=intersect_0.outputs["output_data"],
train_data=psi_0.outputs["output_data"],
**config_param)
"""linr_1 = CoordinatedLinR("linr_1",
test_data=intersect_0.outputs["output_data"],
test_data=psi_0.outputs["output_data"],
input_model=linr_0.outputs["output_model"])"""

evaluation_0 = Evaluation("evaluation_0",
Expand All @@ -77,7 +77,7 @@ def main(config="../../config.yaml", param="./linr_config.yaml", namespace=""):
"rmse"],
input_data=linr_0.outputs["train_output_data"])

pipeline.add_task(intersect_0)
pipeline.add_task(psi_0)
pipeline.add_task(linr_0)
# pipeline.add_task(linr_1)
pipeline.add_task(evaluation_0)
Expand Down
6 changes: 3 additions & 3 deletions examples/benchmark_quality/lr/breast_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ init_param:
learning_rate_scheduler:
method: "constant"
scheduler_params:
factor: 1.0
factor: 0.5
total_iters: 5
optimizer:
method: "rmsprop"
penalty: "l2"
optimizer_params:
lr: 0.12
alpha: 0.1
lr: 0.15
alpha: 0.01
batch_size: 240
early_stop: "diff"
72 changes: 36 additions & 36 deletions examples/benchmark_quality/lr/lr_benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,24 @@ data:
table_name: vehicle_scale_hetero_host
namespace: experiment
role: host_0
#hetero_lr-binary-0-breast:
# local:
# script: "./sklearn-lr-binary.py"
# conf: "./breast_lr_sklearn_config.yaml"
# FATE-hetero-lr:
# script: "./pipeline-lr-binary.py"
# conf: "./breast_config.yaml"
# compare_setting:
# relative_tol: 0.01
#hetero_lr-binary-1-default-credit:
# local:
# script: "./sklearn-lr-binary.py"
# conf: "./default_credit_lr_sklearn_config.yaml"
# FATE-hetero-lr:
# script: "./pipeline-lr-binary.py"
# conf: "./default_credit_config.yaml"
# compare_setting:
# relative_tol: 0.01
hetero_lr-binary-0-breast:
local:
script: "./sklearn-lr-binary.py"
conf: "./breast_lr_sklearn_config.yaml"
FATE-hetero-lr:
script: "./pipeline-lr-binary.py"
conf: "./breast_config.yaml"
compare_setting:
relative_tol: 0.01
hetero_lr-binary-1-default-credit:
local:
script: "./sklearn-lr-binary.py"
conf: "./default_credit_lr_sklearn_config.yaml"
FATE-hetero-lr:
script: "./pipeline-lr-binary.py"
conf: "./default_credit_config.yaml"
compare_setting:
relative_tol: 0.01
hetero_lr-binary-2-epsilon-5k:
local:
script: "./sklearn-lr-binary.py"
Expand All @@ -206,21 +206,21 @@ hetero_lr-binary-2-epsilon-5k:
conf: "./epsilon_5k_config.yaml"
compare_setting:
relative_tol: 0.01
#hetero_lr-binary-3-give-credit:
# local:
# script: "./sklearn-lr-binary.py"
# conf: "./give_credit_lr_sklearn_config.yaml"
# FATE-hetero-lr:
# script: "./pipeline-lr-binary.py"
# conf: "./give_credit_config.yaml"
# compare_setting:
# relative_tol: 0.01
#multi-vehicle:
# local:
# script: "./sklearn-lr-multi.py"
# conf: "./vehicle_lr_sklearn_config.yaml"
# FATE-hetero-lr:
# script: "./pipeline-lr-multi.py"
# conf: "./vehicle_config.yaml"
# compare_setting:
# relative_tol: 0.01
hetero_lr-binary-3-give-credit:
local:
script: "./sklearn-lr-binary.py"
conf: "./give_credit_lr_sklearn_config.yaml"
FATE-hetero-lr:
script: "./pipeline-lr-binary.py"
conf: "./give_credit_config.yaml"
compare_setting:
relative_tol: 0.01
multi-vehicle:
local:
script: "./sklearn-lr-multi.py"
conf: "./vehicle_lr_sklearn_config.yaml"
FATE-hetero-lr:
script: "./pipeline-lr-multi.py"
conf: "./vehicle_config.yaml"
compare_setting:
relative_tol: 0.01
18 changes: 9 additions & 9 deletions examples/benchmark_quality/lr/pipeline-lr-binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import argparse

from fate_client.pipeline import FateFlowPipeline
from fate_client.pipeline.components.fate import CoordinatedLR, Intersection
from fate_client.pipeline.components.fate import CoordinatedLR, PSI
from fate_client.pipeline.components.fate import Evaluation
from fate_client.pipeline.interface import DataWarehouseChannel
from fate_client.pipeline.utils import test_utils
Expand Down Expand Up @@ -45,11 +45,11 @@ def main(config="../../config.yaml", param="./breast_config.yaml", namespace="")
host_train_data = {"name": host_data_table, "namespace": f"experiment{namespace}"}
pipeline = FateFlowPipeline().set_roles(guest=guest, host=host, arbiter=arbiter)

intersect_0 = Intersection("intersect_0", method="raw")
intersect_0.guest.component_setting(input_data=DataWarehouseChannel(name=guest_train_data["name"],
namespace=guest_train_data["namespace"]))
intersect_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name=host_train_data["name"],
namespace=host_train_data["namespace"]))
psi_0 = PSI("psi_0")
psi_0.guest.component_setting(input_data=DataWarehouseChannel(name=guest_train_data["name"],
namespace=guest_train_data["namespace"]))
psi_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name=host_train_data["name"],
namespace=host_train_data["namespace"]))

lr_param = {
}
Expand All @@ -65,10 +65,10 @@ def main(config="../../config.yaml", param="./breast_config.yaml", namespace="")
}
lr_param.update(config_param)
lr_0 = CoordinatedLR("lr_0",
train_data=intersect_0.outputs["output_data"],
train_data=psi_0.outputs["output_data"],
**lr_param)
lr_1 = CoordinatedLR("lr_1",
test_data=intersect_0.outputs["output_data"],
test_data=psi_0.outputs["output_data"],
input_model=lr_0.outputs["output_model"])

evaluation_0 = Evaluation("evaluation_0",
Expand All @@ -77,7 +77,7 @@ def main(config="../../config.yaml", param="./breast_config.yaml", namespace="")
metrics=["auc", "binary_precision", "binary_accuracy", "binary_recall"],
input_data=lr_0.outputs["train_output_data"])

pipeline.add_task(intersect_0)
pipeline.add_task(psi_0)
pipeline.add_task(lr_0)
pipeline.add_task(lr_1)
pipeline.add_task(evaluation_0)
Expand Down
18 changes: 9 additions & 9 deletions examples/benchmark_quality/lr/pipeline-lr-multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import argparse

from fate_client.pipeline import FateFlowPipeline
from fate_client.pipeline.components.fate import CoordinatedLR, Intersection
from fate_client.pipeline.components.fate import CoordinatedLR, PSI
from fate_client.pipeline.components.fate import Evaluation
from fate_client.pipeline.interface import DataWarehouseChannel
from fate_client.pipeline.utils import test_utils
Expand All @@ -44,11 +44,11 @@ def main(config="../../config.yaml", param="./vehicle_config.yaml", namespace=""
host_train_data = {"name": host_data_table, "namespace": f"experiment{namespace}"}
pipeline = FateFlowPipeline().set_roles(guest=guest, host=host, arbiter=arbiter)

intersect_0 = Intersection("intersect_0", method="raw")
intersect_0.guest.component_setting(input_data=DataWarehouseChannel(name=guest_train_data["name"],
namespace=guest_train_data["namespace"]))
intersect_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name=host_train_data["name"],
namespace=host_train_data["namespace"]))
psi_0 = PSI("psi_0")
psi_0.guest.component_setting(input_data=DataWarehouseChannel(name=guest_train_data["name"],
namespace=guest_train_data["namespace"]))
psi_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name=host_train_data["name"],
namespace=host_train_data["namespace"]))

lr_param = {
}
Expand All @@ -64,15 +64,15 @@ def main(config="../../config.yaml", param="./vehicle_config.yaml", namespace=""
}
lr_param.update(config_param)
lr_0 = CoordinatedLR("lr_0",
train_data=intersect_0.outputs["output_data"],
train_data=psi_0.outputs["output_data"],
**config_param)
lr_1 = CoordinatedLR("lr_1",
test_data=intersect_0.outputs["output_data"],
test_data=psi_0.outputs["output_data"],
input_model=lr_0.outputs["output_model"])

evaluation_0 = Evaluation('evaluation_0',
metrics=['multi_recall', 'multi_accuracy', 'multi_precision'])
pipeline.add_task(intersect_0)
pipeline.add_task(psi_0)
pipeline.add_task(lr_0)
pipeline.add_task(lr_1)
pipeline.add_task(evaluation_0)
Expand Down
33 changes: 17 additions & 16 deletions examples/pipeline/coordinated_lr/test_lr_sid.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import argparse

from fate_client.pipeline import FateFlowPipeline
from fate_client.pipeline.components.fate import CoordinatedLR, Intersection
from fate_client.pipeline.components.fate import CoordinatedLR, PSI
from fate_client.pipeline.components.fate import Evaluation
from fate_client.pipeline.interface import DataWarehouseChannel
from fate_client.pipeline.utils import test_utils
Expand All @@ -36,42 +36,43 @@ def main(config="./config.yaml", namespace=""):
if config.timeout:
pipeline.conf.set("timeout", config.timeout)

intersect_0 = Intersection("intersect_0", method="raw")
intersect_0.guest.component_setting(input_data=DataWarehouseChannel(name="breast_hetero_guest",
namespace=f"experiment{namespace}"))
intersect_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name="breast_hetero_host",
namespace=f"experiment{namespace}"))
psi_0 = PSI("psi_0")
psi_0.guest.component_setting(input_data=DataWarehouseChannel(name="breast_hetero_guest",
namespace=f"experiment{namespace}"))
psi_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name="breast_hetero_host",
namespace=f"experiment{namespace}"))
lr_0 = CoordinatedLR("lr_0",
epochs=4,
epochs=10,
batch_size=None,
optimizer={"method": "SGD", "optimizer_params": {"lr": 0.01}},
init_param={"fit_intercept": True, "method": "zeros"},
train_data=intersect_0.outputs["output_data"],
learning_rate_scheduler={"method": "constant", "scheduler_params": {"factor": 1.0,
"total_iters": 100}})
optimizer={"method": "SGD", "optimizer_params": {"lr": 0.21}},
init_param={"fit_intercept": True, "method": "random_uniform"},
train_data=psi_0.outputs["output_data"],
learning_rate_scheduler={"method": "linear", "scheduler_params": {"start_factor": 0.7,
"total_iters": 100}})

evaluation_0 = Evaluation("evaluation_0",
label_column_name="y",
runtime_roles=["guest"],
default_eval_setting="binary",
input_data=lr_0.outputs["train_output_data"])

pipeline.add_task(intersect_0)
pipeline.add_task(psi_0)
pipeline.add_task(lr_0)
pipeline.add_task(evaluation_0)

pipeline.compile()
print(pipeline.get_dag())
pipeline.fit()

pipeline.deploy([intersect_0, lr_0])
pipeline.deploy([psi_0, lr_0])

predict_pipeline = FateFlowPipeline()

deployed_pipeline = pipeline.get_deployed_pipeline()
deployed_pipeline.intersect_0.guest.component_setting(
deployed_pipeline.psi_0.guest.component_setting(
input_data=DataWarehouseChannel(name="breast_hetero_guest",
namespace=f"experiment{namespace}"))
deployed_pipeline.intersect_0.hosts[0].component_setting(
deployed_pipeline.psi_0.hosts[0].component_setting(
input_data=DataWarehouseChannel(name="breast_hetero_host",
namespace=f"experiment{namespace}"))

Expand Down
16 changes: 8 additions & 8 deletions examples/pipeline/coordinated_lr/test_lr_sid_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import argparse

from fate_client.pipeline import FateFlowPipeline
from fate_client.pipeline.components.fate import CoordinatedLR, Intersection
from fate_client.pipeline.components.fate import CoordinatedLR, PSI
from fate_client.pipeline.interface import DataWarehouseChannel
from fate_client.pipeline.utils import test_utils

Expand All @@ -34,20 +34,20 @@ def main(config="./config.yaml", namespace=""):
if config.timeout:
pipeline.conf.set("timeout", config.timeout)

intersect_0 = Intersection("intersect_0", method="raw")
intersect_0.guest.component_setting(input_data=DataWarehouseChannel(name="breast_hetero_guest",
namespace=f"experiment{namespace}"))
intersect_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name="breast_hetero_host",
namespace=f"experiment{namespace}"))
psi_0 = PSI("psi_0")
psi_0.guest.component_setting(input_data=DataWarehouseChannel(name="breast_hetero_guest",
namespace=f"experiment{namespace}"))
psi_0.hosts[0].component_setting(input_data=DataWarehouseChannel(name="breast_hetero_host",
namespace=f"experiment{namespace}"))
lr_0 = CoordinatedLR("lr_0",
epochs=2,
batch_size=100,
optimizer={"method": "sgd", "optimizer_params": {"lr": 0.01}},
init_param={"fit_intercept": True},
cv_data=intersect_0.outputs["output_data"],
cv_data=psi_0.outputs["output_data"],
cv_param={"n_splits": 3})

pipeline.add_task(intersect_0)
pipeline.add_task(psi_0)
pipeline.add_task(lr_0)
pipeline.compile()
print(pipeline.get_dag())
Expand Down
Loading

0 comments on commit 2db064d

Please sign in to comment.