Skip to content

Commit

Permalink
Merge branch 'NVIDIA:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nvidianz authored Aug 13, 2024
2 parents 65a44e5 + 73b75c9 commit 17581f2
Show file tree
Hide file tree
Showing 52 changed files with 676 additions and 756 deletions.
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.10"

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand All @@ -26,6 +26,6 @@ sphinx:
python:
install:
- method: pip
path: .[doc]
path: .[dev]
# system_packages: true

2 changes: 1 addition & 1 deletion build_doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function clean_docs() {
}

function build_html_docs() {
pip install -e .[doc]
pip install -e .[dev]
sphinx-apidoc --module-first -f -o docs/apidocs/ nvflare "*poc" "*private"
sphinx-build -b html docs docs/_build
}
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/vertical_xgboost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The model will be saved to `test.model.json`.
## Results
Model accuracy can be visualized in tensorboard:
```
tensorboard --logdir /tmp/nvflare/vertical_xgb/simulate_job/tb_events
tensorboard --logdir /tmp/nvflare/vertical_xgb/server/simulate_job/tb_events
```

An example training (pink) and validation (orange) AUC graph from running vertical XGBoost on HIGGS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, data_split_path, psi_path, id_col, label_owner, train_proport
self.label_owner = label_owner
self.train_proportion = train_proportion

def load_data(self, client_id: str):
def load_data(self, client_id: str, training_mode: str = ""):
client_data_split_path = self.data_split_path.replace("site-x", client_id)
client_psi_path = self.psi_path.replace("site-x", client_id)

Expand Down
10 changes: 7 additions & 3 deletions examples/advanced/vertical_xgboost/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
nvflare~=2.4.0rc
nvflare~=2.5.0rc
openmined.psi==1.1.1
pandas
tensorboard
torch
xgboost>=2.0.0
tensorboard
# require xgboost 2.2 version, for now need to install a binary build
# "xgboost>=2.2"

