evo-simpo-code-reproduction
SkillProductivityImplements the SimPO (Simple Preference Optimization) loss function and handles environment setup, execution, and result saving for code reproduction tasks.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the evo-simpo-code-reproduction skill
What this skill tells your AI
The instructions your AI receives, as published by openlair/openskill in tasks-evolved/simpo-code-reproduction/environment/skills/evo-simpo-code-reproduction/SKILL.md and read by ahel’s review.
Overview
Complete skill for reproducing the SimPO (Simple Preference Optimization) loss function from the paper by Meng et al. (2024). Handles implementation of the simpo_loss method, environment setup, unit test execution, and saving results.
Key Concepts (from the paper)
SimPO Loss Formula
L_SimPO = -log(sigmoid(beta/|y_w| * sum(log π(y_w|x)) - beta/|y_l| * sum(log π(y_l|x)) - gamma))
Critical Implementation Details
-
Inputs are pre-normalized:
policy_chosen_logpsandpolicy_rejected_logpsare already length-averaged (mean log probs per token) before enteringsimpo_loss. The averaging happens inget_batch_logpswithaverage_log_prob=True. -
Margin factoring: The code computes
logits = pi_logratios - gamma/beta, then appliesbeta * logitsinside logsigmoid. This is algebraically equivalent tobeta * pi_logratios - gamma. -
gamma computation: In the SimPO trainer,
gamma = self.gamma_beta_ratio * self.beta(wheregamma_beta_ratiodefaults to ~0.25, giving gamma≈0.5 for beta=2.0). The paper recommends gamma/beta ≈ 0.5. -
Loss types:
- Sigmoid (default):
losses = -F.logsigmoid(beta * logits) * (1 - label_smoothing) - F.logsigmoid(-beta * logits) * label_smoothing - Hinge:
losses = torch.relu(1 - beta * logits)
- Sigmoid (default):
-
Rewards are detached:
chosen_rewards = beta * chosen_logps.detach(),rejected_rewards = beta * rejected_logps.detach() -
Return shape: Per-example losses of shape
(batch_size,)— reduction happens upstream.
Sigmoid Loss with Label Smoothing (label_smoothing=0 by default)
When label_smoothing=0, the second term vanishes, leaving pure SimPO loss:
losses = -F.logsigmoid(self.beta * logits)
When label_smoothing > 0:
losses = (
-F.logsigmoid(self.beta * logits) * (1 - self.label_smoothing)
- F.logsigmoid(-self.beta * logits) * self.label_smoothing
)
Environment Setup
- Python 3.10+
pip install torch transformers 'trl==0.8.6' datasets accelerate peft numpy- trl>=0.29 removed CPOTrainer; use trl==0.8.6 for compatibility with the SimPO codebase
Usage
import sys
sys.path.insert(0, '/app/environment/skills/evo-simpo-code-reproduction/scripts')
from simpo_loss_impl import implement_simpo_loss
from run_and_save import setup_environment, run_unit_test, log_python_info
# Step 1: Setup environment
setup_environment()
# Step 2: Implement the loss function
implement_simpo_loss('/root/SimPO/scripts/simpo_trainer.py')
# Step 3: Run unit test and save results
run_unit_test()
# Step 4: Log python info
log_python_info()
Common Pitfalls
- Sum vs Mean: SimPO uses MEAN log probs (already done upstream), not sum. Don't re-normalize.
- gamma/beta factoring: The margin is
gamma/betasubtracted from logratios, then multiplied by beta. Don't subtract gamma directly before beta scaling. - Detach rewards: Always
.detach()rewards to prevent memory leaks. - Hinge loss formula: Uses
torch.relu(1 - beta * logits), nottorch.relu(-logits). - Device handling: Some implementations move tensors to accelerator device; in unit tests without accelerator, this may need to be handled gracefully.
Signals
- GitHub stars
- 89
- Forks
- 4
- Last commit
- Sep 2026
Advanced
- Catalog kind
- skill
- Gateway key
evo-simpo-code-reproduction- Source
- github.com/openlair/openskill