|
| 1 | +# How to Select the API protocol for a Deployment |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Hopsworks supports both REST and gRPC as API protocols for sending inference requests to model deployments. While REST API protocol is supported in all types of model deployments, support for gRPC is only available for models served with [KServe](predictor.md#serving-tool). |
| 6 | + |
| 7 | +!!! warning |
| 8 | + At the moment, gRPC API protocol is only supported for **Python model deployments** (e.g., scikit-learn, xgboost, ...). Support for Tensorflow model deployments is coming soon. |
| 9 | + |
| 10 | +## GUI |
| 11 | + |
| 12 | +### Step 1: Create new deployment |
| 13 | + |
| 14 | +If you have at least one model already trained and saved in the Model Registry, navigate to the deployments page by clicking on the `Deployments` tab on the navigation menu on the left. |
| 15 | + |
| 16 | +<p align="center"> |
| 17 | + <figure> |
| 18 | + <img src="../../../../assets/images/guides/mlops/serving/deployments_tab_sidebar.png" alt="Deployments navigation tab"> |
| 19 | + <figcaption>Deployments navigation tab</figcaption> |
| 20 | + </figure> |
| 21 | +</p> |
| 22 | + |
| 23 | +Once in the deployments page, click on `New deployment` if there are not existing deployments or on `Create new deployment` at the top-right corner to open the deployment creation form. |
| 24 | + |
| 25 | +### Step 2: Go to advanced options |
| 26 | + |
| 27 | +A simplified creation form will appear including the most common deployment fields among all the configuration possible. Resource allocation is part of the advanced options of a deployment. To navigate to the advanced creation form, click on `Advanced options`. |
| 28 | + |
| 29 | +<p align="center"> |
| 30 | + <figure> |
| 31 | + <img style="max-width: 85%; margin: 0 auto" src="../../../../assets/images/guides/mlops/serving/deployment_simple_form_adv_options.png" alt="Advance options"> |
| 32 | + <figcaption>Advanced options. Go to advanced deployment creation form</figcaption> |
| 33 | + </figure> |
| 34 | +</p> |
| 35 | + |
| 36 | +### Step 3: Select the API protocol |
| 37 | + |
| 38 | +Enabling gRPC as the API protocol for a model deployment requires KServe as the serving platform for the deployment. Make sure that KServe is enabled by activating the corresponding checkbox. |
| 39 | + |
| 40 | +<p align="center"> |
| 41 | + <figure> |
| 42 | + <img src="../../../../assets/images/guides/mlops/serving/deployment_adv_form_kserve.png" alt="KServe enabled in advanced deployment form"> |
| 43 | + <figcaption>Enable KServe in the advanced deployment form</figcaption> |
| 44 | + </figure> |
| 45 | +</p> |
| 46 | + |
| 47 | +Then, you can select the API protocol to be enabled in your model deployment. |
| 48 | + |
| 49 | +!!! note "Only one API protocol can be enabled simultaneously" |
| 50 | + Currently, KServe model deployments are limited to one API protocol at a time. Therefore, only one of REST or gRPC API protocols can be enabled at the same time on the same model deployment. |
| 51 | + |
| 52 | +<p align="center"> |
| 53 | + <figure> |
| 54 | + <img src="../../../../assets/images/guides/mlops/serving/deployment_grpc_select.png" alt="Select gRPC API protocol"> |
| 55 | + <figcaption>Select gRPC API protocol</figcaption> |
| 56 | + </figure> |
| 57 | +</p> |
| 58 | + |
| 59 | +Once you are done with the changes, click on `Create new deployment` at the bottom of the page to create the deployment for your model. |
| 60 | + |
| 61 | +## Code |
| 62 | + |
| 63 | +### Step 1: Connect to Hopsworks |
| 64 | + |
| 65 | +```python |
| 66 | +import hopsworks |
| 67 | + |
| 68 | +project = hopsworks.login() |
| 69 | + |
| 70 | +# get Hopsworks Model Registry handle |
| 71 | +mr = project.get_model_registry() |
| 72 | + |
| 73 | +# get Hopsworks Model Serving handle |
| 74 | +ms = project.get_model_serving() |
| 75 | +``` |
| 76 | + |
| 77 | +### Step 2: Create a deployment with a specific API protocol |
| 78 | + |
| 79 | +```python |
| 80 | + |
| 81 | +my_model = mr.get_model("my_model", version=1) |
| 82 | + |
| 83 | +my_predictor = ms.create_predictor(my_model, |
| 84 | + api_protocol="GRPC" # defaults to "REST" |
| 85 | + ) |
| 86 | +my_predictor.deploy() |
| 87 | + |
| 88 | +# or |
| 89 | + |
| 90 | +my_deployment = ms.create_deployment(my_predictor) |
| 91 | +my_deployment.save() |
| 92 | +``` |
| 93 | + |
| 94 | +### API Reference |
| 95 | + |
| 96 | +[API Protocol](https://docs.hopsworks.ai/machine-learning-api/{{{ hopsworks_version }}}/generated/api/api-protocol/) |
0 commit comments