파이썬 백엔드 커스텀 메트릭 예제

파이썬 백엔드 커스텀 메트릭 예제

이 섹션에서는 Python 백엔드의 Custom Metrics API를 위한 엔드투엔드 예제를 보여줘요. 모델 저장소에는 custom_metrics 모델이 들어 있어야 합니다. custom_metrics 모델은 Custom Metrics API를 사용해 커스텀 메트릭을 등록·수집해요.

커스텀 메트릭 모델 배포하기

  1. 모델 저장소를 만듭니다:
mkdir -p models/custom_metrics/1/

# Copy the Python models
cp examples/custom_metrics/model.py models/custom_metrics/1/model.py
cp examples/custom_metrics/config.pbtxt models/custom_metrics/config.pbtxt
  1. tritonserver를 시작합니다:
tritonserver --model-repository `pwd`/models
  1. 서버에 추론 요청을 보냅니다:
python3 examples/custom_metrics/client.py

클라이언트 터미널에서 아래와 비슷한 출력을 볼 수 있어요.

custom_metrics example: found pattern '# HELP requests_process_latency_ns Cumulative time spent processing requests' in metrics
custom_metrics example: found pattern '# TYPE requests_process_latency_ns counter' in metrics
custom_metrics example: found pattern 'requests_process_latency_ns{model="custom_metrics",version="1"}' in metrics
PASS: custom_metrics

Triton Server를 실행하는 터미널에서는 아래와 비슷한 출력을 볼 수 있어요.

Cumulative requests processing latency: 223406.0

model.py 모델 파일에는 각 함수 호출에 대한 설명이 담긴 상세 주석이 있어요.

클라이언트 출력 설명

client.pyhttp://localhost:8002/metrics url로 HTTP 요청을 보내 Triton 서버에서 메트릭을 가져와요. 그다음 클라이언트는 모델 파일에 추가한 커스텀 메트릭이 올바르게 보고되는지 검증합니다.

출처: 공식 문서 - Custom Metrics Example (Python Backend)

더 알아보기 (Learn more)