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

Update Secure XGBoost example w.r.t. XGBoost's code changes #2686

Merged
merged 54 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
874192c
Initial commit for xgboost-secure
ZiyueXu77 Jan 31, 2024
6d495e1
Initial commit for xgboost-secure
ZiyueXu77 Jan 31, 2024
79077e6
Change model output path
ZiyueXu77 Jan 31, 2024
ec18079
Change data mode
ZiyueXu77 Jan 31, 2024
e559659
Most basic xgboost process for coding
ZiyueXu77 Jan 31, 2024
1a94339
Most basic xgboost process for coding
ZiyueXu77 Feb 6, 2024
49a38d2
Most basic xgboost process for coding
ZiyueXu77 Feb 6, 2024
5af1e44
Most basic xgboost process for coding
ZiyueXu77 Feb 6, 2024
9dd5204
First prototype for secure vertical pipeline
ZiyueXu77 Feb 7, 2024
5e93842
Phase 1 concludes
ZiyueXu77 Feb 8, 2024
c26ce67
add seal pipeline in C++
ZiyueXu77 Feb 15, 2024
5059f29
experiment will more tree depth to ensure correct node behavior
ZiyueXu77 Feb 23, 2024
a6f041d
experiment will more tree depth to ensure correct node behavior
ZiyueXu77 Feb 23, 2024
4decc5e
update secureboost eval bench
ZiyueXu77 Feb 27, 2024
d3b42b4
set header to none for sample alignment
ZiyueXu77 Mar 15, 2024
ca3211f
config processor interface from python
ZiyueXu77 Apr 12, 2024
106f4ed
simplify data preparation, add horizontal testing codes
ZiyueXu77 Apr 22, 2024
4b66301
remove redundants
ZiyueXu77 Apr 22, 2024
1dc7ad6
horizontal exps
ZiyueXu77 Apr 26, 2024
9010d7a
Merge branch 'NVIDIA:main' into secureboost
ZiyueXu77 Apr 30, 2024
6bd6e37
update scripts
ZiyueXu77 May 2, 2024
ae75d1d
update test scripts
ZiyueXu77 May 20, 2024
b2edc5b
add feature tests
ZiyueXu77 May 24, 2024
fe70f9c
update to align all outputs' format
ZiyueXu77 May 29, 2024
9b83c68
remove conflict
ZiyueXu77 Jun 12, 2024
7c2fa9b
Merge branch 'main' into secureboost
ZiyueXu77 Jun 12, 2024
dbcba1f
reorganize
ZiyueXu77 Jun 12, 2024
2d3a3ef
format
ZiyueXu77 Jun 12, 2024
aed8219
add flare jobs
ZiyueXu77 Jun 12, 2024
e065a75
add readme and experiment results
ZiyueXu77 Jun 13, 2024
ad0ec98
Merge branch 'main' into secureboost
ZiyueXu77 Jun 13, 2024
ace2b79
Merge branch 'main' into secureboost
ZiyueXu77 Jun 14, 2024
1fc731a
Merge branch 'main' into secureboost
ZiyueXu77 Jun 14, 2024
2ffa5ee
update secure xgboost example to align with new xgboost branch
ZiyueXu77 Jul 10, 2024
c54db5d
update secure xgboost example to align with new xgboost branch
ZiyueXu77 Jul 10, 2024
364e28d
Merge branch 'main' into secureboost
ZiyueXu77 Jul 10, 2024
f322361
add gpu scripts
ZiyueXu77 Jul 15, 2024
51226b4
modify split for gpu exp
ZiyueXu77 Jul 15, 2024
62f8796
modify split for gpu exp
ZiyueXu77 Jul 15, 2024
b8df4fd
Merge branch 'NVIDIA:main' into secureboost
ZiyueXu77 Jul 16, 2024
fa515cc
refine readme with Yuanting's inputs
ZiyueXu77 Jul 16, 2024
e84f901
update gpu scripts
ZiyueXu77 Jul 16, 2024
c6a1ccb
update gpu scripts
ZiyueXu77 Jul 16, 2024
a1eed18
update gpu script
ZiyueXu77 Jul 16, 2024
ca66e36
data preparation minor update
ZiyueXu77 Jul 18, 2024
fe8190b
Merge branch 'NVIDIA:main' into secureboost
ZiyueXu77 Jul 19, 2024
9f9ffc0
consolidate all testing scripts
ZiyueXu77 Jul 23, 2024
e650635
Merge branch 'main' into secureboost
ZiyueXu77 Jul 23, 2024
a4d15c2
Merge branch 'NVIDIA:main' into secureboost
ZiyueXu77 Aug 12, 2024
0db0b02
update readme and standalone scripts
ZiyueXu77 Aug 12, 2024
57bb3dc
format update
ZiyueXu77 Aug 12, 2024
4bf17c0
format update
ZiyueXu77 Aug 12, 2024
e6c75fe
minor refinements
ZiyueXu77 Aug 12, 2024
17e6aa4
Merge branch 'main' into secureboost
ZiyueXu77 Aug 12, 2024
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
60 changes: 41 additions & 19 deletions examples/advanced/xgboost_secure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ In this example, we further extend the existing horizontal and vertical federate

