iamseungpil

research-debug

Research-driven debugging workflow that combines web research for similar cases, deep code analysis with task-planner-analyzer, and iterative fixes with modular-code-architect and code-reviewer. Use when encountering training collapse, gibberish generation, or architecture-level bugs where the problem may be documented in research literature. Parallel execution of research and fixes for efficiency.

iamseungpil 3 1 Updated 8mo ago

Resources

1
GitHub

Install

npx skillscat add iamseungpil/claude-for-dslab/research-debug

Install via the SkillsCat registry.

SKILL.md

Research-Driven Debugging (research-debug)

๋ณต์žกํ•œ ML ํ•™์Šต ๋ฌธ์ œ๋‚˜ architecture-level ๋ฒ„๊ทธ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ํ†ตํ•ฉ ์›Œํฌํ”Œ๋กœ์šฐ์ž…๋‹ˆ๋‹ค. ์›น ์—ฐ๊ตฌ, ์ฝ”๋“œ ๋ถ„์„, ๋ฐ˜๋ณต์  ์ˆ˜์ •์„ ๋ณ‘๋ ฌ๋กœ ์ง„ํ–‰ํ•˜์—ฌ ๊ทผ๋ณธ ์›์ธ์„ ์ฐพ๊ณ  ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

๐ŸŽฏ ์‚ฌ์šฉ ์‹œ์ 

โœ… Ideal Use Cases

  • Training collapse/divergence: ํ•™์Šต์ด ์ดˆ๊ธฐ์—๋Š” ์ž˜ ๋˜๋‹ค๊ฐ€ ๊ฐ‘์ž๊ธฐ ๋ถ•๊ดด
  • Gibberish generation: ๋ชจ๋ธ์ด ๋ฌด์˜๋ฏธํ•œ ์ถœ๋ ฅ ์ƒ์„ฑ
  • Known research problem: ๋ฌธ์ œ๊ฐ€ ๋…ผ๋ฌธ/๋ธ”๋กœ๊ทธ์—์„œ ๋…ผ์˜๋œ ์ ์ด ์žˆ์„ ๊ฒƒ ๊ฐ™์€ ๊ฒฝ์šฐ
  • Architecture-level bugs: ๋‹จ์ˆœ ๊ตฌํ˜„ ๋ฒ„๊ทธ๊ฐ€ ์•„๋‹Œ ์„ค๊ณ„ ๊ฒฐํ•จ์ด ์˜์‹ฌ๋  ๋•Œ
  • Performance anomalies: ์˜ˆ์ƒ๊ณผ ๋‹ค๋ฅธ ์„ฑ๋Šฅ ํŒจํ„ด (loss spike, reward collapse ๋“ฑ)

โŒ Not Suitable For

  • Simple bugs: Syntax error, typo ๋“ฑ์€ ์ง์ ‘ ์ˆ˜์ •
  • Well-defined requirements: "Add feature X" ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์€ ์ง์ ‘ ๊ตฌํ˜„
  • No literature: ์™„์ „ํžˆ ์ƒˆ๋กœ์šด ๋ฌธ์ œ๋Š” research ๋‹จ๊ณ„๊ฐ€ ๋น„ํšจ์œจ์ 

๐Ÿ“‹ Workflow Phases

Phase 1: Evidence Gathering (๋ณ‘๋ ฌ ์‹คํ–‰)

# ๋™์‹œ์— 3๊ฐ€์ง€ ์ž‘์—… ์‹œ์ž‘:
# 1. Web research for similar cases
# 2. Deep code analysis with task-planner-analyzer
# 3. Start safe fixes (config changes, monitoring)

Step 1.1: Web Research

WebSearch(
    query="[problem description] [domain] [year]"
)
# Example: "GRPO policy gradient collapse vocabulary 2024 2025"

