-
Notifications
You must be signed in to change notification settings - Fork 249
Dev caesar vfl #346
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
base: master
Are you sure you want to change the base?
Dev caesar vfl #346
Changes from all commits
b62c19f
3a3d464
a7db665
6696f66
e109608
9ed2bcd
7d99dc9
8d2f8ca
c987069
964a259
c91cb91
4f5fdfe
d52aa81
142f449
7f8752f
4a56999
5acead8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,14 +24,14 @@ class AdditiveSecretSharing(SecretSharing): | |
| AdditiveSecretSharing class, which can split a number into frames and | ||
| recover it by summing up | ||
| """ | ||
| def __init__(self, shared_party_num, size=60): | ||
| def __init__(self, shared_party_num, size=20): | ||
| super(SecretSharing, self).__init__() | ||
| assert shared_party_num > 1, "AdditiveSecretSharing require " \ | ||
| "shared_party_num > 1" | ||
| self.shared_party_num = shared_party_num | ||
| self.maximum = 2**size | ||
| self.mod_number = 2 * self.maximum + 1 | ||
| self.epsilon = 1e8 | ||
| self.epsilon = 1e4 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, setting 1e-8 will not be better, and sometimes worse depending on the size below |
||
| self.mod_funs = np.vectorize(lambda x: x % self.mod_number) | ||
| self.float2fixedpoint = np.vectorize(self._float2fixedpoint) | ||
| self.fixedpoint2float = np.vectorize(self._fixedpoint2float) | ||
|
|
@@ -73,16 +73,23 @@ def secret_reconstruct(self, secret_seq): | |
| To recover the secret | ||
| """ | ||
| assert len(secret_seq) == self.shared_party_num | ||
| merge_model = secret_seq[0].copy() | ||
| merge_model = None | ||
| secret_seq = [np.asarray(x) for x in secret_seq] | ||
| if isinstance(merge_model, dict): | ||
| for key in merge_model: | ||
| for idx in range(len(secret_seq)): | ||
| if idx == 0: | ||
| merge_model[key] = secret_seq[idx][key] | ||
| merge_model[key] = secret_seq[idx][key].copy() | ||
| else: | ||
| merge_model[key] += secret_seq[idx][key] | ||
| merge_model[key] = self.fixedpoint2float(merge_model[key]) | ||
|
|
||
| else: | ||
| for idx in range(len(secret_seq)): | ||
| if idx == 0: | ||
| merge_model = secret_seq[idx].copy() | ||
| else: | ||
| merge_model += secret_seq[idx] | ||
| merge_model = self.fixedpoint2float(merge_model) | ||
| return merge_model | ||
|
|
||
| def _float2fixedpoint(self, x): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| ### Caesar Vertical Federated Learning | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can move this README.md to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
|
||
| We provide an example for seCure lArge-scalE SpArse logistic Regression (caesar) vertical federated learning, you can run with: | ||
| ```bash | ||
| python3 ../../main.py --cfg caesar_v_fl.yaml | ||
| ``` | ||
|
|
||
| Implementation of caesar vertical FL refer to `When Homomorphic Encryption | ||
| Marries Secret Sharing: Secure Large-Scale Sparse Logistic Regression and | ||
| Applications in Risk Control` [Chen, et al., 2021] | ||
| (https://arxiv.org/abs/2008.08753) | ||
|
|
||
| You can specify customized configurations in `caesar_v_fl.yaml`, such as `data.type` and `federate.total_round_num`. | ||
|
|
||
|
|
||
| Note that FederatedScope only provide an `abstract_paillier`, user can refer to [pyphe](https://github.com/data61/python-paillier/blob/master/phe/paillier.py) for the detail implementation, or adopt other homomorphic encryption algorithms. | ||
|
|
||
| More support for vertical federated learning is coming soon! We really appreciate any contributions to FederatedScope ! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from federatedscope.vertical.Paillier.abstract_paillier import * |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| use_gpu: False | ||
| federate: | ||
| mode: standalone | ||
| client_num: 2 | ||
| total_round_num: 30 | ||
| model: | ||
| type: lr | ||
| use_bias: False | ||
| train: | ||
| optimizer: | ||
| lr: 0.001 | ||
| data: | ||
| type: caesar_v_fl_data | ||
| batch_size: 50 | ||
| caesar_vertical: | ||
| use: True | ||
| key_size: 256 | ||
| trainer: | ||
| type: none | ||
| eval: | ||
| freq: 5 | ||
| best_res_update_round_wise_key: test_loss |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from federatedscope.vertical.caesar_v_fl.worker.vertical_client \ | ||
| import vFLClient | ||
| from federatedscope.vertical.caesar_v_fl.worker.vertical_server \ | ||
| import vFLServer | ||
|
|
||
| __all__ = ['vFLServer', 'vFLClient'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, setting
size=20is not secure hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about 50? I tried epsilon=1e4 and size=50, and the acc is 0.82. Making size larger, the acc will decrease.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why the acc would be affected by the
size