In the following, we illustrate both *horizontal* and *vertical* federated XGBoost, *without* and *with* homomorphic encryption. Please refer to our [documentation]() for more details on the pipeline design and the encryption logic.

## Installation
To be able to run all the examples, please install the requirements first.
```
pip install -r requirements.txt
```

## Data Preparation
### Download and Store Data
To run the examples, we first download the dataset from this [link](https://www.kaggle.com/datasets/mlg-ulb/creditcardfraud), which is a single `.csv` file.
Expand Down Expand Up @@ -43,16 +49,44 @@ For more details regarding federated XGBoost and the interface-plugin design, pl

To run all experiments, we provide a script for all settings.
```
bash run_training_local.sh
bash run_training_standalone.sh
```
This will cover baseline centralized training, local FL with and without secure feature.

From the results, we can have three observations:
## Run Federated Experiments with NVFlare
Next, we run the federated XGBoost training without and with homomorphic encryption using NVFlare.
We run the NVFlare jobs using simulator with:
```
bash run_training_fl.sh
```
The running time of each job depends mainly on the encryption workload.

## Results
Comparing the AUC results with centralized baseline, we have four observations:
1. The performance of the model trained with homomorphic encryption is identical to its counterpart without encryption.
2. Vertical federated learnings have identical performance as the centralized baseline.
3. Horizontal federated learnings have performance slightly different from the centralized baseline. This is because under horizontal FL, the local histogram quantiles are based on the local data distribution, which may not be the same as the global distribution.
2. Vertical federated learning (both secure and non-secure) have identical performance as the centralized baseline.
3. Horizontal federated learning (both secure and non-secure) have performance slightly different from the centralized baseline. This is because under horizontal FL, the local histogram quantiles are based on the local data distribution, which may not be the same as the global distribution.
4. GPU leads to different results compared to CPU, which is expected as the GPU involves some data conversions.
YuanTingHsieh marked this conversation as resolved.
Show resolved Hide resolved

Below are sample results for CPU training:

The AUC of vertical learning (both secure and non-secure):
```
[0] eval-auc:0.90515 train-auc:0.92747
[1] eval-auc:0.90516 train-auc:0.92748
[2] eval-auc:0.90518 train-auc:0.92749
```
The AUC of horizontal learning (both secure and non-secure):
```
[0] eval-auc:0.89789 train-auc:0.92732
[1] eval-auc:0.89791 train-auc:0.92733
[2] eval-auc:0.89791 train-auc:0.92733
```

Upon closer inspection over the tree models (under `/tmp/nvflare/xgb_exp`), we can observe that the tree structures are identical between the baseline and the vertical FL models, while different for horizontal models. Further, the secure vertical FL produces different tree records at different parties - because each party holds different feature subsets:
Comparing the tree models with centralized baseline, we have the following observations:
1. Vertical federated learning (non-secure) has exactly the same tree model as the centralized baseline.
2. Vertical federated learning (secure) has the same tree structures as the centralized baseline, however, it produces produces different tree records at different parties - because each party holds different feature subsets, as illustrated below.
3. Horizontal federated learning (both secure and non-secure) have different tree models from the centralized baseline.

| ![Tree Structures](./figs/tree.base.png) |
|:-------------------------------------------------:|
Expand All @@ -68,17 +102,5 @@ In this case we can notice that Party 0 holds Feature 7 and 10, Party 1 holds Fe

By combining the feature splits at all parties, the tree structures will be identical to the centralized baseline model.

## Run Federated Experiments with NVFlare
Next, we run the federated XGBoost training without and with homomorphic encryption using NVFlare. This time, instead of using the `mock` plugin, we use the real encryption plugins to perform homomorphic encryption.
We run the NVFlare jobs with:
```
bash run_training_fl.sh
```
The running time of each job depends mainly on the encryption workload.




To add:
- link to the documentation
- FL job results and time comparison, specify the computation environment
## Different Encryption Plugins
We can switch to different plugins for encryption/decryption in federated xgboost. The plugin information is specified in `xgb.collective.CommunicatorContext`.
9 changes: 9 additions & 0 deletions examples/advanced/xgboost_secure/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nvflare~=2.4.2rc
ZiyueXu77 marked this conversation as resolved.
Show resolved Hide resolved
ipcl_python @ git+https://github.com/intel/pailliercryptolib_python.git@development
xgboost @ https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/vertical-federated-learning/xgboost-2.1.0.dev0%2Bde4013fc733648dfe5c2c803a13e2782056e00a2-py3-none-manylinux_2_28_x86_64.whl
pandas
scikit-learn
shap
matplotlib
tensorboard
tenseal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
WORKSPACE_ROOT="/tmp/nvflare/xgb_workspaces"
n=3
n=2

echo "Training horizontal"
nvflare simulator jobs/xgb_hori -w ${WORKSPACE_ROOT}/workspace_hori -n ${n} -t ${n}
Expand Down
13 changes: 0 additions & 13 deletions examples/advanced/xgboost_secure/run_training_local.sh

This file was deleted.

30 changes: 30 additions & 0 deletions examples/advanced/xgboost_secure/run_training_standalone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

directory="/tmp/nvflare/xgb_exp"
if [ ! -e "$directory" ]; then
mkdir -p "$directory"
echo "Directory created: $directory"
else
echo "Directory already exists: $directory"
fi

echo "Training baseline CPU"
python3 ./train_standalone/train_base.py --out_path "/tmp/nvflare/xgb_exp/base_cpu" --gpu 0
echo "Training baseline GPU"
python3 ./train_standalone/train_base.py --out_path "/tmp/nvflare/xgb_exp/base_gpu" --gpu 1
echo "Training horizontal CPU non-encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/horizontal_xgb_data" --out_path "/tmp/nvflare/xgb_exp/hori_cpu_non_enc" --vert 0 --gpu 0 --enc 0
echo "Training horizontal CPU encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/horizontal_xgb_data" --out_path "/tmp/nvflare/xgb_exp/hori_cpu_enc" --vert 0 --gpu 0 --enc 1
echo "Training horizontal GPU non-encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/horizontal_xgb_data" --out_path "/tmp/nvflare/xgb_exp/hori_gpu_non_enc" --vert 0 --gpu 1 --enc 0
echo "Training horizontal GPU encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/horizontal_xgb_data" --out_path "/tmp/nvflare/xgb_exp/hori_gpu_enc" --vert 0 --gpu 1 --enc 1
echo "Training vertical CPU non-encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/vertical_xgb_data" --out_path "/tmp/nvflare/xgb_exp/vert_cpu_non_enc" --vert 1 --gpu 0 --enc 0
echo "Training vertical CPU encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/vertical_xgb_data" --out_path "/tmp/nvflare/xgb_exp/vert_cpu_enc" --vert 1 --gpu 0 --enc 1
echo "Training vertical GPU non-encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/vertical_xgb_data" --out_path "/tmp/nvflare/xgb_exp/vert_gpu_non_enc" --vert 1 --gpu 1 --enc 0
echo "Training vertical GPU encrypted"
python3 ./train_standalone/train_federated.py --data_train_root "/tmp/nvflare/xgb_dataset/vertical_xgb_data" --out_path "/tmp/nvflare/xgb_exp/vert_gpu_enc" --vert 1 --gpu 1 --enc 1
161 changes: 0 additions & 161 deletions examples/advanced/xgboost_secure/train_local/train_hori_base.py

This file was deleted.

Loading
Loading