simpo-loss
/simpo-loss
Implementuje funkcję straty SimPO (Simple Preference Optimization) z artykułu z NeurIPS 2024, w tym nagrody znormalizowane długością i marginesy nagrody.
- Autor
- cxcscmu ↗
- Repozytorium
- SkillLearnBench ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 02.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 02.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Implementuje funkcję straty SimPO (Simple Preference Optimization) z artykułu z NeurIPS 2024, w tym nagrody znormalizowane długością i marginesy nagrody.
Oryginalny opis (EN)
Implement the SimPO (Simple Preference Optimization) loss function from the NeurIPS 2024 paper. Use this skill whenever implementing SimPO, preference optimization losses, or DPO variants that use length-normalized rewards and reward margins.
Jak działa
- Core Formula (Eq. 6 from the paper)
- Key Design Decisions
- Implementation Pattern
- Config Parameters (SimPOConfig)
- Returns
Podgląd SKILL.md
---
name: simpo-loss
description: Implement the SimPO (Simple Preference Optimization) loss function from the NeurIPS 2024 paper. Use this skill whenever implementing SimPO, preference optimization losses, or DPO variants that use length-normalized rewards and reward margins.
---
# SimPO Loss Implementation
## Core Formula (Eq. 6 from the paper)
The SimPO objective:
```
L_SimPO(πθ) = -E log σ( (β/|yw|) log πθ(yw|x) - (β/|yl|) log πθ(yl|x) - γ )
```
Where:
- `β` (beta): scaling factor for reward difference (default: 2.0)
- `γ` (gamma): target reward margin, computed as `gamma_beta_ratio * beta` (default ratio: 0.25)
- `|yw|`, `|yl|`: lengths of winning/losing responses
- `σ`: sigmoid function
## Key Design Decisions
1. **Length-normalized reward**: `r(x,y) = (β/|y|) * log πθ(y|x)` — the average log probability scaled by β
2. **Target reward margin γ**: ensures winning response reward exceeds losing by at least γ
3. **No reference model needed** — unlike DPO
## Implementation Pattern
Given `policy_chosen_logps` and `policy_rejected_logps` (already length-normalized average log probs):
```python
pi_logratios = policy_chosen_logps - policy_rejected_logps
gamma = self.gamma_beta_ratio * self.beta
logits = pi_logratios * self.beta - gamma
# Sigmoid loss (with optional label smoothing)
losses = (
-F.logsigmoid(logits) * (1 - self.label_smoothing)
- F.logsigmoid(-logits) * self.label_smoothing
)
# Hinge loss variant
# losses = torch.relu(1 - logits)
chosen_rewards = self.beta * policy_chosen_logps.detach()
rejected_rewards = self.beta * policy_rejected_logps.detach()
```
## Config Parameters (SimPOConfig)
| Parameter | Default | Description |
|-----------|---------|-------------|
| beta | 2.0 | Reward scaling factor |
| gamma_beta_ratio | 0.25 | γ/β ratio |
| label_smoothing | 0.0 | Label smoothing factor |
| loss_type | "sigmoid" | "sigmoid" or "hinge" |
| sft_weight | 0.0 | Optional SFT loss weight |
## Returns
Tuple of `(losses, chosen_rewards, rejected_rewards)` — all tensors of shape `(batch_size,)`.
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · cxcscmu/SkillLearnBench | 100 | MIT |
| cxcscmu/SkillLearnBench | 100 | MIT |
| cxcscmu/SkillLearnBench | 100 | MIT |
Migawka bazy z 28.10.2026 · wersja paczki 366ecb71b760 (skrót SHA-256 całej paczki)
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100simpo-loss-implementation
Implementuje funkcję straty SimPO dla modeli językowych dopasowanych do preferencji: cele treningowe, nagrody znormalizowane długością i przekład wzorów z artykułu na kod PyTorch. - 95simpo-loss-implementation
Pokazuje, jak zaimplementować funkcję straty SimPO (Simple Preference Optimization) według publikacji w metodzie simpo_loss klasy SimPOTrainer. - 95simpo-training
Opisuje i wspiera trening SimPO do dopasowania modeli językowych, czyli metodę bez modelu referencyjnego, alternatywną wobec DPO. - 100preference-optimization
Dopasowuje dostrojony model do danych preferencji metodami DPO, ORPO, KTO lub SimPO i pomaga dobrać metodę oraz hiperparametry albo debugować przebieg DPO. - 100add-reward
Prowadzi przez dodanie nowej funkcji nagrody do AReaL. - 100add-reward
Prowadzi przez dodanie nowej funkcji nagrody do AReaL.