parent
c9b0c96b7b
commit
9e61b81f68
@ -0,0 +1,34 @@
|
|||||||
|
#We assume your host model absolute path = $PWD and your docker model absolute path = /models
|
||||||
|
|
||||||
|
#For Server
|
||||||
|
|
||||||
|
#Start docker
|
||||||
|
docker pull registry.baidubce.com/paddlepaddle/fastdeploy_serving_cpu_only:22.09
|
||||||
|
docker run -dit --net=host --name fastdeploy --shm-size="1g" -v $PWD:/models registry.baidubce.com/paddlepaddle/fastdeploy_serving_cpu_only:22.09
|
||||||
|
docker exec -it -u root fastdeploy bash
|
||||||
|
|
||||||
|
#Inside the docker
|
||||||
|
apt-get install build-essential python3-dev libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev libsndfile1 language-pack-zh-hans wget zip
|
||||||
|
pip install paddlespeech
|
||||||
|
export LC_ALL="zh_CN.UTF-8"
|
||||||
|
export LANG="zh_CN.UTF-8"
|
||||||
|
export LANGUAGE="zh_CN:zh:en_US:en"
|
||||||
|
|
||||||
|
#Download models
|
||||||
|
cd /models/streaming_tts_serving/1
|
||||||
|
wget https://paddlespeech.bj.bcebos.com/Parakeet/released_models/fastspeech2/fastspeech2_cnndecoder_csmsc_streaming_onnx_1.0.0.zip
|
||||||
|
wget https://paddlespeech.bj.bcebos.com/Parakeet/released_models/mb_melgan/mb_melgan_csmsc_onnx_0.2.0.zip
|
||||||
|
unzip fastspeech2_cnndecoder_csmsc_streaming_onnx_1.0.0.zip
|
||||||
|
unzip mb_melgan_csmsc_onnx_0.2.0.zip
|
||||||
|
|
||||||
|
#Start the server
|
||||||
|
fastdeployserver --model-repository=/models --model-control-mode=explicit --load-model=streaming_tts_serving
|
||||||
|
|
||||||
|
|
||||||
|
#For Client
|
||||||
|
|
||||||
|
#Install
|
||||||
|
pip3 install tritonclient[all]
|
||||||
|
|
||||||
|
#Request
|
||||||
|
python3 /models/streaming_tts_serving/stream_client.py
|
@ -0,0 +1,33 @@
|
|||||||
|
name: "streaming_tts_serving"
|
||||||
|
backend: "python"
|
||||||
|
max_batch_size: 0
|
||||||
|
model_transaction_policy {
|
||||||
|
decoupled: True
|
||||||
|
}
|
||||||
|
input [
|
||||||
|
{
|
||||||
|
name: "INPUT_0"
|
||||||
|
data_type: TYPE_STRING
|
||||||
|
dims: [ 1 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
output [
|
||||||
|
{
|
||||||
|
name: "OUTPUT_0"
|
||||||
|
data_type: TYPE_FP32
|
||||||
|
dims: [ -1, 1 ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "status"
|
||||||
|
data_type: TYPE_BOOL
|
||||||
|
dims: [ 1 ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
instance_group [
|
||||||
|
{
|
||||||
|
count: 1
|
||||||
|
kind: KIND_CPU
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,126 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
import argparse
|
||||||
|
import numpy as np
|
||||||
|
import sys
|
||||||
|
import queue
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import tritonclient.grpc as grpcclient
|
||||||
|
from tritonclient.utils import *
|
||||||
|
|
||||||
|
FLAGS = None
|
||||||
|
|
||||||
|
|
||||||
|
class UserData:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._completed_requests = queue.Queue()
|
||||||
|
|
||||||
|
|
||||||
|
# Define the callback function. Note the last two parameters should be
|
||||||
|
# result and error. InferenceServerClient would povide the results of an
|
||||||
|
# inference as grpcclient.InferResult in result. For successful
|
||||||
|
# inference, error will be None, otherwise it will be an object of
|
||||||
|
# tritonclientutils.InferenceServerException holding the error details
|
||||||
|
def callback(user_data, result, error):
|
||||||
|
if error:
|
||||||
|
user_data._completed_requests.put(error)
|
||||||
|
else:
|
||||||
|
user_data._completed_requests.put(result)
|
||||||
|
|
||||||
|
|
||||||
|
def async_stream_send(triton_client, values, request_id,
|
||||||
|
model_name):
|
||||||
|
|
||||||
|
infer_inputs = []
|
||||||
|
outputs = []
|
||||||
|
for idx, data in enumerate(values):
|
||||||
|
data = np.array([data.encode('utf-8')],
|
||||||
|
dtype=np.object_)
|
||||||
|
infer_input = grpcclient.InferInput('INPUT_0', [len(data)],
|
||||||
|
"BYTES")
|
||||||
|
infer_input.set_data_from_numpy(data)
|
||||||
|
infer_inputs.append(infer_input)
|
||||||
|
|
||||||
|
outputs.append(grpcclient.InferRequestedOutput('OUTPUT_0'))
|
||||||
|
# Issue the asynchronous sequence inference.
|
||||||
|
triton_client.async_stream_infer(model_name=model_name,
|
||||||
|
inputs=infer_inputs,
|
||||||
|
outputs=outputs,
|
||||||
|
request_id=request_id)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-v',
|
||||||
|
'--verbose',
|
||||||
|
action="store_true",
|
||||||
|
required=False,
|
||||||
|
default=False,
|
||||||
|
help='Enable verbose output')
|
||||||
|
parser.add_argument(
|
||||||
|
'-u',
|
||||||
|
'--url',
|
||||||
|
type=str,
|
||||||
|
required=False,
|
||||||
|
default='localhost:8001',
|
||||||
|
help='Inference server URL and it gRPC port. Default is localhost:8001.'
|
||||||
|
)
|
||||||
|
|
||||||
|
FLAGS = parser.parse_args()
|
||||||
|
|
||||||
|
# We use custom "sequence" models which take 1 input
|
||||||
|
# value. The output is the accumulated value of the inputs. See
|
||||||
|
# src/custom/sequence.
|
||||||
|
model_name = "streaming_tts_serving"
|
||||||
|
|
||||||
|
values = ["哈哈哈哈"]
|
||||||
|
|
||||||
|
request_id = "0"
|
||||||
|
#string_sequence_id0 = str(uuid.uuid4())
|
||||||
|
|
||||||
|
string_result0_list = []
|
||||||
|
|
||||||
|
user_data = UserData()
|
||||||
|
|
||||||
|
# It is advisable to use client object within with..as clause
|
||||||
|
# when sending streaming requests. This ensures the client
|
||||||
|
# is closed when the block inside with exits.
|
||||||
|
with grpcclient.InferenceServerClient(
|
||||||
|
url=FLAGS.url, verbose=FLAGS.verbose) as triton_client:
|
||||||
|
try:
|
||||||
|
# Establish stream
|
||||||
|
triton_client.start_stream(callback=partial(callback, user_data))
|
||||||
|
# Now send the inference sequences...
|
||||||
|
async_stream_send(triton_client,
|
||||||
|
values,
|
||||||
|
request_id,
|
||||||
|
model_name)
|
||||||
|
except InferenceServerException as error:
|
||||||
|
print(error)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Retrieve results...
|
||||||
|
recv_count = 0
|
||||||
|
result_dict = {}
|
||||||
|
status = True
|
||||||
|
while True:
|
||||||
|
data_item = user_data._completed_requests.get()
|
||||||
|
if type(data_item) == InferenceServerException:
|
||||||
|
raise data_item
|
||||||
|
else:
|
||||||
|
this_id = data_item.get_response().id
|
||||||
|
if this_id not in result_dict.keys():
|
||||||
|
result_dict[this_id] = []
|
||||||
|
result_dict[this_id].append((recv_count, data_item))
|
||||||
|
sub_wav = data_item.as_numpy('OUTPUT_0')
|
||||||
|
status = data_item.as_numpy('status')
|
||||||
|
print('sub_wav = ', sub_wav, "subwav.shape = ", sub_wav.shape)
|
||||||
|
print('status = ', status)
|
||||||
|
if status[0] == True:
|
||||||
|
break
|
||||||
|
recv_count += 1
|
||||||
|
|
||||||
|
print("PASS: stream_client")
|
Loading…
Reference in new issue