Open Source

[OpenLLM] 직접 사용해보기

키독 2023. 6. 25. 23:55

ChatGPT가 핫해진 이후 여러 파인튜닝된 LLM 모델들이 나오고 있다.

사내에서도 비개발자분들이 조금더 쉽게 최신 기술들을 접하실 수 있도록 기술 친화적인 페이지를 개설 후 제공해드리고 있다.

그러한 분위기 속에서 만들어진 것이 "AI와 친해지기, 스터디 모임"이다. 개발자분들을 포함하여 최신 기술에 대해 관심이 많은 비개발자분들과 함께 여러 툴들을 사용해보고 사용후기 및 느낌점을 공유하기 위한 모임이다.

geek news를 통해 "OpenLLM"이라는 깃허브 링크를 접하게 되었고, 해당 모임에 사용법과 사용후기를 공유해드리기 위한 내용을 정리하려고 한다. 

https://github.com/bentoml/OpenLLM/

 

GitHub - bentoml/OpenLLM: An open platform for operating large language models (LLMs) in production. Fine-tune, serve, deploy, a

An open platform for operating large language models (LLMs) in production. Fine-tune, serve, deploy, and monitor any LLMs with ease. - GitHub - bentoml/OpenLLM: An open platform for operating large...

github.com

 

OpenLLM에 대해 한마디로 소개해보자면 다음과 같다.

An open platform for operating large language models (LLMs) in production. Fine-tune, serve, deploy, and monitor any LLMs with ease.

 

이제 내가 경험해본 사용 방법에 대해 소개해보고자 한다.

환경 세팅 작업

  • terminal 접속

Cmd + Space > 'Terminal' 입력 후 진입

  • create conda environment
conda create --name openllm python=3.8
conda activate openllm
pip install openllm

"openllm -h" 명령어를 입력하여 아래와 같은 화면을 확인한다면 제대로 설치가 된것이다.

 

지원 가능한 모델 리스트 확인

  • 모델 리스트 확인
openllm models --show-available -o json

위와 같은 명령어를 통해 지원가능한 모델 리스트를 확인할 수 있다.

 

(Optional) 새로운 모델 추가하기 

https://github.com/bentoml/OpenLLM/blob/main/ADDING_NEW_MODEL.md

 

GitHub - bentoml/OpenLLM: An open platform for operating large language models (LLMs) in production. Fine-tune, serve, deploy, a

An open platform for operating large language models (LLMs) in production. Fine-tune, serve, deploy, and monitor any LLMs with ease. - GitHub - bentoml/OpenLLM: An open platform for operating large...

github.com

모델을 추가하는 방법은 위 링크를 통해 자세히 알 수 있다. (PR 요청하면 다음 릴리즈에 반영해주시는듯..)

 

OpenLLM 서버 띄우기

  • OpenLLM 서버 시작
openllm start {모델 이름} --model-id {모델 id} 
# openllm start flan-t5 --model-id google/flan-t5-large

위와 같은 명령어를 통해 openllm REST 서버를 실행시킬 수 있다.

내가 돌려본 것은 dolly-v2 모델이며 서버가 시작되면 아래와 같은 모습을 확인할 수 있을 것이다.
(실행시키려는 모델을 다운받은 적이 없는 경우에는 모델을 다운받는 과정이 추가적으로 돌아가며, 모델 사이즈에 따라 시간이 꽤 걸릴 수 있다.)

터미널에서 서버를 시작한 모습
localhost:3000으로 접속해보면 화면과 같이 api에 대한 정보를 확인할 수 있다.

 

LLM 모델 결과 확인

  • 새 터미널에서 query를 던져 답변 확인
export OPENLLM_ENDPOINT=http://localhost:3000
openllm query 'Explain to me the difference between "further" and "farther"'

새 터미널에서 2일간의 부산 일정을 짜달라는 질문에 대한 답변을 받아보았다.
서울에 있는 마포대교나 노량진.. 등 잘못된 정보와 존재하지도 않는 동수대 궁전(?)을 방문해보라는 hallucination이 발생해보이네요.. ;(

  • 파이썬으로 답변 확인

 

 

+) 추가 정보

 

Deploying Bento

Deployment Overview: BentoML is designed to provide a unified packaging format, for deploying AI applications via a wide range of serving patterns, including real-time inference API, offline batch ...

docs.bentoml.org

예제 service.py
실행 터미널

  • OpenLLM은 사용자 데이터를 모은다고 한다. 내 데이터가 공유되는게 싫다면 "export OPENLLM_DO_NOT_TRACK=true"를 이용하여 사용 트래킹을 끌 수 있다고 한다.