SWE-smith 部署与问题解决技术报告

这篇记录部署和跑通 SWE-smith(一个批量生成软件工程任务的工具)时踩的一串坑。SWE-smith 本身是多组件系统:bug 生成、验证、补丁收集、issue 生成串成一条流水线,任何一环卡住整条就跑不动。

权限:推不上去

第一个坑在 python -m swesmith.harness.gather,git push 直接 128:

subprocess.CalledProcessError: Command 'git push origin catchorg__Catch2.9b3f508a.func_pm_ctrl_invert_if__7p0kyikq' returned non-zero exit status 128.
ERROR: Permission to swesmith/catchorg__Catch2.9b3f508a.git denied to fredsun02.

原因是原始代码把镜像仓库建在 swesmith 组织下,而我的 GitHub Token 没有往这个组织推的权限。改 swesmith/constants.py,把组织名换成自己的账号,镜像仓库就都建到个人名下了:

# ORG_NAME_GH = "swesmith"
ORG_NAME_GH = "fredsun02"

内存:进程被 kill

issue 生成阶段直接 OOM,exit code 137:

exit code 137  # 内存不足

机器只有 1.9GB 内存,而代码要加载 SWE-bench_VerifiedSWE-bench/SWE-smith 这些大数据集,再加上本地模型,根本扛不住。两头下手。一是用 API 顶掉本地模型,加个精简配置 configs/issue_gen/ig_api.yaml

model: anthropic/claude-3-5-sonnet-20241022
system: |-
  You are a software engineer helping to create a realistic dataset of synthetic GitHub issues.  
demonstration: ""

二是改 swesmith/issue_gen/generate.py,把 SWE-bench_Verified 改成延迟加载、只在真正需要时才拉,本地数据集则跳过多余的过滤。

一串依赖与代码错

后面是几个连续的版本和代码问题,逐个修。

litellmopenai 版本不兼容:

ImportError: cannot import name 'ResponseTextConfig' from 'openai.types.responses.response'
pip install --upgrade openai litellm

静态 issue 生成引用了不存在的常量:

ImportError: cannot import name 'PM_TECHNIQUES_CLASSES' from 'swesmith.bug_gen.procedural.generate'

swesmith/issue_gen/get_static.py 的导入:

# from swesmith.bug_gen.procedural.generate import PM_TECHNIQUES_CLASSES, PM_TECHNIQUES_FUNCS
from swesmith.bug_gen.procedural import MAP_EXT_TO_MODIFIERS

F2P 方法少传一个参数:

TypeError: run_command_in_container() missing 1 required positional argument: 'rp'

swesmith/issue_gen/get_from_tests.py 里补上 rp

# test_output = run_command_in_container(instance, cmd)
test_output = run_command_in_container(instance, cmd, rp)

跑通后的完整流程

修完之后,一条完整的 SWE-smith 流程是这样:

  1. Bug 生成
    python -m swesmith.bug_gen.procedural.generate --repo catchorg/Catch2 --n_instances 10
    
  2. 验证
    python -m swesmith.harness.validate --dataset_path logs/bug_gen/catchorg__Catch2.9b3f508a_all_patches.json
    
  3. 收集补丁
    python -m swesmith.harness.gather logs/run_validation/catchorg__Catch2.9b3f508a/ --debug_subprocess
    
  4. Issue 生成(三选一)
    • API:python -m swesmith.issue_gen.generate -d logs/task_insts/catchorg__Catch2.9b3f508a.json -c configs/issue_gen/ig_api.yaml -w 1
    • 静态:python -m swesmith.issue_gen.get_static logs/task_insts/catchorg__Catch2.9b3f508a.json
    • F2P:python -m swesmith.issue_gen.get_from_tests logs/task_insts/catchorg__Catch2.9b3f508a.json

最终生成了 10 个 bug 分支并推到 GitHub、9 个 issue 和一套完整的任务实例数据集。API 方式处理 9 个实例总成本约 $0.152,平均每个约 $0.017。回头看,坑基本集中在三处:权限(组织 vs 个人账号)、资源(内存受限就优先用 API 加延迟加载)、以及依赖版本和过时的导入/调用。