用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill simpo-loss-function命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | simpo-loss-function |
| description | Implement SimPO loss with length-normalized rewards and target margin. |
SimPO (Simple Preference Optimization) implements a preference optimization objective that uses length-normalized average log probability as an implicit reward, with a target reward margin component.
L_SimPO(πθ) = -E_(x,yw,yl)~D log σ(β/|yw| log πθ(yw|x) - β/|yl| log πθ(yl|x) - γ)
r_SimPO(x, y) = β/|y| * log πθ(y|x)p(yw ≻ yl | x) = σ(r(x, yw) - r(x, yl) - γ)# log_probs shape: (batch_size, seq_len)
# Sum across sequence dimension to get total log probability
log_prob_sum = log_probs.sum(dim=1) # (batch_size,)
# Divide by sequence length for normalization
seq_lengths = (input_ids != pad_token_id).sum(dim=1) # (batch_size,)
avg_log_prob = log_prob_sum / seq_lengths.float() # (batch_size,)
# Batch structure: pairs of (winning, losing) responses
batch_size = avg_log_probs.shape[0]
winning_rewards = avg_log_probs[:batch_size//2]
losing_rewards = avg_log_probs[batch_size//2:]
# Reward difference with margin
reward_diff = beta * winning_rewards - beta * losing_rewards - gamma
# Bradley-Terry with sigmoid
import torch.nn.functional as F
sigmoid_term = torch.sigmoid(reward_diff)
loss = -torch.log(sigmoid_term).mean()