用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill run2-simpo-testing-and-verification命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Handles reading, populating, and saving .docx files using the python-docx library. Use this skill for any tasks involving template filling or modifying Word documents.
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
This skill includes search capability in 13F, such as fuzzy search a fund information using possibly inaccurate name, or fuzzy search a stock cusip info using its name.
基于 SOC 职业分类
正在显示 SKILL.md
| name | run2_simpo-testing-and-verification |
| description | Testing SimPO loss function with fixed tensors and output verification |
The SimPO implementation uses pre-computed fixed tensors for deterministic testing:
# Load pre-computed tensors
policy_chosen_logps = torch.load("unit_test/tensors/policy_chosen_logps.pt")
policy_rejected_logps = torch.load("unit_test/tensors/policy_rejected_logps.pt")
# Create trainer instance
config = SimPOConfig(output_dir="./simpo_output")
trainer = SimPOTrainer(model="sshleifer/tiny-gpt2", args=config)
# Run loss function
losses, chosen_rewards, rejected_rewards = trainer.simpo_loss(
policy_chosen_logps,
policy_rejected_logps,
)
# Verify and save
assert losses.shape == (100,) # Batch size 100
np.savez("/root/loss.npz", losses=losses.detach().cpu().numpy())
losses: (batch_size,) - one loss per samplechosen_rewards: (batch_size,) - one reward per chosen responserejected_rewards: (batch_size,) - one reward per rejected responseBased on unit test with 100 samples:
import numpy as np
data = np.load('/root/loss.npz')
assert 'losses' in data, "Missing 'losses' key"
losses = data['losses']
assert losses.dtype in [np.float32, np.float64], f"Wrong dtype: {losses.dtype}"
assert losses.shape == (100,), f"Wrong shape: {losses.shape}"
assert np.all(losses > 0), "Negative losses found!"
assert not np.isnan(losses).any(), "NaN values found!"
assert not np.isinf(losses).any(), "Inf values found!"
print("✓ All validations passed!")
# Manually compute loss for first sample
beta = 2.0
gamma = beta * 0.25 # default gamma_beta_ratio
chosen_logp = policy_chosen_logps[0].item()
rejected_logp = policy_rejected_logps[0].item()
chosen_reward = beta * chosen_logp
rejected_reward = beta * rejected_logp
reward_diff = chosen_reward - rejected_reward - gamma
expected_loss = -np.log(1 / (1 + np.exp(-reward_diff)))
computed_loss = losses[0].item()
assert np.isclose(expected_loss, computed_loss, rtol=1e-5), \
f"Loss mismatch: {expected_loss} vs {computed_loss}"
Save Python environment information:
python -VV > python_info.txt
python -m pip freeze >> python_info.txt
This allows exact reproduction of the test:
cd /root/SimPO
python3 -m unittest unit_test.unit_test_1.TestModelOutputs.test_random_pairs -v
python3 << 'EOF'
from unit_test.unit_test_1 import TestModelOutputs
import unittest
# Create test suite
suite = unittest.TestSuite()
suite.addTest(TestModelOutputs('test_random_pairs'))
# Run with verbose output
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
# Check result
if result.wasSuccessful():
print("\n✓ Test passed successfully!")
else:
print("\n✗ Test failed!")
for error in result.errors:
print(f"Error: {error[1]}")
EOF
Solution: Install packages
pip install torch transformers trl numpy
Solution: Use tiny-gpt2 for testing (small, fast to load)
model = "sshleifer/tiny-gpt2" # ~10MB, trains instantly
Verification: Check formula
loss = -log(sigmoid(chosen_reward - rejected_reward - gamma))
Should be positive, typically 0.01 to 2.0 range.
Cause: Using log(sigmoid()) directly
Solution: Already fixed in implementation via F.logsigmoid()