상세 컨텐츠

본문 제목

hugging face fine tuning with LoRa

카테고리 없음

by 리치윈드 - windFlex 2023. 11. 13. 17:28

본문

반응형

 

 

!pip install transformers datasets evaluate accelerate -q

 

> accelerate 는 병렬처리 등을 위한 

 

train_dataloader = DataLoader(train_tensor, shuffle=True, batch_size=8)
eval_dataloader = DataLoader(eval_tensor, batch_size=8)
model = AutoModelForSequenceClassification.from_pretrained("bert-base-cased", num_labels=5)
optimizer = AdamW(model.parameters(), lr=5e-5)

 

 

기존에는 HuggingFace에서 Tokenizer와 Classifier를 각각 따로 불러왔어야만 했다. 

그러나, 최근에는 AutoOOOO 등의 Warpper Class가 등장했는데, 이는 hugging Face의 모델명만 입력하면 자동으로 HuggingFace에 등록된 모델을 로딩하는 클래스들이다.  대표적으로, `AutoTokenizer` , `AutoModelForSequenceClassification` 등이 있다. 각각 Tokenizer와 Model에 대한 Auto Class이다. 

 

참조 : huggingface

 

기존에 pretraining matrix W는 고정하고, 여기에 새로운 변화하는 dW만 (Rank가 현저히 작은) 를 더해서.

 

 

 

 

 

 

 

 

[참조] https://medium.com/@alexmriggio/lora-low-rank-adaptation-from-scratch-code-and-theory-f31509106650

 

LoRA: Low-Rank Adaptation from Scratch — Code and Theory

Transformer models can have a lot of parameters which can make fine-tuning them an expensive and time-consuming endeavor that is sometimes…

medium.com

 

 

 

 

 

 

 

 

 

 

 

 

 

반응형

댓글 영역