์ฐพ์„ ๊ฒƒ:

  • Documented failure modes (๋ฌธ์„œํ™”๋œ ์‹คํŒจ ํŒจํ„ด)
  • Fundamental design flaws (๊ทผ๋ณธ์  ์„ค๊ณ„ ๊ฒฐํ•จ)
  • Known workarounds (์•Œ๋ ค์ง„ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•)
  • Recent papers addressing the issue (์ตœ์‹  ์—ฐ๊ตฌ)

Step 1.2: Code Analysis (Task-Planner-Analyzer)

Task(
    subagent_type="task-planner-analyzer",
    prompt=f"""
Analyze {problem_description} in this codebase.

**Context from web research:**
{web_search_findings}

**Files to examine:**
{list_of_relevant_files}

**Your tasks:**
1. Examine codebase structure
2. Identify design flaws matching literature
3. Check for known anti-patterns
4. Create prioritized TODO list with:
   - File paths and line numbers
   - Root causes vs symptoms
   - Risk assessment
   - Dependencies and constraints
    """
)

Step 1.3: Start Safe Fixes (Optional)

# If you already know some safe fixes (e.g., config changes), start them
# while analysis is running
python scripts/train.py --config fixed_config.yaml > logs/new_run.log 2>&1 &

Phase 2: Root Cause Triangulation

Cross-Reference Literature โ†” Code

Create a mapping table:

Literature Finding Code Location Match? Impact Priority
Token-level issue line 316 โœ… YES HIGH 1
Entropy collapse line 888 โœ… YES CRITICAL 1
Conflicting grads multiple โœ… YES MEDIUM 2

Prioritize by Impact

  1. CRITICAL: Collapse trigger (direct cause of observed failure)
  2. HIGH: Fundamental flaw (will cause problems at scale)
  3. MEDIUM: Optimization (improves stability but not essential)
  4. LOW: Cosmetic (code quality, not behavior)

Phase 3: Iterative Fix-and-Verify

Fix Loop

FOR each priority (CRITICAL โ†’ HIGH โ†’ MEDIUM):
    1. Modular-Code-Architect: Apply fix
    2. Code-Reviewer: Verify no side effects
    3. Run tests (if applicable)
    4. Monitor metrics for early warnings
    5. If problem recurs โ†’ back to Task-Planner

Apply Fixes with Modular-Code-Architect

Task(
    subagent_type="modular-code-architect",
    prompt=f"""
Implement fix for {root_cause} based on this analysis:
{analysis_from_phase2}

**Constraints:**
{list_of_constraints}

**Verification criteria:**
{how_to_verify_fix_worked}

Follow modular design: minimal changes, plug-and-play.
    """
)

Verify with Code-Reviewer

Task(
    subagent_type="code-reviewer",
    prompt="""
Review recent changes for:
1. Critical issues (logic errors, side effects)
2. Consistency with architecture constraints
3. Whether the fix actually addresses the root cause

Use ultrathink level.
    """
)

Verification Criteria

  • No collapse for 100+ steps (or 10x previous collapse point)
  • Metrics stay within healthy ranges
  • No new issues introduced (regression tests pass)
  • Edge cases handled

Phase 4: Documentation

Create Analysis Document

# File: logs/{problem}_root_cause_analysis.md

## Problem Summary
[What happened]

## Root Causes (Ranked)
1. **RC1**: [Description]
   - Evidence: [Literature + Code]
   - Fix: [What was applied]
   - Verification: [How we know it worked]

## Fixes Applied
[Detailed changelog]

## Verification Results
[Metrics before/after]

## Lessons Learned
[What to watch for next time]

Update Project Memory

Add to MEMORY.md or similar:

  • New failure modes discovered
  • Effective fixes
  • Ineffective approaches (to avoid repeating)
  • Monitoring metrics to add

๐Ÿ” Monitoring & Debugging

Key Metrics to Watch

# For ML training issues:
metrics_to_monitor = [
    "loss",              # Should decrease steadily
    "reward",            # Should be stable or improve
    "entropy",           # High = gibberish, Low = mode collapse
    "gradient_norm",     # Should be bounded
    "v_norm",            # For LoRA: should not hit clamp boundary
    "kl_loss",           # For RL: should be non-zero when active
]

