ModelServe sklearnserve Serve
The serve action deploys scikit-learn ML models as services on Kubernetes. A Task is created by calling run() on the Function; task parameters are passed through that call.
Overview
The sklearnserve function kind supports deploying scikit-learn models as REST API services. The model must be saved in pickle format (.pkl).
Quick example
function = dh.new_function(
name="my-sklearn-service",
kind="sklearnserve",
path=model.key
)
run = function.run(
action="serve",
replicas=1
)
Parameters
Function Parameters
Must be specified when creating the function.
| Name | Type | Description |
|---|---|---|
| project | str | Project name. Required only when creating from the library; otherwise MUST NOT be set. |
| name | str | Name that identifies the object. Required. |
| kind | str | Function kind. Must be sklearnserve. Required. |
| uuid | str | Object ID in UUID4 format. |
| description | str | Description of the object. |
| labels | list[str] | List of labels. |
| embedded | bool | Whether the object should be embedded in the project. |
| path | str | Model path. Required. |
| model_name | str | Name of the model. |
| image | str | Docker image where to serve the model. |
Model Path
The model path must consists of the model key or the s3 path partition where the model files are or a zip containing the model files.
Model Image
Model image must follow the pattern:
Task Parameters
Can only be specified when calling function.run().
| Name | Type | Description |
|---|---|---|
| action | str | Task action. Required. Must be serve |
| node_selector | list[dict] | Node selector. |
| volumes | list[dict] | List of volumes. |
| resources | dict | Resource limits/requests. |
| affinity | dict | Affinity configuration. |
| tolerations | list[dict] | Tolerations. |
| envs | list[dict] | Environment variables. |
| secrets | list[str] | List of secret names. |
| profile | str | Profile template. |
| replicas | int | Number of replicas. |
| service_type | str | Service type. |
| service_name | str | Service name. |
Run Parameters
Can only be specified when calling function.run().
No specific parameters for run of this action.
Entity methods
Run methods
Once the run is created, you can access its attributes and methods through the run object.
invoke
Invoke served model. By default it exposes infer v2 endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model. |
None
|
method
|
str
|
Method of the request. |
'POST'
|
url
|
str
|
URL of the request. |
None
|
**kwargs
|
dict
|
Keyword arguments to pass to the request. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
Response from the request. |