Skip to content

Commit cbc160b

Browse files
authored
Update models documentation (#1556)
1 parent a8be61c commit cbc160b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

docs/deployments/realtime-api/models.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,20 @@ Usage varies based on the predictor type:
189189

190190
### Python
191191

192-
To use live model reloading with the Python predictor, the model path(s) must be specified in the API's `predictor` configuration (via the `model_path` or `models` field). When models are specified in this manner, your `PythonPredictor` class must implement the `load_model()` function, and models can be retrieved by using the `get_model()` method of the `python_client` that's passed to the predictor's constructor:
192+
To use live model reloading with the Python predictor, the model path(s) must be specified in the API's `predictor` configuration (via the `model_path` or `models` field). When models are specified in this manner, your `PythonPredictor` class must implement the `load_model()` function, and models can be retrieved by using the `get_model()` method of the `python_client` that's passed into your predictor's constructor.
193+
194+
The `load_model()` function that you implement in your `PythonPredictor` can return anything that you need to make a prediction. There is one caveat: whatever the return value is, it must be unloadable from memory via the `del` keyword. The following frameworks have been tested to work:
195+
196+
* PyTorch (CPU & GPU)
197+
* ONNX (CPU & GPU)
198+
* Sklearn/MLFlow (CPU)
199+
* Numpy (CPU)
200+
* Pandas (CPU)
201+
* Caffe (not tested, but should work on CPU & GPU)
202+
203+
Python data structures containing these types are also supported (e.g. lists and dicts).
204+
205+
The `load_model()` function takes a single argument, with is a path (on disk) to the model to be loaded. It is called behind the scenes when you call the `python_client`'s `get_model()` method from your predictor's `predict()` method. Whatever `load_model()` returns will be the exact return value of `python_client.get_model()`. Here is the schema for `python_client.get_model()`:
193206

194207
```python
195208
def get_model(model_name, model_version):
@@ -203,11 +216,11 @@ def get_model(model_name, model_version):
203216
model_version (string, optional): Version of the model to retrieve. Can be omitted or set to "latest" to select the highest version.
204217
205218
Returns:
206-
The model as loaded by the load_model() method.
219+
The value that's returned by your predictor's load_model() method.
207220
"""
208221
```
209222

210-
For example:
223+
Here's an example:
211224

212225
```python
213226
class PythonPredictor:
@@ -234,7 +247,7 @@ class PythonPredictor:
234247
return model.predict(payload)
235248
```
236249

237-
`python_client.get_model()` can also accept a model version if a version other than the highest version number is desired:
250+
`python_client.get_model()` can also accept a model version if a version other than the highest is desired:
238251

239252
```python
240253
class PythonPredictor:
@@ -287,7 +300,7 @@ class TensorFlowPredictor:
287300
return self.client.predict(payload, query_params["model"])
288301
```
289302

290-
`tensorflow_client.predict()` can also accept a model version if a version other than the highest version number is desired:
303+
`tensorflow_client.predict()` can also accept a model version if a version other than the highest is desired:
291304

292305
```python
293306
class TensorFlowPredictor:
@@ -341,7 +354,7 @@ class ONNXPredictor:
341354
return self.client.predict(payload, query_params["model"])
342355
```
343356

344-
`onnx_client.predict()` can also accept a model version if a version other than the highest version number is desired:
357+
`onnx_client.predict()` can also accept a model version if a version other than the highest is desired:
345358

346359
```python
347360
class ONNXPredictor:

pkg/workloads/cortex/lib/client/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_model(self, model_name: Optional[str] = None, model_version: str = "late
9898
model_version (string, optional): Version of the model to retrieve. Can be omitted or set to "latest" to select the highest version.
9999
100100
Returns:
101-
The model as loaded by the load_model() method.
101+
The value that's returned by your predictor's load_model() method.
102102
"""
103103

104104
if model_version != "latest" and not model_version.isnumeric():

0 commit comments

Comments
 (0)