Early Warning Signs

# Add to training code:
if entropy > 0.9 * log(vocab_size):
    logger.warning("Entropy collapse imminent - gibberish likely")

if all_advantages_zero and mean_reward > 0.5:
    logger.warning("Perfect accuracy but zero variance - KL-only training")

if v_norm >= max_norm * 0.95:
    logger.warning("V-vector at clamp boundary - may be fighting constraint")

๐Ÿ“š Example: GRPO Collapse

Phase 1: Evidence Gathering

WebSearch: Found 5 papers documenting GRPO instability

  • Token-level importance weight fails (DAPO)
  • Catastrophic model collapse (GSPO)
  • Entropy collapse & gibberish (OpenReview)

Task-Planner: Identified 5 root causes in code

  • KL-only collapse trigger (CRITICAL)
  • Token-level mismatch (HIGH)
  • Task overfitting (HIGH)

Phase 2: Triangulation

Finding Both Sources? Priority
KL-only steps โœ… Yes CRITICAL
Token-level โœ… Yes HIGH
Task overfit Code only HIGH

Phase 3: Fix & Verify

  1. Fix 1: Advantage-aware KL gating
    • Applied, verified, no collapse at step 20
  2. Fix 2: Length-normalized log-probs
    • Importance ratios stable [0.5, 2.0]
  3. Fix 3: Reduce steps_per_task 20โ†’3
    • New tasks every 3 steps, stable 200+ steps

Phase 4: Documentation

  • โœ… Root cause analysis written
  • โœ… MEMORY.md updated
  • โœ… Workflow recipe created

โš ๏ธ Common Pitfalls

1. Fixing Symptoms Instead of Root Causes

โŒ Bad: "Gibberish appeared, let's increase temperature"
โœ… Good: "Gibberish = entropy collapse. What causes that? KL-only signal."

2. Serial Execution (Wasting Time)

โŒ Bad: WebSearch โ†’ wait โ†’ Analyze โ†’ wait โ†’ Fix โ†’ wait
โœ… Good: WebSearch || Analyze || Start Safe Fixes โ†’ Integrate

3. Ignoring Literature

โŒ Bad: "This is unique, no point searching"
โœ… Good: "Let me check if anyone has seen this before"

4. Not Documenting Failures

โŒ Bad: "That didn't work, let's try something else"
โœ… Good: "Failed BECAUSE X, documented for future reference"

๐Ÿš€ Quick Start Template

# 1. Start parallel evidence gathering
WebSearch("problem_description 2024 2025")
Task(subagent_type="task-planner-analyzer", prompt="Analyze {problem}...")

# 2. Start monitoring while waiting
tail -f logs/training.log &

# 3. Apply fixes iteratively
Task(subagent_type="modular-code-architect", prompt="Fix {root_cause}...")
Task(subagent_type="code-reviewer", prompt="Review changes...")

# 4. Document everything
Write("logs/root_cause_analysis.md", content="...")
Edit("MEMORY.md", add="New learnings...")

๐ŸŽ“ Success Criteria

Process Metrics

  • Time to root cause: < 2 hours (with parallel execution)
  • Fix iterations: < 3 (if root cause correct)
  • Regression rate: < 10% (good code review)

Outcome Metrics

  • Problem resolved: Yes/No
  • Stability duration: Steps until next issue
  • Knowledge captured: Documentation complete

๐Ÿ“– Related Skills

  • iterative-code-review: Use after fixes applied for quality verification
  • code-reviewer: Standalone code quality checks
  • debugger: When tests fail during verification phase
  • task-planner-analyzer: Can be used standalone for planning

Remember: This is a flexible workflow, not a rigid process. Adapt to your specific problem while maintaining the core principles: evidence-based, parallel execution, root-cause focused, and well-documented.