--extra-index-url https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/list.html?prefix=federated-secure/
xgboost
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"format_version": 2,
"server": {
"heart_beat_timeout": 600
},
"task_data_filters": [],
"task_result_filters": [],
"components": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
{
"format_version": 2,
"num_rounds": 100,
"executors": [
{
"tasks": [
"config", "start"
],
"executor": {
"id": "Executor",
"path": "nvflare.app_opt.xgboost.histogram_based_v2.executor.FedXGBHistogramExecutor",
"path": "nvflare.app_opt.xgboost.histogram_based_v2.fed_executor.FedXGBHistogramExecutor",
"args": {
"data_loader_id": "dataloader",
"metrics_writer_id": "metrics_writer",
"early_stopping_rounds": 2,
"xgb_params": {
"max_depth": 8,
"eta": 0.1,
"objective": "binary:logistic",
"eval_metric": "auc",
"tree_method": "hist",
"nthread": 16
}
"metrics_writer_id": "metrics_writer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@
"workflows": [
{
"id": "xgb_controller",
"path": "nvflare.app_opt.xgboost.histogram_based_v2.controller.XGBFedController",
"path": "nvflare.app_opt.xgboost.histogram_based_v2.fed_controller.XGBFedController",
"args": {
"num_rounds": "{num_rounds}"
"num_rounds": "{num_rounds}",
"training_mode": "horizontal",
"xgb_params": {
"max_depth": 8,
"eta": 0.1,
"objective": "binary:logistic",
"eval_metric": "auc",
"tree_method": "hist",
"nthread": 16
},
"xgb_options": {
"early_stopping_rounds": 2
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json

import pandas as pd
import xgboost as xgb

from nvflare.app_opt.xgboost.data_loader import XGBDataLoader


def _read_higgs_with_pandas(data_path, start: int, end: int):
data_size = end - start
data = pd.read_csv(data_path, header=None, skiprows=start, nrows=data_size)
data_num = data.shape[0]

# split to feature and label
x = data.iloc[:, 1:].copy()
y = data.iloc[:, 0].copy()

return x, y, data_num


class HIGGSDataLoader(XGBDataLoader):
def __init__(self, data_split_filename):
"""Reads HIGGS dataset and return XGB data matrix.
Args:
data_split_filename: file name to data splits
"""
self.data_split_filename = data_split_filename

def load_data(self, client_id: str, training_mode: str = ""):
with open(self.data_split_filename, "r") as file:
data_split = json.load(file)

data_path = data_split["data_path"]
data_index = data_split["data_index"]

# check if site_id and "valid" in the mapping dict
if client_id not in data_index.keys():
raise ValueError(
f"Data does not contain Client {client_id} split",
)

if "valid" not in data_index.keys():
raise ValueError(
"Data does not contain Validation split",
)

site_index = data_index[client_id]
valid_index = data_index["valid"]

# training
x_train, y_train, total_train_data_num = _read_higgs_with_pandas(
data_path=data_path, start=site_index["start"], end=site_index["end"]
)
dmat_train = xgb.DMatrix(x_train, label=y_train)

# validation
x_valid, y_valid, total_valid_data_num = _read_higgs_with_pandas(
data_path=data_path, start=valid_index["start"], end=valid_index["end"]
)
dmat_valid = xgb.DMatrix(x_valid, label=y_valid)

return dmat_train, dmat_valid
10 changes: 10 additions & 0 deletions examples/advanced/xgboost/histogram-based/jobs/base_v2/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "xgboost_histogram_based_v2",
"resource_spec": {},
"deploy_map": {
"app": [
"@ALL"
]
},
"min_clients": 2
}
8 changes: 6 additions & 2 deletions examples/advanced/xgboost/histogram-based/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
nvflare~=2.4.0rc
nvflare~=2.5.0rc
pandas
xgboost>=2.0.0
scikit-learn
torch
tensorboard
# require xgboost 2.2 version, for now need to install a binary build
# "xgboost>=2.2"

--extra-index-url https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/list.html?prefix=federated-secure/
xgboost
4 changes: 3 additions & 1 deletion examples/advanced/xgboost/prepare_job_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TREE_METHOD="hist"

prepare_job_config() {
python3 utils/prepare_job_config.py --site_num "$1" --training_mode "$2" --split_method "$3" \
python3 utils/prepare_job_config.py --site_num "$1" --training_algo "$2" --split_method "$3" \
--lr_mode "$4" --nthread 16 --tree_method "$5"
}

Expand All @@ -21,4 +21,6 @@ prepare_job_config 20 cyclic uniform uniform $TREE_METHOD

prepare_job_config 2 histogram uniform uniform $TREE_METHOD
prepare_job_config 5 histogram uniform uniform $TREE_METHOD
prepare_job_config 2 histogram_v2 uniform uniform $TREE_METHOD
prepare_job_config 5 histogram_v2 uniform uniform $TREE_METHOD
echo "Job configs generated"
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
],
"executor": {
"id": "Executor",
"name": "FedXGBTreeExecutor",
"path": "nvflare.app_opt.xgboost.tree_based.executor.FedXGBTreeExecutor",
"args": {
"data_loader_id": "dataloader",
"training_mode": "bagging",
"num_client_bagging": 5,
"num_local_parallel_tree": 1,
"local_subsample": 1,
"lr_mode": "scaled",
"local_model_path": "model.json",
"global_model_path": "model_global.json",
"learning_rate": 0.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"format_version": 2,
"num_rounds": 101,

"server": {
"heart_beat_timeout": 600,
"task_request_interval": 0.05
},

"task_data_filters": [],
"task_result_filters": [],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"executor": {
"id": "Executor",
"name": "FedXGBTreeExecutor",
"path": "nvflare.app_opt.xgboost.tree_based.executor.FedXGBTreeExecutor",
"args": {
"data_loader_id": "dataloader",
"training_mode": "cyclic",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"format_version": 2,
"num_rounds": 20,

"server": {
"heart_beat_timeout": 600,
"task_request_interval": 0.05
},

"task_data_filters": [],
"task_result_filters": [],

Expand Down
8 changes: 6 additions & 2 deletions examples/advanced/xgboost/tree-based/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
nvflare~=2.4.0rc
nvflare~=2.5.0rc
pandas
xgboost
scikit-learn
torch
tensorboard
# require xgboost 2.2 version, for now need to install a binary build
# "xgboost>=2.2"

--extra-index-url https://s3-us-west-2.amazonaws.com/xgboost-nightly-builds/list.html?prefix=federated-secure/
xgboost
Loading

0 comments on commit 17581f2

Please sign in to comment.