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.
Resources
1Install
npx skillscat add iamseungpil/claude-for-dslab/research-debug Install via the SkillsCat registry.
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
- CRITICAL: Collapse trigger (direct cause of observed failure)
- HIGH: Fundamental flaw (will cause problems at scale)
- MEDIUM: Optimization (improves stability but not essential)
- 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-PlannerApply 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
- Fix 1: Advantage-aware KL gating
- Applied, verified, no collapse at step 20
- Fix 2: Length-normalized log-probs
- Importance ratios stable [0.5, 2.0]
- 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.