Axolotl 通用微调
在 Clore.ai 上使用 Axolotl 进行 YAML 驱动的 LLM 微调——LoRA、QLoRA、DPO、多 GPU
最后更新于
这有帮助吗?
这有帮助吗?
# 克隆并安装
git clone https://github.com/OpenAccess-AI-Collective/axolotl.git
cd axolotl
pip install packaging ninja
pip install -e '.[flash-attn,deepspeed]'docker run --gpus all -it --rm \
-v /workspace:/workspace \
winglian/axolotl:main-latestbase_model: meta-llama/Meta-Llama-3.1-8B-Instruct
model_type: LlamaForCausalLM
tokenizer_type: AutoTokenizer
load_in_4bit: true
adapter: qlora
lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_linear: true
datasets:
- path: yahma/alpaca-cleaned
type: alpaca
sequence_len: 2048
sample_packing: true
pad_to_sequence_len: true
wandb_project: axolotl-clore
wandb_name: llama3-qlora
output_dir: /workspace/axolotl-output
gradient_accumulation_steps: 4
micro_batch_size: 2
num_epochs: 1
learning_rate: 2e-4
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
warmup_steps: 10
bf16: auto
flash_attention: true
gradient_checkpointing: true
logging_steps: 10
save_strategy: steps
save_steps: 500
eval_steps: 500
evals_per_epoch:
val_set_size: 0.02# 单 GPU
accelerate launch -m axolotl.cli.train config.yml
# 多 GPU(所有可用 GPU)
accelerate launch --multi_gpu -m axolotl.cli.train config.yml# Alpaca 风格(instruction / input / output)
datasets:
- path: yahma/alpaca-cleaned
type: alpaca
# ShareGPT 多轮对话
datasets:
- path: anon8231489123/ShareGPT_Vicuna_unfiltered
type: sharegpt
conversation: chatml
# 聊天模板(从分词器自动检测)
datasets:
- path: HuggingFaceH4/ultrachat_200k
type: chat_template
field_messages: messages
message_field_role: role
message_field_content: content
# 本地 JSONL 文件
datasets:
- path: /workspace/data/my_dataset.jsonl
type: alpaca
ds_type: json{
"bf16": { "enabled": true },
"zero_optimization": {
"stage": 2,
"offload_optimizer": { "device": "cpu" },
"allgather_partitions": true,
"allgather_bucket_size": 5e8,
"reduce_scatter": true,
"reduce_bucket_size": 5e8,
"overlap_comm": true,
"contiguous_gradients": true
},
"train_micro_batch_size_per_gpu": "auto",
"gradient_accumulation_steps": "auto",
"gradient_clipping": 1.0
}deepspeed: deepspeed_zero2.jsonaccelerate launch --num_processes 4 -m axolotl.cli.train config.ymlbase_model: meta-llama/Meta-Llama-3.1-8B-Instruct
rl: dpo
# 或: rl: orpo
datasets:
- path: argilla/ultrafeedback-binarized-preferences
type: chat_template.default
field_messages: chosen
field_chosen: chosen
field_rejected: rejected
dpo_beta: 0.1base_model: meta-llama/Meta-Llama-3.1-8B-Instruct
# 无适配器,无量化
adapter:
load_in_4bit: false
load_in_8bit: false
learning_rate: 5e-6
micro_batch_size: 1
gradient_accumulation_steps: 8
gradient_checkpointing: true
flash_attention: true
bf16: auto
deepspeed: deepspeed_zero3.json # 8B+ 完整微调所需# 启动交互式推理
accelerate launch -m axolotl.cli.inference config.yml \
--lora_model_dir /workspace/axolotl-outputaccelerate launch -m axolotl.cli.merge_lora config.yml \
--lora_model_dir /workspace/axolotl-output \
--output_dir /workspace/merged-modelpython -m axolotl.cli.preprocess config.yml