Skip to content

Commit 95ffcb0

Browse files
authored
Merge branch 'main' into fsi_update
2 parents 784922e + 259191f commit 95ffcb0

File tree

12 files changed

+205
-109
lines changed

12 files changed

+205
-109
lines changed

docs/user_guide/data_scientist_guide/flower_integration/flower_job_structure.rst

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Here is an example of ``pyproject.toml``, taken from :github_nvflare_link:`this
4343
description = ""
4444
license = "Apache-2.0"
4545
dependencies = [
46-
"flwr>=1.16,<1.26",
46+
"flwr>=1.26",
4747
"nvflare~=2.5.0rc",
4848
"torch==2.2.1",
4949
"torchvision==0.17.1",
@@ -62,15 +62,14 @@ Here is an example of ``pyproject.toml``, taken from :github_nvflare_link:`this
6262
[tool.flwr.app.config]
6363
num-server-rounds = 3
6464
65-
[tool.flwr.federations]
66-
default = "local-simulation"
67-
68-
[tool.flwr.federations.local-simulation]
69-
options.num-supernodes = 2
70-
7165
7266
.. note:: Note that the information defined in pyproject.toml must match the code in the project folder!
7367

68+
.. note:: For NVFlare-managed Flower jobs, NVFlare creates a job-scoped
69+
``$FLWR_HOME/config.toml`` with the SuperLink connection details. You do not
70+
need to define a ``[tool.flwr.federations]`` section in ``pyproject.toml`` for
71+
FLARE execution.
72+
7473
Project Name
7574
~~~~~~~~~~~~
7675
The project name should match the name of the project folder, though not a requirement. In this example, it is ``flwr_pt``.
@@ -136,13 +135,9 @@ The content of this section is specific to the server app code. The ``server.py`
136135
Note that you can also pass `run_config` arguments directly through the job definition via
137136
`FlowerRecipe(..., run_config={"num-server-rounds": 5})` to override the default values listed in `pyproject.toml`.
138137

139-
Supernode Count
140-
~~~~~~~~~~~~~~~
141-
If you run the Flower job with its simulation (not as a FLARE job), you need to specify how many clients (supernodes) to use
142-
for the simulation in the ``[tool.flwr.federations.local-simulation]`` section, like this:
143-
144-
.. code-block:: toml
145-
146-
options.num-supernodes = 2
147-
148-
But this does not apply when submitting it as a FLARE job.
138+
Simulation Profiles
139+
~~~~~~~~~~~~~~~~~~~
140+
If you run the Flower job directly with Flower simulation instead of submitting it
141+
as a FLARE job, configure the simulation profile using Flower's current simulation
142+
configuration mechanism. This is separate from the NVFlare execution path, where
143+
NVFlare manages the SuperLink connection through ``$FLWR_HOME/config.toml``.

docs/user_guide/data_scientist_guide/flower_integration/flower_run_as_flare_job.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ Run Flower Application as FLARE Job
44

55
Before running Flower applications with FLARE, you must have both FLARE and Flower frameworks
66
installed in your Python environment. NVFlare 2.7 Flower integration currently requires
7-
``flwr>=1.16,<1.26``.
7+
``flwr>=1.26``.
88

99
.. code-block:: shell
1010
11-
pip install 'flwr>=1.16,<1.26'
11+
pip install 'flwr>=1.26'
12+
13+
With Flower 1.26 and newer, SuperLink connections are no longer configured in
14+
``pyproject.toml`` for NVFlare jobs. Instead, NVFlare writes a job-scoped Flower
15+
configuration file at ``$FLWR_HOME/config.toml`` and uses it to connect
16+
``flwr run``, ``flwr list``, and ``flwr stop`` to the job's dynamically assigned
17+
SuperLink control API address.
1218

1319
To run a Flower application as a job in FLARE, follow these steps:
1420

examples/hello-world/hello-flower/flwr-pt-tb/flwr_pt_tb/task.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import warnings
1415
from collections import OrderedDict
1516
from logging import INFO
1617

18+
import numpy as np
1719
import torch
1820
import torch.nn as nn
1921
import torch.nn.functional as F
@@ -24,6 +26,13 @@
2426

2527
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
2628

29+
try:
30+
VISIBLE_DEPRECATION_WARNING = np.exceptions.VisibleDeprecationWarning
31+
except AttributeError:
32+
VISIBLE_DEPRECATION_WARNING = Warning
33+
34+
CIFAR10_NUMPY_PICKLE_WARNING = r".*align should be passed as Python or NumPy boolean.*align=0.*"
35+
2736

2837
class Net(nn.Module):
2938
"""Model (simple CNN adapted from 'PyTorch: A 60 Minute Blitz')"""
@@ -49,11 +58,23 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
4958
def load_data():
5059
"""Load CIFAR-10 (training and test set)."""
5160
trf = Compose([ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
52-
trainset = CIFAR10("./data", train=True, download=True, transform=trf)
53-
testset = CIFAR10("./data", train=False, download=True, transform=trf)
61+
trainset = _load_cifar10_dataset(train=True, transform=trf)
62+
testset = _load_cifar10_dataset(train=False, transform=trf)
5463
return DataLoader(trainset, batch_size=32, shuffle=True), DataLoader(testset)
5564

5665

66+
def _load_cifar10_dataset(train: bool, transform):
67+
# NumPy 2.4 warns when unpickling CIFAR-10's legacy dtype metadata, but
68+
# torchvision still reads the dataset correctly.
69+
with warnings.catch_warnings():
70+
warnings.filterwarnings(
71+
"ignore",
72+
message=CIFAR10_NUMPY_PICKLE_WARNING,
73+
category=VISIBLE_DEPRECATION_WARNING,
74+
)
75+
return CIFAR10("./data", train=train, download=True, transform=transform)
76+
77+
5778
def train(net, trainloader, valloader, epochs, device, learning_rate, momentum):
5879
"""Train the model on the training set."""
5980
log(INFO, "Starting training...")

examples/hello-world/hello-flower/flwr-pt-tb/pyproject.toml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
# Tested with:
6-
# flwr==1.20.0
7-
# nvflare==2.6.1
8-
# torch==2.7.1
9-
# torchvision==0.22.1
6+
# flwr==1.27.0
7+
# nvflare==2.7.2
8+
# torch==2.11.0
9+
# torchvision==0.26.0
1010
# tensorboard==2.20.0
1111

1212
[project]
@@ -15,7 +15,7 @@ version = "1.0.0"
1515
description = ""
1616
license = "Apache-2.0"
1717
dependencies = [
18-
"flwr>=1.16,<1.26",
18+
"flwr>=1.26",
1919
"nvflare~=2.6.0rc",
2020
"torch",
2121
"torchvision",
@@ -36,11 +36,3 @@ clientapp = "flwr_pt_tb.client:app"
3636
num-server-rounds = 3
3737
learning-rate = 0.001
3838
momentum = 0.9
39-
40-
[tool.flwr.federations]
41-
default = "local-simulation"
42-
43-
[tool.flwr.federations.local-simulation]
44-
options.num-supernodes = 2
45-
address = "127.0.0.1:9093"
46-
insecure = true

examples/hello-world/hello-flower/flwr-pt/flwr_pt/task.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import warnings
1415
from collections import OrderedDict
1516
from logging import INFO
1617

18+
import numpy as np
1719
import torch
1820
import torch.nn as nn
1921
import torch.nn.functional as F
@@ -24,6 +26,13 @@
2426

2527
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
2628

29+
try:
30+
VISIBLE_DEPRECATION_WARNING = np.exceptions.VisibleDeprecationWarning
31+
except AttributeError:
32+
VISIBLE_DEPRECATION_WARNING = Warning
33+
34+
CIFAR10_NUMPY_PICKLE_WARNING = r".*align should be passed as Python or NumPy boolean.*align=0.*"
35+
2736

2837
class Net(nn.Module):
2938
"""Model (simple CNN adapted from 'PyTorch: A 60 Minute Blitz')"""
@@ -49,11 +58,23 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
4958
def load_data():
5059
"""Load CIFAR-10 (training and test set)."""
5160
trf = Compose([ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
52-
trainset = CIFAR10("./data", train=True, download=True, transform=trf)
53-
testset = CIFAR10("./data", train=False, download=True, transform=trf)
61+
trainset = _load_cifar10_dataset(train=True, transform=trf)
62+
testset = _load_cifar10_dataset(train=False, transform=trf)
5463
return DataLoader(trainset, batch_size=32, shuffle=True), DataLoader(testset)
5564

5665

66+
def _load_cifar10_dataset(train: bool, transform):
67+
# NumPy 2.4 warns when unpickling CIFAR-10's legacy dtype metadata, but
68+
# torchvision still reads the dataset correctly.
69+
with warnings.catch_warnings():
70+
warnings.filterwarnings(
71+
"ignore",
72+
message=CIFAR10_NUMPY_PICKLE_WARNING,
73+
category=VISIBLE_DEPRECATION_WARNING,
74+
)
75+
return CIFAR10("./data", train=train, download=True, transform=transform)
76+
77+
5778
def train(net, trainloader, valloader, epochs, device, learning_rate, momentum):
5879
"""Train the model on the training set."""
5980
log(INFO, "Starting training...")

examples/hello-world/hello-flower/flwr-pt/pyproject.toml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
# Tested with:
6-
# flwr==1.20.0
7-
# nvflare==2.6.1
8-
# torch==2.7.1
9-
# torchvision==0.22.1
6+
# flwr==1.27.0
7+
# nvflare==2.7.2
8+
# torch==2.11.0
9+
# torchvision==0.26.0
1010
# tensorboard==2.20.0
1111

1212
[project]
@@ -15,7 +15,7 @@ version = "1.0.0"
1515
description = ""
1616
license = "Apache-2.0"
1717
dependencies = [
18-
"flwr>=1.16,<1.26",
18+
"flwr>=1.26",
1919
"nvflare~=2.6.0rc",
2020
"torch",
2121
"torchvision",
@@ -36,11 +36,3 @@ clientapp = "flwr_pt.client:app"
3636
num-server-rounds = 3
3737
learning-rate = 0.001
3838
momentum = 0.9
39-
40-
[tool.flwr.federations]
41-
default = "local-simulation"
42-
43-
[tool.flwr.federations.local-simulation]
44-
options.num-supernodes = 2
45-
address = "127.0.0.1:9093"
46-
insecure = true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
nvflare~=2.7.2rc
2-
flwr>=1.16,<1.26
2+
flwr>=1.26
33
torch
44
torchvision
55
tensorboard

0 commit comments

Comments
 (0)