본문 바로가기
AI/LLM

[LLM] 왔다, LLaMA3!

by didi0di 2024. 4. 19.
728x90

 

드디어 LLaMA3가 나왔습니다.

 

 

 

LLaMA3라서 라마 3마리를.... 은근 귀엽네요 ㅋㅋㅋ

근데 왜 도박을 하고 있을까요? 뭔가 의미가 있나? LLM 판을 뒤집어 버리시겠따...? 잭팟을 터트리려나 봅니다 ㅋㅋㅋ

 

무튼 전작에 이어 이번에도 오픈소스로 공개했고, 깃헙에서 확인할 수 있습니다.

https://github.com/meta-llama/llama3

 

GitHub - meta-llama/llama3: The official Meta Llama 3 GitHub site

The official Meta Llama 3 GitHub site. Contribute to meta-llama/llama3 development by creating an account on GitHub.

github.com

 

 

프롬프트 셋팅은 LLaMA Recipes 깃헙에 올라와 있구요.

파인튜닝 방법도 마찬가지로 올라와 있으니 참고하시면 좋을 것 같습니다 :)

 

https://github.com/meta-llama/llama-recipes

 

GitHub - meta-llama/llama-recipes: Scripts for fine-tuning Llama2 with composable FSDP & PEFT methods to cover single/multi-node

Scripts for fine-tuning Llama2 with composable FSDP & PEFT methods to cover single/multi-node GPUs. Supports default & custom datasets for applications such as summarization & question ...

github.com

 

참고로 라마 레시피는 pip install 을 지원합니다.

pip install --extra-index-url https://download.pytorch.org/whl/test/cu118 llama-recipes

 

 

하지만 좀 더 up-to-data에 가깝게 설치하려면 깃헙이 낫긴 하겠죠!

깃헙 소스로 설치하는 방법은 아래와 같습니다. 

 

git clone git@github.com:meta-llama/llama-recipes.git
cd llama-recipes
pip install -U pip setuptools
pip install --extra-index-url https://download.pytorch.org/whl/test/cu118 -e .

 

 

모델을 사용하기 앞서, 제일 중요한건 아무래도 성능 개선이죠.

본격적으로 리뷰하기에 앞서, LLaMA3의 벤치마크 성능부터 살펴보고 가겠습니다.

 

벤치마크 성능

 

먼저 LLaMA3 Base모델의 벤치마크 성능은 다음과 같습니다.

당연히 LLaMA3 70B의 성능이 제일 좋고,  전체적으로 확실히 LLaMA2보다 많이 개선된게 보이네요. 

 

 

 

 

MMLU같은 경우에는 모델 사이즈 별로 조금씩 차이는 있지만, 그래도 LLaMA2 대비 10% 이상 성능이 개선되었군요.

 

대다수의 벤치마크 데이터셋에서 10%~ 40% 정도의 성능 향상이 일어난 것 같습니다.

 

 

 

instruction tuned 모델의 벤치마크 성능도 마찬가지입니다.

 

 

 

그럼 성능은 확인했으니, 본격적으로 LLaMA3에 대해 리뷰해보겠습니다.

렛츠고!

 

 


 

LLaMA3 리뷰

 

우선 모델 사이즈는 8B 부터 70B까지 있습니다.

pre-trained 버전과 instruction tuned variants 들로 구성되어 있구요.

 

input으로는 아직까지는 text only, ouput으로는 text와 code가 있습니다.

 

Training Data Params Context length GQA Token count Knowledge cutoff
Llama 3 A new mix of publicly available online data. 8B 8k Yes 15T+ March, 2023
70B 8k Yes December, 2023

 

