Skip to main content

BentoML

ML 모델 패키징 및 서빙 프레임워크입니다. 학습된 모델을 API 서버로 패키징하고 Docker 이미지로 배포할 수 있습니다.

어디에 쓰이나요?

  • 모델 API 서빙: Python으로 학습한 모델을 REST/gRPC API로 배포
  • 모델 패키징: 모델 + 전처리/후처리 코드 + 의존성을 하나의 패키지(Bento)로 묶어서 관리
  • 적응형 배치: 요청을 자동으로 모아서 배치 처리하여 GPU 활용률 향상
  • 멀티 모델 파이프라인: 여러 모델을 하나의 서비스로 구성 (Runner 패턴)
Triton이 사전 변환된 모델(ONNX, TensorRT)을 서빙하는 데 강점이 있다면, BentoML은 Python 코드로 작성된 모델을 그대로 서빙할 수 있어 더 유연합니다.

Docker Compose

BentoML은 모델 서비스를 Bento로 빌드한 후 Docker 이미지로 변환합니다.

1. 서비스 코드 작성 (service.py)

import bentoml
from bentoml.io import JSON

runner = bentoml.sklearn.get("iris_classifier:latest").to_runner()
svc = bentoml.Service("iris_classifier", runners=[runner])

@svc.api(input=JSON(), output=JSON())
async def predict(input_data):
    result = await runner.predict.async_run(input_data["features"])
    return {"prediction": result.tolist()}

2. Bento 빌드 및 Docker 이미지 생성

bentoml build
bentoml containerize iris_classifier:latest

3. Docker Compose로 실행

docker-compose.yml
services:
  bentoml:
    image: iris_classifier:latest
    container_name: bentoml
    restart: unless-stopped
    ports:
      - "3000:3000"

실행

docker compose up -d

접속 확인

curl -X POST http://localhost:3000/predict \
  -H "Content-Type: application/json" \
  -d '{"features": [5.1, 3.5, 1.4, 0.2]}'

기본 정보

항목
API 포트3000
API 형식REST / gRPC

라이선스

구분내용
라이선스Apache License 2.0
개인 사용자유롭게 사용 가능
상업적 사용자유롭게 사용 가능, 수정/재배포 제한 없음

참고