Editing
Reinforcement Learning from Human Feedback
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''DPO fine-tuning with TRL:''' <syntaxhighlight lang="python"> from datasets import load_dataset from transformers import AutoModelForCausalLM, AutoTokenizer from trl import DPOTrainer, DPOConfig # Load base model + tokenizer model_name = "meta-llama/Llama-3.2-1B-Instruct" model = AutoModelForCausalLM.from_pretrained(model_name) ref_model = AutoModelForCausalLM.from_pretrained(model_name) # Frozen reference tokenizer = AutoTokenizer.from_pretrained(model_name) # Preference dataset format: {prompt, chosen, rejected} # "chosen" = preferred response, "rejected" = less preferred dataset = load_dataset("trl-lib/ultrafeedback_binarized", split="train") # Dataset format: # {"prompt": "What is...", "chosen": "Great answer...", "rejected": "Bad answer..."} # DPO training config config = DPOConfig( beta=0.1, # KL penalty weight (higher = stay closer to reference) learning_rate=5e-7, per_device_train_batch_size=2, gradient_accumulation_steps=8, num_train_epochs=1, max_length=1024, max_prompt_length=512, output_dir="./dpo_output", ) trainer = DPOTrainer( model=model, ref_model=ref_model, # Reference model for KL constraint args=config, train_dataset=dataset, tokenizer=tokenizer, ) trainer.train() trainer.save_model("./aligned_model") </syntaxhighlight> ; RLHF variant comparison : '''Original RLHF (PPO)''' β Best-studied; used in ChatGPT, Claude 1; complex to implement : '''DPO''' β Simpler; no explicit reward model; now dominant in open-source : '''RLAIF''' β AI-generated feedback at scale; reduces human annotation cost : '''Constitutional AI''' β Rule-based self-critique; Anthropic's approach for safety : '''GRPO (Group Relative Policy Optimization)''' β DeepSeek's variant; no value model needed : '''Best-of-N''' β Simple baseline; generate N samples, pick highest reward model score </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information