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

Make flower-simulation accept ClientApp and ServerApp objects #3024

Merged
merged 168 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
4c83a5e
init
jafermarq Feb 21, 2024
a85db40
base backend
jafermarq Feb 21, 2024
b770312
update
jafermarq Feb 21, 2024
b9c6455
update docstrings
jafermarq Feb 21, 2024
cd48539
minor fixes
jafermarq Feb 21, 2024
2791163
updates
jafermarq Feb 22, 2024
4ca33ec
backend-config should contain value types
jafermarq Feb 22, 2024
1b6564a
fix
jafermarq Feb 22, 2024
bad8727
w/ previous
jafermarq Feb 22, 2024
a68172f
fix
jafermarq Feb 22, 2024
e2b072e
Merge branch 'vce-flee-api' into vce-fleet-api-backends
jafermarq Feb 22, 2024
6881866
fix for json.loads
jafermarq Feb 22, 2024
935e333
keep backend-config as json string
jafermarq Feb 22, 2024
704d667
merged
jafermarq Feb 22, 2024
adfe198
added `RayBackend` and `SimpleActorPool`
jafermarq Feb 22, 2024
d0bab9a
complete VCE loop; works with `simulation-pytorch` example
jafermarq Feb 22, 2024
5e0ee74
fix exclude generation logic
jafermarq Feb 22, 2024
82836ad
Merge branch 'vce-fleet-api-backends-ray' into vce-fleet-api-loop
jafermarq Feb 22, 2024
4853813
simulation-tf w/ Flower-next; updates pytorch example too
jafermarq Feb 22, 2024
31787cf
format
jafermarq Feb 22, 2024
8522022
passing actor init kwargs
jafermarq Feb 22, 2024
788e63f
Merge branch 'vce-fleet-api-backends-ray' into vce-fleet-api-loop
jafermarq Feb 22, 2024
9200513
updated examples
jafermarq Feb 22, 2024
d8935b3
auto enable GPU growth if 'tensorflow' passed
jafermarq Feb 22, 2024
b108be2
return to default 1xCPU for virtual client
jafermarq Feb 22, 2024
17e3089
Merge branch 'main' into vce-flee-api
danieljanes Feb 22, 2024
0e02b05
moved import
jafermarq Feb 22, 2024
b77e4e8
Merge branch 'vce-flee-api' into vce-fleet-api-backends
jafermarq Feb 22, 2024
fd67f22
Apply suggestions from code review
jafermarq Feb 22, 2024
cf004d8
renamed vars; exporting
jafermarq Feb 22, 2024
f10a6ca
Merge branch 'vce-flee-api' into vce-fleet-api-backends
jafermarq Feb 22, 2024
d097bcd
Merge branch 'main' into vce-fleet-api-backends
jafermarq Feb 22, 2024
e669e2a
merge
jafermarq Feb 22, 2024
a521b40
moved
jafermarq Feb 22, 2024
890e329
Merge branch 'move-server-functions' into vce-fleet-api-backends-ray
jafermarq Feb 22, 2024
2ccf612
Merge branch 'main' into vce-fleet-api-backends
jafermarq Feb 22, 2024
0f7a071
Merge branch 'vce-fleet-api-backends' into vce-fleet-api-backends-ray
jafermarq Feb 22, 2024
443551f
revisited imports readiness for chosen backend
jafermarq Feb 23, 2024
bdfcccb
merge w/ main
jafermarq Feb 23, 2024
79f363e
Apply suggestions from code review
jafermarq Feb 23, 2024
12fa44c
remove suprefluous if
jafermarq Feb 23, 2024
c309046
fixes
jafermarq Feb 23, 2024
d217677
merge and more
jafermarq Feb 23, 2024
ee20d50
merge w/ main
jafermarq Feb 23, 2024
b16d0b8
init; need resolve circular imports
jafermarq Feb 24, 2024
93918db
gracefully shutdown
jafermarq Feb 25, 2024
0e4ab14
terminate method for backend; asyncio event to trigger stop
jafermarq Feb 25, 2024
e173312
Merge branch 'vce-fleet-terminate-and-rename' into vce-fleet-api-loop
jafermarq Feb 25, 2024
261f516
.
jafermarq Feb 25, 2024
21e9932
propagate terminate asyncio logic
jafermarq Feb 25, 2024
89de845
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 25, 2024
2faef27
merge
jafermarq Feb 26, 2024
f8b57c5
added build/process/terminate tests
jafermarq Feb 26, 2024
accc67c
Merge branch 'vce-fleet-raybackend-tests' into vce-fleet-api-loop
jafermarq Feb 26, 2024
39e3234
format
jafermarq Feb 26, 2024
8ea4b08
fix for py3.8
jafermarq Feb 26, 2024
fb9bfc2
Merge branch 'vce-fleet-raybackend-tests' into vce-fleet-api-loop
jafermarq Feb 26, 2024
35c55d4
fix py3.11
jafermarq Feb 26, 2024
49bc661
fix import
jafermarq Feb 26, 2024
4506a17
wrapped asyncio test under `IsolatedAsyncioTestCase` class
jafermarq Feb 26, 2024
7d6f821
Merge branch 'vce-fleet-raybackend-tests' into vce-fleet-api-loop
jafermarq Feb 26, 2024
ed5b181
start/shutdown tests
jafermarq Feb 26, 2024
2c05cdd
full loop tests; tweaks
jafermarq Feb 26, 2024
c589f7d
erge w/ main
jafermarq Feb 26, 2024
98fb4b4
.
jafermarq Feb 26, 2024
b15cebd
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 26, 2024
65c8b79
undoing changes to simulation examples
jafermarq Feb 26, 2024
2dfc83f
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 26, 2024
87d7a4c
adding back examples
jafermarq Feb 26, 2024
35ab1f3
Apply suggestions from code review
jafermarq Feb 26, 2024
5b3365a
Apply suggestions from code review
jafermarq Feb 26, 2024
785ac91
introduced `partition_id`.
jafermarq Feb 26, 2024
eba053a
fix for ray proxies and tests
jafermarq Feb 26, 2024
3d15041
Merge branch 'main' into metadata-with-partition-id
jafermarq Feb 26, 2024
ee84f85
Merge branch 'main' into metadata-with-partition-id
danieljanes Feb 26, 2024
27d2bb1
re written
jafermarq Feb 26, 2024
b7d5521
Merge branch 'metadata-with-partition-id' into vce-fleet-api-loop
jafermarq Feb 26, 2024
1969aac
using `metadata.partition_id`
jafermarq Feb 26, 2024
17d4b23
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 26, 2024
8f1ca09
more efficient
jafermarq Feb 27, 2024
f44b595
undo
jafermarq Feb 27, 2024
33e7be3
Merge branch 'main' into vce-fleet-api-loop
jafermarq Feb 27, 2024
666c65f
Merge branch 'main' into vce-fleet-api-loop
danieljanes Feb 27, 2024
ab55b0c
more tests
jafermarq Feb 27, 2024
28dda2d
more
jafermarq Feb 27, 2024
5cd047e
minor update
jafermarq Feb 27, 2024
4be09c2
handle loading of non-existing ClientApp
jafermarq Feb 27, 2024
17d3d34
merge /w branch ahead; test vce with non existing clientapp
jafermarq Feb 27, 2024
3c616e9
better tests; reorg
jafermarq Feb 27, 2024
ffed29b
Merge branch 'more-raybackend-tests-yes' into vce-fleet-api-loop
jafermarq Feb 27, 2024
aed4420
update
jafermarq Feb 27, 2024
96519dc
w/ previous
jafermarq Feb 27, 2024
e491b7b
Merge branch 'more-raybackend-tests-yes' into vce-fleet-api-loop
jafermarq Feb 27, 2024
3b7dc4c
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 27, 2024
1aa3b36
post merge update
jafermarq Feb 27, 2024
21f03a9
fix
jafermarq Feb 27, 2024
ab63974
Merge branch 'minor-fix-cli-test' into more-raybackend-tests-yes
jafermarq Feb 27, 2024
1d137da
Merge branch 'main' into more-raybackend-tests-yes
jafermarq Feb 27, 2024
a4590af
Merge branch 'more-raybackend-tests-yes' into vce-fleet-api-loop
jafermarq Feb 27, 2024
141be7b
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 27, 2024
4d8ee73
minor tweak
jafermarq Feb 27, 2024
1ac8e2b
runs passing server-app; client-app modules
jafermarq Feb 27, 2024
c366604
w/ previous
jafermarq Feb 27, 2024
a62a0d1
wip
jafermarq Feb 27, 2024
8f6de1e
Merge branch 'main' into more-raybackend-tests-yes
danieljanes Feb 27, 2024
c45c4af
no need for separate test/ dir
jafermarq Feb 27, 2024
e2ac2b0
Merge branch 'more-raybackend-tests-yes' into vce-fleet-api-loop
jafermarq Feb 27, 2024
c9492f0
update
jafermarq Feb 27, 2024
98b31e0
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 27, 2024
91e4413
Merge branch 'vce-fleet-run-simulation' into vce-fleet-notebook-ready
jafermarq Feb 27, 2024
b1e0460
merge w/ main
jafermarq Feb 27, 2024
fdb7ace
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 27, 2024
82878f6
updates
jafermarq Feb 27, 2024
12ed070
merge w/ `vce-fleet-run-simulation`
jafermarq Feb 27, 2024
b3d397b
better handling of exceptions in vce's ; adjust test for
jafermarq Feb 27, 2024
bd7b1aa
completed tests.
jafermarq Feb 27, 2024
4e32264
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 27, 2024
0dce992
update import
jafermarq Feb 27, 2024
1936631
wip
jafermarq Feb 28, 2024
d679ce6
merge and update
jafermarq Feb 28, 2024
6e3271b
minior formatting
jafermarq Feb 28, 2024
67777c5
Apply suggestions from code review
jafermarq Feb 28, 2024
35f4566
Merge branch 'main' into vce-fleet-api-loop
jafermarq Feb 28, 2024
46eac84
fixes post review
jafermarq Feb 28, 2024
f2ee2cd
Merge branch 'main' into vce-fleet-api-loop
jafermarq Feb 28, 2024
2bc3869
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 28, 2024
cc6a145
instantiating backend in asyncio event loop
jafermarq Feb 28, 2024
99a2522
Merge branch 'vce-fleet-api-loop' into vce-fleet-run-simulation
jafermarq Feb 28, 2024
662579e
minor
jafermarq Feb 28, 2024
91c3eb2
Merge branch 'vce-fleet-run-simulation' into vce-fleet-notebook-ready
jafermarq Feb 28, 2024
6dd034b
updated TF notebook
jafermarq Feb 28, 2024
ed375a4
Merge branch 'main' into vce-fleet-run-simulation
jafermarq Feb 28, 2024
2aba895
moved `run_driver_api_grpc()`
jafermarq Feb 28, 2024
744084c
Merge branch 'move-run-driver-api-grpc' into vce-fleet-run-simulation
jafermarq Feb 28, 2024
f3d2c63
update and format
jafermarq Feb 28, 2024
c3fcdf6
Merge branch 'main' into vce-fleet-run-simulation
jafermarq Feb 28, 2024
c2a4dc8
better exception handling; updated simp.py examples
jafermarq Feb 29, 2024
eafc2ed
Merge branch 'main' into vce-fleet-run-simulation
jafermarq Feb 29, 2024
1b3bc49
merge; fixed conflicts; better docstrings
jafermarq Feb 29, 2024
94c2649
updates
jafermarq Feb 29, 2024
bebf3c6
merge w/ main
jafermarq Feb 29, 2024
2783865
Merge branch 'main' into vce-fleet-notebook-ready
jafermarq Mar 1, 2024
b00e840
better
jafermarq Mar 1, 2024
afef4e5
Merge branch 'main' into vce-run-simulation-th-handling
danieljanes Mar 1, 2024
6f9bd9e
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 1, 2024
32d8b33
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 1, 2024
a29b5b6
merge
jafermarq Mar 1, 2024
16d9c57
merge w/ main
jafermarq Mar 1, 2024
57a84e5
pyling, mypy fixes
jafermarq Mar 1, 2024
5ef65ee
handling asyncio event loop running by default in colab/jupyter
jafermarq Mar 1, 2024
5f16bee
join thread, else bad things happen
jafermarq Mar 1, 2024
232a82b
Update src/py/flwr/server/run_serverapp.py
danieljanes Mar 2, 2024
7a56928
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 2, 2024
2859e3e
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 2, 2024
8e0f95c
exposing relevant args to entry point through python env / notebook; …
jafermarq Mar 2, 2024
39f443b
Merge branch 'main' into vce-fleet-notebook-ready
jafermarq Mar 4, 2024
86f3761
moved input args; fix enable GPU growth in ServerApp thread; other minor
jafermarq Mar 4, 2024
f3ed0c9
simplifications; option `--verbose`
jafermarq Mar 4, 2024
43bd2e1
discarded changes to notebooks
jafermarq Mar 5, 2024
91683fe
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
8531ab6
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
0de86ad
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
a7e875a
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
6a18a1e
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
bceabb0
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
037eda4
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
af97609
Update src/py/flwr/simulation/run_simulation.py
danieljanes Mar 5, 2024
fb506c8
Merge branch 'main' into vce-fleet-notebook-ready
danieljanes Mar 5, 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ flower-fleet-api = "flwr.server:run_fleet_api"
flower-superlink = "flwr.server:run_superlink"
flower-client-app = "flwr.client:run_client_app"
flower-server-app = "flwr.server:run_server_app"
flower-simulation = "flwr.simulation:run_simulation"
flower-simulation = "flwr.simulation:run_simulation_from_cli"