Inference scalability를 개선하기 위해 Grouped-Query Attention (GQA를 사용했다고 합니다.

 

모델에 대한 보다 자세한 설명은 모델 카드에서 확인할 수 있습니다.

 

llama3/MODEL_CARD.md at main · meta-llama/llama3

The official Meta Llama 3 GitHub site. Contribute to meta-llama/llama3 development by creating an account on GitHub.

github.com

 

 

Model Architecture 

 

 

 

Llama 3는 최적화된 트랜스포머 아키텍처를 사용한 auto-regressive language model 입니다.

tuned versions은  SFT(supervised fine-tuning) RLHF (reinforcement learning with human feedback)가 있습니다.

RLHF는 다들 잘 아시다시피 helpfulness와 safety를 위해 human preferences와 align을 맞추려고 사용했다고 합니다.

 

LLaMA3 모델 다운로드

 

모델 웨이트랑 토크나이저를 다운받기 위해서는 우선 메타 홈페이지에서 신청을 해야합니다.

 

Download Llama

Request access to Llama.

llama.meta.com

 

 

당연히 허깅페이스에서도 다운받을 수 있구요.

 

meta-llama (Meta Llama)

The Llama Family From Meta Welcome to the official Hugging Face organization for Llama 2, Llama Guard, and Code Llama models from Meta! In order to access models here, please visit a repo of one of the three families and accept the license terms and accept

huggingface.co

 

 

얘네 모델 세트를 LLaMA Family 라고 부르는데... 귀엽네요 ㅋㅋㅋㅋ

LLaMA 3 Family 중에서는 역시나 가벼운 모델인 LLaMA3 8B의 인기가 제일 많은 것 같습니다.

 

 

meta-llama/Meta-Llama-3-8B · Hugging Face

The information you provide will be collected, stored, processed and shared in accordance with the Meta Privacy Policy. Meta Llama 3 Version Release Date: April 18, 2024 "Agreement" means the terms and conditions for use, reproduction, distribution and mod

huggingface.co

 

 

 

How to Use

 

트랜스포머를 이용한 허깅페이스 모델 사용법은 다음과 같습니다.

 

import transformers
import torch

model_id = "meta-llama/Meta-Llama-3-8B"

pipeline = transformers.pipeline(
pipeline("Hey how are you doing today?")

 

 

 

토크나이저 테스트 결과, 한글 캐릭터가 꽤 커버되는 것 같은데

자세한 건 다른 모델들과 비교해봐야 겠습니다.

gemma 토크나이저가 한글 캐릭터를 대부분 커버해서 한국어를 그냥 입력해도 엄청 잘한다고 들었는데,

Llama3 비슷한 양상일  같네요!

 

 

또한 Llama 3는 tiktoken tokenizer 기반의 새로운 프롬프트 템플릿과 스페셜 토큰을 사용한다고 하는데요.

보다 자세한 내용은 아래와 같습니다.

 

TokenDescription

<|begin_of_text|> This is equivalent to the BOS token.
<|eot_id|> This signifies the end of the message in a turn.
<|start_header_id|>{role}<|end_header_id|> These tokens enclose the role for a particular message. The possible roles can be: system, user, assistant.
<|end_of_text|> This is equivalent to the EOS token. On generating this token, Llama 3 will cease to generate more tokens

 

 

 

multiturn-conversation prompt template:

 

멀티턴 대화에서 프롬프트 템플릿은 다음과 같습니다.

 

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

{{ system_prompt }}<|eot_id|><|start_header_id|>user<|end_header_id|>

{{ user_message_1 }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{{ model_answer_1 }}<|eot_id|><|start_header_id|>user<|end_header_id|>

{{ user_message_2 }}<|eot_id|><|start_header_id|>assistant<|end_header_id|>

 

 

 

variation

 

LLaMA3가 나오자마자 메타에서 variation을 쏟아내고 있는데, 또 다른 finetune toolkit이라고 합니다.


메모리와 속도에서 이점이 크다고 합니다.
https://github.com/unslothai/unsloth

 

GitHub - unslothai/unsloth: 2-5X faster 80% less memory LLM finetuning

2-5X faster 80% less memory LLM finetuning. Contribute to unslothai/unsloth development by creating an account on GitHub.

github.com

 

 

 

이렇게 LLaMA3에 대해 알아보는 시간을 가졌습니다.

LLaMA3가 LLM 시장에 또 어떤 파동을 불러일으킬지, 기대가 되는 한편

기술의 발전 속도가 어마무시하게 빨라서 정말 꾸준히 따라가지 않으면 도태되겠다는 생각이 드네요.

 

자고 일어날 때마 새로운 모델들이 쏟아져 나오는군요! 하하하!! 정말 신납니다!!

728x90

댓글