Programming/Others

BentoML이란?!

어쩌다통계 2023. 3. 15. 22:57
728x90

이 글이 도움 되셨다면 광고 클릭 부탁드립니다 : )

 

BentoML에 대해 찾아보며 알게된 내용을 정리한 포스트입니다.


BentoML이란?!

 

0. BentoML 기본 정보

The Unified Model Serving Framework, BentoML makes it easy to create Machine Learning services that are ready to deploy and scale.
모델을 쉽고 빠르게 배포하는 도구
모델 API 서버 구성을 쉽게 할 수 있고 dockerfile

Data Scientists and ML Engineers use BentoML to:

Accelerate and standardize the process of taking ML models to production

Build scalable and high performance prediction services

Continuously deploy, monitor, and operate prediction services in production

Bento : 일본의 도시락 요리. 위키피디아 - 우리의 머신러닝 모델이 패킹된 것
Yatai : 일본식 포장마차로 타코야키, 오코노미야키 등을 판매. 위키피디아 - 머신러닝 모델을 관리해주는 친구
Pack : 음식을 포장해서 Bento로 만드는 행위 - 머신러닝 모델을 저장하는 과정
우리는 Bento에 들어갈 음식(모델 Artifact 및 코드)을 만들고 BentoML에게 패킹(포장)을 요청, 배달(Deploy)을 자동으로 해준다고 이해하면 된다. Bento를 확인하고 싶다면 Yatai 가서 패킹되거나 배달된 Bento를 확인할 수 있음

 

  • 라이센스 : Apache License 2.0, 상업적 사용 가능

 

 

1. BentoML의 기능

  • Unified Model Serving API, 간편하게 모델 API 서버 구성할 수 있다.
    • Framework-agnostic model packaging for Tensorflow, PyTorch, XGBoost, Scikit-Learn, ONNX, and many more!
    • Write custom Python code alongside model inference for pre/post-processing and business logic
    • Apply the same code for online(REST API or gRPC), offline batch, and streaming inference
    • Simple abstractions for building multi-model inference pipelines or graphs

 

  • Standardized process for a frictionless transition to production, 도커 이미지화 가능하고 타 라이브러리로 확장이 용이하다.
    • Build Bento as the standard deployable artifact for ML services
    • Automatically generate docker images with the desired dependencies
    • Easy CUDA setup for inference with GPU
    • Rich integration with the MLOps ecosystem, including Kubeflow, Airflow, MLFlow, Triton

 

  • Scalable with powerful performance optimizations, 높은 성능(flask기반 모델보다 100배 처리량, Adaptive Micro Batching 메커니즘을 활용)을 보인다.
    • Adaptive batching dynamically groups inference requests on server-side optimal performance
    • Runner abstraction scales model inference separately from your custom code
    • Maximize your GPU and multi-core CPU utilization with automatic provisioning

 

  • Deploy anywhere in a DevOps-friendly way, 간편하고 빠르게 배포 가능하다.
    • Streamline production deployment workflow via:
      • BentoML Cloud: the fastest way to deploy your bento, simple and at scale
      • Yatai: Model Deployment at scale on Kubernetes
      • bentoctl: Fast model deployment on AWS SageMaker, Lambda, ECE, GCP, Azure, Heroku, and more!
    • Run offline batch inference jobs with Spark or Dask
    • Built-in support for Prometheus metrics and OpenTelemetry
    • Flexible APIs for advanced CI/CD workflows

 

 

2. BentoML 핵심 요소

  • bentoml.BentoService
    • BentoML을 이용하여 모델의 추론 서비스를 빌딩 하는 가장 기본적인 컴포넌트
    • 모델이 어떤 artifacts로 구성되어 있고, 어떤 환경이 준비되어야 하는 지 등 모델의 prediction을 위해 필요한 모든 내용을 요약하고 담고 있는 하나의 유닛

 

  • Model Artifacts 패키징
    • BentoML은 Model의 종류(sklearn/ pytorch/ tensorflow...)에 따라 최적화된 artifacts로 패키징 할 수 있음

 

  • API functions and adapters
    • BentoService API는 클라이언트가 예측 서비스에 접근하기 위한 End Point
    • Adapter는 API callback 함수를 정의하고 다양한 형태로 예측을 요청하는 추상화 레이어
      • BentoService는 python 스크립트에서 Class 형식으로 구현되는데, 그 아래 predict 함수와 @api 데코레이터를 통해 API 객체를 선언할 수 있음
      • 이렇게 선언한 API는 adapters를 통해 입출력형식, 배치 여부, 최대 사이즈 및 최대 latency 등 상세한 스펙 사항을 정의할 수 있고, 입력 받은 데이터가 어떤 추론 로직을 거쳐야하는 지 정의할 수 있음

 

  • Model Serving
    • BentoService가 Bento로 저장되면 다양한 방법으로 배포할 수 있음
      • Online Serving : API endpoint를 통해 실시간 예측
        • BentoService를 저장하기만 하면 REST API 서버를 쉽게 만들 수 있음
        • Bento를 저장하면 Dockerfile이 생성됨 -> docker build 가능
        • Adaptive Micro-Batching -> 동시에 많은 요청이 들어와도 높은 처리량을 보여줌
      • Offline Batch Serving : 배치로 처리한 후, 결과를 스토리지에 저장함
      • Edge Serving : 모바일, IoT 기기에 모델 배포

 

  • Model management & Yatai
    • Yatai : model management를 위한 컴포넌트
    • CLI, Web UI, BentoML 번들을 생성하기 위한 Python API 제공
    • 팀 전용 Yatai 서버를 구축해서 팀의 모든 모델을 관리하고 CI/CD를 구축할 수 있음

 

 

3. 모니터링

  • BentoML에서 자체적으로 Prometheus metric API 제공
  • Prometheus와 Grafana 활용 가능
    • Prometheus : 쿼리를 통해 쿠버네티스 리소스를 pull 하는 방식으로 metric 추출
    • Grafana : 추출된 metric을 받아서 사용자가 보기 쉽게 그래프로 시각화 가능
  • 메모리 사용량/ 작업량 확인

 

 

 

4. 참고 사이트

 

 

 

 

반응형