flwr-nightly 1.9.0.dev20240422__py3-none-any.whl → 1.9.0.dev20240423__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flwr-nightly might be problematic. Click here for more details.
- flwr/cli/new/new.py +1 -0
- flwr/cli/new/templates/app/code/client.sklearn.py.tpl +94 -0
- flwr/cli/new/templates/app/code/server.sklearn.py.tpl +17 -0
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +24 -0
- {flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/METADATA +1 -1
- {flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/RECORD +9 -6
- {flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/WHEEL +0 -0
- {flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/entry_points.txt +0 -0
flwr/cli/new/new.py
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""$project_name: A Flower / Scikit-Learn app."""
|
|
2
|
+
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from flwr.client import NumPyClient, ClientApp
|
|
7
|
+
from flwr_datasets import FederatedDataset
|
|
8
|
+
from sklearn.linear_model import LogisticRegression
|
|
9
|
+
from sklearn.metrics import log_loss
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_model_parameters(model):
|
|
13
|
+
if model.fit_intercept:
|
|
14
|
+
params = [
|
|
15
|
+
model.coef_,
|
|
16
|
+
model.intercept_,
|
|
17
|
+
]
|
|
18
|
+
else:
|
|
19
|
+
params = [model.coef_]
|
|
20
|
+
return params
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def set_model_params(model, params):
|
|
24
|
+
model.coef_ = params[0]
|
|
25
|
+
if model.fit_intercept:
|
|
26
|
+
model.intercept_ = params[1]
|
|
27
|
+
return model
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def set_initial_params(model):
|
|
31
|
+
n_classes = 10 # MNIST has 10 classes
|
|
32
|
+
n_features = 784 # Number of features in dataset
|
|
33
|
+
model.classes_ = np.array([i for i in range(10)])
|
|
34
|
+
|
|
35
|
+
model.coef_ = np.zeros((n_classes, n_features))
|
|
36
|
+
if model.fit_intercept:
|
|
37
|
+
model.intercept_ = np.zeros((n_classes,))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class FlowerClient(NumPyClient):
|
|
41
|
+
def __init__(self, model, X_train, X_test, y_train, y_test):
|
|
42
|
+
self.model = model
|
|
43
|
+
self.X_train = X_train
|
|
44
|
+
self.X_test = X_test
|
|
45
|
+
self.y_train = y_train
|
|
46
|
+
self.y_test = y_test
|
|
47
|
+
|
|
48
|
+
def get_parameters(self, config):
|
|
49
|
+
return get_model_parameters(self.model)
|
|
50
|
+
|
|
51
|
+
def fit(self, parameters, config):
|
|
52
|
+
set_model_params(self.model, parameters)
|
|
53
|
+
|
|
54
|
+
# Ignore convergence failure due to low local epochs
|
|
55
|
+
with warnings.catch_warnings():
|
|
56
|
+
warnings.simplefilter("ignore")
|
|
57
|
+
self.model.fit(self.X_train, self.y_train)
|
|
58
|
+
|
|
59
|
+
return get_model_parameters(self.model), len(self.X_train), {}
|
|
60
|
+
|
|
61
|
+
def evaluate(self, parameters, config):
|
|
62
|
+
set_model_params(self.model, parameters)
|
|
63
|
+
|
|
64
|
+
loss = log_loss(self.y_test, self.model.predict_proba(self.X_test))
|
|
65
|
+
accuracy = self.model.score(self.X_test, self.y_test)
|
|
66
|
+
|
|
67
|
+
return loss, len(self.X_test), {"accuracy": accuracy}
|
|
68
|
+
|
|
69
|
+
fds = FederatedDataset(dataset="mnist", partitioners={"train": 2})
|
|
70
|
+
|
|
71
|
+
def client_fn(cid: str):
|
|
72
|
+
dataset = fds.load_partition(int(cid), "train").with_format("numpy")
|
|
73
|
+
|
|
74
|
+
X, y = dataset["image"].reshape((len(dataset), -1)), dataset["label"]
|
|
75
|
+
|
|
76
|
+
# Split the on edge data: 80% train, 20% test
|
|
77
|
+
X_train, X_test = X[: int(0.8 * len(X))], X[int(0.8 * len(X)) :]
|
|
78
|
+
y_train, y_test = y[: int(0.8 * len(y))], y[int(0.8 * len(y)) :]
|
|
79
|
+
|
|
80
|
+
# Create LogisticRegression Model
|
|
81
|
+
model = LogisticRegression(
|
|
82
|
+
penalty="l2",
|
|
83
|
+
max_iter=1, # local epoch
|
|
84
|
+
warm_start=True, # prevent refreshing weights when fitting
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Setting initial parameters, akin to model.compile for keras models
|
|
88
|
+
set_initial_params(model)
|
|
89
|
+
|
|
90
|
+
return FlowerClient(model, X_train, X_test, y_train, y_test).to_client()
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Flower ClientApp
|
|
94
|
+
app = ClientApp(client_fn=client_fn)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""$project_name: A Flower / Scikit-Learn app."""
|
|
2
|
+
|
|
3
|
+
from flwr.server import ServerApp, ServerConfig
|
|
4
|
+
from flwr.server.strategy import FedAvg
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
strategy = FedAvg(
|
|
8
|
+
fraction_fit=1.0,
|
|
9
|
+
fraction_evaluate=1.0,
|
|
10
|
+
min_available_clients=2,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
# Create ServerApp
|
|
14
|
+
app = ServerApp(
|
|
15
|
+
config=ServerConfig(num_rounds=3),
|
|
16
|
+
strategy=strategy,
|
|
17
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "$project_name"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = ""
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "The Flower Authors", email = "hello@flower.ai" },
|
|
11
|
+
]
|
|
12
|
+
license = {text = "Apache License (2.0)"}
|
|
13
|
+
dependencies = [
|
|
14
|
+
"flwr[simulation]>=1.8.0,<2.0",
|
|
15
|
+
"flwr-datasets[vision]>=0.0.2,<1.0.0",
|
|
16
|
+
"scikit-learn>=1.1.1",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[tool.hatch.build.targets.wheel]
|
|
20
|
+
packages = ["."]
|
|
21
|
+
|
|
22
|
+
[flower.components]
|
|
23
|
+
serverapp = "$project_name.server:app"
|
|
24
|
+
clientapp = "$project_name.client:app"
|
{flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/RECORD
RENAMED
|
@@ -4,7 +4,7 @@ flwr/cli/app.py,sha256=38thPnMydBmNAxNE9mz4By-KdRUhJfoUgeDuAxMYF_U,1095
|
|
|
4
4
|
flwr/cli/config_utils.py,sha256=1wTPQqOU2fKeU4FP5KyG0xMa0F-qy8x1m2WvztPORb4,5597
|
|
5
5
|
flwr/cli/example.py,sha256=1bGDYll3BXQY2kRqSN-oICqS5n1b9m0g0RvXTopXHl4,2215
|
|
6
6
|
flwr/cli/new/__init__.py,sha256=cQzK1WH4JP2awef1t2UQ2xjl1agVEz9rwutV18SWV1k,789
|
|
7
|
-
flwr/cli/new/new.py,sha256=
|
|
7
|
+
flwr/cli/new/new.py,sha256=hqcHjun3keeREegDrdLJMPHKkVBYIN4HUUeCl3hzVgI,5404
|
|
8
8
|
flwr/cli/new/templates/__init__.py,sha256=4luU8RL-CK8JJCstQ_ON809W9bNTkY1l9zSaPKBkgwY,725
|
|
9
9
|
flwr/cli/new/templates/app/.gitignore.tpl,sha256=XixnHdyeMB2vwkGtGnwHqoWpH-9WChdyG0GXe57duhc,3078
|
|
10
10
|
flwr/cli/new/templates/app/README.md.tpl,sha256=_qGtgpKYKoCJVjQnvlBMKvFs_1gzTcL908I3KJg0oAM,668
|
|
@@ -13,13 +13,16 @@ flwr/cli/new/templates/app/code/__init__.py,sha256=EM6vfvgAILKPaPn7H1wMV1Wi01WyZ
|
|
|
13
13
|
flwr/cli/new/templates/app/code/__init__.py.tpl,sha256=olwrBeJemHNBWvjc6gJURloFRqW40dAy7FRQA5pDqHU,21
|
|
14
14
|
flwr/cli/new/templates/app/code/client.numpy.py.tpl,sha256=mTh7Y_jOJrPUvDYHVJy4wJCnjXZV_q-jlDkB07U5GSk,521
|
|
15
15
|
flwr/cli/new/templates/app/code/client.pytorch.py.tpl,sha256=671daPcdZaC4Z5k-dqmCovfb2_FShGmqfjwaR8y6EC8,1173
|
|
16
|
+
flwr/cli/new/templates/app/code/client.sklearn.py.tpl,sha256=S71SZiHaRXtKqUk3m5Elc_c6HhKAIKLalrKOQ3p20No,2801
|
|
16
17
|
flwr/cli/new/templates/app/code/client.tensorflow.py.tpl,sha256=N9SbnI65r2K9FHV_wn4JSpmVeyYpD0qEMehbHcGm4t0,1911
|
|
17
18
|
flwr/cli/new/templates/app/code/server.numpy.py.tpl,sha256=fRxrDXV7pB1aDhQUXMBmrCsC1zp0uKwsBxZBx1JzbHA,248
|
|
18
19
|
flwr/cli/new/templates/app/code/server.pytorch.py.tpl,sha256=xtKvUivNMzgOcLSOtnjWouJzIFbXdUQVYMm27uwyJpI,594
|
|
20
|
+
flwr/cli/new/templates/app/code/server.sklearn.py.tpl,sha256=cLzOpQzGIUzEazuFsjBpXAQUNPy6in6zR33SCqhix6o,341
|
|
19
21
|
flwr/cli/new/templates/app/code/server.tensorflow.py.tpl,sha256=GUGH8c_6cxgUB9obVJPaA4thxI7OVXsItyfQDsn9E5k,371
|
|
20
22
|
flwr/cli/new/templates/app/code/task.pytorch.py.tpl,sha256=NvajdZN-eTyfdqKK0v2MrvWITXw9BjJ3Ri5c1haPJDs,3684
|
|
21
23
|
flwr/cli/new/templates/app/pyproject.numpy.toml.tpl,sha256=0oTH0lY7q-PpRV4HA5woxJ1eWIgZRFcFsHa7-1lULIQ,489
|
|
22
24
|
flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl,sha256=GYbMAFD90JBRvy8fJbLU7nDITD3sxHv1TncQrg6mjEE,558
|
|
25
|
+
flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl,sha256=7p6s2jJpC8ZO-TfiJ0cE3fzkIhc4ndj9SY1hiYvSM5Q,538
|
|
23
26
|
flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl,sha256=7I8BYtE28cnc7ZiOlOp6_zeLsjLRlwa0Y4sjoP7r9VU,537
|
|
24
27
|
flwr/cli/run/__init__.py,sha256=oCd6HmQDx-sqver1gecgx-uMA38BLTSiiKpl7RGNceg,789
|
|
25
28
|
flwr/cli/run/run.py,sha256=qxXgShEXHONx-Gjpl515HF60QzRA-Ygpj2sbl0bZUAA,2331
|
|
@@ -205,8 +208,8 @@ flwr/simulation/ray_transport/ray_actor.py,sha256=_wv2eP7qxkCZ-6rMyYWnjLrGPBZRxj
|
|
|
205
208
|
flwr/simulation/ray_transport/ray_client_proxy.py,sha256=oDu4sEPIOu39vrNi-fqDAe10xtNUXMO49bM2RWfRcyw,6738
|
|
206
209
|
flwr/simulation/ray_transport/utils.py,sha256=TYdtfg1P9VfTdLMOJlifInGpxWHYs9UfUqIv2wfkRLA,2392
|
|
207
210
|
flwr/simulation/run_simulation.py,sha256=nxXNv3r8ODImd5o6f0sa_w5L0I08LD2Udw2OTXStRnQ,15694
|
|
208
|
-
flwr_nightly-1.9.0.
|
|
209
|
-
flwr_nightly-1.9.0.
|
|
210
|
-
flwr_nightly-1.9.0.
|
|
211
|
-
flwr_nightly-1.9.0.
|
|
212
|
-
flwr_nightly-1.9.0.
|
|
211
|
+
flwr_nightly-1.9.0.dev20240423.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
212
|
+
flwr_nightly-1.9.0.dev20240423.dist-info/METADATA,sha256=zdE6sLfyJNTW7D0GQYAswEN0TE1pJUSzVFZ_KgNmWYk,15260
|
|
213
|
+
flwr_nightly-1.9.0.dev20240423.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
214
|
+
flwr_nightly-1.9.0.dev20240423.dist-info/entry_points.txt,sha256=DBrrf685V2W9NbbchQwvuqBEpj5ik8tMZNoZg_W2bZY,363
|
|
215
|
+
flwr_nightly-1.9.0.dev20240423.dist-info/RECORD,,
|
{flwr_nightly-1.9.0.dev20240422.dist-info → flwr_nightly-1.9.0.dev20240423.dist-info}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|