[tool.poetry.dependencies]
python = "^3.8"
Expand Down
6 changes: 3 additions & 3 deletions src/py/flwr/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def run_superlink() -> None:
f_stop = asyncio.Event() # Does nothing
_run_fleet_api_vce(
num_supernodes=args.num_supernodes,
client_app_module_name=args.client_app,
client_app_attr=args.client_app,
backend_name=args.backend,
backend_config_json_stream=args.backend_config,
working_dir=args.dir,
Expand Down Expand Up @@ -438,7 +438,7 @@ def _run_fleet_api_grpc_rere(
# pylint: disable=too-many-arguments
def _run_fleet_api_vce(
num_supernodes: int,
client_app_module_name: str,
client_app_attr: str,
backend_name: str,
backend_config_json_stream: str,
working_dir: str,
Expand All @@ -449,7 +449,7 @@ def _run_fleet_api_vce(

start_vce(
num_supernodes=num_supernodes,
client_app_module_name=client_app_module_name,
client_app_attr=client_app_attr,
backend_name=backend_name,
backend_config_json_stream=backend_config_json_stream,
state_factory=state_factory,
Expand Down
23 changes: 14 additions & 9 deletions src/py/flwr/server/run_serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


import argparse
import asyncio
import sys
from logging import DEBUG, WARN
from pathlib import Path
Expand All @@ -30,17 +29,27 @@


def run(
server_app_attr: str,
driver: Driver,
server_app_dir: str,
stop_event: Optional[asyncio.Event] = None,
server_app_attr: Optional[str] = None,
loaded_server_app: Optional[ServerApp] = None,
) -> None:
"""Run ServerApp with a given Driver."""
if not (server_app_attr is None) ^ (loaded_server_app is None):
raise ValueError(
"Either `server_app_attr` or `loaded_server_app` should be set "
"but not both. "
)

if server_app_dir is not None:
sys.path.insert(0, server_app_dir)

# Load ServerApp if needed
def _load() -> ServerApp:
server_app: ServerApp = load_server_app(server_app_attr)
if server_app_attr:
server_app: ServerApp = load_server_app(server_app_attr)
if loaded_server_app:
server_app = loaded_server_app
return server_app

server_app = _load()
Expand All @@ -52,10 +61,6 @@ def _load() -> ServerApp:
server_app(driver=driver, context=context)

log(DEBUG, "ServerApp finished running.")
# Upon completion, trigger stop event if one was passed
if stop_event is not None:
log(DEBUG, "Triggering stop event.")
stop_event.set()


def run_server_app() -> None:
Expand Down Expand Up @@ -117,7 +122,7 @@ def run_server_app() -> None:
)

# Run the Server App with the Driver
run(server_app_attr, driver, server_app_dir)
run(driver=driver, server_app_dir=server_app_dir, server_app_attr=server_app_attr)

# Clean up
driver.__del__() # pylint: disable=unnecessary-dunder-call
Expand Down
18 changes: 15 additions & 3 deletions src/py/flwr/server/superlink/fleet/vce/vce_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,23 @@ async def run(

# pylint: disable=too-many-arguments,unused-argument,too-many-locals
def start_vce(
client_app_module_name: str,
backend_name: str,
backend_config_json_stream: str,
working_dir: str,
f_stop: asyncio.Event,
client_app: Optional[ClientApp] = None,
client_app_attr: Optional[str] = None,
num_supernodes: Optional[int] = None,
state_factory: Optional[StateFactory] = None,
existing_nodes_mapping: Optional[NodeToPartitionMapping] = None,
) -> None:
"""Start Fleet API with the Simulation Engine."""
if client_app_attr is not None and client_app is not None:
raise ValueError(
"Both `client_app_attr` and `client_app` are provided, "
"but only one is allowed."
)

if num_supernodes is not None and existing_nodes_mapping is not None:
raise ValueError(
"Both `num_supernodes` and `existing_nodes_mapping` are provided, "
Expand Down Expand Up @@ -292,10 +299,15 @@ def backend_fn() -> Backend:
"""Instantiate a Backend."""
return backend_type(backend_config, work_dir=working_dir)

log(INFO, "client_app_module_name = %s", client_app_module_name)
log(INFO, "client_app_attr = %s", client_app_attr)

# Load ClientApp if needed
def _load() -> ClientApp:
app: ClientApp = load_client_app(client_app_module_name)

if client_app_attr:
app: ClientApp = load_client_app(client_app_attr)
if client_app:
app = client_app
return app

app_fn = _load
Expand Down
8 changes: 4 additions & 4 deletions src/py/flwr/server/superlink/fleet/vce/vce_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _autoresolve_working_dir(rel_client_app_dir: str = "backend") -> str:
# pylint: disable=too-many-arguments
def start_and_shutdown(
backend: str = "ray",
clientapp_module: str = "raybackend_test:client_app",
client_app_attr: str = "raybackend_test:client_app",
working_dir: str = "",
num_supernodes: Optional[int] = None,
state_factory: Optional[StateFactory] = None,
Expand Down Expand Up @@ -162,7 +162,7 @@ def start_and_shutdown(

start_vce(
num_supernodes=num_supernodes,
client_app_module_name=clientapp_module,
client_app_attr=client_app_attr,
backend_name=backend,
backend_config_json_stream=backend_config,
state_factory=state_factory,
Expand All @@ -183,7 +183,7 @@ def test_erroneous_no_supernodes_client_mapping(self) -> None:
with self.assertRaises(ValueError):
start_and_shutdown(duration=2)

def test_erroneous_clientapp_module_name(self) -> None:
def test_erroneous_client_app_attr(self) -> None:
"""Tests attempt to load a ClientApp that can't be found."""
num_messages = 7
num_nodes = 59
Expand All @@ -193,7 +193,7 @@ def test_erroneous_clientapp_module_name(self) -> None:
)
with self.assertRaises(RuntimeError):
start_and_shutdown(
clientapp_module="totally_fictitious_app:client",
client_app_attr="totally_fictitious_app:client",
state_factory=state_factory,
nodes_mapping=nodes_mapping,
)
Expand Down
7 changes: 2 additions & 5 deletions src/py/flwr/simulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import importlib

from flwr.simulation.run_simulation import run_simulation
from flwr.simulation.run_simulation import run_simulation, run_simulation_from_cli

is_ray_installed = importlib.util.find_spec("ray") is not None

Expand All @@ -36,7 +36,4 @@ def start_simulation(*args, **kwargs): # type: ignore
raise ImportError(RAY_IMPORT_ERROR)


__all__ = [
"start_simulation",
"run_simulation",
]
__all__ = ["start_simulation", "run_simulation_from_cli", "run_simulation"]
Loading