pytorch-preference-optimization

pytorch-preference-optimization is a skill for Claude Code, Codex from cxcscmu/SkillLearnBench. It costs 29 tokens per session (297 once invoked), scanned A, original, MIT.

PyTorch code patterns for calculating preference-training losses such as DPO and SimPO for language models.

In plain words
What is it for?
Use it when implementing or testing preference-optimization loss functions in PyTorch.
Why use it?
It provides the tensor operations needed to compare preferred and rejected answers and produce training signals.

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/pytorch-preference-optimization
Any agent
npx skills add cxcscmu/SkillLearnBench --skill pytorch-preference-optimization
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 pytorch-preference-optimization

README.md
[![agentmods](https://agentmods.dev/badge/skills/cxcscmu/skilllearnbench/pytorch-preference-optimization.svg)](https://agentmods.dev/skills/cxcscmu/skilllearnbench/pytorch-preference-optimization)
Your own site
<a href="https://agentmods.dev/skills/cxcscmu/skilllearnbench/pytorch-preference-optimization"><img src="https://agentmods.dev/badge/skills/cxcscmu/skilllearnbench/pytorch-preference-optimization.svg" alt="Measured on agentmods" height="20"></a>
Per session 29 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 297 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.1 $0.00029 $0.00297
Opus 5 $0.00015 $0.00148
Sonnet 5 $0.00006 $0.00059
Haiku 4.5 $0.00003 $0.00030

Measured 2d ago against content hash 78924966a723, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

pytorch-preference-optimization 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 2d ago.

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-claude-opus-4-6/nlp-paper-reproduction/pytorch-preference-optimization/SKILL.md · 37 lines

What it actually says

PyTorch Preference Optimization Patterns

Key Functions

  • torch.nn.functional.logsigmoid(x): Numerically stable log-sigmoid, used in Bradley-Terry losses.
  • torch.relu(x): Used for hinge-loss variants.
  • torch.FloatTensor: Common type for log probability tensors.

Implementation Pattern

import torch
import torch.nn.functional as F

def preference_loss(chosen_logps, rejected_logps, beta, gamma, label_smoothing=0.0, loss_type="sigmoid"):
    logits = beta * (chosen_logps - rejected_logps) - 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)

    chosen_rewards = beta * chosen_logps.detach()
    rejected_rewards = beta * rejected_logps.detach()

    return losses, chosen_rewards, rejected_rewards

Environment Setup

  • trl==0.9.6 is needed for compatibility with older SimPO codebases (CPOTrainer import).
  • PyTorch CPU is sufficient for loss computation testing.
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. 2d ago First seen · 37 lines · 29 tokens per session scan A 78924966a723

Subscribe to this mod's changes

pytorch-preference-optimization is a skill published in the GitHub repository cxcscmu/SkillLearnBench (83 stars, last pushed 1mo ago), licensed MIT. It adds 29 tokens to every session and 297 once invoked, about $0.0001 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