Skip to content

Commit

Permalink
Merge pull request #1149 from apache/dev-postgresql
Browse files Browse the repository at this point in the history
merge development branch to master branch for V4.2
  • Loading branch information
lzjpaul authored Mar 11, 2024
2 parents ba51f34 + f0d23a9 commit 6d9cd7f
Show file tree
Hide file tree
Showing 258 changed files with 12,306 additions and 7,713 deletions.
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

0 comments on commit 6d9cd7f

Please sign in to comment.