[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KH4T74A8WR6MM7X1FXB1BK":3,"skill-same:01M6KH4T74A8WR6MM7X1FXB1BK":58},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":31,"linkOnly":32,"markdownContent":33,"markdownBody":34,"frontMatter":35,"refName":36,"commitSha":37,"skillDirectory":38,"forksCount":39,"repositoryHtmlUrl":40,"repositoryHomepageUrl":41,"ownerHtmlUrl":42,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":43,"install":44,"resources":57},"01M6KH4T74A8WR6MM7X1FXB1BK","simpo-loss-implementation",null,"How to implement the SimPO (Simple Preference Optimization) loss function based on the SimPO paper. Use this when implementing the simpo_loss method in SimPOTrainer.","cxcscmu\u002FSkillLearnBench","cxcscmu","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F142838272?v=4","01M6KCQDFQWPDSN0MKZY96MSQP","01M6KCQDM7G70TKJ28NTSQC0RZ",93,"MIT","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fb3-teacher-feedback-claude-opus-4-6\u002Fnlp-paper-reproduction\u002Frun3_simpo-loss-implementation\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30],"implementation","simpo","simpo loss","simpo loss implementation","implement","Optimization","how","use","simple","paper","how to","Preference Optimization","implementing","2026-11-10 10:12:30",false,"---\nname: simpo-loss-implementation\ndescription: How to implement the SimPO (Simple Preference Optimization) loss function based on the SimPO paper. Use this when implementing the simpo_loss method in SimPOTrainer.\n---\n\n## SimPO Loss Function\n\nSimPO (Simple Preference Optimization) is a reference-free reward formulation for preference optimization that uses the average log probability of a sequence as the implicit reward.\n\n### Key Formula\n\nThe SimPO loss is defined as:\n\n```\nL_SimPO = -log(sigmoid(β\u002F|y_w| * log π_θ(y_w|x) - β\u002F|y_l| * log π_θ(y_l|x) - γ))\n```\n\nWhere:\n- `β` (beta) is a scaling hyperparameter\n- `γ` (gamma) is a target reward margin (the paper calls this the margin term)\n- `y_w` is the winning\u002Fchosen response\n- `y_l` is the losing\u002Frejected response\n- `|y_w|` and `|y_l|` are the lengths (number of tokens) of the responses\n- `π_θ(y|x)` is the policy model's probability of generating y given x\n- The average log probability `1\u002F|y| * log π_θ(y|x)` serves as the implicit reward\n\n### Implementation Details\n\n```python\ndef simpo_loss(\n    self,\n    policy_chosen_logps: torch.FloatTensor,\n    policy_rejected_logps: torch.FloatTensor,\n) -> Tuple[torch.FloatTensor, torch.FloatTensor, torch.FloatTensor]:\n    \"\"\"Compute the SimPO loss for a batch of policy model log probabilities.\n    \n    Args:\n        policy_chosen_logps: Average log probabilities of the policy model \n            for the chosen responses. Shape: (batch_size,)\n        policy_rejected_logps: Average log probabilities of the policy model \n            for the rejected responses. Shape: (batch_size,)\n\n    Returns:\n        A tuple of three tensors: (losses, chosen_rewards, rejected_rewards).\n        losses: The SimPO loss for each example in the batch.\n        chosen_rewards: Reward for chosen responses (β * avg_logp).\n        rejected_rewards: Reward for rejected responses (β * avg_logp).\n    \"\"\"\n    pi_logratios = policy_chosen_logps - policy_rejected_logps\n    pi_logratios = pi_logratios.to(self.accelerator.device)\n    logits = pi_logratios - self.gamma  # gamma is the margin term\n\n    # The beta scaling is applied to the already-averaged log probs\n    if self.loss_type == \"sigmoid\":\n        losses = (\n            -F.logsigmoid(self.beta * logits)\n        )\n    elif self.loss_type == \"hinge\":\n        losses = torch.relu(1 - self.beta * logits)\n    else:\n        raise ValueError(\n            f\"Unknown loss type: {self.loss_type}. Should be one of ['sigmoid', 'hinge']\"\n        )\n\n    chosen_rewards = self.beta * policy_chosen_logps.to(self.accelerator.device).detach()\n    rejected_rewards = self.beta * policy_rejected_logps.to(self.accelerator.device).detach()\n\n    return losses, chosen_rewards, rejected_rewards\n```\n\n### Critical Notes\n\n1. **Average log probabilities**: The inputs `policy_chosen_logps` and `policy_rejected_logps` are ALREADY length-averaged log probabilities. The length normalization happens in the `concatenated_forward` method, not in `simpo_loss` itself. In SimPO, when computing log probabilities, they divide by the number of tokens:\n   ```python\n   all_logps = all_logps \u002F size_completion  # length normalization\n   ```\n\n2. **Gamma (margin)**: The `self.gamma` parameter is subtracted from the log-ratio difference BEFORE multiplying by beta. This is the target reward margin that ensures the winning response's reward exceeds the losing response's reward by at least gamma.\n\n3. **Beta**: The `self.beta` parameter scales the entire logit (after margin subtraction) inside the sigmoid\u002Floss function.\n\n4. **Loss type**: Default is \"sigmoid\" which uses `-log(sigmoid(β * (avg_logp_w - avg_logp_l - γ)))`.\n\n5. **No reference model needed**: Unlike DPO, SimPO does not require a reference model. The reward is simply `β * avg_log_prob`.","## SimPO Loss Function\n\nSimPO (Simple Preference Optimization) is a reference-free reward formulation for preference optimization that uses the average log probability of a sequence as the implicit reward.\n\n### Key Formula\n\nThe SimPO loss is defined as:\n\n```\nL_SimPO = -log(sigmoid(β\u002F|y_w| * log π_θ(y_w|x) - β\u002F|y_l| * log π_θ(y_l|x) - γ))\n```\n\nWhere:\n- `β` (beta) is a scaling hyperparameter\n- `γ` (gamma) is a target reward margin (the paper calls this the margin term)\n- `y_w` is the winning\u002Fchosen response\n- `y_l` is the losing\u002Frejected response\n- `|y_w|` and `|y_l|` are the lengths (number of tokens) of the responses\n- `π_θ(y|x)` is the policy model's probability of generating y given x\n- The average log probability `1\u002F|y| * log π_θ(y|x)` serves as the implicit reward\n\n### Implementation Details\n\n```python\ndef simpo_loss(\n    self,\n    policy_chosen_logps: torch.FloatTensor,\n    policy_rejected_logps: torch.FloatTensor,\n) -> Tuple[torch.FloatTensor, torch.FloatTensor, torch.FloatTensor]:\n    \"\"\"Compute the SimPO loss for a batch of policy model log probabilities.\n    \n    Args:\n        policy_chosen_logps: Average log probabilities of the policy model \n            for the chosen responses. Shape: (batch_size,)\n        policy_rejected_logps: Average log probabilities of the policy model \n            for the rejected responses. Shape: (batch_size,)\n\n    Returns:\n        A tuple of three tensors: (losses, chosen_rewards, rejected_rewards).\n        losses: The SimPO loss for each example in the batch.\n        chosen_rewards: Reward for chosen responses (β * avg_logp).\n        rejected_rewards: Reward for rejected responses (β * avg_logp).\n    \"\"\"\n    pi_logratios = policy_chosen_logps - policy_rejected_logps\n    pi_logratios = pi_logratios.to(self.accelerator.device)\n    logits = pi_logratios - self.gamma  # gamma is the margin term\n\n    # The beta scaling is applied to the already-averaged log probs\n    if self.loss_type == \"sigmoid\":\n        losses = (\n            -F.logsigmoid(self.beta * logits)\n        )\n    elif self.loss_type == \"hinge\":\n        losses = torch.relu(1 - self.beta * logits)\n    else:\n        raise ValueError(\n            f\"Unknown loss type: {self.loss_type}. Should be one of ['sigmoid', 'hinge']\"\n        )\n\n    chosen_rewards = self.beta * policy_chosen_logps.to(self.accelerator.device).detach()\n    rejected_rewards = self.beta * policy_rejected_logps.to(self.accelerator.device).detach()\n\n    return losses, chosen_rewards, rejected_rewards\n```\n\n### Critical Notes\n\n1. **Average log probabilities**: The inputs `policy_chosen_logps` and `policy_rejected_logps` are ALREADY length-averaged log probabilities. The length normalization happens in the `concatenated_forward` method, not in `simpo_loss` itself. In SimPO, when computing log probabilities, they divide by the number of tokens:\n   ```python\n   all_logps = all_logps \u002F size_completion  # length normalization\n   ```\n\n2. **Gamma (margin)**: The `self.gamma` parameter is subtracted from the log-ratio difference BEFORE multiplying by beta. This is the target reward margin that ensures the winning response's reward exceeds the losing response's reward by at least gamma.\n\n3. **Beta**: The `self.beta` parameter scales the entire logit (after margin subtraction) inside the sigmoid\u002Floss function.\n\n4. **Loss type**: Default is \"sigmoid\" which uses `-log(sigmoid(β * (avg_logp_w - avg_logp_l - γ)))`.\n\n5. **No reference model needed**: Unlike DPO, SimPO does not require a reference model. The reward is simply `β * avg_log_prob`.",{"name":5,"description":7},"main","726e1f79b96b0cb3d729d0e55a1c847e0b5353ae","skills\u002Fb3-teacher-feedback-claude-opus-4-6\u002Fnlp-paper-reproduction\u002Frun3_simpo-loss-implementation",8,"https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench","https:\u002F\u002Fcxcscmu.github.io\u002FSkillLearnBench","https:\u002F\u002Fgithub.com\u002Fcxcscmu","2026-10-02 22:55:36",{"source":8,"skillName":5,"commands":45,"prompt":55,"zipAvailable":56},[46,49,52],{"tool":47,"command":48},"npx","npx skills add cxcscmu\u002FSkillLearnBench --skill simpo-loss-implementation",{"tool":50,"command":51},"bunx","bunx skills add cxcscmu\u002FSkillLearnBench --skill simpo-loss-implementation",{"tool":53,"command":54},"pnpm","pnpm dlx skills add cxcscmu\u002FSkillLearnBench --skill simpo-loss-implementation","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fb3-teacher-feedback-claude-opus-4-6\u002Fnlp-paper-reproduction\u002Frun3_simpo-loss-implementation\u002FSKILL.md",true,[],[59,72,94,112,132,143],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":31},"01M6KM5KH175P5ABP5JMX2SBDQ","object_counter","Count occurrences of an object in the image using computer vision algorithm.","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fhuman_authored\u002Fvideo-object-counting\u002Fobject_counter\u002FSKILL.md",[],[66,67,68,69,70,71],"object counter","object","vision","computer","Computer Vision","image",{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":31},"01M6KM51TMVXG79MMPCS6Y8G86","travel-planning-workflow","Invoke this skill when performing travel planning. It defines a structured workflow for generating itineraries. Following this workflow is essential to ensure the final plan satisfies user requirements.","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fhuman_authored\u002Ftravel-planning\u002Ftravel-planning-workflow\u002FSKILL.md",[],[79,80,81,82,83,84,85,86,87,88,89,90,91,92,93],"workflow","planning","planning workflow","travel","travel planning","travel planning workflow","structured","performing","plan","for","user","it","requirements","essential","itineraries",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":31},"01M6KM4DY820XHS9YTSK5QP5HD","bundled-dataset-search-tool","invoke this skill when you need to perform database search for travel planning. This skill provides some useful pre-packaged tools to look up accommodations, attractions, cities, driving distance, flights, and restaurants from the bundled dataset.","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fhuman_authored\u002Ftravel-planning\u002Fbundled-dataset-search-tool\u002FSKILL.md",[],[101,102,103,104,105,106,107,82,108,109,83,110,88,111,80],"search","tool","dataset","bundled dataset search tool","restaurants","Tools","up","look","flights","you","database",{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":31},"01M6KM465BB9PQ0B548HQSVAWZ","glm-output","Output-processing guidance for GLM tasks. Especially useful after glm-basics and glm-calibration when you need verifier-matching metrics from output.nc and a final \u002Froot\u002Fmetrics.json.","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fhuman_authored\u002Ftemperature-simulation\u002Fglm-output\u002FSKILL.md",[],[119,120,121,88,122,123,124,125,126,127,128,129,110,130,131],"glm output","output","glm","tasks","metrics","json","basics","guidance","matching","verifier","processing","root","calibration",{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":31},"01M6KM40KY3QWDW5W97S39R2BC","glm-calibration","Calibration guidance for GLM tasks. Often most effective after glm-basics has clarified the setup; glm-output is the companion skill for exact final metric computation.","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fhuman_authored\u002Ftemperature-simulation\u002Fglm-calibration\u002FSKILL.md",[],[139,131,121,120,126,125,122,140,141,88,142],"glm calibration","setup","companion","metric",{"skillNo":144,"name":145,"nameZh":6,"description":146,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":147,"categories":148,"keywords":149,"publishedAt":31},"01M6KM3VHHVSGMGHJQB3PPT6YG","glm-basics","A good starting point for GLM calibration tasks. Use to inspect glm3.nml, confirm how GLM runs, and identify the relevant files before moving on to calibration and output evaluation.","https:\u002F\u002Fgithub.com\u002Fcxcscmu\u002FSkillLearnBench\u002Fblob\u002Fmain\u002Fskills\u002Fhuman_authored\u002Ftemperature-simulation\u002Fglm-basics\u002FSKILL.md",[],[150,121,125,151,139,131,88,120,152,153,154,25,24,155,122],"glm basics","inspect","relevant","files","good","Evaluation"]