Running Meta Llama on Linux 문서의 내용을 참고하여 Llama 3.2 1B 모델로 다음 두 가지 기능을 실습합니다.
- 문장 완성
- 챗팅 완성
실습 환경
- Ubuntu 20.04.6 LTS
- Python 3.12.7
- Llama3.2-1B, Llama3.2-1B-Instruct
- rustc 1.83.0
- NVIDIA RTX 4090 24GB
프로그램 준비
-
실습에서 사용할
wget,md5sum설치sudo apt-get install wget sudo apt-get install md5sum -
NVIDIA GPU 설치 여부 확인
nvidia-smi -
실습 디렉토리 만들기
mkdir llama3-demo cd llama3-demo git clone https://github.com/meta-llama/llama3.git -
Python 3.10 이상의 버전으로 가상환경 만들고 활성화
python -m venv llama-venv . llama-venv/bin/activate -
Rust 컴파일러 설치
How To Install Rust on Ubuntu 20.04 문서를 참고하여 Rust 컴파일러를 설치합니다.
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh위 명령을 실행하면 아래와 같이 세 가지 선택 옵션이 나타나는데 그냥 엔터를 쳐서 1번 옵션으로 진행합니다.
... 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation아래 명령을 실행하여 현재 쉘에 반영하고 설치된 컴파일러 버전을 확인합니다.
source $HOME/.cargo/env rustc --version -
의존 라이브러리 설치
pip install -e .
모델 다운로드
-
Llama 웹 사이트에서 신청
선택 옵션에 따라 다운로드할 수 있는 모델들과 커스텀 URL이 화면에 표시되고 이메일로도 전송됩니다.
-
모델 목록 표시
llama model list위 명령을 수행하면 아래와 같은 모델 목록이 표시됩니다.
+-----------------------------------------+-----------------------------------------------------+----------------+ | Model Descriptor | Hugging Face Repo | Context Length | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-1B | meta-llama/Llama-3.2-1B | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-3B | meta-llama/Llama-3.2-3B | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-11B-Vision | meta-llama/Llama-3.2-11B-Vision | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-90B-Vision | meta-llama/Llama-3.2-90B-Vision | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-1B-Instruct | meta-llama/Llama-3.2-1B-Instruct | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-3B-Instruct | meta-llama/Llama-3.2-3B-Instruct | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-1B-Instruct:int4-qlora-eo8 | meta-llama/Llama-3.2-1B-Instruct-QLORA_INT4_EO8 | 8K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-1B-Instruct:int4-spinquant-eo8 | meta-llama/Llama-3.2-1B-Instruct-SpinQuant_INT4_EO8 | 8K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-3B-Instruct:int4-qlora-eo8 | meta-llama/Llama-3.2-3B-Instruct-QLORA_INT4_EO8 | 8K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-3B-Instruct:int4-spinquant-eo8 | meta-llama/Llama-3.2-3B-Instruct-SpinQuant_INT4_EO8 | 8K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-11B-Vision-Instruct | meta-llama/Llama-3.2-11B-Vision-Instruct | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ | Llama3.2-90B-Vision-Instruct | meta-llama/Llama-3.2-90B-Vision-Instruct | 128K | +-----------------------------------------+-----------------------------------------------------+----------------+ -
모델 다운로드
llama download --source meta --model-id Llama3.2-1B llama download --source meta --model-id Llama3.2-1B-Instruct다운로드된 모델들은 아래 디렉토리에 저장됩니다.
$HOME/.llama/checkpoints
예제 실행
-
텍스트 생성 예제 실행
torchrun --nproc_per_node 1 example_text_completion.py --ckpt_dir $HOME/.llama/checkpoints/Llama3.2-1B/ --tokenizer_path $HOME/.llama/checkpoints/Llama3.2-1B/tokenizer.model --max_seq_len 128 --max_batch_size 4example_text_completion.py실행시 다음과 같은 에러가 발생합니다.TypeError: ModelArgs.__init__() got an unexpected keyword argument 'use_scaled_rope'이 문제를 해결하기 위하여
$HOME/.llama/checkpoints/Llama3.2-1B/params.json에서"use_scaled_rope": true,항목을 제거합니다. -
질의 응답 예제 실행
torchrun --nproc_per_node 1 example_chat_completion.py --ckpt_dir $HOME/.llama/checkpoints/Llama3.2-1B-Instruct/ --tokenizer_path $HOME/.llama/checkpoints/Llama3.2-1B-Instruct/tokenizer.model --max_seq_len 512 --max_batch_size 6
Written with StackEdit.
댓글
댓글 쓰기