Huggingface trl
Using Hugging Face TRL library for building custom trainers for Preference Optimization methods like DPO, SimPO, etc.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill huggingface-trlAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.1 KB, 240 tokens by cl100k_base, as published. Nobody here has run it
Hugging Face TRL (Transformer Reinforcement Learning)
TRL is a library by Hugging Face that provides tools to train language models using Reinforcement Learning and Preference Optimization (like PPO, DPO, etc.).
Custom Trainers
To implement custom loss functions like SimPO, you can subclass the DPOTrainer and override its specific methods (like dpo_loss or in this case, simpo_loss).
from trl import DPOTrainer
import torch
import torch.nn.functional as F
class CustomTrainer(DPOTrainer):
def custom_loss(self, policy_chosen_logps, policy_rejected_logps):
pi_logratios = policy_chosen_logps - policy_rejected_logps
logits = pi_logratios - self.margin
losses = -F.logsigmoid(self.beta * logits)
return losses
Setup & Dependencies
Commonly requires transformers, torch, trl, and accelerate.
Make sure you have the matching versions as defined in the project's requirement file (e.g. environment.yml or requirements.txt).
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.