AgentSkillsCN

code-audit

验证 LaTeX 论文与 Python 实现的一致性。从超参数匹配、架构对齐、损失函数正确性,到算法步骤顺序,逐一核验。适用于完成代码实现后,或在确认代码是否与论文完全一致时使用。

SKILL.md
--- frontmatter
name: code-audit
description: >
  Verify consistency between LaTeX paper and Python implementation.
  Checks hyperparameter matches, architecture alignment, loss function
  correctness, and algorithm step ordering. Use after implementation
  or when checking if code matches the paper.
allowed-tools: Read, Grep, Glob, Bash

Code Audit — LaTeX ↔ Python Consistency

Quick Scan Script

Run the automated check first:

bash
# 1. Hyperparameter match via CONFIG-SYNC markers
echo "=== HYPERPARAMETER CHECK ==="
grep "CONFIG-SYNC" workspace/paper/main.tex | while read line; do
    param=$(echo "$line" | grep -oP '\w+ = [\w.e-]+')
    param_name=$(echo "$param" | cut -d= -f1 | xargs)
    param_val=$(echo "$param" | cut -d= -f2 | xargs)
    code_val=$(grep "$param_name" workspace/src/config.py | grep -oP '= .+' | head -1)
    echo "  LaTeX: $param_name = $param_val | Code: $param_name $code_val"
done

# 2. Architecture dimension check
echo "=== ARCHITECTURE CHECK ==="
grep -n "hidden_dim\|input_dim\|output_dim\|num_layers\|num_heads" workspace/src/config.py
grep -n "d_h\|d_{in}\|d_{out}\|L =" workspace/paper/main.tex

Manual Verification Checklist

1. Hyperparameters (MUST all match)

ParameterLaTeX Locationconfig.py VariableMatch?
Learning rateSection IVlearning_rate
Batch sizeSection IVbatch_size
EpochsSection IVnum_epochs
Weight decaySection IVweight_decay
Architecture dimsSection IIIvarious

2. Loss Function

Read the loss equation in main.tex and compare term-by-term with loss.py:

  • Main loss term matches
  • Regularization terms match
  • Weighting coefficients match
  • Reduction method (mean vs sum) matches

3. Algorithm Steps

Read Algorithm 1 in main.tex and compare with train.py:

  • Step ordering matches
  • Gradient computation matches
  • Special procedures (warmup, scheduling, clipping) match

4. Model Architecture

Read Section III and compare with model.py:

  • Layer count matches
  • Activation functions match
  • Skip connections / residual structures match
  • Each custom layer has equation reference comment

Output Format

Write findings to workspace/logs/code_audit.json:

json
{
  "timestamp": "...",
  "iteration": N,
  "status": "PASS | WARN | CRITICAL",
  "mismatches": [
    {
      "parameter": "learning_rate",
      "latex_value": "1e-3",
      "code_value": "1e-4",
      "severity": "CRITICAL"
    }
  ],
  "architecture_match": true,
  "loss_match": true,
  "algorithm_match": true,
  "score": X
}

Any CRITICAL mismatch = immediate pipeline halt.