simpo-loss-function
Implement SimPO loss with length-normalized rewards and target margin.
Skill by cxcscmu
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/cxcscmu-simpo-loss-function
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: research
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/simpo-loss-function
What's inside
- Skill name
simpo-loss-function- Description
- Implement SimPO loss with length-normalized rewards and target margin.
- License
- MIT
- Instructions
- 79 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# SimPO Loss Function Implementation ## Overview 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. ## Key Formula ``` L_SimPO(πθ) = -E_(x,yw,yl)~D log σ(β/|yw| log πθ(yw|x) - β/|yl| log πθ(yl|x) - γ) ``` ## Components ### 1. Length-Normalized Reward - **Formula**: `r_SimPO(x, y) = β/|y| * log πθ(y|x)` - **Purpose**: Average log probability per token, prevents length bias - **Why**: Aligns training with generation metric (which uses average log likelihood for beam search) ### 2. Bradley-Terry Objective - **Formula**: `p(yw ≻ yl | x) = σ(r(x, yw) - r(x, yl) - γ)` - **Purpose**: Probabilistic ranking between winning and losing responses - **Function**: σ is sigmoid function ### 3. Target Reward Margin (γ) - **Purpose**: Ensure reward difference exceeds a target threshold - **Effect**: Improves generalization by enforcing margin between classes - **Typical range**: 0.5 to 1.5 ## Implementation Details ### Computing Log Probabilities ```python # 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,) ``` ### Computing Reward Differences ```python # 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 ``` ### Computing Loss ```python # Bradley-Terry with sigmoid import torch.nn.functional as F sigmoid_term = torch.sigmoid(reward_diff) loss = -torch.log(sigmoid_term).mean() ``` ## Common Pitfalls 1. **Not using length normalization**: Creates bias toward longer sequences 2. **Wrong batch structure**: Ensure paired winning/losing responses 3. **Missing average in log probabilities**: Use sum/length, not just sum 4. **Gradient flow**: Ensure no detach() breaks gradients to model ## Hyperparameters - **β**: Temperature parameter, typically 2.0-2.5 - **γ**: Target margin, typically 0.3-1.6, depends on setting - **learning_rate**: Usually small, 1e-6 to 5e-7 ## References - SimPO Paper: Section 2.3 "The SimPO Objective" - Length normalization: Equation (3) in paper - Gradient analysis: Appendix F
From cxcscmu/SkillLearnBench, MIT.
More from cxcscmu/SkillLearnBench
- 0.523score
skill-creator
cxcscmu
Create modular skill documents (SKILL.md files) for Claude Code.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
package-lock-parsing
cxcscmu
Parse and extract package information from npm package-lock.json files to identify dependencies and their installed versions.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
mandarin-rhyming-guide
cxcscmu
Master modern Mandarin pinyin finals and tone systems to create accurate rhymes for classical poetry following contemporary pronunciation standards.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
trivy-vulnerability-scanning
cxcscmu
Use Trivy vulnerability scanner in offline mode to detect CVEs in npm dependencies and generate structured JSON reports.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
cvss-score-extraction
cxcscmu
Extract and handle CVSS scores from multiple vulnerability data sources (NVD, GHSA, RedHat) with proper fallback priority.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
github-metrics-processing
cxcscmu
Process GitHub API data to calculate PR/issue metrics including merge time averages, author rankings, and bug categorization.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
security-audit-csv-reporting
cxcscmu
Generate structured CSV security audit reports from vulnerability data with proper filtering, formatting, and field mapping.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
classical-poetry-peace-theme
cxcscmu
Compose classical Chinese poetry on peace themes using authentic imagery, perspective shifts, and the voice of ordinary people experiencing war's aftermath.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
seven-char-regulated-verse
cxcscmu
Master the structure, tonal patterns, and rhyming requirements of classical seven-character regulated verse (七言律诗) in Chinese poetry.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
jackson-deserialization-validation
cxcscmu
Securing Jackson JSON deserialization by validating input before processing and preventing unknown properties.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
python-pillow-graphics
cxcscmu
Create technical graphics, diagrams, and posters using Python Pillow library with precise color control and typography.
SkillDFreshness: D★ 91Claude Code +9 - 0.512score
git-patch-workflow
cxcscmu
Creating, managing, and applying unified diff patches with Git for source code modifications.
SkillDFreshness: D★ 91Claude Code +9
Signals
- Stars
- 91
- Forks
- 7
- Open issues
- 6
- Last commit (this folder)
- Apr 24, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/cxcscmu/SkillLearnBench
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from cxcscmu
- 0.523score
skill-creator
cxcscmu
Create modular skill documents (SKILL.md files) for Claude Code.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
seven-char-regulated-verse
cxcscmu
Master the structure, tonal patterns, and rhyming requirements of classical seven-character regulated verse (七言律诗) in Chinese poetry.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
security-audit-csv-reporting
cxcscmu
Generate structured CSV security audit reports from vulnerability data with proper filtering, formatting, and field mapping.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
classical-poetry-peace-theme
cxcscmu
Compose classical Chinese poetry on peace themes using authentic imagery, perspective shifts, and the voice of ordinary people experiencing war's aftermath.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
cvss-score-extraction
cxcscmu
Extract and handle CVSS scores from multiple vulnerability data sources (NVD, GHSA, RedHat) with proper fallback priority.
SkillDFreshness: D★ 91Claude Code +9 - 0.515score
mandarin-rhyming-guide
cxcscmu
Master modern Mandarin pinyin finals and tone systems to create accurate rhymes for classical poetry following contemporary pronunciation standards.
SkillDFreshness: D★ 91Claude Code +9
Cite this page
simpo-loss-function skill. Agent Mart. https://agentmart.dev/skills/cxcscmu-simpo-loss-function (last updated 2026-10-24)