NLP

Llama2(라마2) 소개 및 설치

ianyang 2023. 7. 24. 16:18

Llama2

7월 19일(수) meta의 Llama2(라마2)가 공개됐다.

Llama1과 비교했을 때 크게 바뀐 점이라고 한다면 상업적으로 이용이 가능한 모델이라는 점이다.

성능면에서도 Llama1보다 40%의 데이터를 더 학습시켰으며 context 길이가 2배로 늘어난점 등이 있다.

모델 종류로는 7B, 13B, 70B가 있으며 70B의 경우에는 몇몇 GPU를 가지고 있지 않는 이상 돌려보긴 쉽지 않을 것이다.

그리고 기본적으로 7B, 13B도 GPU환경에서 구동하여야 한다.

Llama2 성능비교표

Llama2 공식 홈페이지를 참고하여 보면 다른 모델들과 비교한 성능표가 있는데 기존 모델들 보다 좋은 성능을 보이며 70B모델의 경우 Llama1 65B모델에 비해서 확실히 좋은 성능을 보인다.

Llama2 설치

설치하는 방법에는 몇 가지가 있는데 자신의 상황에 맞춰서 사용하면 될 것 같다.

  1. 공식사이트 다운로드 방법 (비추)

  • 공식 홈페이지에 접속하여 위의 그림과 같이 Download the Model 버튼을 찾아서 클릭한다.
  • 이름, 이메일, 국가 등을 입력하고 라이센스와 정책에 동의하고 기다리면 승인 후 기입한 이메일로 메일이 온다.
  • 메일을 받은 후 meta 깃허브에 있는 download.sh를 받으면 된다.
  • 깃허브에서 다운 받는 방법
# 깃을 클론할 곳으로 이동
cd 저장할폴더

# git clone 할 때 해당 주소가 안된다면 직접 meta 깃허브에 들어가서 clone 복사를 하면된다.
git clone https://github.com/facebookresearch/llama.git 

# 클론된 폴더로 이동
cd llama

git pull

# download.sh에만 권한을 주면 됨
chmod 744 download.sh

# 이걸 입력하면 중간에 'Enter the URL from email:'이 나오면 이메일에서 받은 https://download~로 된 링크 붙여넣기
# 그 다음 모델을 선택해서 써 넣으면 된다. 모델 리스트 : [7B,13B,70B,7B-chat,13B-chat,70B-chat]
./download.sh

2. huggingface 다운로드 방법 (추천)

  • 첫 번째 방법과 같이 공식 홈페이지에 접속하여 이름,이메일 등을 적고 신청한다. 신청하는 것까지는 동일하고 승인이 되야 허깅페이스도 승인이 된다.
  • 허깅페이스의 meta-llama로 접속하여 Llama2모델 중에 하나를 클릭하여 정책 동의에 클릭해야 한다.
  • 단, 허깅페이스 아이디의 이메일과 공식 홈페이지에서 적은 이메일이 동일해야 이를 매칭시켜서 승인해준다.
  • 승인이 되면 이메일로 모델별로 승인됐다고 이메일이 온다
  • 사용 방법
# 해당 방법으로 로그인 시 Token입력 창에 본인의 huggingface 토큰을 넣으면 된다.
!huggingface-cli login
#!huggingface-cli login --token '본인의 huggingface 토큰'

# 사용할 모델 명 정확히 입력
model = "meta-llama/Llama-2-7b-chat-hf"

# 이후 용도에 알맞는 코드 사용

3. cpu 버전 다운로드 방법

  • 만약 CPU만 사용할 수 있는 상황이라면 위의 모델들을 다운로드해도 작동시키기 힘들 것이다.
  • 이 때는 Llama2-cpp에서 제공하는 GGML이라고 붙은 모델을 다운로드하여 사용해야 한다.
  • 따로 승인 받을 필요없이 해당 링크에 접속하여 본인에게 맞는 GGML이 붙은 모델을 찾아서 클릭하고 Files and versions에 들어가서 하나를 다운받아 사용하면 된다.

  • 예를 들어 Llama-2-13B-chat-GGML 모델을 사용한다고 할 때 이 정도의 세분화된 모델이 존재하는데 Model card에 모델 별로 설명이 적혀있어 이를 보고 하나를 고르면 된다.

참고 사이트

Llama2 홈페이지 : https://ai.meta.com/llama/

 

Llama 2 - Meta AI

We have a broad range of supporters around the world who believe in our open approach to today’s AI — companies that have given early feedback and are excited to build with Llama 2, cloud providers that will include the model as part of their offering

ai.meta.com

Llama2 github : https://github.com/facebookresearch/llama

 

GitHub - facebookresearch/llama: Inference code for LLaMA models

Inference code for LLaMA models. Contribute to facebookresearch/llama development by creating an account on GitHub.

github.com

Llama2 recipes github : https://github.com/facebookresearch/llama-recipes

 

GitHub - facebookresearch/llama-recipes: Examples and recipes for Llama 2 model

Examples and recipes for Llama 2 model. Contribute to facebookresearch/llama-recipes development by creating an account on GitHub.

github.com

Llama2 huggingface : https://huggingface.co/meta-llama

 

meta-llama (Meta Llama 2)

Llama 2 From Meta Welcome to the official Hugging Face organization for Llama 2 models from Meta! In order to access models here, please visit the Meta website and accept our license terms and acceptable use policy before requesting access to a model. Requ

huggingface.co

Llama2 cpp : https://huggingface.co/TheBloke

 

TheBloke (Tom Jobbins)

 

huggingface.co