flwr-nightly 1.11.0.dev20240823__py3-none-any.whl → 1.12.0.dev20240906__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.

Files changed (48) hide show
  1. flwr/cli/app.py +0 -2
  2. flwr/cli/new/new.py +24 -10
  3. flwr/cli/new/templates/app/LICENSE.tpl +202 -0
  4. flwr/cli/new/templates/app/README.baseline.md.tpl +127 -0
  5. flwr/cli/new/templates/app/README.flowertune.md.tpl +16 -6
  6. flwr/cli/new/templates/app/code/__init__.baseline.py.tpl +1 -0
  7. flwr/cli/new/templates/app/code/client.baseline.py.tpl +58 -0
  8. flwr/cli/new/templates/app/code/dataset.baseline.py.tpl +36 -0
  9. flwr/cli/new/templates/app/code/flwr_tune/{client.py.tpl → client_app.py.tpl} +50 -40
  10. flwr/cli/new/templates/app/code/flwr_tune/dataset.py.tpl +32 -2
  11. flwr/cli/new/templates/app/code/flwr_tune/models.py.tpl +0 -3
  12. flwr/cli/new/templates/app/code/flwr_tune/server_app.py.tpl +95 -0
  13. flwr/cli/new/templates/app/code/flwr_tune/strategy.py.tpl +83 -0
  14. flwr/cli/new/templates/app/code/model.baseline.py.tpl +80 -0
  15. flwr/cli/new/templates/app/code/server.baseline.py.tpl +46 -0
  16. flwr/cli/new/templates/app/code/strategy.baseline.py.tpl +1 -0
  17. flwr/cli/new/templates/app/code/utils.baseline.py.tpl +1 -0
  18. flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +138 -0
  19. flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +34 -7
  20. flwr/cli/run/run.py +2 -2
  21. flwr/client/__init__.py +0 -4
  22. flwr/client/grpc_rere_client/client_interceptor.py +13 -4
  23. flwr/client/supernode/app.py +3 -1
  24. flwr/common/config.py +14 -11
  25. flwr/common/telemetry.py +36 -30
  26. flwr/server/__init__.py +0 -4
  27. flwr/server/app.py +13 -13
  28. flwr/server/compat/app.py +0 -5
  29. flwr/server/driver/grpc_driver.py +1 -3
  30. flwr/server/run_serverapp.py +15 -1
  31. flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +19 -8
  32. flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +11 -11
  33. flwr/server/superlink/state/in_memory_state.py +15 -15
  34. flwr/server/superlink/state/sqlite_state.py +10 -10
  35. flwr/server/superlink/state/state.py +8 -8
  36. flwr/simulation/run_simulation.py +23 -6
  37. flwr/superexec/__init__.py +0 -6
  38. flwr/superexec/app.py +3 -1
  39. {flwr_nightly-1.11.0.dev20240823.dist-info → flwr_nightly-1.12.0.dev20240906.dist-info}/METADATA +3 -3
  40. {flwr_nightly-1.11.0.dev20240823.dist-info → flwr_nightly-1.12.0.dev20240906.dist-info}/RECORD +43 -35
  41. flwr_nightly-1.12.0.dev20240906.dist-info/entry_points.txt +10 -0
  42. flwr/cli/new/templates/app/code/flwr_tune/app.py.tpl +0 -89
  43. flwr/cli/new/templates/app/code/flwr_tune/config.yaml.tpl +0 -34
  44. flwr/cli/new/templates/app/code/flwr_tune/server.py.tpl +0 -48
  45. flwr/cli/new/templates/app/code/flwr_tune/static_config.yaml.tpl +0 -11
  46. flwr_nightly-1.11.0.dev20240823.dist-info/entry_points.txt +0 -10
  47. {flwr_nightly-1.11.0.dev20240823.dist-info → flwr_nightly-1.12.0.dev20240906.dist-info}/LICENSE +0 -0
  48. {flwr_nightly-1.11.0.dev20240823.dist-info → flwr_nightly-1.12.0.dev20240906.dist-info}/WHEEL +0 -0
