simpo-loss-implementation

simpo-loss-implementation is a skill for Claude Code, Codex from cxcscmu/SkillLearnBench. It costs 34 tokens per session (566 once invoked), scanned A, original, MIT.

A PyTorch implementation guide for SimPO, a method that trains a language model to prefer selected answers over rejected ones. It uses length-adjusted model probabilities and a target reward margin.

In plain words
What is it for?
Use it to implement the SimPO loss in PyTorch with chosen and rejected response probabilities, scaling, margins, label smoothing, and loss-type settings.
Why use it?
It gives the mathematical definition and expected inputs needed to implement this preference-training loss. This helps avoid mistakes in reward scaling and comparison between answers.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/cxcscmu/skilllearnbench/simpo-loss-implementation
Any agent
npx skills add cxcscmu/SkillLearnBench --skill simpo-loss-implementation
Clone the repo
git clone --depth 1 https://github.com/cxcscmu/SkillLearnBench

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for simpo-loss-implementation

README.md
[![agentmods](https://agentmods.dev/badge/skills/cxcscmu/skilllearnbench/simpo-loss-implementation.svg)](https://agentmods.dev/skills/cxcscmu/skilllearnbench/simpo-loss-implementation)
Your own site
<a href="https://agentmods.dev/skills/cxcscmu/skilllearnbench/simpo-loss-implementation"><img src="https://agentmods.dev/badge/skills/cxcscmu/skilllearnbench/simpo-loss-implementation.svg" alt="Measured on agentmods" height="20"></a>
Per session 34 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 566 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00034 $0.00566
Opus 5 $0.00017 $0.00283
Sonnet 5 $0.00007 $0.00113
Haiku 4.5 $0.00003 $0.00057

Measured yesterday against content hash b4e7e2ed4cc0, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

simpo-loss-implementation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/b1-one-shot-gemini-3-flash-preview/nlp-paper-reproduction/simpo-loss-implementation/SKILL.md · 65 lines

How it starts

The opening of the file, as written. The whole thing — 65 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SimPO Loss Implementation

SimPO is a reference-free preference optimization algorithm that uses length-normalized log probabilities as rewards and incorporates a target reward margin.

Mathematical Formulation

The SimPO loss is defined as: $$L_{SimPO}(\pi_\theta) = -\mathbb{E}{(x, y_w, y_l) \sim \mathcal{D}} \left[ \log \sigma \left( \beta r\theta(x, y_w) - \beta r_\theta(x, y_l) - \gamma \right) \right]$$

Where:

  • $r_\theta(x, y) = \frac{1}{|y|} \log \pi_\theta(y|x)$ is the length-normalized log probability.
  • $\beta$ is a scaling factor.
  • $\gamma$ is the target reward margin.

PyTorch Implementation

import torch
import torch.nn.functional as F

def simpo_loss(
    policy_chosen_logps: torch.FloatTensor,
    policy_rejected_logps: torch.FloatTensor,
    beta: float,
    gamma: float,
    label_smoothing: float = 0.0,
    loss_type: str = "sigmoid"
):
    """
    Args:
        policy_chosen_logps: Average log probabilities of the chosen responses. (batch_size,)
        policy_rejected_logps: Average log probabilities of the rejected responses. (batch_size,)
        beta: Scaling factor for rewards.
        gamma: Target reward margin.
        label_smoothing: Label smoothing factor.
        loss_type: Type of loss ("sigmoid" or "hinge").
    """
    # rewards are beta * average logps
    chosen_rewards = beta * policy_chosen_logps
    rejected_rewards = beta * policy_rejected_logps

    logits = chosen_rewards - rejected_rewards - gamma

    if loss_type == "sigmoid":
        losses = (
            -F.logsigmoid(logits) * (1 - label_smoothing)
            - F.logsigmoid(-logits) * label_smoothing
        )
    elif loss_type == "hinge":
        losses = torch.relu(1 - logits)
    else:
        raise ValueError(f"Unknown loss type: {loss_type}")

    return losses, chosen_rewards, rejected_rewards

Usage in Trainer

In a trainer class, ensure that policy_chosen_logps and policy_rejected_logps are already length-normalized (divided by the number of non-padded tokens).

Read the full file on GitHub · 65 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 65 lines · 34 tokens per session scan A b4e7e2ed4cc0

Subscribe to this mod's changes

simpo-loss-implementation is a skill published in the GitHub repository cxcscmu/SkillLearnBench (83 stars, last pushed 1mo ago), licensed MIT. It adds 34 tokens to every session and 566 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

trl

Reference for the TRL (Transformer Reinforcement Learning) library codebase. Use proactively before reading or editing any file under trl/ so you have the intended contracts and invariants in mind, not just what the current code says. Covers trainer hierarchy (SFT, DPO, GRPO, KTO), shared utility functions…

benchflow-ai/skillsbench · 100 tokens

Pré-processamento de áudio para transcrição Whisper

Executa o pipeline de redução de ruído e normalização de volume em arquivos de áudio usando Python (bibliotecas como Silero, noisereduce, numpy e scipy) para otimizar a entrada para modelos de reconhecimento de voz como o Whisper.

ECNU-ICALK/AutoSkill · 61 tokens

pytorch-patterns

PyTorch deep learning patterns and best practices for building robust, efficient, and reproducible training pipelines, model architectures, and data loading.

affaan-m/ECC · 32 tokens

azure-mgmt-fabric-py

Azure Fabric Management SDK for Python. Use for managing Microsoft Fabric capacities and resources. Triggers: "azure-mgmt-fabric", "FabricMgmtClient", "Fabric capacity", "Microsoft Fabric", "Power BI capacity".

microsoft/skills · 51 tokens

data360-code-extension-generate

Develop and deploy Data Cloud Code Extensions using SF CLI plugin. Use this skill when creating custom Python transformations for Data Cloud, deploying code extensions, or testing data transformations. Supports init, run, scan, and deploy operations.

forcedotcom/sf-skills · 51 tokens

pcap-analysis

Guidance for analyzing network packet captures (PCAP files) and computing network statistics using Python, with tested utility functions.

benchflow-ai/skillsbench · 28 tokens