8 位元訓練準備
你想開始進行 RLHF 微調,但一直遇到記憶體不足錯誤。為了解決這個問題,你決定切換到 8 位元精度,以提升微調效率,並利用 Hugging Face 的 peft 函式庫。
以下模組已預先匯入:
- 來自
transformers的AutoModelForCausalLM - 來自
peft的prepare_model_for_int8_training - 來自
trl的AutoModelForCausalLMWithValueHead
本練習屬於課程
Reinforcement Learning from Human Feedback(RLHF)
練習說明
- 載入預訓練模型,並確保包含 8 位元精度的參數。
- 使用
prepare_model_for_int8_training函式,讓模型可進行基於 LoRA 的微調。 - 載入包含 value head 的模型,以進行
PPO訓練。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
model_name = "gpt2"
# Load the model in 8-bit precision
pretrained_model = AutoModelForCausalLM.from_pretrained(
model_name,
____=True
)
# Prepare the model for fine-tuning
pretrained_model_8bit = ____(pretrained_model)
# Load the model with a value head
model = ____.from_pretrained(pretrained_model_8bit)