Reproduce research papers into working code. Use when user wants to implement ML/AI papers, reproduce experiments, extract algorithms from PDFs, or convert research into executable code...
Transform research papers into production-ready, verified code with multi-agent orchestration, equation-first verification, and benchmark validation.
User: "Reproduce this paper" + [attaches PDF or provides arXiv URL]
You:
1. Clarify intent (validate/implement/extend)
2. Spawn extraction agent(s) per paper
3. Create context documents
4. Implement with equation verification
5. Format, test, document
6. Init git, ready for execution
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RESEARCH REPRODUCTION PIPELINE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Phase 0: INTENT CLARIFICATION β
β ββ What: Validate understanding / Implement / Extend / Benchmarkβ
β ββ Papers: Single / Multiple related / Paper family β
β ββ Scope: Full paper / Specific algorithm / Core contribution β
β ββ Resources: Local / Colab / GPU requirements β
β β
β Phase 1: PARALLEL EXTRACTION (Multi-Agent) β
β ββ Spawn one extraction agent per paper β
β ββ Each agent creates context document (NOT full paper) β
β ββ Extract: equations, algorithms, architecture, hyperparams β
β ββ Output: .context.md files in project root β
β β
β Phase 2: CONTEXT SYNTHESIS β
β ββ Orchestrator reads all .context.md files β
β ββ Build dependency graph (which paper depends on which) β
β ββ Create unified implementation plan β
β ββ Output: IMPLEMENTATION_PLAN.md β
β β
β Phase 3: EQUATION-FIRST IMPLEMENTATION β
β ββ For EACH equation: write test FIRST β
β ββ Implement module to pass test β
β ββ Verify shapes, gradients, numerical stability β
β ββ Output: src/ with tests/ alongside β
β β
β Phase 4: CODE QUALITY β
β ββ Format with ruff β
β ββ Type check with ty (Astral) β
β ββ Verify all tests pass β
β ββ Output: Clean, typed, formatted code β
β β
β Phase 5: DOCUMENTATION β
β ββ Generate README.md with usage instructions β
β ββ Create ARCHITECTURE.md with diagrams β
β ββ Document each module's paper reference β
β ββ Output: docs/ folder + root README β
β β
β Phase 6: GIT & EXECUTION PREP β
β ββ git init, .gitignore, initial commit β
β ββ Prepare for gh repo create β
β ββ Create run scripts (notebook + CLI) β
β ββ Output: Ready for git push and execution β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ALWAYS START HERE. Ask the user:
## Research Reproduction - Let's clarify your goals
**1. What's your intent?**
- [ ] Validate understanding - Quick implementation to verify I understand the paper
- [ ] Full reproduction - Complete implementation matching paper's experiments
- [ ] Specific component - Implement only [specific algorithm/module]
- [ ] Extend/modify - Build on paper with custom changes
- [ ] Benchmark only - Run existing code, verify results
**2. Paper scope:**
- [ ] Single paper
- [ ] Multiple related papers (specify dependencies)
- [ ] Paper family (e.g., TITANS β MIRAS β Hope)
**3. Execution environment:**
- [ ] Local CPU only
- [ ] Local GPU (specify VRAM)
- [ ] Google Colab (Free/Pro - specify units budget)
- [ ] Cloud GPU (specify provider)
**4. Output preferences:**
- [ ] Jupyter notebook for experimentation
- [ ] CLI scripts for training/inference
- [ ] Both notebook + scripts
For EACH paper, spawn an extraction subagent:
# Subagent task (do NOT load full paper into orchestrator context)
Task: Extract from [paper_name]
Output: [paper_name].context.md
The extraction agent will:
1. Convert PDF to markdown (markitdown)
2. Extract ALL equations with LaTeX
3. Extract ALL algorithms (pseudocode)
4. Extract architecture diagrams (describe in text)
5. Extract hyperparameters and training details
6. Extract benchmark datasets and metrics
7. Note dependencies on other papers
Extraction Agent Prompt: See prompts/extraction-agent.md
Context Document Format: See templates/context-document.md
When papers reference each other:
Paper A (Foundation) βββββββΊ Paper B (Extension) βββββββΊ Paper C (Application)
β β β
βΌ βΌ βΌ
A.context.md B.context.md C.context.md
β β β
ββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββ
β
βΌ
IMPLEMENTATION_PLAN.md
(ordered by dependency)
After all extraction agents complete:
.context.md filesIMPLEMENTATION_PLAN.mdSynthesis Template: See templates/implementation-plan.md
CRITICAL: Write test BEFORE implementation for EVERY equation.
# tests/test_equation_3_memory_update.py
"""
Paper: TITANS (arXiv:2501.00663)
Equation 3: M_{t+1} = M_t + Ξ· Β· βl(M_t; x_t)
Description: Memory update rule with gradient-based learning
"""
import torch
import pytest
def test_equation_3_shapes():
"""Verify tensor shapes match paper specification."""
batch_size, memory_size, dim = 4, 64, 256
M_t = torch.randn(batch_size, memory_size, dim)
x_t = torch.randn(batch_size, dim)
eta = 0.01
# Your implementation
from src.memory import memory_update
M_t_plus_1 = memory_update(M_t, x_t, eta)
assert M_t_plus_1.shape == M_t.shape, f"Expected {M_t.shape}, got {M_t_plus_1.shape}"
def test_equation_3_gradient_flow():
"""Verify gradients flow correctly through memory update."""
M_t = torch.randn(4, 64, 256, requires_grad=True)
x_t = torch.randn(4, 256)
from src.memory import memory_update
M_t_plus_1 = memory_update(M_t, x_t, eta=0.01)
loss = M_t_plus_1.sum()
loss.backward()
assert M_t.grad is not None, "Gradients should flow to M_t"
assert not torch.isnan(M_t.grad).any(), "Gradients should not be NaN"
def test_equation_3_numerical_stability():
"""Verify numerical stability with extreme values."""
M_t = torch.randn(4, 64, 256) * 1000 # Large values
x_t = torch.randn(4, 256) * 1000
from src.memory import memory_update
M_t_plus_1 = memory_update(M_t, x_t, eta=0.01)
assert not torch.isnan(M_t_plus_1).any(), "Should handle large values"
assert not torch.isinf(M_t_plus_1).any(), "Should not overflow"
# src/memory.py
"""
Memory module implementing TITANS neural memory.
Paper References:
- Equation 3: memory_update()
- Equation 5: surprise_metric()
- Algorithm 1: MemoryLayer forward pass
"""
import torch
import torch.nn as nn
def memory_update(M_t: torch.Tensor, x_t: torch.Tensor, eta: float) -> torch.Tensor:
"""
Equation 3: M_{t+1} = M_t + Ξ· Β· βl(M_t; x_t)
Args:
M_t: Current memory state [batch, memory_size, dim]
x_t: Input token [batch, dim]
eta: Learning rate
Returns:
M_t_plus_1: Updated memory [batch, memory_size, dim]
"""
# Implementation here
...
Full verification patterns: See references/equation-patterns.md
Run these checks before considering implementation complete:
# 1. Format with ruff
uv run ruff format src/ tests/
# 2. Lint with ruff
uv run ruff check src/ tests/ --fix
# 3. Type check with ty (Astral's type checker)
uv run ty check src/
# 4. Run all tests
uv run pytest tests/ -v --tb=short
# 5. Check test coverage
uv run pytest tests/ --cov=src --cov-report=term-missing
Quality Script: See scripts/quality_check.py
Generate comprehensive documentation:
# [Paper Name] Reproduction
> [One-line paper description]
## Quick Start
\`\`\`bash
# Clone and setup
git clone [repo]
cd [repo]
uv sync
# Run example
uv run python -m src.main --config configs/default.yaml
\`\`\`
## Paper Reference
- **Title:** [Full title]
- **Authors:** [Authors]
- **arXiv:** [Link]
- **Original Code:** [If exists]
## Implementation Status
| Component | Paper Section | Status | Tests |
|-----------|--------------|--------|-------|
| Memory Module | Β§3.1, Eq 3-5 | β
| 12/12 |
| Attention Layer | Β§3.2, Eq 8-10 | β
| 8/8 |
| Training Loop | Β§4.1 | β
| 5/5 |
## Architecture
[ASCII diagram or Mermaid]
## Usage
### Training
\`\`\`bash
uv run python -m src.train --config configs/train.yaml
\`\`\`
### Inference
\`\`\`bash
uv run python -m src.inference --checkpoint checkpoints/best.pt
\`\`\`
## Benchmarks
| Dataset | Paper Result | Our Result | Status |
|---------|-------------|------------|--------|
| WikiText-103 | 17.2 PPL | TBD | β³ |
## Project Structure
\`\`\`
βββ src/
β βββ __init__.py
β βββ model.py # Main model (Β§3)
β βββ memory.py # Memory module (Β§3.1)
β βββ train.py # Training loop (Β§4)
βββ tests/
β βββ test_memory.py
β βββ test_model.py
βββ configs/
β βββ default.yaml
βββ notebooks/
β βββ exploration.ipynb
βββ docs/
βββ ARCHITECTURE.md
\`\`\`
Documentation Template: See templates/readme-template.md
# Initialize git
git init
# Create .gitignore
cat > .gitignore << 'EOF'
# Python
__pycache__/
*.py[cod]
.venv/
*.egg-info/
# UV
.python-version
# IDE
.vscode/
.idea/
# Data & Models
data/
checkpoints/
*.pt
*.pth
wandb/
# Jupyter
.ipynb_checkpoints/
EOF
# Initial commit
git add .
git commit -m "Initial implementation: [Paper Name]
- Core model implementation (Β§3)
- Equation-verified modules (Eq 3-10)
- Test suite with X% coverage
- Documentation and examples
Paper: [arXiv link]"
# Create repo (requires gh CLI authenticated)
gh repo create [repo-name] --public --source=. --remote=origin
# Or prepare for manual push
echo "Ready to push:"
echo " git remote add origin git@github.com:USER/REPO.git"
echo " git push -u origin main"
CLI Script:
#!/usr/bin/env bash
# run_training.sh
set -e
uv run python -m src.train "$@"
Notebook Entry:
# notebooks/quickstart.ipynb
# Cell 1: Setup
!uv sync
from src.model import Model
from src.train import Trainer
# Cell 2: Quick test
model = Model.from_config("configs/default.yaml")
print(f"Parameters: {sum(p.numel() for p in model.parameters()):,}")
This skill includes UV single-file scripts for complex operations:
| Script | Purpose | Usage |
|---|---|---|
scripts/extract_paper.py |
Convert PDF to markdown, extract equations | uv run scripts/extract_paper.py paper.pdf |
scripts/quality_check.py |
Run ruff + ty + pytest | uv run scripts/quality_check.py |
scripts/verify_equations.py |
Run equation-specific tests | uv run scripts/verify_equations.py |
scripts/benchmark_runner.py |
Run benchmarks, compare to paper | uv run scripts/benchmark_runner.py |
scripts/generate_docs.py |
Generate README and architecture docs | uv run scripts/generate_docs.py |
[paper-name]-reproduction/
βββ .gitignore
βββ .python-version
βββ pyproject.toml
βββ uv.lock
βββ README.md
βββ ARCHITECTURE.md
βββ IMPLEMENTATION_PLAN.md
β
βββ papers/ # Original papers (gitignored if large)
β βββ [paper].context.md # Extracted context (committed)
β
βββ src/
β βββ __init__.py
β βββ model.py # Main model
β βββ layers/ # Individual layers/modules
β β βββ __init__.py
β β βββ memory.py # Memory module
β β βββ attention.py # Attention variants
β βββ train.py # Training loop
β βββ inference.py # Inference utilities
β βββ utils/
β βββ __init__.py
β βββ config.py # Configuration handling
β
βββ tests/
β βββ __init__.py
β βββ test_equations/ # Equation-specific tests
β β βββ test_eq3_memory.py
β β βββ test_eq5_surprise.py
β βββ test_layers/
β β βββ test_memory.py
β βββ test_integration.py
β
βββ configs/
β βββ default.yaml
β βββ small.yaml # Quick testing config
β βββ paper.yaml # Paper's exact config
β
βββ notebooks/
β βββ exploration.ipynb # Development notebook
β βββ quickstart.ipynb # User-facing notebook
β
βββ scripts/
β βββ train.sh
β βββ evaluate.sh
β
βββ docs/
βββ equations.md # All equations with implementations
βββ benchmarks.md # Benchmark results
uv run pytest)uv run ruff format)uv run ty check src/)After code is ready and verified locally:
# Connect to Colab GPU
lecoder-cgpu connect
# Upload project
lecoder-cgpu upload ./
# Run training
lecoder-cgpu run "cd [project] && uv sync && uv run python -m src.train"
# Download results
lecoder-cgpu download checkpoints/
See tools/colab-execution.md for detailed Colab integration.