Skip to content

Commit 7acd226

Browse files
authored
Add/documentation (#237)
* add API reference for Export, Import, PymiloServer, PymiloClient to `README.md` * gitignore the pdf of paper refs * drop the `Type` column * update `enum` field mentioning, explain in text.
1 parent 0cbb4bb commit 7acd226

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ out
100100
gen
101101

102102
/.VSCodeCounter
103-
/tests/exported*
103+
/tests/exported*
104+
/paper/refs

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,26 @@ from pymilo import Export
9898
Export(model).save("model.json")
9999
```
100100

101+
#### Export
102+
103+
The `Export` class facilitates exporting of machine learning models to JSON files.
104+
105+
| **Parameter** | **Description** |
106+
| ------------- | --------------- |
107+
| model | The machine learning model to be exported |
108+
109+
| **Property** | **Description** |
110+
| ------------ | --------------- |
111+
| data | The serialized model data including all learned parameters |
112+
| version | The scikit-learn version used to train the model |
113+
| type | The type/class name of the exported model |
114+
115+
| **Method** | **Description** |
116+
| ---------- | --------------- |
117+
| save | Save the exported model to a JSON file |
118+
| to_json | Return the model as a JSON string representation |
119+
| batch_export | Export multiple models to individual JSON files in a directory |
120+
101121
You can check out your model as a JSON file now.
102122
```json
103123
{
@@ -149,6 +169,28 @@ model = Import("model.json").to_model()
149169
pred = model.predict(np.array([[3, 5]]))
150170
# pred = [16.] (=1 * 3 + 2 * 5 + 3)
151171
```
172+
173+
#### Import
174+
175+
The `Import` class facilitates importing of serialized models from JSON files, JSON strings, or URLs.
176+
177+
| **Parameter** | **Description** |
178+
| ------------- | --------------- |
179+
| file_adr | Path to the JSON file containing the serialized model |
180+
| json_dump | JSON string representation of the serialized model |
181+
| url | URL to download the serialized model from |
182+
183+
| **Property** | **Description** |
184+
| ------------ | --------------- |
185+
| data | The deserialized model data |
186+
| version | The scikit-learn version of the original model |
187+
| type | The type/class name of the imported model |
188+
189+
| **Method** | **Description** |
190+
| ---------- | --------------- |
191+
| to_model | Convert the imported data back to a scikit-learn model |
192+
| batch_import | Import multiple models from JSON files in a directory |
193+
152194
This loaded model is exactly the same as the original trained model.
153195

154196
### ML streaming
@@ -173,6 +215,33 @@ communicator = PymiloServer(
173215
).communicator
174216
communicator.run()
175217
```
218+
219+
#### PymiloServer
220+
221+
The `PymiloServer` class facilitates streaming machine learning models over a network.
222+
223+
| **Parameter** | **Description** |
224+
| ------------- | --------------- |
225+
| port | Port number for the server to listen on (default: 8000) |
226+
| host | Host address for the server (default: "127.0.0.1") |
227+
| compressor | Compression method from `Compression` enum |
228+
| communication_protocol | Communication protocol from `CommunicationProtocol` enum |
229+
230+
The `compressor` parameter accepts values from the `Compression` enum including `NULL` (no compression), `GZIP`, `ZLIB`, `LZMA`, or `BZ2`. The `communication_protocol` parameter accepts values from the `CommunicationProtocol` enum including `REST` or `WEBSOCKET`.
231+
232+
| **Method** | **Description** |
233+
| ---------- | --------------- |
234+
| init_client | Initialize a new client with the given client ID |
235+
| remove_client | Remove an existing client by client ID |
236+
| init_ml_model | Initialize a new ML model for a given client |
237+
| set_ml_model | Set or update the ML model for a client |
238+
| remove_ml_model | Remove an existing ML model for a client |
239+
| get_ml_models | Get all ML model IDs for a client |
240+
| execute_model | Execute model methods or access attributes |
241+
| grant_access | Allow a client to access another client's model |
242+
| revoke_access | Revoke access to a client's model |
243+
| get_allowed_models | Get models a client is allowed to access |
244+
176245
Now `PymiloServer` runs on port `8000` and exposes REST API to `upload`, `download` and retrieve **attributes** either **data attributes** like `model._coef` or **method attributes** like `model.predict(x_test)`.
177246

178247
ℹ️ By default, `PymiloServer` listens on the loopback interface (`127.0.0.1`). To make it accessible over a local network (LAN), specify your machine’s LAN IP address in the `host` parameter of the `PymiloServer` constructor.
@@ -190,6 +259,35 @@ pymilo_client.toggle_mode(PymiloClient.Mode.DELEGATE)
190259
result = pymilo_client.predict(x_test)
191260
```
192261

262+
#### PymiloClient
263+
264+
The `PymiloClient` class facilitates working with remote PyMilo servers.
265+
266+
| **Parameter** | **Description** |
267+
| ------------- | --------------- |
268+
| model | The local ML model to wrap around |
269+
| mode | Operating mode (LOCAL or DELEGATE) |
270+
| compressor | Compression method from `Compression` enum |
271+
| server_url | URL of the PyMilo server |
272+
| communication_protocol | Communication protocol from `CommunicationProtocol` enum |
273+
274+
The `mode` parameter accepts two values `LOCAL` to execute operations on the local model, or `DELEGATE` to delegate operations to the remote server. The `compressor` parameter accepts values from the `Compression` enum including `NULL` (no compression), `GZIP`, `ZLIB`, `LZMA`, or `BZ2`. The `communication_protocol` parameter accepts values from the `CommunicationProtocol` enum including `REST` or `WEBSOCKET`.
275+
276+
| **Method** | **Description** |
277+
| ---------- | --------------- |
278+
| toggle_mode | Switch between LOCAL and DELEGATE modes |
279+
| register | Register the client with the remote server |
280+
| deregister | Deregister the client from the server |
281+
| register_ml_model | Register an ML model with the server |
282+
| deregister_ml_model | Deregister an ML model from the server |
283+
| upload | Upload the local model to the remote server |
284+
| download | Download the remote model to local |
285+
| get_ml_models | Get all registered ML models for this client |
286+
| grant_access | Grant access to this client's model to another client |
287+
| revoke_access | Revoke access previously granted to another client |
288+
| get_allowance | Get clients who have access to this client's models |
289+
| get_allowed_models | Get models this client is allowed to access from another client |
290+
193291
ℹ️ If you've deployed `PymiloServer` locally (on port `8000` for instance), then `SERVER_URL` would be `http://127.0.0.1:8000` or `ws://127.0.0.1:8000` based on the selected protocol for the communication medium.
194292

195293
You can also download the remote ML model into your local and execute functions locally on your model.

0 commit comments

Comments
 (0)