Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xgb homoeval #549

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions federatedscope/core/configs/cfg_fl_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def extend_fl_setting_cfg(cfg):
# Default values for 'dp': {'bucket_num':100, 'epsilon':None}
# Default values for 'op_boost': {'algo':'global', 'lower_bound':1,
# 'upper_bound':100, 'epsilon':2}
cfg.vertical.eval = ''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comments

cfg.vertical.data_size_for_debug = 0 # use a subset for debug in vfl,
# 0 indicates using the entire dataset (disable debug mode)

Expand Down
4 changes: 3 additions & 1 deletion federatedscope/vertical_fl/loss/binary_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def _process_y_pred(self, y_pred):

def get_metric(self, y, y_pred):
y_pred = self._process_y_pred(y_pred)
from sklearn import metrics
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to top of this file

auc = metrics.roc_auc_score(y, y_pred)
y_pred = (y_pred >= 0.5).astype(np.float32)
acc = np.sum(y_pred == y) / len(y)
return {'acc': acc}
return {'acc': acc, 'auc': auc}

def get_loss(self, y, y_pred):
y_pred = self._process_y_pred(y_pred)
Expand Down
8 changes: 6 additions & 2 deletions federatedscope/vertical_fl/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from federatedscope.vertical_fl.xgb_base.worker import wrap_client_for_train, \
wrap_server_for_train, wrap_client_for_evaluation, \
wrap_server_for_evaluation
from federatedscope.vertical_fl.xgb_base.worker.homo_evaluation_wrapper\
import wrap_client_for_homo_evaluation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

homo - > he



def wrap_vertical_server(server, config):
Expand All @@ -13,7 +15,9 @@ def wrap_vertical_server(server, config):

def wrap_vertical_client(client, config):
if config.vertical.algo in ['xgb', 'gbdt', 'rf']:
if config.vertical.eval == 'homo':
client = wrap_client_for_homo_evaluation(client)
else:
client = wrap_client_for_evaluation(client)
client = wrap_client_for_train(client)
client = wrap_client_for_evaluation(client)

return client
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use_gpu: False
device: 0
backend: torch
federate:
mode: standalone
client_num: 2
model:
type: gbdt_tree
lambda_: 0.1
gamma: 0
num_of_trees: 10
max_tree_depth: 4
data:
root: data/
type: abalone
splits: [0.8, 0.2]
dataloader:
type: raw
batch_size: 2000
criterion:
type: RegressionMSELoss
trainer:
type: verticaltrainer
train:
optimizer:
# learning rate for xgb model
eta: 0.5
vertical:
use: True
dims: [4, 8]
algo: 'gbdt'
data_size_for_debug: 2000
feature_subsample_ratio: 0.5
eval:
freq: 3
best_res_update_round_wise_key: test_loss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use_gpu: False
device: 0
backend: torch
federate:
mode: standalone
client_num: 2
model:
type: random_forest
lambda_: 0.1
gamma: 0
num_of_trees: 10
max_tree_depth: 4
data:
root: data/
type: abalone
splits: [0.8, 0.2]
dataloader:
type: raw
batch_size: 2000
criterion:
type: RegressionMSELoss
trainer:
type: verticaltrainer
vertical:
use: True
dims: [4, 8]
algo: 'rf'
data_size_for_debug: 1500
feature_subsample_ratio: 0.5
eval:
freq: 3
best_res_update_round_wise_key: test_loss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data:
splits: [0.8, 0.2]
dataloader:
type: raw
batch_size: 4000
batch_size: 2000
criterion:
type: RegressionMSELoss
trainer:
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the name of this file

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use_gpu: False
device: 0
backend: torch
federate:
mode: standalone
client_num: 2
model:
type: xgb_tree
lambda_: 0.1
gamma: 0
num_of_trees: 10
max_tree_depth: 3
data:
root: data/
type: adult
splits: [1.0, 0.0]
dataloader:
type: raw
batch_size: 2000
criterion:
type: CrossEntropyLoss
trainer:
type: verticaltrainer
train:
optimizer:
# learning rate for xgb model
eta: 0.5
vertical:
use: True
dims: [7, 14]
algo: 'xgb'
eval: 'homo'
data_size_for_debug: 2000
eval:
freq: 3
best_res_update_round_wise_key: test_loss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use_gpu: False
device: 0
backend: torch
federate:
mode: standalone
client_num: 2
model:
type: xgb_tree
lambda_: 0.1
gamma: 0
num_of_trees: 10
max_tree_depth: 3
data:
root: data/
type: abalone
splits: [0.8, 0.2]
dataloader:
type: raw
batch_size: 2000
criterion:
type: RegressionMSELoss
trainer:
type: verticaltrainer
train:
optimizer:
# learning rate for xgb model
eta: 0.5
vertical:
use: True
dims: [4, 8]
algo: 'xgb'
protect_object: 'feature_order'
protect_method: 'dp'
protect_args: [ { 'bucket_num': 100, 'epsilon': 10 } ]
data_size_for_debug: 2000
eval:
freq: 5
best_res_update_round_wise_key: test_loss
8 changes: 8 additions & 0 deletions federatedscope/vertical_fl/xgb_base/worker/XGBClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def __init__(self,
self.msg_buffer = {'train': {}, 'eval': {}}
self.client_num = self._cfg.federate.client_num

# TODO: the following is used for homo_evaluation,
# which may be put in an if condition
from federatedscope.vertical_fl.Paillier import \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this to the top of this file

abstract_paillier
keys = abstract_paillier.generate_paillier_keypair(
n_length=self._cfg.vertical.key_size)
self.public_key, self.private_key = keys

self.feature_order = None
self.merged_feature_order = None

Expand Down
5 changes: 4 additions & 1 deletion federatedscope/vertical_fl/xgb_base/worker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
wrap_server_for_train, wrap_client_for_train
from federatedscope.vertical_fl.xgb_base.worker.evaluation_wrapper import \
wrap_server_for_evaluation, wrap_client_for_evaluation
from federatedscope.vertical_fl.xgb_base.worker.homo_evaluation_wrapper\
import wrap_client_for_homo_evaluation

__all__ = [
'XGBServer', 'XGBClient', 'wrap_server_for_train', 'wrap_client_for_train',
'wrap_server_for_evaluation', 'wrap_client_for_evaluation'
'wrap_server_for_evaluation', 'wrap_client_for_evaluation',
'wrap_client_for_homo_evaluation'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

]
Loading