얕고 넓게

[AI] Llama 파인 튜닝 본문

IT/AI.ML

[AI] Llama 파인 튜닝

블랙오닉스 2025. 1. 17. 16:10

2025.01.17

그냥 무작정 따라해 본다.

https://jjaegii.tistory.com/35

 

KoAlpaca 데이터셋을 활용한 Llama 3.1 LoRA 기반 PEFT

Llama 3.1 모델을 LoRA(Low-Rank Adaptation) 기법을 사용해 한국어 데이터셋인 KoAlpaca를 기반으로 Parameter Efficient Fine-Tuning 하는 과정을 다룬다.LoRA는 대규모 언어 모델을 적은 자원으로도 효율적으로 학습

jjaegii.tistory.com


command 실행하고 위의 내용대로 python 라이브러리 설치

pip install accelerate
Collecting accelerate
  Downloading accelerate-1.2.1-py3-none-any.whl.metadata (19 kB)
Collecting numpy<3.0.0,>=1.17 (from accelerate)
  Using cached numpy-2.2.1-cp311-cp311-win_amd64.whl.metadata (60 kB)
Collecting packaging>=20.0 (from accelerate)
  Using cached packaging-24.2-py3-none-any.whl.metadata (3.2 kB)
Collecting psutil (from accelerate)
  Using cached psutil-6.1.1-cp37-abi3-win_amd64.whl.metadata (23 kB)
...
Successfully installed MarkupSafe-3.0.2 accelerate-1.2.1 certifi-2024.12.14 charset-normalizer-3.4.1 colorama-0.4.6 filelock-3.16.1 fsspec-2024.12.0 huggingface-hub-0.27.1 idna-3.10 jinja2-3.1.5 mpmath-1.3.0 networkx-3.4.2 numpy-2.2.1 packaging-24.2 psutil-6.1.1 pyyaml-6.0.2 requests-2.32.3 safetensors-0.5.2 sympy-1.13.1 torch-2.5.1 tqdm-4.67.1 typing-extensions-4.12.2 urllib3-2.3.0

잔뜩 설치한다. numpy도 설치되는 건가?

현재 130GB 여유 공간

pip install peft
Collecting peft
  Downloading peft-0.14.0-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: numpy>=1.17 in c:\users\black\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from peft) (2.2.1)
...
Successfully installed peft-0.14.0 regex-2024.11.6 tokenizers-0.21.0 transformers-4.48.0

 

pip install bitsandbytes
Collecting bitsandbytes
  Downloading bitsandbytes-0.45.0-py3-none-win_amd64.whl.metadata (2.9 kB)
Requirement already satisfied: torch in c:\users\black\appdata\local\packages\pythonsoftwarefoundation.python.3.11_qbz5n2kfra8p0\localcache\local-packages\python311\site-packages (from bitsandbytes) (2.5.1)
...
Successfully installed bitsandbytes-0.45.0

 

pip install transformers

이건 이미 깔려 있는듯

 

pip install datasets
...
Successfully installed aiohappyeyeballs-2.4.4 aiohttp-3.11.11 aiosignal-1.3.2 attrs-24.3.0 datasets-3.2.0 dill-0.3.8 frozenlist-1.5.0 fsspec-2024.9.0 multidict-6.1.0 multiprocess-0.70.16 pandas-2.2.3 propcache-0.2.1 pyarrow-19.0.0 python-dateutil-2.9.0.post0 pytz-2024.2 six-1.17.0 tzdata-2024.2 xxhash-3.5.0 yarl-1.18.3

 

pip install trl
...
Successfully installed markdown-it-py-3.0.0 mdurl-0.1.2 pygments-2.19.1 rich-13.9.4 trl-0.13.0

 

pip install pandas

이것도 이미 설치됨


KoAlpaca에서 부터 막힌다.

Hugging Face에서 받으라는 것인지, GitHub에서 받는 것인지...

https://github.com/Beomi/KoAlpaca

 

GitHub - Beomi/KoAlpaca: KoAlpaca: 한국어 명령어를 이해하는 오픈소스 언어모델 (KoAlpaca: An open-source langu

KoAlpaca: 한국어 명령어를 이해하는 오픈소스 언어모델 (KoAlpaca: An open-source language model to understand Korean instructions) - Beomi/KoAlpaca

github.com

 

일단 현재 디렉토리에서 KoAlpaca를 clone

git clone https://github.com/Beomi/KoAlpaca.git

 

그다음은 모르겠다.


좋은 자료. 위의 블로그와 같은데 FT 에 대해서 잘 설명되어 있다.

https://jjaegii.tistory.com/34?category=1156976

 

PEFT: Parameter-Efficient Fine-Tuning

PEFT(Parameter-Efficient Fine-Tuning)는 대규모 사전 학습된 모델을 조금만 수정해서 특정 작업에 적합하도록 만드는 기법이다.요즘 AI 모델은 매우 크고 복잡해서, 모든 파라미터를 다시 학습하는 것은

jjaegii.tistory.com

관련된 자료가  Llama3.3 70b를 사용하고 있어서 다시 받아본다.

>ollama run llama3.3:70b
pulling manifest
pulling 4824460d29f2... 100% ▕████████████████████████████████████████████████████████▏  42 GB
pulling 948af2743fc7... 100% ▕████████████████████████████████████████████████████████▏ 1.5 KB
pulling bc371a43ce90... 100% ▕████████████████████████████████████████████████████████▏ 7.6 KB
pulling 53a87df39647... 100% ▕████████████████████████████████████████████████████████▏ 5.6 KB
pulling 56bb8bd477a5... 100% ▕████████████████████████████████████████████████████████▏   96 B
pulling c7091aa45e9b... 100% ▕████████████████████████████████████████████████████████▏  562 B
verifying sha256 digest
writing manifest
success
>>> who are you?
I'm an artificial intelligence model known as Llama. Llama stands for "Large Language Model Meta AI."

엄청 느리다 llama3.3으로 받았던 것이 304?가 아닌 70b였나? GPU를 거의 안쓴다??

 

다시 검색

https://ollama.com/library/llama3

 

llama3

Meta Llama 3: The most capable openly available LLM to date

ollama.com

 

CLI

Open the terminal and run ollama run llama3

API

Example using curl:

curl -X POST http://localhost:11434/api/generate -d '{
  "model": "llama3",
  "prompt":"Why is the sky blue?"
 }'

API documentation

Model variants

Instruct is fine-tuned for chat/dialogue use cases.

Example: ollama run llama3 ollama run llama3:70b

Pre-trained is the base model.

Example: ollama run llama3:text ollama run llama3:70b-text

 

'IT > AI.ML' 카테고리의 다른 글

[AI] NLP 용어 정리  (0) 2025.01.24
[AI] Llama 파인튜닝 재도전  (0) 2025.01.23
[AI] Llama 버전 비교  (0) 2025.01.19
[AI] Ollama 설치 @Window11  (0) 2025.01.13
[AI] TensorFlow 설정 @CentOS7  (0) 2022.08.09