Skip to content

Commit

Permalink
Update xgboost example (#2813)
Browse files Browse the repository at this point in the history
* Update xgboost example

* Add feedback

---------

Co-authored-by: Chester Chen <[email protected]>
  • Loading branch information
YuanTingHsieh and chesterxgchen authored Aug 20, 2024
1 parent d75f0f2 commit ed1633a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions examples/advanced/xgboost_secure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,9 @@ 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.

When comparing the training and validation accuracy as well as the model outputs,
experiments conducted with NVFlare produce results that are identical
to those obtained from standalone scripts.

For more information on the secure xgboost user guide please refer to
https://nvflare.readthedocs.io/en/main/user_guide/federated_xgboost/secure_xgboost_user_guide.html
8 changes: 4 additions & 4 deletions examples/advanced/xgboost_secure/prepare_flare_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ nvflare config -jt ../../../job_templates/

# create horizontal job
nvflare job create -force -w xgboost -j ./jobs/xgb_hori \
-f config_fed_server.conf secure_training=false split_mode=0 \
-f config_fed_server.conf secure_training=false data_split_mode=0 \
-f config_fed_client.conf folder="/tmp/nvflare/xgb_dataset/horizontal_xgb_data"

# create horizontal secure job
nvflare job create -force -w xgboost -j ./jobs/xgb_hori_secure \
-f config_fed_server.conf secure_training=true split_mode=0 \
-f config_fed_server.conf secure_training=true data_split_mode=0 \
-f config_fed_client.conf folder="/tmp/nvflare/xgb_dataset/horizontal_xgb_data"

# create vertical job
nvflare job create -force -w xgboost -j ./jobs/xgb_vert \
-f config_fed_server.conf secure_training=false split_mode=1 \
-f config_fed_server.conf secure_training=false data_split_mode=1 \
-f config_fed_client.conf folder="/tmp/nvflare/xgb_dataset/vertical_xgb_data"

# create vertical secure job
nvflare job create -force -w xgboost -j ./jobs/xgb_vert_secure \
-f config_fed_server.conf secure_training=true split_mode=1 \
-f config_fed_server.conf secure_training=true data_split_mode=1 \
-f config_fed_client.conf folder="/tmp/nvflare/xgb_dataset/vertical_xgb_data"
4 changes: 2 additions & 2 deletions examples/advanced/xgboost_secure/run_training_flare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ nvflare simulator jobs/xgb_hori -w ${WORKSPACE_ROOT}/workspace_hori -n ${n} -t $
echo "Prepare secure horizontal tenseal context"
nvflare provision -p project.yml -w ${WORKSPACE_ROOT}/workspace_hori_secure
echo "Training secure horizontal"
nvflare simulator jobs/xgb_hori_secure \
-w ${WORKSPACE_ROOT}/workspace_hori_secure/example_project/prod_00/site-1 -n ${n} -t ${n}
nvflare simulator jobs/xgb_hori_secure \
-w ${WORKSPACE_ROOT}/workspace_hori_secure/example_project/prod_00/site-1 -n ${n} -t ${n}
echo "Training vertical"
nvflare simulator jobs/xgb_vert -w ${WORKSPACE_ROOT}/workspace_vert -n ${n} -t ${n}
echo "Training secure vertical"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ def run_worker(port: int, world_size: int, rank: int, args) -> None:

# Load file, file will not be sharded in federated mode.
if args.vert:
split_mode = 1
data_split_mode = 1
if rank == 0:
label = "&label_column=0"
else:
label = ""
else:
split_mode = 0
data_split_mode = 0
label = "&label_column=0"
dtrain = xgb.DMatrix(train_path + f"?format=csv{label}", data_split_mode=split_mode)
dvalid = xgb.DMatrix(valid_path + f"?format=csv{label}", data_split_mode=split_mode)
dtrain = xgb.DMatrix(train_path + f"?format=csv{label}", data_split_mode=data_split_mode)
dvalid = xgb.DMatrix(valid_path + f"?format=csv{label}", data_split_mode=data_split_mode)

if PRINT_SAMPLE:
# print number of rows and columns for each worker
Expand Down
2 changes: 1 addition & 1 deletion job_templates/xgboost/config_fed_server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ workflows = [
path = "nvflare.app_opt.xgboost.histogram_based_v2.fed_controller.XGBFedController"
args {
num_rounds = "{num_rounds}"
split_mode = 0
data_split_mode = 0
secure_training = false
xgb_options {
early_stopping_rounds = 3
Expand Down

0 comments on commit ed1633a

Please sign in to comment.