Skip to content

Commit

Permalink
fix: readme doc
Browse files Browse the repository at this point in the history
 - add logs

Signed-off-by: jagadeesh <jagadeeshj@ideas2it.com>
  • Loading branch information
jagadeesh committed Aug 4, 2023
1 parent 0c0fd22 commit 456d476
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
37 changes: 33 additions & 4 deletions kubernetes/kserve/kserve_wrapper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ sudo mkdir -p /mnt/models/model-store

For v1 protocol

``export TS_SERVICE_ENVELOPE=kserve`
`export TS_SERVICE_ENVELOPE=kserve`

For v2 protocol

``export TS_SERVICE_ENVELOPE=kservev2`
`export TS_SERVICE_ENVELOPE=kservev2`

- Step 10: Move the config.properties to /mnt/models/config/.
The config.properties file is as below :
Expand Down Expand Up @@ -93,6 +93,20 @@ torchserve --start --ts-config /mnt/models/config/config.properties

- Step 12: Run the below command to start the KFServer

- Step 13: Set protocol version

For v1 protocol

`export PROTOCOL_VERSION=v1`

For v2 protocol

`export PROTOCOL_VERSION=v2`

For grpc protocol v2 format set

`export PROTOCOL_VERSION=grpc-v2`

```bash
python3 serve/kubernetes/kserve/kserve_wrapper/__main__.py
```
Expand Down Expand Up @@ -127,7 +141,7 @@ Output:

The curl request for explain is as below:

```
```bash
curl -H "Content-Type: application/json" --data @serve/kubernetes/kserve/kf_request_json/v1/mnist.json http://0.0.0.0:8080/v1/models/mnist:explain
```

Expand Down Expand Up @@ -169,7 +183,7 @@ Response:

The curl request for explain is as below:

```
```bash
curl -H "Content-Type: application/json" --data @serve/kubernetes/kserve/kf_request_json/v1/mnist.json http://0.0.0.0:8080/v2/models/mnist/explain
```

Expand All @@ -192,6 +206,21 @@ Response:
}
```

For grpc-v2 protocol

- Download the proto file

```bash
curl -O https://github.com/kserve/kserve/master/docs/predict-api/v2/grpc_predict_v2.proto
```
- Download [grpcurl](https://github.com/fullstorydev/grpcurl)

Make gRPC request

```bash
grpcurl -vv -plaintext -proto grpc_predict_v2.proto -d @ localhost:8081 inference.GRPCInferenceService.ModelInfer <<< $(cat "serve/kubernetes/kserve/kf_request_json/v2/mnist_tensor_bytes_grpc.json")
```

## KServe Wrapper Testing in Local for BERT

- Step 1: Follow the same steps from to 10 as what was done for MNIST.
Expand Down
2 changes: 2 additions & 0 deletions kubernetes/kserve/kserve_wrapper/TorchserveModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(

logging.info("Predict URL set to %s", self.predictor_host)
logging.info("Explain URL set to %s", self.explainer_host)
logging.info("Protocol version is %s", self.protocol)

def grpc_client(self):
if self._grpc_client_stub is None:
Expand All @@ -88,6 +89,7 @@ def grpc_client(self):
async def _grpc_predict(
self,
payload: Union[ModelInferRequest, InferRequest],
headers: Dict[str, str] = None,
) -> ModelInferResponse:
"""Overrides the `_grpc_predict` method in Model class. The predict method calls
the `_grpc_predict` method if the self.protocol is "grpc_v2"
Expand Down
11 changes: 4 additions & 7 deletions kubernetes/kserve/kserve_wrapper/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" KServe wrapper to handler inference in the kserve_predictor """
import json
import logging
import os

import kserve
from kserve.model_server import ModelServer
Expand Down Expand Up @@ -50,9 +51,6 @@ def parse_config():
models = keys["model_snapshot"]["models"]
model_names = []

protocol = "grpc-v2"
# protocol = "v2"

# Get all the model_names
for model, value in models.items():
model_names.append(model)
Expand All @@ -75,12 +73,11 @@ def parse_config():
model_store = DEFAULT_MODEL_STORE

logging.info(
"Wrapper : Model names %s, inference address %s, management address %s, grpc_inference_address, %s, protocol %s, model store %s",
"Wrapper : Model names %s, inference address %s, management address %s, grpc_inference_address, %s, model store %s",
model_names,
inference_address,
management_address,
grpc_inference_address,
protocol,
model_store,
)

Expand All @@ -89,7 +86,6 @@ def parse_config():
inference_address,
management_address,
grpc_inference_address,
protocol,
model_store,
)

Expand All @@ -101,10 +97,11 @@ def parse_config():
inference_address,
management_address,
grpc_inference_address,
protocol,
model_dir,
) = parse_config()

protocol = os.environ.get("PROTOCOL_VERSION")

models = []

for model_name in model_names:
Expand Down

0 comments on commit 456d476

Please sign in to comment.