示例默认使用 decapoda-research/llama-7b-hf,需自行准备 LLaMA 权重;全权重微调需额外 pip install deepspeed;PPO 阶段需自行填入已微调模型、奖励模型和 tokenizer 路径,并依赖 wandb 记录
pip install -r requirements.txt 硬件要求按 README 说明
README 未说明显存要求;示例命令均以 8 卡并行(nproc_per_node 8)运行,全权重微调需 DeepSpeed offload,未列出支持的 GPU 厂商或型号
用 PPO 加 LoRA 微调 LLaMA 的完整三阶段训练脚本,从 SFT 到奖励模型再到 RL 调优
用 PPO 强化学习和 LoRA 低秩适配微调 LLaMA 模型,做 RLHF 对齐训练,显存占用低,适合在单卡上跑通大模型偏好优化流程。
核心能力
- 用 TRL 实现 PPO 强化学习微调
- 用 PEFT 的 LoRA 做参数高效微调
- 提供 SFT、奖励模型、PPO 三阶段脚本
- 支持 DeepSpeed stage-3 全权重微调与 offload
- 采用 GPT-4-LLM 的指令跟随数据集
容易踩的坑
内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选共 0 条
还没有人点评。第一个说出真实体验的人最有价值。
- Implement PPO (Proximal Policy Optimization) with TRL (Transformer Reinforcement Learning)
- Implement LoRA (Low-Rank Adaption of Large Language Models) with PEFT (Parameter-Efficient Fine-Tuning)
- Collect instruction-following data from this repo GPT-4-LLM
Setup
Install dependencies
pip install -r requirements.txt
How to use?
- Step 1 - Supervised Fine-tuning
torchrun --nnodes 1 --nproc_per_node 8 supervised_finetuning.py \
--base_model 'decapoda-research/llama-7b-hf' \
--dataset_name './data/alpaca_gpt4_data.json' \
--streaming \
--lr_scheduler_type 'cosine' \
--learning_rate 1e-5 \
--max_steps 4000 \
--output_dir './checkpoints/supervised_llama/'
or full weight supervised fine-tuning with DeepSpeed stage-3 (offload)
pip install deepspeed
torchrun --nnodes 1 --nproc_per_node 8 supervised_finetuning_full_weight.py \
--base_model 'decapoda-research/llama-7b-hf' \
--dataset_name './data/alpaca_gpt4_data.json' \
--streaming \
--lr_scheduler_type 'cosine' \
--learning_rate 2e-5 \
--weight_decay 0. \
--warmup_ratio 0.03 \
--seq_length 1024 \
--batch_size 4 \
--gradient_accumulation_steps 8 \
--eval_freq 2000 \
--save_freq 2000 \
--max_steps 4000 \
--save_total_limit 1 \
--deepspeed "./configs/default_offload_opt_param.json" \
--run_name 'llama-7b-sft-full-weight' \
--output_dir './checkpoints/supervised_llama_full_weight/'
- Step 2 - Training Reward Model
torchrun --nnodes 1 --nproc_per_node 8 training_reward_model.py \
--model_name 'decapoda-research/llama-7b-hf' \
--dataset_name './data/comparison_data.json' \
--output_dir './checkpoints/training_reward_model/'
- Step 3 - Tuning LM with PPO
accelerate launch --multi_gpu --num_machines 1 --num_processes 8 \
tuning_lm_with_rl.py \
--log_with wandb \
--model_name <LLAMA_FINETUNED_MODEL> \
--reward_model_name <LLAMA_RM_MODEL> \
--adafactor False \
--tokenizer_name <LLAMA_TOKENIZER> \
--save_freq 100 \
--output_max_length 128 \
--batch_size 8 \
--gradient_accumulation_steps 8 \
--batched_gen True \
--ppo_epochs 4 \
--learning_rate 1.4e-5 \
--early_stopping True \
--output_dir './checkpoints/tuning_llama_rl/'