Organize Open-SWE-Traces data prep project
This commit is contained in:
147
README.md
Normal file
147
README.md
Normal file
@@ -0,0 +1,147 @@
|
||||
# TI Coding Agent Data Prep
|
||||
|
||||
这个仓库用于整理 `nvidia/Open-SWE-Traces` 的数据准备流程,目标是把原先分散在 probe 目录里的脚本项目化,形成三个清晰阶段:
|
||||
|
||||
1. `probing`:检查数据结构、统计唯一 problem/repo、比较 tokenizer、统计 token。
|
||||
2. `filtering`:对原始 trajectory 做 hard filter/audit,筛掉明显不适合作为 SFT 训练样本的轨迹。
|
||||
3. `repurposing`:把筛选后的轨迹拆解成阶段化子任务,或导出为 ModelScope-SWIFT / pi-mono 相关格式。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```text
|
||||
.
|
||||
├── data/ # 本地数据目录,不进 git
|
||||
│ └── Open-SWE-Traces/ # 建议放 nvidia/Open-SWE-Traces clone 或下载结果
|
||||
├── docs/
|
||||
│ └── legacy_subproblem_decomposition_README.md
|
||||
├── runs/ # 所有脚本输出目录,不进 git
|
||||
├── scripts/
|
||||
│ ├── probing/ # 探查、统计、tokenizer/token 相关脚本
|
||||
│ ├── filtering/ # native trace audit / hard filter
|
||||
│ └── repurposing/ # 子问题拆解、SWIFT 导出、pi-mono 格式转换
|
||||
├── src/ti_coding_agent_data_prep/
|
||||
│ └── openswe/ # 共享常量和路径 helper
|
||||
├── pyproject.toml
|
||||
├── README.md
|
||||
└── SKILL.md
|
||||
```
|
||||
|
||||
## 环境部署
|
||||
|
||||
建议只使用 repo-local 环境,避免污染共享机器:
|
||||
|
||||
```bash
|
||||
cd /ssd/workspace/yi/ti_coding_agent_data_prep
|
||||
export http_proxy=http://100.72.0.101:8888
|
||||
export https_proxy=http://100.72.0.101:8888
|
||||
export HTTP_PROXY=http://100.72.0.101:8888
|
||||
export HTTPS_PROXY=http://100.72.0.101:8888
|
||||
export HF_ENDPOINT=https://hf-mirror.com
|
||||
|
||||
uv venv .venv --python 3.10
|
||||
source .venv/bin/activate
|
||||
uv pip install -e '.[dev]'
|
||||
```
|
||||
|
||||
如果不用 `uv`,也可以用普通 venv 后执行 `pip install -e '.[dev]'`。
|
||||
|
||||
## 数据准备
|
||||
|
||||
默认所有脚本都从 `data/Open-SWE-Traces` 读取数据。可以把已有数据软链进来:
|
||||
|
||||
```bash
|
||||
cd /ssd/workspace/yi/ti_coding_agent_data_prep
|
||||
ln -s /ssd/workspace/yi/openswetraces_probe/Open-SWE-Traces data/Open-SWE-Traces
|
||||
```
|
||||
|
||||
## Probing 入口
|
||||
|
||||
检查样本结构:
|
||||
|
||||
```bash
|
||||
python scripts/probing/inspect_sample.py
|
||||
```
|
||||
|
||||
统计 unique instance/repo,并随机拆 20 条 fine-grained subproblem:
|
||||
|
||||
```bash
|
||||
python scripts/probing/analyze_and_decompose.py
|
||||
```
|
||||
|
||||
比较 Qwen tokenizer:
|
||||
|
||||
```bash
|
||||
python scripts/probing/compare_qwen_tokenizers.py
|
||||
```
|
||||
|
||||
精确统计 Qwen token 数,输出会持续写入 `runs/native_trace_audit/qwen_exact_token_count.json`:
|
||||
|
||||
```bash
|
||||
python scripts/probing/count_qwen_tokens_exact_parallel.py \
|
||||
--input-root data/Open-SWE-Traces \
|
||||
--output runs/native_trace_audit/qwen_exact_token_count.json \
|
||||
--model Qwen/Qwen3-32B \
|
||||
--workers 12
|
||||
```
|
||||
|
||||
## Filtering 入口
|
||||
|
||||
对 native trajectory 做 hard filter/audit:
|
||||
|
||||
```bash
|
||||
python scripts/filtering/audit_native_traces.py \
|
||||
--input-root data/Open-SWE-Traces \
|
||||
--output-dir runs/native_trace_audit
|
||||
```
|
||||
|
||||
主要 hard filter 覆盖:
|
||||
|
||||
- malformed tool call JSON
|
||||
- tool call/result 对不上
|
||||
- tool 名或参数被模型输出污染
|
||||
- final patch 为空或不是合理 diff
|
||||
- patch 文件和 trajectory 明显不一致
|
||||
- trajectory 过长
|
||||
- 重复、无推进的 tool loop
|
||||
- unresolved 且明显走偏
|
||||
|
||||
## Repurposing 入口
|
||||
|
||||
把 fine-grained 子问题合并为粗阶段:
|
||||
|
||||
```bash
|
||||
python scripts/repurposing/coarse_decompose.py
|
||||
```
|
||||
|
||||
构建 5k ModelScope-SWIFT training probe:
|
||||
|
||||
```bash
|
||||
python scripts/repurposing/build_swift_training_probe_5k.py
|
||||
```
|
||||
|
||||
构建 500 条 validation split:
|
||||
|
||||
```bash
|
||||
python scripts/repurposing/build_swift_validation_500.py
|
||||
```
|
||||
|
||||
SWIFT 导出的关键策略:
|
||||
|
||||
- MiniMax 样本按 thinking 模式处理,`reasoning_content` 会包成 `<think>...</think>` 放入 assistant content。
|
||||
- Qwen 样本按 non-thinking 模式处理,不主动加入 reasoning 内容;异常非空 reasoning 会计数。
|
||||
- `system`、`user`、`tool` message 标记为 `loss=false`,只让 assistant 输出参与 loss。
|
||||
|
||||
尝试转换到 pi-mono 风格消息:
|
||||
|
||||
```bash
|
||||
python scripts/repurposing/convert_openswe_to_pi_mono.py \
|
||||
--input-root data/Open-SWE-Traces \
|
||||
--output-root runs/pi_mono_converted
|
||||
```
|
||||
|
||||
注意:pi-mono 转换脚本保留为研究/兼容入口。由于不同 scaffold 的 system prompt、tool schema、tool call 语义不同,最安全的训练路径仍是优先保留 native trace 格式并筛掉坏样本。
|
||||
|
||||
## 输出产物
|
||||
|
||||
`runs/` 和 `data/` 默认不进 git。推荐把所有大文件、parquet、jsonl、token 统计、audit report 都留在这两个目录下。
|
||||
|
||||
Reference in New Issue
Block a user