|
| 1 | +# KServe gRPC frontend |
| 2 | +## Motivation |
| 3 | +[KServe v2 API](https://github.com/kserve/kserve/tree/master/docs/predict-api/v2) is one of the industry standard protocol for machine learning model inference. Triton inference server is one of the inference solutions that comply with KServe v2 API and it has gained a lot of adoption. To quickly enable Triton users to explore with Dynamo benefits, Dynamo provides a KServe gRPC frontend. |
| 4 | + |
| 5 | +This documentation assumes readers are familiar with the usage of KServe v2 API and focuses on explaining the Dynamo parts that work together to support KServe API and how users may migrate existing KServe deployment to Dynamo. |
| 6 | + |
| 7 | +## Supporting endpoint |
| 8 | +* `ModelInfer` endpoint: KServe Standard endpoint as described [here](https://github.com/kserve/kserve/blob/master/docs/predict-api/v2/required_api.md#inference-1) |
| 9 | +* `ModelStreamInfer` endpoint: Triton extension endpoint that provide bi-directional streaming version of the inference RPC to allow a sequence of inference requests/responses to be sent over a GRPC stream, as described [here](https://github.com/triton-inference-server/common/blob/main/protobuf/grpc_service.proto#L84-L92) |
| 10 | +* `ModelMetadata` endpoint: KServe standard endpoint as described [here](https://github.com/kserve/kserve/blob/master/docs/predict-api/v2/required_api.md#model-metadata-1) |
| 11 | +* `ModelConfig` endpoint: Triton extension endpoint as described [here](https://github.com/triton-inference-server/server/blob/main/docs/protocol/extension_model_configuration.md) |
| 12 | +## Starting the frontend |
| 13 | +To start the KServe frontend, run the below command |
| 14 | +``` |
| 15 | +python -m dynamo.frontend --kserve-grpc-server |
| 16 | +``` |
| 17 | + |
| 18 | +## Register a backend |
| 19 | +Similar to HTTP frontend, the registered backend will be auto-discovered and added to the frontend list of serving model. To register a backend, the same `register_llm()` API will be used. Currently the frontend support serving of the following model type and model input combination: |
| 20 | +* `ModelType:Completions` and `ModelInput::Text`: Combination for LLM backend that uses custom preprocessor |
| 21 | +* `ModelType:Completions` and `ModelInput::Token`: Combination for LLM backend that uses Dynamo preprocessor (i.e. Dynamo vLLM / SGLang / TRTLLM backend) |
| 22 | +* `ModelType:TensorBased` and `ModelInput::Tensor`: Combination for backend that is used for generic tensor based inference |
| 23 | + |
| 24 | +The first two combinations are backed by OpenAI Completions API, see [OpenAI Completions section](#openai-completions) for more detail. Whereas the last combination is most aligned with KServe API and the users can replace existing deployment with Dynamo once their backends implements adaptor for `NvCreateTensorRequest/NvCreateTensorResponse`, see [Tensor section](#tensor) for more detail: |
| 25 | + |
| 26 | +### OpenAI Completions |
| 27 | +Most of the Dynamo features are tailored for LLM inference and the combinations that are backed by OpenAI API can enable those features and are best suited for exploring those Dynamo features. However, this implies specific conversion between generic tensor based messages and OpenAI message and imposes specific structure of the KServe request message. |
| 28 | + |
| 29 | +#### Model metadata / config |
| 30 | +The metadata and config endpoint will report the registered backend to have the below, note that this is not the exact response. |
| 31 | +``` |
| 32 | +{ |
| 33 | + name: $MODEL_NAME, |
| 34 | + version: 1, |
| 35 | + platform: "dynamo", |
| 36 | + backend: "dynamo", # model config specific |
| 37 | + inputs: [ |
| 38 | + { |
| 39 | + name: "text_input", |
| 40 | + datatype: "BYTES", |
| 41 | + shape: [1] |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "streaming", |
| 45 | + datatype: "BOOL", |
| 46 | + shape: [1], |
| 47 | + optional: true |
| 48 | + } |
| 49 | + ] |
| 50 | + outputs: [ |
| 51 | + { |
| 52 | + name: "text_output", |
| 53 | + datatype: "BYTES", |
| 54 | + shape: [-1] |
| 55 | + }, |
| 56 | + { |
| 57 | + name: "finish_reason", |
| 58 | + datatype: "BYTES", |
| 59 | + shape: [-1], |
| 60 | + optional: true |
| 61 | + } |
| 62 | + ] |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +#### Inference |
| 67 | +On receiving inference request, the following conversion will be performed: |
| 68 | +* `text_input`: the element is expected to contain the user prompt string and will be converted to `prompt` field in OpenAI Completion request |
| 69 | +* `streaming`: the element will be converted to `stream` field in OpenAI Completion request |
| 70 | +On receiving model response, the following conversion will be performed: |
| 71 | +* `text_output`: each element corresponds to one choice in OpenAI Completion response, and the content will be set to `text` of the choice. |
| 72 | +* `finish_reason`: each element corresponds to one choice in OpenAI Completion response, and the content will be set to `finish_reason` of the choice. |
| 73 | + |
| 74 | +### Tensor |
| 75 | +This combination is used when the user is migrating an existing KServe based backend into Dynamo ecosystem. |
| 76 | + |
| 77 | +#### Model metadata / config |
| 78 | +When registering the backend, the backend must provide the model's metadata as tensor based deployment is generic and the frontend can't make any assumptions like for OpenAI Completions model. There are two methods to provide model metadata: |
| 79 | +* [TensorModelConfig](../../lib/llm/src/protocols/tensor.rs): This is Dynamo defined structure for model metadata, the backend can provide the model metadata as shown in this [example](../../lib/bindings/python/tests/test_tensor.py). For metadata provided in such way, the following field will be set to a fixed value: `version: 1`, `platform: "dynamo"`, `backend: "dynamo"`. Note that for model config endpoint, the rest of the fields will be set to their default values. |
| 80 | +* [triton_model_config](../../lib/llm/src/protocols/tensor.rs): For users that already have Triton model config and require the full config to be returned for client side logic, they can set the config in `TensorModelConfig::triton_model_config` which will supersedes other fields in `TensorModelConfig` and be used for endpoint responses. `triton_model_config` is expected to be the serialized string of the `ModelConfig` protobuf message, see [echo_tensor_worker.py](../../tests/frontend/grpc/echo_tensor_worker.py) for example. |
| 81 | + |
| 82 | +#### Inference |
| 83 | +When receiving inference request, the backend will receive [NvCreateTensorRequest](../../lib/llm/src/protocols/tensor.rs) and be expected to return [NvCreateTensorResponse](../../lib/llm/src/protocols/tensor.rs), which are the mapping of ModelInferRequest / ModelInferResponse protobuf message in Dynamo. |
| 84 | + |
| 85 | +## Python binding |
| 86 | +The frontend may be started via Python binding, this is useful when integrating Dynamo in existing system that desire the frontend to be run in the same process with other components. See [server.py](../../lib/bindings/python/examples/kserve_grpc_service/server.py) for example. |
0 commit comments