뱁새유니버스

Meta Llama3 메타 AI LLM 성능 테스트 GPT openAI

by 뱁새유니버스

1. 세줄요약

01. 메타 Llama 3 을 google colab에서 돌렸다. GPU 기준 약 1분에서 3분 정도 소요된다. (token 256 기준)

02. 기술 이해는 부족하지만 Llama2에서 안됐던 한국어가 Llama 3에선 비슷하게 흉내를 낸다.(신기신기)

03. 조금만 있으면 Local에서 LLM을 사용할 수 있는 날이 올 것이다.(확신에 찬 어조)

2. 내용

(1) 구글 Colab 실행

Google Colab을 실행합니다. 상단에 <런타임> 메뉴를 클릭하고 런타임 유형 변경을 클릭합니다.

하드웨어 가속기로 T4 GPU를 선택해줍니다. 프리미엄 GPU를 살 돈이 없습니다..(사랑해요 구글)

성능을 한번 확인해봅시다.

!nvidia-smi

Tesla T4인 것을 확인했습니다. GPU Colab 최고! 

이제 아래 스크립트를 차례대로 실행합니다.

#accelerate 설치하기
!pip install accelerate
import os
os.environ['HF_TOKEN'] = "Meta Llama3 token을 입력하세요."

 

여기서 Meta Llama3를 구동하려면 token을 받아야 합니다.

https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct

 

meta-llama/Meta-Llama-3-8B-Instruct · 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

여기서 토큰을 받은 다음 토큰을 입력하면 됩니다.

#eta-Llama-3-8B-Instruct 모델 불러오기 및 설정

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

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

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)
#LLM 응답을 위한 함수 정의하기
def generate_response(system_message, user_message):
  messages = [
      {"role": "system", "content": system_message},
      {"role": "user", "content": user_message},
  ]

  input_ids = tokenizer.apply_chat_template(
      messages,
      add_generation_prompt=True,
      return_tensors="pt"
  ).to(model.device)

  terminators = [
      tokenizer.eos_token_id,
      tokenizer.convert_tokens_to_ids("<|eot_id|>")
  ]

  outputs = model.generate(
      input_ids,
      max_new_tokens=256,
      eos_token_id=terminators,
      do_sample=True,
      temperature=0.6,
      top_p=0.9
  )

  response = outputs[0][input_ids.shape[-1]:]

  return tokenizer.decode(response, skip_special_tokens=True)
response = generate_response(system_message="",
                             user_message="한국어로 얘기해줘. 미국 초대 대통령이 누구야?")
print(response)

 

한국어로 Llama3를 사용할 수 있었습니다!!! 미국 초대 대통령을 물어보니 잘 대답해주네요!

대한민국 임시정부를 수립한 초대 대통령이 누구냐고 하니까 김구선생님이라고 답하네요. 확실히 미국 데이터가 학습이 잘된 것 같습니다.

3. 마치며

이번 시간은 최근에 나온 메타 Llama3 LLM을 테스트해봤습니다. 

Local에서 돌릴 수 있다는 특장점을 갖고 있는 메타 Llama3는 ChatGPT4와도 견줄 수 있다고 하는데 과연 그런지 더 테스트해봐야 알 것 같습니다.

질문이 있으시면 언제든 댓글 남겨주세요! 답변드리겠습니다. 같이 공부합시다^^
이 글을 보는 모든 분들 오늘 하루가 행복하시길 바랍니다.
감사합니다.

반응형

블로그의 정보

가슴이 웅장해지는 모든것

뱁새유니버스

활동하기