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

merge development branch to master branch for V4.2 #1149

Merged
merged 53 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
323acf0
Create a horizontal federated learning example
lemonviv Dec 9, 2023
d632b6d
Merge pull request #1124 from lemonviv/add-hfl-example
lzjpaul Dec 9, 2023
3475df0
Add implementation for server and client for the hfl example
lemonviv Dec 11, 2023
d950067
Merge pull request #1125 from lemonviv/add-hfl-example
lzjpaul Dec 11, 2023
ec21358
Add implementation for model and data processing for the hfl example
lemonviv Dec 19, 2023
75d04de
Merge pull request #1126 from lemonviv/add-hfl-example
lzjpaul Jan 6, 2024
5dbea4c
Create the src folder for server and client in the hfl example
lzjpaul Jan 29, 2024
a957514
Merge pull request #1127 from lzjpaul/24-1-29-hfl-src
nudles Jan 29, 2024
335fc3a
add utils for example
Zrealshadow Jan 30, 2024
fd93d45
Merge pull request #1128 from Zrealshadow/add_utils
lzjpaul Jan 31, 2024
60613e6
Add the interface proto file for the HFL bank example
Zrealshadow Jan 31, 2024
36ea80c
Merge pull request #1129 from Zrealshadow/hfl_add_interface
chrishkchris Jan 31, 2024
fd9937d
Add the sql file for the filtering phase
liye-li Feb 3, 2024
d76ed96
Merge pull request #1130 from liye-li/filter
lzjpaul Feb 3, 2024
3f82d8f
Add the sql file for the refinement phase
zhangteng398 Feb 5, 2024
bc9fe47
Merge pull request #1131 from zhangteng398/dev-postgresql
lzjpaul Feb 5, 2024
3d68345
Add the interface proto file for the bank HFL example
Zrealshadow Feb 5, 2024
a261e24
Merge pull request #1132 from Zrealshadow/interface_proto_pgsql
chrishkchris Feb 6, 2024
0b1d73c
Update the proto folder for the hfl example
lzjpaul Feb 8, 2024
17571ab
Merge pull request #1133 from lzjpaul/24-2-8-hfl
chrishkchris Feb 9, 2024
47e062f
Add config folder for the HFL example
NLGithubWP Feb 16, 2024
4eb59d1
Merge pull request #1134 from NLGithubWP/dev-postgresql
lzjpaul Feb 17, 2024
2ac5440
Update the pg_extension sql file for TRAILS model selection
liye-li Feb 20, 2024
9bfc368
Merge pull request #1136 from liye-li/sql_model_selection
nudles Feb 21, 2024
f242b44
Add training datasets
NLGithubWP Mar 5, 2024
34bb62c
Update README.md
NLGithubWP Mar 5, 2024
ed49ac1
Update dockerfile for postgresql
NLGithubWP Mar 5, 2024
5a7ea82
Add dockerfile for the singa with polarDB
NLGithubWP Mar 5, 2024
e233c02
Add init script
NLGithubWP Mar 5, 2024
9a967dc
Sample from the datasets
NLGithubWP Mar 6, 2024
f71613c
Merge pull request #1137 from NLGithubWP/dev-postgresql
lzjpaul Mar 6, 2024
676343d
Update the CMakeLists for v4.2.0
lzjpaul Mar 6, 2024
d3bfa7b
Merge pull request #1138 from lzjpaul/24-3-6-wheel
chrishkchris Mar 7, 2024
a412db1
Update the Trails for model selection
NLGithubWP Mar 7, 2024
ab4f87d
Update README.md
NLGithubWP Mar 7, 2024
403e81e
Merge pull request #1139 from NLGithubWP/dev-postgresql
lzjpaul Mar 7, 2024
2113538
Update deployment configs
NLGithubWP Mar 7, 2024
c0afbd0
Add system design figures
NLGithubWP Mar 7, 2024
419bbc7
Merge pull request #1141 from NLGithubWP/dev-postgresql
lzjpaul Mar 7, 2024
1388887
Update image
NLGithubWP Mar 8, 2024
4ea6b78
Merge pull request #1143 from NLGithubWP/dev-postgresql
lzjpaul Mar 8, 2024
0a9a03c
Add descriptions for the dependencies
NLGithubWP Mar 8, 2024
ce4b616
Merge pull request #1145 from NLGithubWP/dev-postgresql
lzjpaul Mar 8, 2024
7d966ed
Remove the wheel file from the singa
NLGithubWP Mar 9, 2024
6411093
Update README.md
NLGithubWP Mar 9, 2024
8520780
Update the Dockerfile with wheel from remote
NLGithubWP Mar 9, 2024
04435fe
Merge pull request #1146 from NLGithubWP/dev-postgresql
lzjpaul Mar 9, 2024
0c4634a
Update headers
NLGithubWP Mar 9, 2024
68cd882
Delete un-used file
NLGithubWP Mar 9, 2024
3784cce
Add headers for hfl
NLGithubWP Mar 9, 2024
d9c2101
Merge pull request #1147 from NLGithubWP/dev-postgresql
lzjpaul Mar 9, 2024
d84a1b4
Update release files for V4.2.0
lzjpaul Mar 10, 2024
f0d23a9
Merge pull request #1148 from lzjpaul/24-3-10-v42
nudles Mar 11, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ test/samples/
# Sphinx and Doxygen Doc-Site
doc/_build/*
doc/en/docs/model_zoo/
cmake-build-debug/*
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Thirdparty)
#string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")


SET(PACKAGE_VERSION 4.1.0) # ${VERSION})
SET(VERSION 4.1.0)
SET(PACKAGE_VERSION 4.2.0) # ${VERSION})
SET(VERSION 4.2.0)
SET(SINGA_MAJOR_VERSION 4)
SET(SINGA_MINOR_VERSION 1)
SET(SINGA_MINOR_VERSION 2)
SET(SINGA_PATCH_VERSION 0)
#SET(SINGA_MAJOR_VERSION ${VERSION_MAJOR}) # 0 -
#SET(SINGA_MINOR_VERSION ${VERSION_MINOR}) # 0 - 9
Expand Down
14 changes: 1 addition & 13 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,4 @@ developers of Apache SINGA under Apache License, Version 2.0.
./doc/_static/images/sgd.png
./doc/_static/images/singa.png
./doc/_static/images/singav1-sw.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/documents/image-20231020174425377.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/documents/image-20231020174945226.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230421214835152.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230421220338391.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230421220443231.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230702035554579.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230702035622198.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230702035639502.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230702035806963.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230722202555763.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230722205244718.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230724111325368.png
./examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/documents/imgs/image-20230724111659545.png
./examples/model_selection/Trails/documents/ai_db.001.jpeg
30 changes: 30 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
Release Notes - SINGA - Version singa-4.2.0

SINGA is a distributed deep learning library.

This release includes following changes:

* Add support for deep learning models running on top of PolarDB
* Implement efficient model selection for a given dataset stored in the database.
* Add support for dynamic model creation.
* Add support for flexible setting of model training configurations.
* Optimize the in-database analytics modules for scalability, efficiency and memory consumption.

* New example
* Add a horizontal federated learning example using the Bank dataset.

* Enhance examples
* Add sample training data for testing the model selection application.

* Update the website
* Update the star button in the main page.
* Refine the display of star statistics.

* Update the python versions for wheel files

* Fix bugs
* Fix the rat check files.
* Update the license files.

----------------------------------------------------------------------------------------------

Release Notes - SINGA - Version singa-4.1.0

SINGA is a distributed deep learning library.
Expand Down
63 changes: 63 additions & 0 deletions examples/hfl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with < this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->


# Horizontal Federated Learning Example

This is an example of federated learning (FL) using the Singa framework. In FL, there is a server and a set of clients. Each client has a local dataset.
In each iteration, each client trains the model using its local dataset and uploads the model gradient to the server, which aggregates to get the global
gradient using the Federated Average algorithm. The server sends the global gradient to all clients for iterative model training.
This example uses the Bank dataset and an MLP model in FL.

## Preparation

Go to the Conda environment that contains the Singa library, and run

```bash
pip install -r requirements.txt
```

Download the bank dataset and split it into 3 partitions.

```bash
# 1. download the data from https://archive.ics.uci.edu/ml/datasets/bank+marketing
# 2. put it under the /data folder
# 3. run the following command which:
# (1) splits the dataset into N subsets
# (2) splits each subsets into train set and test set (8:2)
python -m bank N
```

## Run the example

Run the server first (set the number of epochs to 3)

```bash
python -m src.server -m 3 --num_clients 3
```

Then, start 3 clients in different terminal

```bash
python -m src.client --model mlp --data bank -m 3 -i 0 -d non-iid
python -m src.client --model mlp --data bank -m 3 -i 1 -d non-iid
python -m src.client --model mlp --data bank -m 3 -i 2 -d non-iid
```

Finally, the server and clients finish the FL training.
8 changes: 8 additions & 0 deletions examples/hfl/config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
29 changes: 29 additions & 0 deletions examples/hfl/config/Singa-HFL.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with < this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Empty file added examples/hfl/data/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions examples/hfl/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pandas
scikit-learn
protobuf
19 changes: 19 additions & 0 deletions examples/hfl/src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#

97 changes: 97 additions & 0 deletions examples/hfl/src/bank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#

# https://github.com/zhengzangw/Fed-SINGA/blob/main/src/client/data/bank.py

import pandas as pd
import numpy as np
import sys
from pandas.api.types import is_numeric_dtype
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffle


def encode(df):
res = pd.DataFrame()
for col in df.columns.values:
if not is_numeric_dtype(df[col]):
tmp = pd.get_dummies(df[col], prefix=col)
else:
tmp = df[col]
res = pd.concat([res, tmp], axis=1)
return res


def load(device_id):
fn_train = "data/bank_train_" + str(device_id) + ".csv"
fn_test = "data/bank_test_" + str(device_id) + ".csv"

train = pd.read_csv(fn_train, sep=',')
test = pd.read_csv(fn_test, sep=',')

train_x = train.drop(['y'], axis=1)
train_y = train['y']
val_x = test.drop(['y'], axis=1)
val_y = test['y']

train_x = np.array((train_x), dtype=np.float32)
val_x = np.array((val_x), dtype=np.float32)
train_y = np.array((train_y), dtype=np.int32)
val_y = np.array((val_y), dtype=np.int32)

train_x, val_x = normalize(train_x, val_x)
num_classes = 2

return train_x, train_y, val_x, val_y, num_classes


def normalize(X_train, X_test):
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
return X_train_scaled, X_test_scaled


def split(num):
filepath = "../data/bank-additional-full.csv"
df = pd.read_csv(filepath, sep=';')
df['y'] = (df['y'] == 'yes').astype(int)
data = encode(df)
data = shuffle(data)
train, test = train_test_split(data, test_size=0.2)

train.to_csv("data/bank_train_.csv", index=False)
test.to_csv("data/bank_test_.csv", index=False)

train_per_client = len(train) // num
test_per_client = len(test) // num

print("train_per_client:", train_per_client)
print("test_per_client:", test_per_client)
for i in range(num):
sub_train = train[i * train_per_client:(i + 1) * train_per_client]
sub_test = test[i * test_per_client:(i + 1) * test_per_client]
sub_train.to_csv("data/bank_train_" + str(i) + ".csv", index=False)
sub_test.to_csv("data/bank_test_" + str(i) + ".csv", index=False)


if __name__ == "__main__":
split(int(sys.argv[1]))

Loading
Loading