resontech 0.1.1__tar.gz
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.
- resontech-0.1.1/LICENSE +201 -0
- resontech-0.1.1/MANIFEST.in +15 -0
- resontech-0.1.1/PKG-INFO +468 -0
- resontech-0.1.1/README.md +444 -0
- resontech-0.1.1/pyproject.toml +40 -0
- resontech-0.1.1/resontech/__init__.py +98 -0
- resontech-0.1.1/resontech/_http.py +117 -0
- resontech-0.1.1/resontech/_s3.py +252 -0
- resontech-0.1.1/resontech/_version.py +1 -0
- resontech-0.1.1/resontech/client.py +496 -0
- resontech-0.1.1/resontech/config.py +62 -0
- resontech-0.1.1/resontech/exceptions.py +26 -0
- resontech-0.1.1/resontech/models/__init__.py +17 -0
- resontech-0.1.1/resontech/models/job.py +60 -0
- resontech-0.1.1/resontech/models/progress.py +15 -0
- resontech-0.1.1/resontech/models/requests.py +51 -0
- resontech-0.1.1/resontech/models/user.py +31 -0
- resontech-0.1.1/resontech/models/worker.py +38 -0
- resontech-0.1.1/resontech/models/workspace.py +48 -0
- resontech-0.1.1/resontech/resources/__init__.py +4 -0
- resontech-0.1.1/resontech/resources/dashboard.py +78 -0
- resontech-0.1.1/resontech/resources/jobs.py +56 -0
- resontech-0.1.1/resontech/rt/__init__.py +24 -0
- resontech-0.1.1/resontech/rt/_platform/__init__.py +2 -0
- resontech-0.1.1/resontech/rt/_platform/custom_client_executor.py +320 -0
- resontech-0.1.1/resontech/rt/_platform/custom_persistor.py +44 -0
- resontech-0.1.1/resontech/rt/builder.py +311 -0
- resontech-0.1.1/resontech/rt/config.py +142 -0
- resontech-0.1.1/resontech.egg-info/PKG-INFO +468 -0
- resontech-0.1.1/resontech.egg-info/SOURCES.txt +32 -0
- resontech-0.1.1/resontech.egg-info/dependency_links.txt +1 -0
- resontech-0.1.1/resontech.egg-info/requires.txt +9 -0
- resontech-0.1.1/resontech.egg-info/top_level.txt +1 -0
- resontech-0.1.1/setup.cfg +4 -0
resontech-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 ResonTech
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
|
|
5
|
+
prune tests
|
|
6
|
+
prune docs
|
|
7
|
+
prune .pytest_cache
|
|
8
|
+
prune build
|
|
9
|
+
prune dist
|
|
10
|
+
|
|
11
|
+
global-exclude __pycache__
|
|
12
|
+
global-exclude *.py[cod]
|
|
13
|
+
global-exclude *.so
|
|
14
|
+
global-exclude .DS_Store
|
|
15
|
+
global-exclude .git*
|
resontech-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: resontech
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: SDK for submitting federated learning jobs to the ResonTech platform
|
|
5
|
+
Author: ResonTech
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: httpx>=0.27
|
|
16
|
+
Requires-Dist: boto3<1.41,>=1.34
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
19
|
+
Requires-Dist: fastapi>=0.111; extra == "dev"
|
|
20
|
+
Requires-Dist: uvicorn[standard]>=0.30; extra == "dev"
|
|
21
|
+
Requires-Dist: httpx>=0.27; extra == "dev"
|
|
22
|
+
Requires-Dist: moto[s3]>=5; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# ResonTech SDK
|
|
26
|
+
|
|
27
|
+
Python SDK for submitting federated learning jobs to the ResonTech platform.
|
|
28
|
+
|
|
29
|
+
The SDK is **task-agnostic** — it does not assume a specific task (image
|
|
30
|
+
classification, NLP, regression, segmentation, RL, …), dataset format, loss,
|
|
31
|
+
or optimizer. You write your model and a one-round training function; the SDK
|
|
32
|
+
ships them to every worker and plumbs global weights in/out of the federation.
|
|
33
|
+
|
|
34
|
+
The SDK's job ends at submission. Progress, logs, output files, and the final
|
|
35
|
+
model are tracked on the web dashboard — the ``Job`` returned from ``rt_submit``
|
|
36
|
+
carries a ``dashboard_url`` you can open to follow along.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install resontech
|
|
44
|
+
# or, from source:
|
|
45
|
+
pip install -e /path/to/sdk
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Requirements:** Python 3.11+, `httpx`, `boto3`. PyTorch is required on the
|
|
49
|
+
worker side (NVFlare workflow runs on PyTorch state dicts).
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Setup — once per user
|
|
54
|
+
|
|
55
|
+
1. Log in to the ResonTech web UI.
|
|
56
|
+
2. Go to **Profile → Storage** and click **Provision Bucket**.
|
|
57
|
+
3. Copy the ``accessKeyId`` and ``secretAccessKey`` it shows you — the secret
|
|
58
|
+
is only displayed once. These are what the SDK uses to upload directly to
|
|
59
|
+
your bucket.
|
|
60
|
+
|
|
61
|
+
No SSH keys, no SFTP — everything goes over the S3 API.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## The user contract
|
|
66
|
+
|
|
67
|
+
Define your model class **and** an `fl_train` function in the same module
|
|
68
|
+
(or notebook cell). The SDK extracts the file/cell verbatim and ships it as
|
|
69
|
+
`model_def.py`. Each round, the worker:
|
|
70
|
+
|
|
71
|
+
1. Loads the latest global weights into your model.
|
|
72
|
+
2. Calls `fl_train(model, env, out_dir, logger)`.
|
|
73
|
+
3. Sends the returned weights back for aggregation.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
class Model(nn.Module): # any name, any signature
|
|
77
|
+
def __init__(self, **kwargs): # gets ModelConfig.model_args
|
|
78
|
+
super().__init__()
|
|
79
|
+
...
|
|
80
|
+
def forward(self, x): ...
|
|
81
|
+
|
|
82
|
+
def fl_train(model, env, out_dir, logger=None) -> dict:
|
|
83
|
+
"""
|
|
84
|
+
env contains: CURRENT_ROUND, SITE_NAME, JOB_ID, DATA_ROOT,
|
|
85
|
+
EPOCHS, BATCH_SIZE, LR, plus every key from TrainingConfig.extra.
|
|
86
|
+
Returns: {"weights": dict[str, Tensor], "samples": int, ...}
|
|
87
|
+
"""
|
|
88
|
+
# You own the dataset, loss, optimizer, training loop.
|
|
89
|
+
return {"weights": model.state_dict(), "samples": N}
|
|
90
|
+
|
|
91
|
+
def fl_validate(model, env, out_dir, logger=None) -> dict: # optional
|
|
92
|
+
...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Quick start (image classification)
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import json, os
|
|
101
|
+
import torch
|
|
102
|
+
import torch.nn as nn
|
|
103
|
+
from torch.utils.data import DataLoader, Dataset
|
|
104
|
+
from torchvision import models, transforms
|
|
105
|
+
|
|
106
|
+
from resontech import (
|
|
107
|
+
ResonTech, ResonTechConfig,
|
|
108
|
+
TrainingConfig, FederationConfig, ModelConfig,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class MyResNet(nn.Module):
|
|
113
|
+
def __init__(self, num_classes: int = 10):
|
|
114
|
+
super().__init__()
|
|
115
|
+
self.backbone = models.resnet18(weights=None)
|
|
116
|
+
self.backbone.fc = nn.Linear(self.backbone.fc.in_features, num_classes)
|
|
117
|
+
|
|
118
|
+
def forward(self, x):
|
|
119
|
+
return self.backbone(x)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def fl_train(model, env, out_dir, logger=None):
|
|
123
|
+
img_size = int(env.get("IMG_SIZE", 224))
|
|
124
|
+
num_classes = int(env.get("NUM_CLASSES", 10))
|
|
125
|
+
manifest = os.path.join(env["DATA_ROOT"], env.get("MANIFEST_FILE", "manifest.ndjson"))
|
|
126
|
+
|
|
127
|
+
class _Dataset(Dataset):
|
|
128
|
+
def __init__(self, path):
|
|
129
|
+
from PIL import Image, ImageFile
|
|
130
|
+
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
|
131
|
+
self.records = [json.loads(l) for l in open(path) if l.strip()]
|
|
132
|
+
self.tx = transforms.Compose([
|
|
133
|
+
transforms.Resize(max(img_size, 256)),
|
|
134
|
+
transforms.CenterCrop(img_size),
|
|
135
|
+
transforms.ToTensor(),
|
|
136
|
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
|
137
|
+
])
|
|
138
|
+
|
|
139
|
+
def __len__(self): return len(self.records)
|
|
140
|
+
|
|
141
|
+
def __getitem__(self, i):
|
|
142
|
+
from PIL import Image
|
|
143
|
+
rec = self.records[i]
|
|
144
|
+
with Image.open(rec["uri"]) as img:
|
|
145
|
+
x = self.tx(img.convert("RGB"))
|
|
146
|
+
y = torch.zeros(num_classes)
|
|
147
|
+
for j in rec.get("y", []):
|
|
148
|
+
y[int(j)] = 1.0
|
|
149
|
+
return x, y
|
|
150
|
+
|
|
151
|
+
ds = _Dataset(manifest)
|
|
152
|
+
loader = DataLoader(ds, batch_size=env["BATCH_SIZE"], shuffle=True)
|
|
153
|
+
optimizer = torch.optim.Adam(model.parameters(), lr=env["LR"])
|
|
154
|
+
loss_fn = nn.BCEWithLogitsLoss()
|
|
155
|
+
device = next(model.parameters()).device
|
|
156
|
+
|
|
157
|
+
model.train()
|
|
158
|
+
for _ in range(int(env["EPOCHS"])):
|
|
159
|
+
for x, y in loader:
|
|
160
|
+
x, y = x.to(device), y.to(device)
|
|
161
|
+
optimizer.zero_grad(set_to_none=True)
|
|
162
|
+
loss_fn(model(x), y).backward()
|
|
163
|
+
optimizer.step()
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
"weights": {k: v.detach().cpu() for k, v in model.state_dict().items()},
|
|
167
|
+
"samples": len(ds),
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
config = ResonTechConfig(
|
|
172
|
+
base_url="https://api.reson.tech",
|
|
173
|
+
email="you@example.com",
|
|
174
|
+
password="your-password",
|
|
175
|
+
s3_access_key_id="AKIA...",
|
|
176
|
+
s3_secret_access_key="...",
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
sdk = ResonTech(config)
|
|
180
|
+
sdk.login()
|
|
181
|
+
|
|
182
|
+
job = sdk.rt_submit(
|
|
183
|
+
model=MyResNet,
|
|
184
|
+
name="my-fl-job",
|
|
185
|
+
shards_dir="./shards",
|
|
186
|
+
requirements_txt="./requirements.txt",
|
|
187
|
+
training=TrainingConfig(
|
|
188
|
+
local_epochs=2,
|
|
189
|
+
batch_size=32,
|
|
190
|
+
learning_rate=1e-3,
|
|
191
|
+
extra={"IMG_SIZE": 224, "NUM_CLASSES": 10, "MANIFEST_FILE": "manifest.ndjson"},
|
|
192
|
+
),
|
|
193
|
+
federation=FederationConfig(num_rounds=5, min_clients=1),
|
|
194
|
+
model_config=ModelConfig(model_args={"num_classes": 10}),
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
print(f"Submitted: {job.id}")
|
|
198
|
+
print(f"Track at: {job.dashboard_url}")
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
For NLP, tabular, regression, segmentation, RL, etc., **replace `fl_train`**
|
|
202
|
+
with whatever your task needs. The SDK does not change.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Core concepts
|
|
207
|
+
|
|
208
|
+
### Model requirements
|
|
209
|
+
|
|
210
|
+
The user's model class can have any signature. The constructor receives
|
|
211
|
+
**only** the keys you put in `ModelConfig.model_args` — the SDK injects
|
|
212
|
+
nothing of its own.
|
|
213
|
+
|
|
214
|
+
### Dataset shards
|
|
215
|
+
|
|
216
|
+
Each worker receives one file from `shards_dir` (one shard per worker).
|
|
217
|
+
Mounted under `env["DATA_ROOT"]` on the worker. The SDK does not enforce a
|
|
218
|
+
file format — your `fl_train` decides how to read whatever you uploaded
|
|
219
|
+
(NDJSON manifests, parquet, raw images, HDF5, anything).
|
|
220
|
+
|
|
221
|
+
### What the SDK uploads for you
|
|
222
|
+
|
|
223
|
+
`sdk.rt_submit(...)` writes directly to `s3://<your-bucket>/jobs/<name>/`:
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
jobs/<name>/
|
|
227
|
+
├── scripts/
|
|
228
|
+
│ ├── model_def.py ← your file/cell, verbatim
|
|
229
|
+
│ ├── custom_client_executor.py ← bundled GenericClientExecutor (or your own)
|
|
230
|
+
│ └── custom_persistor.py
|
|
231
|
+
├── configs/
|
|
232
|
+
│ ├── config_fed_client.json
|
|
233
|
+
│ ├── config_fed_server.json
|
|
234
|
+
│ └── meta.json
|
|
235
|
+
├── requirements/
|
|
236
|
+
│ └── requirements.txt
|
|
237
|
+
├── shards/
|
|
238
|
+
│ ├── shard_0.zip
|
|
239
|
+
│ └── …
|
|
240
|
+
└── model/ ← optional warm-start weights
|
|
241
|
+
└── checkpoint.pt
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
No local temp directories are created. Shards stream from your disk directly
|
|
245
|
+
via S3 multipart (50 MB parts, 5 concurrent).
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## API reference
|
|
250
|
+
|
|
251
|
+
### `ResonTechConfig`
|
|
252
|
+
|
|
253
|
+
| Parameter | Type | Default | Description |
|
|
254
|
+
|-----------|------|---------|-------------|
|
|
255
|
+
| `base_url` | str | — | REST API base URL (HTTPS required for non-loopback hosts) |
|
|
256
|
+
| `email` | str | — | Account email |
|
|
257
|
+
| `password` | str | — | Account password |
|
|
258
|
+
| `s3_access_key_id` | str | — | Garage S3 access key (from the UI) |
|
|
259
|
+
| `s3_secret_access_key` | str | — | Garage S3 secret (from the UI) |
|
|
260
|
+
| `s3_bucket_alias` | str | `""` | Bucket alias — auto-resolved on login if empty |
|
|
261
|
+
| `s3_endpoint` | str | `https://s3.reson.tech` | S3-compatible endpoint URL |
|
|
262
|
+
| `s3_region` | str | `"garage"` | AWS region label |
|
|
263
|
+
| `dashboard_url` | str | `https://app.reson.tech` | Web UI base used in the tracking message |
|
|
264
|
+
|
|
265
|
+
### `TrainingConfig`
|
|
266
|
+
|
|
267
|
+
| Parameter | Type | Default | Description |
|
|
268
|
+
|-----------|------|---------|-------------|
|
|
269
|
+
| `local_epochs` | int | `1` | Local epochs per round → `env["EPOCHS"]` |
|
|
270
|
+
| `batch_size` | int | `32` | Mini-batch size hint → `env["BATCH_SIZE"]` |
|
|
271
|
+
| `learning_rate` | float | `0.001` | Optimiser LR hint → `env["LR"]` |
|
|
272
|
+
| `extra` | dict | `{}` | Free-form, task-specific knobs merged into `env` |
|
|
273
|
+
|
|
274
|
+
Anything task-specific — image size, num_classes, sequence length, optimizer
|
|
275
|
+
name, mixup alpha, etc. — goes into `extra` and reaches your `fl_train`
|
|
276
|
+
function via the `env` dict, with no SDK interpretation.
|
|
277
|
+
|
|
278
|
+
### `ModelConfig`
|
|
279
|
+
|
|
280
|
+
| Parameter | Type | Default | Description |
|
|
281
|
+
|-----------|------|---------|-------------|
|
|
282
|
+
| `model_class` | str | auto | Importable path to the model class (auto-filled by `rt_submit`) |
|
|
283
|
+
| `model_args` | dict | `{}` | Kwargs forwarded to the model constructor on every site |
|
|
284
|
+
| `adapter_module` | str | `"model_def"` | Module the executor imports |
|
|
285
|
+
| `train_fn` | str | `"fl_train"` | Name of the user training function |
|
|
286
|
+
| `validate_fn` | str | `"fl_validate"` | Name of the optional user validation function |
|
|
287
|
+
|
|
288
|
+
### `FederationConfig`
|
|
289
|
+
|
|
290
|
+
| Parameter | Type | Default | Description |
|
|
291
|
+
|-----------|------|---------|-------------|
|
|
292
|
+
| `num_rounds` | int | `5` | Total training rounds |
|
|
293
|
+
| `min_clients` | int | `1` | Clients required per round |
|
|
294
|
+
| `wait_time_after_min_received` | int | `10` | Seconds to wait after min clients respond |
|
|
295
|
+
| `heart_beat_timeout` | int | `600` | Client heartbeat timeout (seconds) |
|
|
296
|
+
| `job_name` | str | `"rt_job"` | Name stored in job metadata |
|
|
297
|
+
| `aggregator_path` / `aggregator_args` | str / dict | `InTimeAccumulateWeightedAggregator` w/ `expected_data_kind="WEIGHTS"` | Server-side aggregator |
|
|
298
|
+
| `shareable_generator_path` / `shareable_generator_args` | str / dict | `FullModelShareableGenerator` | Wraps weights into NVFlare Shareables |
|
|
299
|
+
| `workflow_path` / `workflow_extra_args` | str / dict | `ScatterAndGather` | Server workflow — swap in FedProx, FedOpt, cyclic, swarm, etc. |
|
|
300
|
+
|
|
301
|
+
### `ResonTech`
|
|
302
|
+
|
|
303
|
+
#### `sdk.login() → User`
|
|
304
|
+
|
|
305
|
+
Authenticates and sets the JWT token. Auto-resolves `s3_bucket_alias` via
|
|
306
|
+
`GET /api/users/storage/bucket` if not set. Raises `StorageError` if the
|
|
307
|
+
user has not provisioned a bucket yet.
|
|
308
|
+
|
|
309
|
+
#### `sdk.rt_submit(...) → Job`
|
|
310
|
+
|
|
311
|
+
Render, upload, and submit a federated learning job in one call.
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
job = sdk.rt_submit(
|
|
315
|
+
model=MyResNet, # nn.Module subclass (required)
|
|
316
|
+
name="my-fl-job", # display name (required)
|
|
317
|
+
shards_dir="./shards", # local directory of shard files (required)
|
|
318
|
+
requirements_txt="./req.txt", # optional
|
|
319
|
+
training=TrainingConfig(...),
|
|
320
|
+
federation=FederationConfig(...),
|
|
321
|
+
model_config=ModelConfig(...), # optional (auto-filled from class name)
|
|
322
|
+
executor=None, # custom NVFlare Executor class (optional)
|
|
323
|
+
persistor=None, # custom NVFlare ModelPersistor class (optional)
|
|
324
|
+
model_checkpoint="./warmstart.pt", # optional warm-start file
|
|
325
|
+
estimated_memory_mb=None, # VRAM hint in MB (optional)
|
|
326
|
+
worker_ids=None, # explicit list (optional)
|
|
327
|
+
auto_select_workers=False, # let server pick (optional)
|
|
328
|
+
only_mine_workers=False, # restrict to your own nodes
|
|
329
|
+
)
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### `sdk.storage`
|
|
333
|
+
|
|
334
|
+
Thin boto3 wrapper pointed at the user's bucket. Exposes `put_bytes`,
|
|
335
|
+
`upload_file`, `head`, `list`, `presign_get`. Useful for double-checking
|
|
336
|
+
what landed in the bucket or sharing a download URL.
|
|
337
|
+
|
|
338
|
+
#### `sdk.dashboard.worker_stats() → WorkerStats`
|
|
339
|
+
|
|
340
|
+
Returns the current cluster availability (online workers, free VRAM).
|
|
341
|
+
|
|
342
|
+
#### `sdk.jobs`
|
|
343
|
+
|
|
344
|
+
`JobsResource` — low-level job submission and retrieval (`submit`, `get`,
|
|
345
|
+
`list`). Prefer `rt_submit` unless you have already uploaded a workspace.
|
|
346
|
+
|
|
347
|
+
### `Job`
|
|
348
|
+
|
|
349
|
+
Thin handle returned by `rt_submit` and `jobs.submit`.
|
|
350
|
+
|
|
351
|
+
| Attribute | Description |
|
|
352
|
+
|-----------|-------------|
|
|
353
|
+
| `job.id` | Unique job ID |
|
|
354
|
+
| `job.name` | Job name |
|
|
355
|
+
| `job.state` | Initial `JobState` returned by the API |
|
|
356
|
+
| `job.dashboard_url` | URL to the job detail page on the web UI |
|
|
357
|
+
|
|
358
|
+
`JobState` values: `PENDING`, `RUNNING`, `FINISHED`, `FAILED`.
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## Advanced: custom executor / persistor
|
|
363
|
+
|
|
364
|
+
Pass your own NVFlare subclasses to override the bundled defaults. The SDK
|
|
365
|
+
extracts their source the same way it does for the model:
|
|
366
|
+
|
|
367
|
+
```python
|
|
368
|
+
from nvflare.apis.executor import Executor
|
|
369
|
+
|
|
370
|
+
class MyExecutor(Executor): ... # full control over the per-round flow
|
|
371
|
+
|
|
372
|
+
job = sdk.rt_submit(
|
|
373
|
+
model=MyResNet,
|
|
374
|
+
name="custom-fl-job",
|
|
375
|
+
shards_dir="./shards",
|
|
376
|
+
executor=MyExecutor,
|
|
377
|
+
)
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Note: a custom executor *replaces* `GenericClientExecutor` entirely — it does
|
|
381
|
+
not have to obey the `fl_train(model, env, out_dir, logger)` contract. You
|
|
382
|
+
own the whole NVFlare task lifecycle.
|
|
383
|
+
|
|
384
|
+
## Advanced: swap the workflow / aggregator
|
|
385
|
+
|
|
386
|
+
`FederationConfig` exposes the NVFlare component paths. Replace the defaults
|
|
387
|
+
with FedProx, FedOpt, cyclic, hierarchical, or any other workflow:
|
|
388
|
+
|
|
389
|
+
```python
|
|
390
|
+
federation = FederationConfig(
|
|
391
|
+
num_rounds=10,
|
|
392
|
+
workflow_path="nvflare.app_common.workflows.cyclic.Cyclic",
|
|
393
|
+
aggregator_path="nvflare.app_opt.pt.fedopt.PTFedOptModelShareableGenerator",
|
|
394
|
+
aggregator_args={"optimizer_args": {"lr": 0.01}},
|
|
395
|
+
)
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Advanced: inspect generated configs
|
|
399
|
+
|
|
400
|
+
`RTJobBuilder` renders configs and scripts as strings — no disk writes:
|
|
401
|
+
|
|
402
|
+
```python
|
|
403
|
+
from resontech.rt.builder import RTJobBuilder
|
|
404
|
+
|
|
405
|
+
builder = RTJobBuilder(training_config=training, federation_config=federation)
|
|
406
|
+
configs = builder.render_configs() # {"client": "...", "server": "...", "meta": "..."}
|
|
407
|
+
scripts = builder.render_scripts(MyResNet) # {"model_def.py": "...", ...}
|
|
408
|
+
|
|
409
|
+
print(configs["client"])
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## Troubleshooting
|
|
415
|
+
|
|
416
|
+
**`StorageError: No S3 bucket configured`**
|
|
417
|
+
You haven't provisioned a bucket yet. Go to the web UI's Profile → Storage
|
|
418
|
+
page and click "Provision Bucket", then copy the secret key into
|
|
419
|
+
`ResonTechConfig`.
|
|
420
|
+
|
|
421
|
+
**`StorageError: ... AccessDenied`**
|
|
422
|
+
The credentials in `s3_access_key_id` / `s3_secret_access_key` do not
|
|
423
|
+
match the bucket on your account. Rotate them from Profile → Storage →
|
|
424
|
+
Rotate Key and try again.
|
|
425
|
+
|
|
426
|
+
**`ValidationError: shards_dir is not a directory` or empty shards list**
|
|
427
|
+
Each worker needs its own shard file. Drop them into `shards_dir` as
|
|
428
|
+
`shard_0.zip`, `shard_1.zip`, … (one per worker).
|
|
429
|
+
|
|
430
|
+
**`name 'nn' is not defined` (server-side error)**
|
|
431
|
+
Put all imports (`import torch`, `import torch.nn as nn`, …) in the
|
|
432
|
+
**same notebook cell** as your model class and `fl_train`. The SDK extracts
|
|
433
|
+
the whole cell verbatim — anything outside that cell does not travel.
|
|
434
|
+
|
|
435
|
+
**`User module 'model_def' does not define class 'X'`** or
|
|
436
|
+
**`... does not define 'fl_train'`**
|
|
437
|
+
Your model class and `fl_train` function must live in the file/cell that
|
|
438
|
+
the SDK extracts. If you renamed either, adjust `ModelConfig.model_class`
|
|
439
|
+
and `ModelConfig.train_fn` accordingly.
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Documentation
|
|
444
|
+
|
|
445
|
+
Focused guides live in [`docs/`](docs):
|
|
446
|
+
|
|
447
|
+
- [Getting started](docs/getting-started.md)
|
|
448
|
+
- [Configuration reference](docs/configuration.md)
|
|
449
|
+
- [Training hyperparameters](docs/training-hyperparameters.md)
|
|
450
|
+
- [Custom classes](docs/custom-classes.md) — model, executor, persistor
|
|
451
|
+
- [Storage](docs/storage.md) — bucket layout and uploads
|
|
452
|
+
- [Job lifecycle](docs/job-lifecycle.md) — states and outputs
|
|
453
|
+
- [Troubleshooting](docs/troubleshooting.md)
|
|
454
|
+
|
|
455
|
+
## Runnable examples
|
|
456
|
+
|
|
457
|
+
Examples live outside the published package, in the project repository:
|
|
458
|
+
|
|
459
|
+
- `submit_job.py` — minimal script demonstrating the `fl_train` contract.
|
|
460
|
+
- `01_quickstart.ipynb` — walk-through notebook mirroring this README.
|
|
461
|
+
- `02_custom_hyperparameters.ipynb` — using `TrainingConfig.extra`.
|
|
462
|
+
- `03_custom_executor_persistor.ipynb` — replacing the bundled NVFlare classes.
|
|
463
|
+
- `04_warmstart_and_inspection.ipynb` — pre-trained checkpoint + bucket inspection.
|
|
464
|
+
|
|
465
|
+
Set the following environment variables before running any of them:
|
|
466
|
+
`RT_BASE_URL`, `RT_EMAIL`, `RT_PASSWORD`,
|
|
467
|
+
`RT_S3_ACCESS_KEY_ID`, `RT_S3_SECRET_ACCESS_KEY`,
|
|
468
|
+
and optionally `RT_S3_ENDPOINT`.
|