Views
No views yet
1# LoRA configuration
2peft_config = LoraConfig(
3 r=16,
4 lora_alpha=16,
5 lora_dropout=0.05,
6 bias="none",
7 task_type="CAUSAL_LM",
8 target_modules=['k_proj', 'gate_proj', 'v_proj', 'up_proj', 'q_proj', 'o_proj', 'down_proj']
9)
10
11# Model to fine-tune
12model = AutoModelForCausalLM.from_pretrained(
13 model_name,
14 torch_dtype=torch.float16,
15 load_in_4bit=True
16)
17model.config.use_cache = False
18
19
20
21# Training arguments
22training_args = TrainingArguments(
23 per_device_train_batch_size=4,
24 gradient_accumulation_steps=4,
25 gradient_checkpointing=True,
26 learning_rate=5e-5,
27 lr_scheduler_type="cosine",
28 max_steps=120,
29 save_strategy="no",
30 logging_steps=1,
31 output_dir=new_model,
32 optim="paged_adamw_32bit",
33 warmup_steps=50,
34 bf16=True,
35 report_to="wandb",
36)
37
38# Create DPO trainer
39dpo_trainer = DPOTrainer(
40 model,
41 args=training_args,
42 train_dataset=dataset,
43 tokenizer=tokenizer,
44 peft_config=peft_config,
45 beta=0.1,
46 max_prompt_length=1024,
47 max_length=1536,
48)
49
50# Fine-tune model with DPO
51dpo_trainer.train()| Metric | Value |
|---|---|
| Avg. | 76.00 |
| AI2 Reasoning Challenge (25-Shot) | 74.06 |
| HellaSwag (10-Shot) | 88.97 |
| MMLU (5-Shot) | 64.41 |
| TruthfulQA (0-shot) | 76.19 |
| Winogrande (5-shot) | 84.29 |
| GSM8k (5-shot) | 68.08 |