Update 1/model.py
This commit is contained in:
parent
a979dd59fc
commit
7041fd52b8
39
1/model.py
39
1/model.py
@ -1,4 +1,3 @@
|
||||
# modify model.py
|
||||
import triton_python_backend_utils as pb_utils
|
||||
import numpy as np
|
||||
import json
|
||||
@ -24,10 +23,6 @@ class TritonPythonModel:
|
||||
responses = []
|
||||
|
||||
for request in requests:
|
||||
# INPUT
|
||||
input_text = self._get_input_value(request, "INPUT")
|
||||
self.logger.log_info(f"INPUT 출력:\n{input_text}")
|
||||
|
||||
# 랜덤 문자열 생성
|
||||
random_string = ''.join(
|
||||
random.choice(string.ascii_letters + string.digits) for _ in range(16)
|
||||
@ -44,39 +39,7 @@ class TritonPythonModel:
|
||||
output_tensors=[output_tensor]
|
||||
))
|
||||
|
||||
return responses
|
||||
|
||||
def _get_input_value(self, request, input_name: str, default=None):
|
||||
"""
|
||||
Triton 추론 요청에서 특정 이름의 입력 텐서 값을 가져옵니다.
|
||||
|
||||
Args:
|
||||
request (pb_utils.InferenceRequest): Triton 추론 요청 객체.
|
||||
input_name (str): 가져올 입력 텐서의 이름.
|
||||
default (any, optional): 입력 텐서가 없을 경우 반환할 기본값. Defaults to None.
|
||||
|
||||
Returns:
|
||||
any: 디코딩된 입력 텐서의 값. 텐서가 없으면 기본값을 반환합니다.
|
||||
"""
|
||||
tensor_value = pb_utils.get_input_tensor_by_name(request, input_name)
|
||||
|
||||
if tensor_value is None:
|
||||
return default
|
||||
|
||||
return self._np_decoder(tensor_value.as_numpy()[0])
|
||||
|
||||
def _np_decoder(self, obj):
|
||||
if isinstance(obj, (bytes, np.bytes_)):
|
||||
return obj.decode('utf-8')
|
||||
if isinstance(obj, str):
|
||||
return obj
|
||||
if np.issubdtype(type(obj), np.integer):
|
||||
return int(obj)
|
||||
if np.issubdtype(type(obj), np.floating):
|
||||
return round(float(obj), 3)
|
||||
if isinstance(obj, (np.bool_, bool)):
|
||||
return bool(obj)
|
||||
return obj
|
||||
return responses
|
||||
|
||||
def finalize(self):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user