TritonFrontend 파이썬 바인딩
TritonFrontend 파이썬 바인딩 (C++ 프론트엔드, Beta)
tritonfrontend 파이썬 패키지는 Triton이 C++로 구현한 기존 프론트엔드를 감싸는 바인딩이에요. 현재 tritonfrontend는 KServeHttp와 KServeGrpc 프론트엔드를 시작할 수 있어요. 이 바인딩을 Triton의 파이썬 인프로세스 API(tritonserver)와 tritonclient와 함께 쓰면, 몇 줄의 파이썬만으로 Triton의 전체 기능을 활용할 수 있게 확장돼요.
출처: 공식문서
간단한 예제로 따라가기
- 먼저 원하는 모델을 로드하고
tritonserver로 서버를 시작해요.
import tritonserver
# Constructing path to Model Repository
model_path = f"server/src/python/examples/example_model_repository"
server_options = tritonserver.Options(
server_id="ExampleServer",
model_repository=model_path,
log_error=True,
log_warn=True,
log_info=True,
)
server = tritonserver.Server(server_options).start(wait_until_ready=True)
참고:
model_path는 자신의 설정에 맞게 수정해야 할 수 있어요.
- 이제
tritonfrontend로 각 서비스를 시작해요.
from tritonfrontend import KServeHttp, KServeGrpc, Metrics
http_options = KServeHttp.Options(thread_count=5)
http_service = KServeHttp(server, http_options)
http_service.start()
# Default options (if none provided)
grpc_service = KServeGrpc(server)
grpc_service.start()
# Can start metrics service as well
metrics_service = Metrics(server)
metrics_service.start()
- 마지막으로 서비스가 실행 중이면
tritonclient나 간단한 curl 명령으로 프론트엔드에 요청을 보내고 응답을 받아요.
import tritonclient.http as httpclient
import numpy as np # Use version numpy < 2
model_name = "identity" # output == input
url = "localhost:8000"
# Create a Triton client
client = httpclient.InferenceServerClient(url=url)
# Prepare input data
input_data = np.array([["Roger Roger"]], dtype=object)
# Create input and output objects
inputs = [httpclient.InferInput("INPUT0", input_data.shape, "BYTES")]
# Set the data for the input tensor
inputs[0].set_data_from_numpy(input_data)
results = client.infer(model_name, inputs=inputs)
# Get the output data
output_data = results.as_numpy("OUTPUT0")
# Print results
print("[INFERENCE RESULTS]")
print("Output data:", output_data)
# Stop respective services and server.
metrics_service.stop()
http_service.stop()
grpc_service.stop()
server.stop()
추가로 tritonfrontend는 컨텍스트 매니저(context manager)도 지원해요. 위의 2~3단계를 다음과 같이도 작성할 수 있어요.
from tritonfrontend import KServeHttp
import tritonclient.http as httpclient
import numpy as np # Use version numpy < 2
with KServeHttp(server) as http_service:
# The identity model returns an exact duplicate of the input data as output
model_name = "identity"
url = "localhost:8000"
# Create a Triton client
with httpclient.InferenceServerClient(url=url) as client:
# Prepare input data
input_data = np.array(["Roger Roger"], dtype=object)
# Create input and output objects
inputs = [httpclient.InferInput("INPUT0", input_data.shape, "BYTES")]
# Set the data for the input tensor
inputs[0].set_data_from_numpy(input_data)
# Perform inference
results = client.infer(model_name, inputs=inputs)
# Get the output data
output_data = results.as_numpy("OUTPUT0")
# Print results
print("[INFERENCE RESULTS]")
print("Output data:", output_data)
server.stop()
이 흐름을 쓰면 클라이언트 요청이 끝난 뒤 각 서비스를 일일이 멈추지 않아도 된답니다.
알려진 문제 (Known Issues)
현재 파이썬 바인딩으로 Triton 프론트엔드 서비스를 띄울 때 아래 기능은 지원되지 않아요.
- Tracing
- Shared Memory
- Restricted Protocols
- VertexAI
- Sagemaker
또한 실행 중인 서버를 멈춘 뒤 클라이언트가 추론 요청을 보내면 Segmentation Fault가 발생해요.
더 알아보기 (Learn more)
- 추론 프로토콜과 API — KServe HTTP·gRPC 프론트엔드 설정
- 인프로세스 Triton 서버 API — 트리톤 코어 로직 직접 포함