소스 정보
- 저장소
- cxcscmu/SkillLearnBench
- 최근 소스 활동
- 2026년 4월 24일 05:14
- 감지된 SKILL.md 언어
- 영어
- 스타
- 77
- 포크
- 4
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill fixed-tensor-testing명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
SOC 직업 분류 기준
| name | fixed-tensor-testing |
| description | Test ML functions with fixed input tensors for reproducibility. |
Fixed tensor testing ensures deterministic, reproducible results for loss functions and model outputs. Enables verification without training dependencies.
import torch
import numpy as np
# Set all random seeds
torch.manual_seed(42)
np.random.seed(42)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(42)
# Fixed log probabilities (typically negative)
log_probs = torch.randn(batch_size, seq_len)
# Ensure reasonable log prob range (e.g., -2 to 0)
log_probs = torch.clamp(log_probs, min=-5.0, max=0.0)
# Fixed sequence lengths
seq_lengths = torch.randint(10, 100, (batch_size,))
# Fixed input IDs (for masking)
input_ids = torch.randint(0, vocab_size, (batch_size, seq_len))
batch_size = 4
seq_len = 10
# Generate fixed tensors
torch.manual_seed(123)
log_probs = torch.randn(batch_size, seq_len)
log_probs = torch.clamp(log_probs, -5.0, 0.0)
# Create mask (e.g., padding)
mask = torch.ones(batch_size, seq_len, dtype=torch.bool)
mask[:, seq_len-2:] = False # Last 2 tokens are padding
# Lengths accounting for mask
seq_lengths = mask.sum(dim=1).float()
import numpy as np
results = {
'losses': loss.cpu().detach().numpy(),
'log_probs': log_probs.cpu().detach().numpy(),
}
np.savez_compressed('/path/to/results.npz', **results)
data = np.load('/path/to/results.npz')
losses = data['losses']
print(f"Shape: {losses.shape}, dtype: {losses.dtype}")
# Loss should be finite and positive
assert torch.isfinite(loss).all(), "Loss contains NaN or Inf"
assert loss.item() > 0, "Loss should be positive"
# Shape validation
assert loss.shape == expected_shape, f"Shape mismatch: {loss.shape}"
# Range checks
assert loss.item() < 100, "Loss unreasonably large"
assert log_probs.min() >= -6.0, "Log probs too small"
# Run computation twice, should get same result
loss1 = compute_loss(fixed_tensors)
loss2 = compute_loss(fixed_tensors)
assert torch.allclose(loss1, loss2), "Loss not reproducible"
def test_simpo_loss():
# Setup fixed inputs
batch_size = 8
torch.manual_seed(42)
log_probs = torch.randn(batch_size, 20)
seq_lengths = torch.full((batch_size,), 20.0)
# Compute loss
beta = 2.0
gamma = 1.0
loss = compute_simpo_loss(log_probs, seq_lengths, beta, gamma)
# Assertions
assert loss.shape == torch.Size([])
assert torch.isfinite(loss)
assert loss.item() > 0
return loss.item()
# Ensure gradients can backpropagate
x = torch.randn(5, 10, requires_grad=True)
loss = some_loss_function(x)
loss.backward()
assert x.grad is not None
assert not torch.allclose(x.grad, torch.zeros_like(x.grad))
# Test with extreme values
extreme_inputs = [
torch.full((5,), -100.0), # Very negative log probs
torch.full((5,), 0.0), # Zero log probs
torch.zeros(5), # All zeros
]
for inp in extreme_inputs:
try:
loss = compute_loss(inp)
assert torch.isfinite(loss), f"Loss not finite for {inp}"
except Exception as e:
print(f"Failed with input {inp}: {e}")
# Print intermediate values
def debug_loss(log_probs, seq_lengths, beta, gamma):
rewards = beta * log_probs / seq_lengths.unsqueeze(1)
print(f"Rewards shape: {rewards.shape}, min: {rewards.min():.4f}, max: {rewards.max():.4f}")
# ... rest of computation
print(f"Final loss: {loss.item():.6f}")
return loss