flwr/cli/app.py CHANGED
@@ -18,7 +18,6 @@ import typer
18
18
  from typer.main import get_command
19
19
 
20
20
  from .build import build
21
- from .example import example
22
21
  from .install import install
23
22
  from .new import new
24
23
  from .run import run
@@ -33,7 +32,6 @@ app = typer.Typer(
33
32
  )
34
33
 
35
34
  app.command()(new)
36
- app.command()(example)
37
35
  app.command()(run)
38
36
  app.command()(build)
39
37
  app.command()(install)
flwr/cli/new/new.py CHANGED
@@ -42,6 +42,7 @@ class MlFramework(str, Enum):
42
42
  MLX = "MLX"
43
43
  NUMPY = "NumPy"
44
44
  FLOWERTUNE = "FlowerTune"
45
+ BASELINE = "Flower Baseline"
45
46
 
46
47
 
47
48
  class LlmChallengeName(str, Enum):
@@ -164,6 +165,8 @@ def new(
164
165
  llm_challenge_str = selected_value[0]
165
166
  llm_challenge_str = llm_challenge_str.lower()
166
167
 
168
+ is_baseline_project = framework_str == "baseline"
169
+
167
170
  print(
168
171
  typer.style(
169
172
  f"\n🔨 Creating Flower App {app_name}...",
@@ -187,24 +190,20 @@ def new(
187
190
  "pyproject.toml": {"template": f"app/pyproject.{framework_str}.toml.tpl"},
188
191
  "README.md": {"template": f"app/README.{framework_str}.md.tpl"},
189
192
  f"{import_name}/__init__.py": {"template": "app/code/__init__.py.tpl"},
190
- f"{import_name}/server.py": {
191
- "template": "app/code/flwr_tune/server.py.tpl"
193
+ f"{import_name}/server_app.py": {
194
+ "template": "app/code/flwr_tune/server_app.py.tpl"
192
195
  },
193
- f"{import_name}/client.py": {
194
- "template": "app/code/flwr_tune/client.py.tpl"
196
+ f"{import_name}/client_app.py": {
197
+ "template": "app/code/flwr_tune/client_app.py.tpl"
195
198
  },
196
- f"{import_name}/app.py": {"template": "app/code/flwr_tune/app.py.tpl"},
197
199
  f"{import_name}/models.py": {
198
200
  "template": "app/code/flwr_tune/models.py.tpl"
199
201
  },
200
202
  f"{import_name}/dataset.py": {
201
203
  "template": "app/code/flwr_tune/dataset.py.tpl"
202
204
  },
203
- f"{import_name}/conf/config.yaml": {
204
- "template": "app/code/flwr_tune/config.yaml.tpl"
205
- },
206
- f"{import_name}/conf/static_config.yaml": {
207
- "template": "app/code/flwr_tune/static_config.yaml.tpl"
205
+ f"{import_name}/strategy.py": {
206
+ "template": "app/code/flwr_tune/strategy.py.tpl"
208
207
  },
209
208
  }
210
209
 
@@ -259,6 +258,21 @@ def new(
259
258
  "template": f"app/code/task.{framework_str}.py.tpl"
260
259
  }
261
260
 
261
+ if is_baseline_project:
262
+ # Include additional files for baseline template
263
+ for file_name in ["model", "dataset", "strategy", "utils", "__init__"]:
264
+ files[f"{import_name}/{file_name}.py"] = {
265
+ "template": f"app/code/{file_name}.{framework_str}.py.tpl"
266
+ }
267
+
268
+ # Replace README.md
269
+ files["README.md"]["template"] = f"app/README.{framework_str}.md.tpl"
270
+
271
+ # Add LICENSE
272
+ files["LICENSE"] = {"template": "app/LICENSE.tpl"}
273
+
274
+ context["framework_str"] = "baseline"
275
+
262
276
  for file_path, value in files.items():
263
277
  render_and_create(
264
278
  file_path=project_dir / file_path,
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,127 @@
1
+ ---
2
+ title: title of the paper # TODO
3
+ url: https://arxiv.org/abs/2007.14390 # TODO: update with the link to your paper
4
+ labels: [label1, label2] # TODO: please add between 4 and 10 single-word (maybe two-words) labels (e.g. system heterogeneity, image classification, asynchronous, weight sharing, cross-silo). Do not use "". Remove this comment once you are done.
5
+ dataset: [dataset1, dataset2] # TODO: list of datasets you include in your baseline. Do not use "". Remove this comment once you are done.
6
+ ---
7
+
8
+ > [!IMPORTANT]
9
+ > This is the template for your `README.md`. Please fill-in the information in all areas with a :warning: symbol.
10
+ > Please refer to the [Flower Baselines contribution](https://flower.ai/docs/baselines/how-to-contribute-baselines.html) and [Flower Baselines usage](https://flower.ai/docs/baselines/how-to-use-baselines.html) guides for more details.
11
+ > Please complete the metadata section at the very top of this README. This generates a table at the top of the file that will facilitate indexing baselines.
12
+ > Please remove this [!IMPORTANT] block once you are done with your `README.md` as well as all the `:warning:` symbols and the comments next to them.
13
+
14
+ > [!IMPORTANT]
15
+ > To help having all baselines similarly formatted and structured, we have included two scripts in `baselines/dev` that when run will format your code and run some tests checking if it's formatted.
16
+ > These checks use standard packages such as `isort`, `black`, `pylint` and others. You as a baseline creator will need to install additional pacakges. These are already specified in the `pyproject.toml` of
17
+ > your baseline. Follow these steps:
18
+
19
+ ```bash
20
+ # Create a python env
21
+ pyenv virtualenv 3.10.14 $project_name
22
+
23
+ # Activate it
24
+ pyenv activate $project_name
25
+
26
+ # Install project including developer packages
27
+ # Note the `-e` this means you install it in editable mode
28
+ # so even if you change the code you don't need to do `pip install`
29
+ # again. However, if you add a new dependency to `pyproject.toml` you
30
+ # will need to re-run the command below
31
+ pip install -e ".[dev]"
32
+
33
+ # Even without modifying or adding new code, you can run your baseline
34
+ # with the placeholder code generated when you did `flwr new`. If you
35
+ # want to test this to familiarise yourself with how flower apps are
36
+ # executed, execute this from the directory where you `pyproject.toml` is:
37
+ flwr run .
38
+
39
+ # At anypoint during the process of creating your baseline you can
40
+ # run the formatting script. For this do:
41
+ cd .. # so you are in the `flower/baselines` directory
42
+
43
+ # Run the formatting script (it will auto-correct issues if possible)
44
+ ./dev/format-baseline.sh $project_name
45
+
46
+ # Then, if the above is all good, run the tests.
47
+ ./dev/test-baseline.sh $project_name
48
+ ```
49
+
50
+ > [!IMPORTANT]
51
+ > When you open a PR to get the baseline merged into the main Flower repository, the `./dev/test-baseline.sh` script will run. Only if test pass, the baseline can be merged.
52
+ > Some issues highlighted by the tests script are easier than others to fix. Do not hesitate in reaching out for help to us (e.g. as a comment in your PR) if you are stuck with these.
53
+ > Before opening your PR, please remove the code snippet above as well all the [!IMPORTANT] message blocks. Yes, including this one.
54
+
55
+ # :warning: *_Title of your baseline_* # Also copy this title to the `description` in the `[project]` section of your `pyproject.toml`.
56
+
57
+ > [!NOTE]
58
+ > If you use this baseline in your work, please remember to cite the original authors of the paper as well as the Flower paper.
59
+
60
+ **Paper:** :warning: *_add the URL of the paper page (not to the .pdf). For instance if you link a paper on ArXiv, add here the URL to the abstract page (e.g. [paper](https://arxiv.org/abs/1512.03385)). If your paper is in from a journal or conference proceedings, please follow the same logic._*
61
+
62
+ **Authors:** :warning: *_list authors of the paper_*
63
+
64
+ **Abstract:** :warning: *_add here the abstract of the paper you are implementing_*
65
+
66
+
67
+ ## About this baseline
68
+
69
+ **What’s implemented:** :warning: *_Concisely describe what experiment(s) (e.g. Figure 1, Table 2, etc) in the publication can be replicated by running the code. Please only use a few sentences. ”_*
70
+
71
+ **Datasets:** :warning: *_List the datasets you used (if you used a medium to large dataset, >10GB please also include the sizes of the dataset). We highly recommend using [FlowerDatasets](https://flower.ai/docs/datasets/index.html) to download and partition your dataset. If you have other ways to download the data, you can also use `FlowerDatasets` to partiion it._*
72
+
73
+ **Hardware Setup:** :warning: *_Give some details about the hardware (e.g. a server with 8x V100 32GB and 256GB of RAM) you used to run the experiments for this baseline. Indicate how long it took to run the experiments. Someone out there might not have access to the same resources you have so, could you list the absolute minimum hardware needed to run the experiment in a reasonable amount of time ? (e.g. minimum is 1x 16GB GPU otherwise a client model can’t be trained with a sufficiently large batch size). Could you test this works too?_*
74
+
75
+ **Contributors:** :warning: *_let the world know who contributed to this baseline. This could be either your name, your name and affiliation at the time, or your GitHub profile name if you prefer. If multiple contributors signed up for this baseline, please list yourself and your colleagues_*
76
+
77
+
78
+ ## Experimental Setup
79
+
80
+ **Task:** :warning: *_what’s the primary task that is being federated? (e.g. image classification, next-word prediction). If you have experiments for several, please list them_*
81
+
82
+ **Model:** :warning: *_provide details about the model you used in your experiments (if more than use a list). If your model is small, describing it as a table would be :100:. Some FL methods do not use an off-the-shelve model (e.g. ResNet18) instead they create your own. If this is your case, please provide a summary here and give pointers to where in the paper (e.g. Appendix B.4) is detailed._*
83
+
84
+ **Dataset:** :warning: *_Earlier you listed already the datasets that your baseline uses. Now you should include a breakdown of the details about each of them. Please include information about: how the dataset is partitioned (e.g. LDA with alpha 0.1 as default and all clients have the same number of training examples; or each client gets assigned a different number of samples following a power-law distribution with each client only instances of 2 classes)? if your dataset is naturally partitioned just state “naturally partitioned”; how many partitions there are (i.e. how many clients)? Please include this an all information relevant about the dataset and its partitioning into a table._*
85
+
86
+ **Training Hyperparameters:** :warning: *_Include a table with all the main hyperparameters in your baseline. Please show them with their default value._*
87
+
88
+
89
+ ## Environment Setup
90
+
91
+ :warning: _Specify the steps to create and activate your environment and install the baseline project. Most baselines are expected to require minimal steps as shown below. These instructions should be comprehensive enough so anyone can run them (if non standard, describe them step-by-step)._
92
+
93
+ :warning: _The dependencies for your baseline are listed in the `pyproject.toml`, extend it with additional packages needed for your baseline._
94
+
95
+ :warning: _Baselines should use Python 3.10, [pyenv](https://github.com/pyenv/pyenv), and the [virtualenv](https://github.com/pyenv/pyenv-virtualenv) plugging.
96
+
97
+ ```bash
98
+ # Create the virtual environment
99
+ pyenv virtualenv 3.10.14 <name-of-your-baseline-env>
100
+
101
+ # Activate it
102
+ pyenv activate <name-of-your-baseline-env>
103
+
104
+ # Install the baseline
105
+ pip install -e .
106
+ ```
107
+
108
+ :warning: _If your baseline requires running some script before starting an experiment, please indicate so here_.
109
+
110
+ ## Running the Experiments
111
+
112
+ :warning: _Make sure you have adjusted the `client-resources` in the federation in `pyproject.toml` so your simulation makes the best use of the system resources available._
113
+
114
+ :warning: _Your baseline implementation should replicate several of the experiments in the original paper. Please include here the exact command(s) needed to run each of those experiments followed by a figure (e.g. a line plot) or table showing the results you obtained when you ran the code. Below is an example of how you can present this. Please add command followed by results for all your experiments._
115
+
116
+ :warning: _You might want to add more hyperparameters and settings for your baseline. You can do so by extending `[tool.flwr.app.config]` in `pyproject.toml`. In addition, you can create a new `.toml` file that can be passed with the `--run-config` command (see below an example) to override several config values **already present** in `pyproject.toml`._
117
+ ```bash
118
+ # it is likely that for one experiment you need to override some arguments.
119
+ flwr run . --run-config learning-rate=0.1,coefficient=0.123
120
+
121
+ # or you might want to load different `.toml` configs all together:
122
+ flwr run . --run-config <my-big-experiment-config>.toml
123
+ ```
124
+
125
+ :warning: _It is preferable to show a single commmand (or multilple commands if they belong to the same experiment) and then a table/plot with the expected results, instead of showing all the commands first and then all the results/plots._
126
+ :warning: _If you present plots or other figures, please include either a Jupyter notebook showing how to create them or include a utility function that can be called after the experiments finish running._
127
+ :warning: If you include plots or figures, save them in `.png` format and place them in a new directory named `_static` at the same level as your `README.md`.
@@ -23,10 +23,12 @@ pip install -e .
23
23
 
24
24
  ## Experimental setup
25
25
 
26
- The dataset is partitioned into $num_clients shards with IID fashion serving as clients.
27
- We randomly sample $fraction_fit clients to be available for each round,
28
- and the federated fine-tuning lasts for `200` rounds.
29
- All settings are defined in `$project_name/conf/static_config.yaml`, which is not allowed to be modified for fair competition if you plan to participated in the [LLM leaderboard](https://flower.ai/benchmarks/llm-leaderboard).
26
+ The dataset is divided into $num_clients partitions in an IID fashion, a partition is assigned to each ClientApp.
27
+ We randomly sample a fraction ($fraction_fit) of the total nodes to participate in each round, for a total of `200` rounds.
28
+ All settings are defined in `pyproject.toml`.
29
+
30
+ > [!IMPORTANT]
31
+ > Please note that `[tool.flwr.app.config.static]` and `options.num-supernodes` under `[tool.flwr.federations.local-simulation]` are not allowed to be modified for fair competition if you plan to participated in the [LLM leaderboard](https://flower.ai/benchmarks/llm-leaderboard).
30
32
 
31
33
 
32
34
  ## Running the challenge
@@ -39,7 +41,7 @@ huggingface-cli login
39
41
  ```
40
42
 
41
43
  Run the challenge with default config values.
42
- The configs are in `$project_name/conf/config.yaml` and `$project_name/conf/static_config.yaml`, and are loaded automatically.
44
+ The configs are defined in `[tool.flwr.app.config]` entry of `pyproject.toml`, and are loaded automatically.
43
45
 
44
46
  ```bash
45
47
  flwr run
@@ -53,4 +55,12 @@ We use Mistral-7B model with 4-bit quantization as default. The estimated VRAM c
53
55
  | :--------: | :--------: | :--------: | :--------: | :--------: |
54
56
  | VRAM | ~25.50 GB | ~17.30 GB | ~22.80 GB | ~17.40 GB |
55
57
 
56
- You can adjust the CPU/GPU resources you assign to each of the clients based on your device, which is specified with `flower.engine.simulation` in `pyproject.toml`.
58
+ You can adjust the CPU/GPU resources you assign to each of the clients based on your device, which are specified with `options.backend.clientapp-cpus` and `options.backend.clientapp-gpus` under `[tool.flwr.federations.local-simulation]` entry in `pyproject.toml`.
59
+
60
+
61
+ ## Model saving
62
+
63
+ The global PEFT model checkpoints are saved every 5 rounds after aggregation on the sever side as default, which can be specified with `train.save-every-round` under [tool.flwr.app.config] entry in `pyproject.toml`.
64
+
65
+ > [!NOTE]
66
+ > Please provide the last PEFT checkpoint if you plan to participated in the [LLM leaderboard](https://flower.ai/benchmarks/llm-leaderboard).
@@ -0,0 +1 @@
1
+ """$project_name: A Flower Baseline."""
@@ -0,0 +1,58 @@
1
+ """$project_name: A Flower Baseline."""
2
+
3
+ import torch
4
+
5
+ from flwr.client import ClientApp, NumPyClient
6
+ from flwr.common import Context
7
+ from $import_name.dataset import load_data
8
+ from $import_name.model import Net, get_weights, set_weights, test, train
9
+
10
+
11
+ class FlowerClient(NumPyClient):
12
+ """A class defining the client."""
13
+
14
+ def __init__(self, net, trainloader, valloader, local_epochs):
15
+ self.net = net
16
+ self.trainloader = trainloader
17
+ self.valloader = valloader
18
+ self.local_epochs = local_epochs
19
+ self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
20
+ self.net.to(self.device)
21
+
22
+ def fit(self, parameters, config):
23
+ """Traim model using this client's data."""
24
+ set_weights(self.net, parameters)
25
+ train_loss = train(
26
+ self.net,
27
+ self.trainloader,
28
+ self.local_epochs,
29
+ self.device,
30
+ )
31
+ return (
32
+ get_weights(self.net),
33
+ len(self.trainloader.dataset),
34
+ {"train_loss": train_loss},
35
+ )
36
+
37
+ def evaluate(self, parameters, config):
38
+ """Evaluate model using this client's data."""
39
+ set_weights(self.net, parameters)
40
+ loss, accuracy = test(self.net, self.valloader, self.device)
41
+ return loss, len(self.valloader.dataset), {"accuracy": accuracy}
42
+
43
+
44
+ def client_fn(context: Context):
45
+ """Construct a Client that will be run in a ClientApp."""
46
+ # Load model and data
47
+ net = Net()
48
+ partition_id = int(context.node_config["partition-id"])
49
+ num_partitions = int(context.node_config["num-partitions"])
50
+ trainloader, valloader = load_data(partition_id, num_partitions)
51
+ local_epochs = context.run_config["local-epochs"]
52
+
53
+ # Return Client instance
54
+ return FlowerClient(net, trainloader, valloader, local_epochs).to_client()
55
+
56
+
57
+ # Flower ClientApp
58
+ app = ClientApp(client_fn)
@@ -0,0 +1,36 @@
1
+ """$project_name: A Flower Baseline."""
2
+
3
+ from flwr_datasets import FederatedDataset
4
+ from flwr_datasets.partitioner import IidPartitioner
5
+ from torch.utils.data import DataLoader
6
+ from torchvision.transforms import Compose, Normalize, ToTensor
7
+
8
+ FDS = None # Cache FederatedDataset
9
+
10
+
11
+ def load_data(partition_id: int, num_partitions: int):
12
+ """Load partition CIFAR10 data."""
13
+ # Only initialize `FederatedDataset` once
14
+ global FDS # pylint: disable=global-statement
15
+ if FDS is None:
16
+ partitioner = IidPartitioner(num_partitions=num_partitions)
17
+ FDS = FederatedDataset(
18
+ dataset="uoft-cs/cifar10",
19
+ partitioners={"train": partitioner},
20
+ )
21
+ partition = FDS.load_partition(partition_id)
22
+ # Divide data on each node: 80% train, 20% test
23
+ partition_train_test = partition.train_test_split(test_size=0.2, seed=42)
24
+ pytorch_transforms = Compose(
25
+ [ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]
26
+ )
27
+
28
+ def apply_transforms(batch):
29
+ """Apply transforms to the partition from FederatedDataset."""
30
+ batch["img"] = [pytorch_transforms(img) for img in batch["img"]]
31
+ return batch
32
+
33
+ partition_train_test = partition_train_test.with_transform(apply_transforms)
34
+ trainloader = DataLoader(partition_train_test["train"], batch_size=32, shuffle=True)
35
+ testloader = DataLoader(partition_train_test["test"], batch_size=32)
36
+ return trainloader, testloader