Triton 서버는 특정 디렉토리 구조를 따라야 함
/models
├── model1
│ └── config.pbtxt
│ └── 1
│ └── model.onnx
├── model2
│ └── config.pbtxt
│ └── 1
│ └── model.pb

NVIDIA Triton Inference Server에서 모델의 메타데이터와 구성을 정의하는 설정 파일
이 파일은 각 모델의 동작을 제어하고, 입력 및 출력 형식, 배칭, 리소스 사용 등 다양한 설정을 지정
예시
name: "model_name"
platform: "tensorflow_graphdef" # 모델의 프레임워크 종류 (예: tensorflow_savedmodel, onnxruntime, tensorrt_plan 등)
max_batch_size: 8 # 배칭을 사용할 경우 최대 배치 크기
input [
{
name: "input_tensor"
data_type: TYPE_FP32 # 입력 데이터 타입 (예: TYPE_INT32, TYPE_FP32 등)
dims: [ 28, 28, 1 ] # 입력 텐서의 형태 (batch 제외)
}
]
output [
{
name: "output_tensor"
data_type: TYPE_FP32
dims: [ 10 ]
}
]
# 추론 파이프라인에 대한 리소스 제한
instance_group [
{
count: 1 # 모델 인스턴스의 수 (GPU 개수와 독립적)
kind: KIND_GPU # 인스턴스를 할당할 장치 종류 (KIND_GPU 또는 KIND_CPU)
}
]
# 배칭 설정
dynamic_batching {
preferred_batch_size: [ 4, 8 ] # 선호하는 배치 크기
max_queue_delay_microseconds: 100 # 최대 큐 대기 시간 (마이크로초)
}
# 입력 텐서가 고정된 형태가 아닌 경우, 텐서의 크기를 자동으로 조절하는 설정
reshape {
shape: [ -1, 28, 28, 1 ] # 첫 번째 차원 (배치 크기)만 가변
}
triton 서버에 올라간 모델을 쓰기 위해 사용하는 라이브러리
import tritonclient.grpc.aio as agrpcclient
import tritonclient.grpc as grpcclient
triton 서버 클라이언트 생성
grpcclient.InferenceServerClient
infer 함수
서버 요청 및 모델 result 를 생성
result = await self.aclient.infer(model_name, inputs, outputs=outputs)
요청 객체 생성
InferenceRequest 생성

후처리
all_embeddings.extend(result.as_numpy("OUTPUT").tolist())
as_numpy 등을 이용해 후처리
입력, 출력 형식 지정
agrpcclient.InferInput("TEXT", input_data.shape, "BYTES")
name, shape, datatype 을 인자로 받음
agrpcclient.InferRequestedOutput("OUTPUT")
name, class_count 를 인자로 받음

모델 폴더 내부에 있는 파일로 모델을 사용하는 로직
python Backend
triton 서버 내부에 파이썬 백엔드를 구성해야 함
https://docs.nvidia.com/deeplearning/triton-inference-server/user-guide/docs/python_backend/README.html
대략 다음과 같은 구조를 따른다.
class TritonPythonModel:
@staticmethod
def auto_complete_config(auto_complete_model_config):
def initialize(self, args):
def execute(self, requests):
return responses
def finalize(self):
--disable-auto-complete-config 라는 명령 없이 로딩될 때)
input_tensor = pb_utils.get_input_tensor_by_name(request, "TEXT")inference_response = pb_utils.InferenceResponse(output_tensors=[pb_utils.Tensor("OUTPUT", sentence_embeddings)])

