Skip to content

Commit 08a9139

Browse files
committed
2 parents 7c19647 + 06e1bf9 commit 08a9139

File tree

7 files changed

+77
-75
lines changed

7 files changed

+77
-75
lines changed

API-REFERENCE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
## Syft
3131

32-
Syft client for static federated learning.
32+
Syft client for model-centric federated learning.
3333

3434
### Parameters
3535

@@ -45,16 +45,16 @@ Syft client for static federated learning.
4545
const client = new Syft({url: "ws://localhost:5000", verbose: true})
4646
const job = client.newJob({modelName: "mnist", modelVersion: "1.0.0"})
4747
job.on('accepted', async ({model, clientConfig}) => {
48-
// execute training
48+
// Execute training
4949
const [...newParams] = await this.plans['...'].execute(...)
5050
const diff = await model.createSerializedDiff(newParams)
5151
await this.report(diff)
5252
})
5353
job.on('rejected', ({timeout}) => {
54-
// re-try later or stop
54+
// Retry later or stop
5555
})
5656
job.on('error', (err) => {
57-
// handle errors
57+
// Handle errors
5858
})
5959
job.start()
6060
```
@@ -70,7 +70,7 @@ Authenticates the client against PyGrid and instantiates new Job with given opti
7070
- `options.modelVersion` **[string][26]** FL Model version.
7171

7272

73-
- Throws **any** Error
73+
- Throws **any** Error if grid client authentication failed.
7474

7575
Returns **[Promise][28]<[Job][29]>**
7676

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
![OpenCollective](https://img.shields.io/opencollective/all/openmined)
88

99
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
10+
1011
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
12+
1113
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1214

1315
# Syft.js
@@ -55,7 +57,7 @@ If you're not using a package manager, you will be able to include Syft.js withi
5557

5658
As a developer, there are few steps to building your own secure federated learning system upon the OpenMined infrastructure:
5759

58-
1. :robot: [Develop ML model and training procedure](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/static-fl/Part%2001%20-%20Create%20Plan.ipynb) (aka `Plan` in PySyft terminology) using [PySyft](https://github.com/OpenMined/PySyft).
60+
1. :robot: [Develop ML model and training procedure](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/model-centric-fl/Part%2001%20-%20Create%20Plan.ipynb) (aka `Plan` in PySyft terminology) using [PySyft](https://github.com/OpenMined/PySyft).
5961
1. :earth_americas: Host model and Plans on [PyGrid](https://github.com/OpenMined/PyGrid), which will deal with all the federated learning components of your pipeline.
6062
1. :tada: Execute the training on the variety of end-user devices using the client library (syft.js, [SwiftSyft](https://github.com/OpenMined/SwiftSyft), [KotlinSyft](https://github.com/OpenMined/KotlinSyft), [PySyft](https://github.com/OpenMined/PySyft)).
6163
1. :lock: Securely aggregate trained user models in PyGrid.
@@ -96,7 +98,7 @@ job.on('accepted', async ({ model, clientConfig }) => {
9698
const batches = LOAD_DATA(batchSize);
9799

98100
// Load model parameters.
99-
let modelParams = model.params.map(p => p.clone());
101+
let modelParams = model.params.map((p) => p.clone());
100102

101103
// Main training loop.
102104
for (let [data, labels] of batches) {
@@ -127,7 +129,7 @@ job.on('rejected', ({ timeout }) => {
127129
// Handle the job rejection, e.g. re-try after timeout.
128130
});
129131

130-
job.on('error', err => {
132+
job.on('error', (err) => {
131133
// Handle errors.
132134
});
133135
```
@@ -209,7 +211,7 @@ PyGrid URL will need to be adjusted accordingly in further steps.
209211
##### Create Model & Plan
210212

211213
After PyGrid is running, the next step is to create the model and training plan and host them in PyGrid.
212-
PySyft tutorials include [MNIST example jupyter notebooks](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/static-fl) that guide you through this process.
214+
PySyft tutorials include [MNIST example jupyter notebooks](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/model-centric-fl) that guide you through this process.
213215

214216
Fire up jupyter notebook in PySyft root folder:
215217

