From 9bffc0af10134eed7f0c16a820d22a44f94dda58 Mon Sep 17 00:00:00 2001 From: shiyu22 Date: Mon, 12 Dec 2022 15:54:55 +0800 Subject: [PATCH] Add triton client Signed-off-by: shiyu22 --- README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++++-- __init__.py | 5 +++ client.py | 34 ++++++++++++++++++++ requirements.txt | 2 ++ 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 __init__.py create mode 100644 client.py create mode 100644 requirements.txt diff --git a/README.md b/README.md index 52633f1..13b5adc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,80 @@ -# client +# Remote Operator -2 \ No newline at end of file +*author: shiyu* + +
+ +## Desription +Remote triton server. + +
+ + + +## Code Example + + *Run with ops:* + +```python +from towhee.dc2 import ops + +c = ops.triton.client(':') +res = c('') +``` + +*Run with pipeline:* + +```python +from towhee.dc2 import ops, pipe + +p = (pipe.input('data') + .map('data', 'res', ops.triton.client(':')) + .output('res')) + +p('').get() +``` + + +
+ + + +## Factory Constructor + +Create the operator via the following factory method: + + + +***towhee.remote(uri, mode='infer', model_name='pipeline', protocol='grpc')*** + + + +**Parameters:** + +***url:*** *str* + +IP address and port for the triton server, such as ':' and '127.0.0.1:8001'. + +***model_name:*** *str* + +The name of the model to run inference, defaults to 'pipline'. + + + +
+ + + +## Interface + +**Parameters:** + +***data:*** + +The data to your triton server. + + + +**Returns:** + +Return the results in triton. diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..a3eafee --- /dev/null +++ b/__init__.py @@ -0,0 +1,5 @@ +from .client import Client + + +def remote(*args, **kwargs): + return Client(*args, **kwargs) \ No newline at end of file diff --git a/client.py b/client.py new file mode 100644 index 0000000..447e985 --- /dev/null +++ b/client.py @@ -0,0 +1,34 @@ +import logging +from towhee.operator import PyOperator +from towhee import triton_client + + +log = logging.getLogger() + + +class Client(PyOperator): + """ + Triton client class. + + Args: + url: str + IP address and https port for the triton server, such as ':', '127.0.0.1:8001'. + model_name: str + The name of the model to run inference, defaults to 'pipline'. + """ + def __init__(self, url, model_name='pipeline'): + super().__init__() + self._client = triton_client(url, model_name) + + def __call__(self, *data): + """ + A one line summary of this function. + + Args: + data: + This data to your triton server. + """ + return self._client(*data) + + def batch(self, data_list): + return self._client.batch(data_list) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..82e6436 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +towhee +tritonclient[all] \ No newline at end of file