/exp-run
执行 wiki/experiments/ 中已规划的实验。
不论是哪种运行模式,在准备好实验代码,准备部署运行前需向用户确认,申请用户手动检查代码、实验配置(如数据集路径,接口参数选择,API 配置等)相关信息,确认无误后运行,否则需执行修改直到用户确认执行
三种运行模式,适应不同场景:
- 默认(deploy):仅 Phase 1-2,部署后立即返回,适合需要数小时/天的实验。
--collect:仅 Phase 3-4,检查已部署实验是否完成,完成则收集结果(--check 为 alias)。
--full:完整 Phase 1-4,适合几分钟内即可完成的本地快速实验。
推荐流程:/exp-run <slug> 部署 → /exp-status 监控 → /exp-run <slug> --collect 收集。
Inputs
experiment:wiki/experiments/ 中的 slug
- deploy 模式:status 必须为
planned
- --collect 模式:status 必须为
running
- --full 模式:status 必须为
planned
--review(可选):Phase 1 中启用 Review LLM code review 审查实验代码(deploy / full 模式有效)
--collect(可选):collect 模式——检查实验是否完成,完成则收集结果;--check 是 alias
--full(可选):完整模式——执行全部 4 个 Phase(适合快速本地实验)
--env local|remote(可选,默认 local):部署环境
local:本机 GPU 直接运行
remote:通过 SSH 部署到远程机器(需 config/server.yaml)
Outputs
- deploy 模式:
- 实验代码:
experiments/code/{slug}/(Phase 1 生成)
wiki/experiments/{slug}.md — status: planned → running
- DEPLOY_REPORT(输出到终端)— 部署确认、session 信息、下一步指引
wiki/log.md — 追加部署日志
- collect 模式(实验已完成时):
wiki/experiments/{slug}.md — status: running → completed,填充 outcome/key_result/date_completed
- RUN_REPORT(输出到终端)— 结果摘要、metrics 对比、下一步建议
wiki/log.md — 追加收集日志
- collect 模式(实验仍在运行时):
- full 模式:同 deploy + collect 的全部输出
Wiki Interaction
Reads
wiki/experiments/{slug}.md — 实验配置:setup、metrics、baseline、hypothesis、linked_idea
wiki/ideas/{linked-idea}.md — 关联 idea 的 approach sketch(指导代码实现,理解实验目的)
wiki/papers/*.md — 相关论文的方法细节和超参数(参考实现)
wiki/experiments/*.md — 同一 idea 的其他实验(参考 setup、避免重复错误)
Writes
experiments/code/{slug}/ — 实验代码目录(Phase 1 生成,deploy / full 模式)
experiments/code/{slug}/train.py — 主训练/推理脚本
experiments/code/{slug}/config.yaml — 超参数配置文件
experiments/code/{slug}/run.sh — 启动封装脚本(含 CUDA_VISIBLE_DEVICES 等)
experiments/code/{slug}/requirements.txt — 依赖(若与主项目不同)
wiki/experiments/{slug}.md — 更新 status、outcome、key_result、date_completed、run_log、remote 块(deploy / collect 模式)
wiki/log.md — 追加操作日志
Graph edges created
- 无。实验与 idea 之间的 tested_by 边已在 /exp-design 中创建。
Workflow
前置:确认工作目录为 wiki 项目根(包含 wiki/、raw/、tools/ 的目录)。
Deploy 模式(默认,status == planned)
Phase 1: 准备(Prepare)
读取实验页面:
wiki/experiments/{slug}.md:提取 setup(model, dataset, hardware, framework)、metrics、baseline、hypothesis
- 验证 status ==
planned
- 若 status 为
running,提示用户使用 --collect 模式
- 若 status 为
completed/abandoned,拒绝执行
加载实现上下文:
- 读取关联 idea 的 approach sketch(实现指南)
- 读取相关论文的方法描述(算法细节)
- 读取同一 idea 的其他实验(参考代码结构)
检验数据集以及其余配置
- 数据集在
wiki/experiments/{slug}.md的setup 中有指定
- 获取数据集路径(根据 --env 参数选择在本地或远程获取),可向用户询问本地(远程)的数据集的路径以及自行检索
- 若 数据集不存在,向用户提示,明确下载数据集的需求,向用户确认安装路径及下载渠道
- 检查数据集是否完整、可用,明确数据集附带的一些结构、使用说明
- 其余配置如:调用LLM的模型名称,url,api key等
编写实验代码,统一写入 experiments/code/{slug}/:
代码的编写模块化思想,除非实验规模较小,逻辑简单,否则不要把大量代码放在一个文件里
train.py:根据 setup 配置生成训练/评估脚本,作为程序的入口,包含:
- 参数解析(argparse,所有超参数可配置)
- 数据加载(支持 setup.dataset)
- 模型初始化(支持 setup.model 和 baseline 模型)
- 训练/推理循环
- 指标计算(对应 metrics 列表)
- 结果保存(JSON 格式,路径:
results/{slug}/seed_{N}.json)
- 随机种子控制(多 seed 运行)
- Checkpoint 保存/恢复(
checkpoints/{slug}/)
- 其余所需的utils、tools 等代码文件夹或者文件(如
utils.py、data_loader.py 等)
config.yaml:所有超参数(learning_rate, batch_size, epochs, seeds 等)
run.sh:封装完整启动命令(含 CUDA_VISIBLE_DEVICES、logging、conda 激活)
requirements.txt:实验专属依赖(若与主项目 requirements 不同)
可选 Review LLM code review(--review):
mcp__llm-review__chat:
system: "You are a senior ML engineer reviewing experiment code.
Focus on: correctness of the training loop, proper evaluation protocol,
fair baseline comparison, reproducibility (seeds, determinism),
proper metric computation, and common pitfalls (data leakage,
wrong split, gradient accumulation bugs)."
message: |
## Experiment
{experiment title and hypothesis}
## Code
{generated code}
## Expected Behavior
{setup details from wiki page}
Review for correctness and potential issues.
根据 Review LLM 反馈修正代码。
Sanity check(小规模验证):
- 用极小规模运行(1 epoch / 100 steps / 小 subset)
- 验证:代码无 crash、数据加载正确、GPU 可用、loss 下降
- 若 sanity 失败 → 修复代码,重试一次;仍然失败则报告错误并停止
Gate: 用户手动检查
注意:在准备好实验代码,准备部署运行前需向用户确认,申请用户手动检查代码、实验配置(数据集路径,接口参数选择,API 配置等)相关信息,确认无误后运行,否则需执行修改直到用户确认执行
Phase 2: 部署(Deploy)
Local 模式(--env local 或默认)
检查 GPU:nvidia-smi 确认 GPU 可用、显存足够。若 setup.hardware 为 cpu/none/空且生成代码无 CUDA/GPU 关键字,跳过 GPU 检查直接进入步骤 2。
启动:
screen -dmS exp-{slug} bash -c \
"cd $(pwd) && bash experiments/code/{slug}/run.sh 2>&1 | tee logs/exp-{slug}.log"
更新 wiki/experiments/{slug}.md:
- status:
running
- run_log:
logs/exp-{slug}.log
估算运行时长,写入 frontmatter:
根据 setup.hardware(GPU 型号/数量)、setup.model(参数量)、setup.dataset(规模)合理估算:
| 典型场景 |
估算范围 |
| 单 GPU + 小数据集(CIFAR / 小 NLP benchmark) |
0.5 – 3h |
| 单 A100 + 中等数据集(ImageNet / GLUE) |
4 – 12h |
| 多 GPU 或大模型 fine-tuning(≥7B) |
8 – 48h |
python3 tools/research_wiki.py set-meta \
wiki/experiments/{slug}.md started "{YYYY-MM-DDTHH:MM}"
python3 tools/research_wiki.py set-meta \
wiki/experiments/{slug}.md estimated_hours {N}
追加日志:
python3 tools/research_wiki.py log wiki/ \
"exp-run | deployed {slug} | env: local | session: exp-{slug} | eta: {N}h"
Remote 模式(--env remote)
前提:用户已配置 config/server.yaml。
确认连通:python3 tools/remote.py status
- 若不可达 → 报错并建议检查 config/server.yaml
查找空闲 GPU:python3 tools/remote.py gpu-status(若 setup.hardware 为 cpu/none/空且代码无 CUDA/GPU 关键字则跳过)
- 若无空闲 GPU → 报告各 GPU 占用情况,建议等待
同步代码:python3 tools/remote.py sync-code
安装依赖(首次或 requirements 有变化):python3 tools/remote.py setup-env
启动远程实验:
python3 tools/remote.py launch \
--name "exp-{slug}" \
--cmd "bash experiments/code/{slug}/run.sh" \
--gpu {gpu_index}
更新 wiki/experiments/{slug}.md frontmatter —— 以下字段已由 /exp-design 写入完整 CLAUDE.md 模板,都是空值:
# 顶层 scalar 字段 —— 用 set-meta
python3 tools/research_wiki.py set-meta wiki/experiments/{slug}.md status running
python3 tools/research_wiki.py set-meta wiki/experiments/{slug}.md run_log "logs/exp-{slug}.log"
嵌套 remote: 块无法通过 set-meta 更新(set-meta 只处理顶层 scalar 字段)。直接用 Edit 工具就地替换这五个空的子字段值。文件里已有的 block 形如:
remote:
server: ""
gpu: ""
session: ""
started: ""
completed: ""
用 5 次 Edit 调用(每个子字段一次)设置 server、gpu、session、started。completed: "" 留空由 Phase 4 填写。如果发现文件里没有 remote: block,说明 /exp-design 没写完整的 CLAUDE.md 模板;停下来报 bug,不要在这里追加 block(追加会让字段顺序偏离 canonical 模板,破坏后续 edit 的匹配)。
估算运行时长,写入 frontmatter(同 local 模式估算逻辑):
python3 tools/research_wiki.py set-meta \
wiki/experiments/{slug}.md started "{YYYY-MM-DDTHH:MM}"
python3 tools/research_wiki.py set-meta \
wiki/experiments/{slug}.md estimated_hours {N}
追加日志:
python3 tools/research_wiki.py log wiki/ \
"exp-run | deployed {slug} | env: remote | server: {host} | gpu: {gpu} | eta: {N}h"
输出 DEPLOY_REPORT 到终端:
# Deploy Report: {experiment title}
### Status: DEPLOYED ✅
- Session: exp-{slug}
- Environment: local | remote ({host} GPU {gpu})
- Log file: logs/exp-{slug}.log
- Code: experiments/code/{slug}/
- Estimated: ~{N}h(预计完成于 {YYYY-MM-DD HH:MM})
### Next Steps
1. Monitor progress: `/exp-status`
2. Check this experiment: `/exp-run {slug} --collect`
3. In /research pipeline: progress saved to wiki/outputs/pipeline-progress.md
### Quick Commands
```bash
# Local: check if still running
screen -ls | grep exp-{slug}
# Local: tail log
tail -f logs/exp-{slug}.log
---
### Collect 模式(`--collect` 或 `--check`,status == running)
**Phase 3: 监控/检查运行状态(Monitor)**
1. **读取部署信息**:从 `wiki/experiments/{slug}.md` frontmatter 获取环境(local 或 remote)和 session 名。
2. **检查进程是否还活着**:
- **Local**:`screen -ls | grep exp-{slug}`
- **Remote**:`python3 tools/remote.py check --name "exp-{slug}"`,解析 `alive` 字段
3. **若实验仍在运行(alive == true)**:
- 获取最近日志:
- Local:`tail -30 logs/exp-{slug}.log`
- Remote:`python3 tools/remote.py tail-log --name "exp-{slug}" --lines 30`
- **异常检测**:
- NaN loss:检测 `loss: nan`
- OOM:`CUDA out of memory`
- Traceback:Python 异常堆栈
- Inf loss:`loss: inf`
- **自动修复尝试**(若检测到异常,最多 1 次):
- NaN/爆炸 → 从最近 checkpoint 恢复,降低学习率
- OOM → 减小 batch size,重启
- **输出进度报告**(不修改 wiki,仅报告):
```
Experiment {slug}: RUNNING
Progress: step {N} / epoch {E}
Latest metric: {metric} = {value}
Anomalies: {none | NaN detected | ...}
Estimated remaining: ~{N} hours
Run `/exp-status` to monitor all running experiments.
```
- **返回**(不执行 Phase 4)
4. **若实验已完成(alive == false / session gone)**:
- 继续执行 Phase 4
**Phase 4: 收集结果(Collect Results)**
1. **拉取远程结果**(仅 remote 模式):
```bash
python3 tools/remote.py pull-results \
--remote-path "results/{slug}/" \
--local-path "./results/{slug}/"
python3 tools/remote.py pull-results \
--remote-path "logs/exp-{slug}.log" \
--local-path "./logs/"
检查结果文件存在:results/{slug}/seed_*.json
解析结果:
- 读取结果文件(JSON)
- 计算每个 metric 的 mean ± std(跨 seeds)
- 与 baseline 对比,计算提升幅度
更新实验页面 wiki/experiments/{slug}.md:
- status:
completed
- outcome:
succeeded / failed / inconclusive
- succeeded:所有 success criteria 满足
- failed:核心指标未达标
- inconclusive:结果混合或方差过大
- key_result: 一句话总结核心发现
- date_completed: 今天日期
- 填充
## Results section:完整结果表格
- 填充
## Analysis section:初步分析
- 若 remote 模式:更新
remote.completed 时间戳
追加日志:
python3 tools/research_wiki.py log wiki/ \
"exp-run | completed {slug} | outcome: {outcome} | key: {key_result}"
输出 RUN_REPORT 到终端:
# Run Report: {experiment title}
## Outcome: {succeeded / failed / inconclusive}
## Results
| Metric | Baseline | Ours (mean±std) | Δ |
|--------|----------|-----------------|---|
| {metric} | {baseline-value} | {mean}±{std} | +{delta} |
## Key Finding
{key_result}
## Next Steps
- Run `/exp-eval {slug}` to update the linked idea in wiki
- {if succeeded: proceed to next experiment in plan}
- {if failed: analyze failure, consider /exp-design revision}
Full 模式(--full,status == planned)
依次执行全部 4 个 Phase(Phase 1 → Phase 2 → Phase 3 → Phase 4),中间不返回。
适用场景:本地 CPU/GPU 几分钟内可完成的快速实验(sanity check、toy dataset 验证等)。
Phase 3 中不需要先检查 "是否还在运行",而是等待 screen session 真正结束后再执行 Phase 4:
# 等待 session 结束(轮询)
while screen -ls | grep -q "exp-{slug}"; do
sleep 30
done
# session 消失,进入 Phase 4
Constraints
- deploy 模式只接受 planned 实验:若 status 为 running,提示使用 --collect;若为 completed,拒绝执行
- collect 模式只接受 running 实验:若 status 为 planned,提示先 deploy;若为 completed,提示已完成
- collect 模式:alive 时不写 wiki:仅报告进度,不修改任何 wiki 文件
- 代码统一写入 experiments/code/{slug}/:不写到项目根目录或其他位置
- 不修改 idea 状态:实验结果只写入 experiments/ 页面;idea 的 status 由 /exp-eval 负责更新
- sanity check 必须通过:Phase 1 sanity 失败则不部署(除非用户明确 override)
- 结果文件必须保存:所有实验结果以 JSON 格式保存在
results/{slug}/seed_{N}.json
- 多 seed 结果取均值:报告 mean ± std,不报告单次运行
- graph edges 不在此 skill 创建:tested_by 边已在 /exp-design 中创建
- 自动修复最多尝试 1 次:防止无限重启循环
Error Handling
- experiment 找不到:提示用户检查 slug,列出 wiki/experiments/ 中的候选(status=planned 或 running)
- deploy 模式但 status == running:提示 "已在运行中,使用
/exp-run {slug} --collect 检查状态"
- collect 模式但 status == completed:提示 "已完成,直接运行
/exp-eval {slug}"
- GPU 不可用:报告错误,建议用 --env remote 或等待 GPU 释放
- Review LLM 不可用(--review 模式):跳过 code review,在 DEPLOY_REPORT 中标注「unreviewed」
- sanity check 失败:详细报告错误信息,尝试自动修复一次,仍失败则停止并建议手动调试
- 远程连接失败:报告 SSH 错误,建议检查连接配置和 config/server.yaml
- 结果文件缺失(collect 模式):报告哪些 seeds 缺失结果,对已有结果正常汇总;若成功 seeds < 2 则标记 inconclusive
- 实验 crash(collect 模式检测到 traceback):在报告中附上 crash 信息和建议修复方向
- --full 模式等待超时:若 screen session 超过预期时间的 2x 仍存在,警告用户但不强制终止
Dependencies
Skills(via Skill tool)
Tools(via Bash)
python3 tools/research_wiki.py log wiki/ "<message>" — 追加日志
python3 tools/remote.py <command> — 远程操作(status, gpu-status, sync-code, setup-env, launch, check, tail-log, pull-results)
nvidia-smi — 本地 GPU 状态
screen — 本地后台运行管理
Configuration
config/server.yaml — 远程服务器配置(仅 --env remote 时需要)
MCP Servers
mcp__llm-review__chat — Phase 1 代码审查(可选,--review 时使用)
Claude Code Native
Read — 读取 wiki 页面和日志文件
Write — 写入 experiments/code/{slug}/ 下的实验代码
Bash — 执行部署命令、监控进程
Called by
/research Stage 3a(deploy 模式)和 Stage 3c(collect 模式)
/exp-status --collect-ready(collect 模式)
- 用户手动调用
1---2name: exp-run3description: 实验执行全流程:准备代码 → 部署运行(运行前需向用户确认,申请用户手动检查) → 监控状态 → 收集结果,支持三种运行模式4---56# /exp-run78> 执行 wiki/experiments/ 中已规划的实验。9> **不论是哪种运行模式,在准备好实验代码,准备部署运行前需向用户确认,申请用户手动检查代码、实验配置(如数据集路径,接口参数选择,API 配置等)相关信息,确认无误后运行,否则需执行修改直到用户确认执行**10> **三种运行模式**,适应不同场景:11> - **默认(deploy)**:仅 Phase 1-2,部署后立即返回,适合需要数小时/天的实验。12> - **`--collect`**:仅 Phase 3-4,检查已部署实验是否完成,完成则收集结果(`--check` 为 alias)。13> - **`--full`**:完整 Phase 1-4,适合几分钟内即可完成的本地快速实验。14>15> 推荐流程:`/exp-run <slug>` 部署 → `/exp-status` 监控 → `/exp-run <slug> --collect` 收集。1617## Inputs1819- `experiment`:wiki/experiments/ 中的 slug20 - deploy 模式:status 必须为 `planned`21 - --collect 模式:status 必须为 `running`22 - --full 模式:status 必须为 `planned`23- `--review`(可选):Phase 1 中启用 Review LLM code review 审查实验代码(deploy / full 模式有效)24- `--collect`(可选):collect 模式——检查实验是否完成,完成则收集结果;`--check` 是 alias25- `--full`(可选):完整模式——执行全部 4 个 Phase(适合快速本地实验)26- `--env local|remote`(可选,默认 `local`):部署环境27 - `local`:本机 GPU 直接运行28 - `remote`:通过 SSH 部署到远程机器(需 `config/server.yaml`)2930## Outputs3132- **deploy 模式**:33 - 实验代码:`experiments/code/{slug}/`(Phase 1 生成)34 - `wiki/experiments/{slug}.md` — status: planned → running35 - **DEPLOY_REPORT**(输出到终端)— 部署确认、session 信息、下一步指引36 - `wiki/log.md` — 追加部署日志37- **collect 模式**(实验已完成时):38 - `wiki/experiments/{slug}.md` — status: running → completed,填充 outcome/key_result/date_completed39 - **RUN_REPORT**(输出到终端)— 结果摘要、metrics 对比、下一步建议40 - `wiki/log.md` — 追加收集日志41- **collect 模式**(实验仍在运行时):42 - 仅输出进度报告到终端,不修改 wiki43- **full 模式**:同 deploy + collect 的全部输出4445## Wiki Interaction4647### Reads48- `wiki/experiments/{slug}.md` — 实验配置:setup、metrics、baseline、hypothesis、linked_idea49- `wiki/ideas/{linked-idea}.md` — 关联 idea 的 approach sketch(指导代码实现,理解实验目的)50- `wiki/papers/*.md` — 相关论文的方法细节和超参数(参考实现)51- `wiki/experiments/*.md` — 同一 idea 的其他实验(参考 setup、避免重复错误)5253### Writes54- `experiments/code/{slug}/` — 实验代码目录(Phase 1 生成,deploy / full 模式)55 - `experiments/code/{slug}/train.py` — 主训练/推理脚本56 - `experiments/code/{slug}/config.yaml` — 超参数配置文件57 - `experiments/code/{slug}/run.sh` — 启动封装脚本(含 CUDA_VISIBLE_DEVICES 等)58 - `experiments/code/{slug}/requirements.txt` — 依赖(若与主项目不同)59- `wiki/experiments/{slug}.md` — 更新 status、outcome、key_result、date_completed、run_log、remote 块(deploy / collect 模式)60- `wiki/log.md` — 追加操作日志6162### Graph edges created63- **无**。实验与 idea 之间的 tested_by 边已在 /exp-design 中创建。6465## Workflow6667**前置**:确认工作目录为 wiki 项目根(包含 `wiki/`、`raw/`、`tools/` 的目录)。6869---7071### Deploy 模式(默认,status == planned)7273**Phase 1: 准备(Prepare)**74751. **读取实验页面**:76 - `wiki/experiments/{slug}.md`:提取 setup(model, dataset, hardware, framework)、metrics、baseline、hypothesis77 - 验证 status == `planned`78 - 若 status 为 `running`,提示用户使用 `--collect` 模式79 - 若 status 为 `completed`/`abandoned`,拒绝执行80812. **加载实现上下文**:82 - 读取关联 idea 的 approach sketch(实现指南)83 - 读取相关论文的方法描述(算法细节)84 - 读取同一 idea 的其他实验(参考代码结构)85863. **检验数据集以及其余配置**87 - 数据集在`wiki/experiments/{slug}.md`的setup 中有指定88 - 获取数据集路径(根据 --env 参数选择在本地或远程获取),**可向用户询问本地(远程)的数据集的路径以及自行检索**89 - 若 数据集不存在,向用户提示,明确**下载数据集的需求**,向用户确认**安装路径**及**下载渠道**90 - 检查数据集是否完整、可用,明确数据集附带的一些结构、使用说明91 - 其余配置如:调用LLM的模型名称,url,api key等92934. **编写实验代码**,统一写入 `experiments/code/{slug}/`:94 **代码的编写模块化思想,除非实验规模较小,逻辑简单,否则不要把大量代码放在一个文件里**95 - `train.py`:根据 setup 配置生成训练/评估脚本,作为程序的入口,包含:96 - 参数解析(argparse,所有超参数可配置)97 - 数据加载(支持 setup.dataset)98 - 模型初始化(支持 setup.model 和 baseline 模型)99 - 训练/推理循环100 - 指标计算(对应 metrics 列表)101 - 结果保存(JSON 格式,路径:`results/{slug}/seed_{N}.json`)102 - 随机种子控制(多 seed 运行)103 - Checkpoint 保存/恢复(`checkpoints/{slug}/`)104 - 其余所需的utils、tools 等代码文件夹或者文件(如 `utils.py`、`data_loader.py` 等)105 - `config.yaml`:所有超参数(learning_rate, batch_size, epochs, seeds 等)106 - `run.sh`:封装完整启动命令(含 CUDA_VISIBLE_DEVICES、logging、conda 激活)107 - `requirements.txt`:实验专属依赖(若与主项目 requirements 不同)1081095. **可选 Review LLM code review**(`--review`):110 ```111 mcp__llm-review__chat:112 system: "You are a senior ML engineer reviewing experiment code.113 Focus on: correctness of the training loop, proper evaluation protocol,114 fair baseline comparison, reproducibility (seeds, determinism),115 proper metric computation, and common pitfalls (data leakage,116 wrong split, gradient accumulation bugs)."117 message: |118 ## Experiment119 {experiment title and hypothesis}120121 ## Code122 {generated code}123124 ## Expected Behavior125 {setup details from wiki page}126127 Review for correctness and potential issues.128 ```129 根据 Review LLM 反馈修正代码。1301316. **Sanity check(小规模验证)**:132 - 用极小规模运行(1 epoch / 100 steps / 小 subset)133 - 验证:代码无 crash、数据加载正确、GPU 可用、loss 下降134 - 若 sanity 失败 → 修复代码,重试一次;仍然失败则报告错误并停止135136137**Gate: 用户手动检查**138139> **注意**:在准备好实验代码,准备部署运行前需向用户确认,申请用户手动检查代码、实验配置(数据集路径,接口参数选择,API 配置等)相关信息,确认无误后运行,否则需执行修改直到用户确认执行140141142**Phase 2: 部署(Deploy)**143144#### Local 模式(`--env local` 或默认)1451461. **检查 GPU**:`nvidia-smi` 确认 GPU 可用、显存足够。若 `setup.hardware` 为 `cpu`/`none`/空且生成代码无 CUDA/GPU 关键字,跳过 GPU 检查直接进入步骤 2。1472. **启动**:148 ```bash149 screen -dmS exp-{slug} bash -c \150 "cd $(pwd) && bash experiments/code/{slug}/run.sh 2>&1 | tee logs/exp-{slug}.log"151 ```1523. 更新 `wiki/experiments/{slug}.md`:153 - status: `running`154 - run_log: `logs/exp-{slug}.log`1554. **估算运行时长**,写入 frontmatter:156 根据 `setup.hardware`(GPU 型号/数量)、`setup.model`(参数量)、`setup.dataset`(规模)合理估算:157158 | 典型场景 | 估算范围 |159 |----------|----------|160 | 单 GPU + 小数据集(CIFAR / 小 NLP benchmark) | 0.5 – 3h |161 | 单 A100 + 中等数据集(ImageNet / GLUE) | 4 – 12h |162 | 多 GPU 或大模型 fine-tuning(≥7B) | 8 – 48h |163164 ```bash165 python3 tools/research_wiki.py set-meta \166 wiki/experiments/{slug}.md started "{YYYY-MM-DDTHH:MM}"167 python3 tools/research_wiki.py set-meta \168 wiki/experiments/{slug}.md estimated_hours {N}169 ```1705. 追加日志:171 ```bash172 python3 tools/research_wiki.py log wiki/ \173 "exp-run | deployed {slug} | env: local | session: exp-{slug} | eta: {N}h"174 ```175176#### Remote 模式(`--env remote`)177178**前提**:用户已配置 `config/server.yaml`。1791801. **确认连通**:`python3 tools/remote.py status`181 - 若不可达 → 报错并建议检查 config/server.yaml1822. **查找空闲 GPU**:`python3 tools/remote.py gpu-status`(若 `setup.hardware` 为 `cpu`/`none`/空且代码无 CUDA/GPU 关键字则跳过)183 - 若无空闲 GPU → 报告各 GPU 占用情况,建议等待1843. **同步代码**:`python3 tools/remote.py sync-code`1854. **安装依赖**(首次或 requirements 有变化):`python3 tools/remote.py setup-env`1865. **启动远程实验**:187 ```bash188 python3 tools/remote.py launch \189 --name "exp-{slug}" \190 --cmd "bash experiments/code/{slug}/run.sh" \191 --gpu {gpu_index}192 ```1936. 更新 `wiki/experiments/{slug}.md` frontmatter —— 以下字段已由 /exp-design 写入完整 CLAUDE.md 模板,都是空值:194 ```bash195 # 顶层 scalar 字段 —— 用 set-meta196 python3 tools/research_wiki.py set-meta wiki/experiments/{slug}.md status running197 python3 tools/research_wiki.py set-meta wiki/experiments/{slug}.md run_log "logs/exp-{slug}.log"198 ```199200 嵌套 `remote:` 块无法通过 `set-meta` 更新(set-meta 只处理顶层 scalar 字段)。直接用 `Edit` 工具就地替换这五个空的子字段值。文件里已有的 block 形如:201 ```yaml202 remote:203 server: ""204 gpu: ""205 session: ""206 started: ""207 completed: ""208 ```209 用 5 次 Edit 调用(每个子字段一次)设置 `server`、`gpu`、`session`、`started`。`completed: ""` 留空由 Phase 4 填写。如果发现文件里没有 `remote:` block,说明 /exp-design 没写完整的 CLAUDE.md 模板;停下来报 bug,不要在这里追加 block(追加会让字段顺序偏离 canonical 模板,破坏后续 edit 的匹配)。2107. **估算运行时长**,写入 frontmatter(同 local 模式估算逻辑):211 ```bash212 python3 tools/research_wiki.py set-meta \213 wiki/experiments/{slug}.md started "{YYYY-MM-DDTHH:MM}"214 python3 tools/research_wiki.py set-meta \215 wiki/experiments/{slug}.md estimated_hours {N}216 ```2178. 追加日志:218 ```bash219 python3 tools/research_wiki.py log wiki/ \220 "exp-run | deployed {slug} | env: remote | server: {host} | gpu: {gpu} | eta: {N}h"221 ```222223**输出 DEPLOY_REPORT 到终端**:224225```markdown226# Deploy Report: {experiment title}227228### Status: DEPLOYED ✅229230- Session: exp-{slug}231- Environment: local | remote ({host} GPU {gpu})232- Log file: logs/exp-{slug}.log233- Code: experiments/code/{slug}/234- Estimated: ~{N}h(预计完成于 {YYYY-MM-DD HH:MM})235236### Next Steps2372381. Monitor progress: `/exp-status`2392. Check this experiment: `/exp-run {slug} --collect`2403. In /research pipeline: progress saved to wiki/outputs/pipeline-progress.md241242### Quick Commands243```bash244# Local: check if still running245screen -ls | grep exp-{slug}246247# Local: tail log248tail -f logs/exp-{slug}.log249```250```251252---253254### Collect 模式(`--collect` 或 `--check`,status == running)255256**Phase 3: 监控/检查运行状态(Monitor)**2572581. **读取部署信息**:从 `wiki/experiments/{slug}.md` frontmatter 获取环境(local 或 remote)和 session 名。2592602. **检查进程是否还活着**:261 - **Local**:`screen -ls | grep exp-{slug}`262 - **Remote**:`python3 tools/remote.py check --name "exp-{slug}"`,解析 `alive` 字段2632643. **若实验仍在运行(alive == true)**:265 - 获取最近日志:266 - Local:`tail -30 logs/exp-{slug}.log`267 - Remote:`python3 tools/remote.py tail-log --name "exp-{slug}" --lines 30`268 - **异常检测**:269 - NaN loss:检测 `loss: nan`270 - OOM:`CUDA out of memory`271 - Traceback:Python 异常堆栈272 - Inf loss:`loss: inf`273 - **自动修复尝试**(若检测到异常,最多 1 次):274 - NaN/爆炸 → 从最近 checkpoint 恢复,降低学习率275 - OOM → 减小 batch size,重启276 - **输出进度报告**(不修改 wiki,仅报告):277 ```278 Experiment {slug}: RUNNING279 Progress: step {N} / epoch {E}280 Latest metric: {metric} = {value}281 Anomalies: {none | NaN detected | ...}282 Estimated remaining: ~{N} hours283 Run `/exp-status` to monitor all running experiments.284 ```285 - **返回**(不执行 Phase 4)2862874. **若实验已完成(alive == false / session gone)**:288 - 继续执行 Phase 4289290**Phase 4: 收集结果(Collect Results)**2912921. **拉取远程结果**(仅 remote 模式):293 ```bash294 python3 tools/remote.py pull-results \295 --remote-path "results/{slug}/" \296 --local-path "./results/{slug}/"297298 python3 tools/remote.py pull-results \299 --remote-path "logs/exp-{slug}.log" \300 --local-path "./logs/"301 ```3023032. **检查结果文件存在**:`results/{slug}/seed_*.json`3043053. **解析结果**:306 - 读取结果文件(JSON)307 - 计算每个 metric 的 mean ± std(跨 seeds)308 - 与 baseline 对比,计算提升幅度3093104. **更新实验页面** `wiki/experiments/{slug}.md`:311 - status: `completed`312 - outcome: `succeeded` / `failed` / `inconclusive`313 - succeeded:所有 success criteria 满足314 - failed:核心指标未达标315 - inconclusive:结果混合或方差过大316 - key_result: 一句话总结核心发现317 - date_completed: 今天日期318 - 填充 `## Results` section:完整结果表格319 - 填充 `## Analysis` section:初步分析320 - 若 remote 模式:更新 `remote.completed` 时间戳3213225. **追加日志**:323 ```bash324 python3 tools/research_wiki.py log wiki/ \325 "exp-run | completed {slug} | outcome: {outcome} | key: {key_result}"326 ```3273286. **输出 RUN_REPORT 到终端**:329 ```markdown330 # Run Report: {experiment title}331332 ## Outcome: {succeeded / failed / inconclusive}333334 ## Results335 | Metric | Baseline | Ours (mean±std) | Δ |336 |--------|----------|-----------------|---|337 | {metric} | {baseline-value} | {mean}±{std} | +{delta} |338339 ## Key Finding340 {key_result}341342 ## Next Steps343 - Run `/exp-eval {slug}` to update the linked idea in wiki344 - {if succeeded: proceed to next experiment in plan}345 - {if failed: analyze failure, consider /exp-design revision}346 ```347348---349350### Full 模式(`--full`,status == planned)351352依次执行全部 4 个 Phase(Phase 1 → Phase 2 → Phase 3 → Phase 4),中间不返回。353354适用场景:本地 CPU/GPU 几分钟内可完成的快速实验(sanity check、toy dataset 验证等)。355356Phase 3 中不需要先检查 "是否还在运行",而是等待 screen session 真正结束后再执行 Phase 4:357```bash358# 等待 session 结束(轮询)359while screen -ls | grep -q "exp-{slug}"; do360 sleep 30361done362# session 消失,进入 Phase 4363```364365---366367## Constraints368369- **deploy 模式只接受 planned 实验**:若 status 为 running,提示使用 --collect;若为 completed,拒绝执行370- **collect 模式只接受 running 实验**:若 status 为 planned,提示先 deploy;若为 completed,提示已完成371- **collect 模式:alive 时不写 wiki**:仅报告进度,不修改任何 wiki 文件372- **代码统一写入 experiments/code/{slug}/**:不写到项目根目录或其他位置373- **不修改 idea 状态**:实验结果只写入 experiments/ 页面;idea 的 status 由 /exp-eval 负责更新374- **sanity check 必须通过**:Phase 1 sanity 失败则不部署(除非用户明确 override)375- **结果文件必须保存**:所有实验结果以 JSON 格式保存在 `results/{slug}/seed_{N}.json`376- **多 seed 结果取均值**:报告 mean ± std,不报告单次运行377- **graph edges 不在此 skill 创建**:tested_by 边已在 /exp-design 中创建378- **自动修复最多尝试 1 次**:防止无限重启循环379380## Error Handling381382- **experiment 找不到**:提示用户检查 slug,列出 wiki/experiments/ 中的候选(status=planned 或 running)383- **deploy 模式但 status == running**:提示 "已在运行中,使用 `/exp-run {slug} --collect` 检查状态"384- **collect 模式但 status == completed**:提示 "已完成,直接运行 `/exp-eval {slug}`"385- **GPU 不可用**:报告错误,建议用 --env remote 或等待 GPU 释放386- **Review LLM 不可用**(--review 模式):跳过 code review,在 DEPLOY_REPORT 中标注「unreviewed」387- **sanity check 失败**:详细报告错误信息,尝试自动修复一次,仍失败则停止并建议手动调试388- **远程连接失败**:报告 SSH 错误,建议检查连接配置和 config/server.yaml389- **结果文件缺失**(collect 模式):报告哪些 seeds 缺失结果,对已有结果正常汇总;若成功 seeds < 2 则标记 inconclusive390- **实验 crash**(collect 模式检测到 traceback):在报告中附上 crash 信息和建议修复方向391- **--full 模式等待超时**:若 screen session 超过预期时间的 2x 仍存在,警告用户但不强制终止392393## Dependencies394395### Skills(via Skill tool)396- 无直接调用子 skill397398### Tools(via Bash)399- `python3 tools/research_wiki.py log wiki/ "<message>"` — 追加日志400- `python3 tools/remote.py <command>` — 远程操作(status, gpu-status, sync-code, setup-env, launch, check, tail-log, pull-results)401- `nvidia-smi` — 本地 GPU 状态402- `screen` — 本地后台运行管理403404### Configuration405- `config/server.yaml` — 远程服务器配置(仅 `--env remote` 时需要)406407### MCP Servers408- `mcp__llm-review__chat` — Phase 1 代码审查(可选,`--review` 时使用)409410### Claude Code Native411- `Read` — 读取 wiki 页面和日志文件412- `Write` — 写入 `experiments/code/{slug}/` 下的实验代码413- `Bash` — 执行部署命令、监控进程414415### Called by416- `/research` Stage 3a(deploy 模式)和 Stage 3c(collect 模式)417- `/exp-status --collect-ready`(collect 模式)418- 用户手动调用