@@ -218,7 +220,7 @@ cd ~/fl-demo/PySyft
218220
jupyter notebook --notebook-dir=$(pwd)
219221
```
220222

221-
In the console, you should see URL you should open, or the browser will open automatically. After this, navigate to `examples/tutorials/static-fl` and [run the first notebook](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/static-fl/Part%2001%20-%20Create%20Plan.ipynb). At this point, you can pull down the model and training plan with syft.js. However, if you'd like to see how to execute the plan using the PySyft FL worker, [try running the second notebook](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/static-fl/Part%2002%20-%20Execute%20Plan.ipynb).
223+
In the console, you should see URL you should open, or the browser will open automatically. After this, navigate to `examples/tutorials/model-centric-fl` and [run the first notebook](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/model-centric-fl/Part%2001%20-%20Create%20Plan.ipynb). At this point, you can pull down the model and training plan with syft.js. However, if you'd like to see how to execute the plan using the PySyft FL worker, [try running the second notebook](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/model-centric-fl/Part%2002%20-%20Execute%20Plan.ipynb).
222224

223225
##### PyGrid Clean-up
224226

@@ -311,6 +313,7 @@ These people were integral part of the efforts to bring syft.js to fruition and
311313

312314
<!-- markdownlint-enable -->
313315
<!-- prettier-ignore-end -->
316+
314317
<!-- ALL-CONTRIBUTORS-LIST:END -->
315318

316319
## License

examples/mnist/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ with [PyGrid](https://github.com/OpenMined/pygrid) to train a plan on local data
66
## Quick Start
77

88
1. Install and start [PyGrid](https://github.com/OpenMined/pygrid)
9-
2. Install [PySyft](https://github.com/OpenMined/PySyft) and [execute the "Part 01 - Create Plan" notebook](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/static-fl/Part%2001%20-%20Create%20Plan.ipynb) from `examples/tutorials/static-fl` folder to seed the MNIST plan and model into PyGrid.
9+
2. Install [PySyft](https://github.com/OpenMined/PySyft) and [execute the "Part 01 - Create Plan" notebook](https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/model-centric-fl/Part%2001%20-%20Create%20Plan.ipynb) from `examples/tutorials/model-centric-fl` folder to seed the MNIST plan and model into PyGrid.
1010
3. Now back in this folder, execute `npm install`
1111
4. And then execute `npm start`
1212

examples/multi-armed-bandit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ While this demo is inherently simple, it's easy to see how one could extend it t
1010
## Quick Start
1111

1212
1. Install and start [PyGrid](https://github.com/OpenMined/pygrid)
13-
2. Install [PySyft](https://github.com/OpenMined/PySyft) and run the [Bandit create plan](<https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/static-fl/Part%2003%20-%20Create%20Plan%20(Bandit%20Demo).ipynb>).
13+
2. Install [PySyft](https://github.com/OpenMined/PySyft) and run the [Bandit create plan](<https://github.com/OpenMined/PySyft/blob/master/examples/tutorials/model-centric-fl/Part%2003%20-%20Create%20Plan%20(Bandit%20Demo).ipynb>).
1414
3. Now back in this folder, execute `npm install`
1515
4. And then execute `npm start`
1616

src/grid-api-client.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { GRID_ERROR } from './_errors';
44
import EventObserver from './events';
55

66
const HTTP_PATH_VERB = {
7-
'model_centric/get-plan': 'GET',
8-
'model_centric/get-model': 'GET',
9-
'model_centric/get-protocol': 'GET',
10-
'model_centric/cycle-request': 'POST',
11-
'model_centric/report': 'POST',
12-
'model_centric/authenticate': 'POST'
7+
'model-centric/get-plan': 'GET',
8+
'model-centric/get-model': 'GET',
9+
'model-centric/get-protocol': 'GET',
10+
'model-centric/cycle-request': 'POST',
11+
'model-centric/report': 'POST',
12+
'model-centric/authenticate': 'POST',
1313
};
1414

1515
export default class GridAPIClient {
@@ -42,10 +42,10 @@ export default class GridAPIClient {
4242
`Authenticating against ${modelName} ${modelVersion} with ${authToken}...`
4343
);
4444

45-
const response = await this._send('model_centric/authenticate', {
45+
const response = await this._send('model-centric/authenticate', {
4646
model_name: modelName,
4747
model_version: modelVersion,
48-
auth_token: authToken
48+
auth_token: authToken,
4949
});
5050

5151
return response;
@@ -56,13 +56,13 @@ export default class GridAPIClient {
5656
`[WID: ${workerId}] Requesting cycle for model ${modelName} v.${modelVersion} [${ping}, ${download}, ${upload}]...`
5757
);
5858

59-
const response = this._send('model_centric/cycle-request', {
59+
const response = this._send('model-centric/cycle-request', {
6060
worker_id: workerId,
6161
model: modelName,
6262
version: modelVersion,
6363
ping: ping,
6464
download: download,
65-
upload: upload
65+
upload: upload,
6666
});
6767

6868
return response;
@@ -74,11 +74,11 @@ export default class GridAPIClient {
7474
);
7575

7676
const response = await this._sendHttp(
77-
'model_centric/get-model',
77+
'model-centric/get-model',
7878
{
7979
worker_id: workerId,
8080
request_key: requestKey,
81-
model_id: modelId
81+
model_id: modelId,
8282
},
8383
'arrayBuffer'
8484
);
@@ -91,12 +91,12 @@ export default class GridAPIClient {
9191
);
9292

9393
const response = await this._sendHttp(
94-
'model_centric/get-plan',
94+
'model-centric/get-plan',
9595
{
9696
worker_id: workerId,
9797
request_key: requestKey,
9898
plan_id: planId,
99-
receive_operations_as: 'tfjs'
99+
receive_operations_as: 'tfjs',
100100
},
101101
'arrayBuffer'
102102
);
@@ -118,10 +118,10 @@ export default class GridAPIClient {
118118
`[WID: ${workerId}, KEY: ${requestKey}] Submitting report...`
119119
);
120120

121-
const response = await this._send('model_centric/report', {
121+
const response = await this._send('model-centric/report', {
122122
worker_id: workerId,
123123
request_key: requestKey,
124-
diff
124+
diff,
125125
});
126126

127127
return response;
@@ -131,35 +131,35 @@ export default class GridAPIClient {
131131
const speedTest = new SpeedTest({
132132
downloadUrl:
133133
this.httpUrl +
134-
'/model_centric/speed-test?worker_id=' +
134+
'/model-centric/speed-test?worker_id=' +
135135
encodeURIComponent(workerId) +
136136
'&random=' +
137137
Math.random(),
138138
uploadUrl:
139139
this.httpUrl +
140-
'/model_centric/speed-test?worker_id=' +
140+
'/model-centric/speed-test?worker_id=' +
141141
encodeURIComponent(workerId) +
142142
'&random=' +
143143
Math.random(),
144144
pingUrl:
145145
this.httpUrl +
146-
'/model_centric/speed-test?is_ping=1&worker_id=' +
146+
'/model-centric/speed-test?is_ping=1&worker_id=' +
147147
encodeURIComponent(workerId) +
148148
'&random=' +
149-
Math.random()
149+
Math.random(),
150150
});
151151

152152
const ping = await speedTest.getPing();
153153
// start tests altogether
154154
const [download, upload] = await Promise.all([
155155
speedTest.getDownloadSpeed(),
156-
speedTest.getUploadSpeed()
156+
speedTest.getUploadSpeed(),
157157
]);
158158

159159
return {
160160
ping,
161161
download,
162-
upload
162+
upload,
163163
};
164164
}
165165

@@ -182,20 +182,20 @@ export default class GridAPIClient {
182182

183183
if (method === 'GET') {
184184
const query = Object.keys(data)
185-
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
185+
.map((k) => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
186186
.join('&');
187187
response = await fetch(this.httpUrl + '/' + path + '?' + query, {
188188
method: 'GET',
189-
mode: 'cors'
189+
mode: 'cors',
190190
});
191191
} else {
192192
response = await fetch(this.httpUrl + '/' + path, {
193193
method: 'POST',
194194
mode: 'cors',
195195
headers: {
196-
'Content-Type': 'application/json'
196+
'Content-Type': 'application/json',
197197
},
198-
body: JSON.stringify(data)
198+
body: JSON.stringify(data),
199199
});
200200
}
201201

@@ -229,7 +229,7 @@ export default class GridAPIClient {
229229
const cleanUp = () => {
230230
// Remove all handlers related to message.
231231
this.wsMessageQueue = this.wsMessageQueue.filter(
232-
item => item !== onMessage
232+
(item) => item !== onMessage
233233
);
234234
this.observer.unsubscribe('ws-error', onError);
235235
this.observer.unsubscribe('ws-close', onClose);
@@ -241,7 +241,7 @@ export default class GridAPIClient {
241241
reject(new Error('Response timeout'));
242242
}, this.responseTimeout);
243243

244-
const onMessage = data => {
244+
const onMessage = (data) => {
245245
if (data.type !== message.type) {
246246
this.logger.log('Received invalid response type, ignoring');
247247
return false;
@@ -250,7 +250,7 @@ export default class GridAPIClient {
250250
resolve(data.data);
251251
};
252252

253-
const onError = event => {
253+
const onError = (event) => {
254254
cleanUp();
255255
reject(new Error(event));
256256
};
@@ -280,12 +280,12 @@ export default class GridAPIClient {
280280
this.ws = ws;
281281
resolve();
282282
};
283-
ws.onerror = event => {
283+
ws.onerror = (event) => {
284284
// couldn't connect
285285
this._handleWsError(event);
286286
reject(new Error(event));
287287
};
288-
ws.onclose = event => {
288+
ws.onclose = (event) => {
289289
// couldn't connect
290290
this._handleWsClose(event);
291291
reject(new Error('WS connection closed during connect'));

0 commit comments

Comments
 (0)