파인튜닝한 bert 모델 서빙서버 EC2에 배포하기
FastApi 프레임워크를 사용하여 웹 애플리케이션을 구축해보겠다.
주요 기능으로는 텍스트 처리 및 AI 모델을 활용한 다양한 응답을 제공하는 API 엔드포인트 정의이다.
FastAPI 코드
1 | import os |
Dockerfile 코드
1 | FROM python:3.11-slim |
로컬에서 테스트해보기
1 | % curl --location 'http://127.0.0.1:5004/predict' \ |
ECR에 도커이미지 push
1 | % aws configure |
AWS 자격 증명 파일(~/.aws/credentials)에 아래 것들이 있어야함
1 | aws_access_key_id=... |
도커 이미지 푸시
1 | # Docker 이미지 태그 |
EC2에서 이미지 pull 하기
1 | $ sudo yum install aws-cli -y |
EC2에서 배포하기
1 | % docker run --name [app name] -p 5004:5004 [id].dkr.ecr.[region].amazonaws.com/[app name]:[tag] |
테스트
1 | $ curl --location 'http://[ec2_ip].compute.amazonaws.com:5004/predict' --header 'Content-Type: application/json' --data '{"input":"This is a test sentence."}' |
API Gateway 연동하기
API Gateway에서 메서드를 만들고 HTTP Request Header를 넣어준다
배포전에 테스트를 해준다
테스트 결과는 아래와 같이 나온다.
배포한 API 로컬 PC에서 호출해보기
1 | % curl --location 'https://wfz4ol6u28.execute-api.ap-northeast-2.amazonaws.com/dev/predict' \ |
파인튜닝한 bert 모델 서빙서버 EC2에 배포하기
https://hamin7.github.io/2024/08/12/AWS-Deploy-Fine-Tuned-BERT-Model-Serving-Server-on-EC2/
You need to set
install_url
to use ShareThis. Please set it in _config.yml
.