Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 26 additions & 58 deletions research/finance_program_v1/README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,37 @@
# Finance Program:non-training 与第一版 Planner SFT
# 金融 Program 主干:原版 F66 + Planner SFT

本目录保留 non-training、教师轨迹采集、第一版学生 Planner SFT 的代码,以及完整金融 **Val422** 的同接口配对评估结果。它是独立研究快照,不替换仓库原应用。
本目录围绕一个实验问题组织:**同一 F66 Program/Skill 框架下,只训练 Planner,是否能改善未训练 Planner 的分类与终止表现?** 主干是 Teacher200 → Planner-only LoRA SFT → `base` / `sft` 固定来源配对评估。

## 完整 Val422 结果
本次整理基于 GitHub 原版 `b6fde9b80802593ad8ab30bdfae66fc28483a849`,只整理金融 Program。运行代码的改动限排版和注释;提示词、Skill body、原控制流、预算、adapter 路由、训练目标和已有结果保持原版语义。2026-11-09 本地 recovery 修复版不在此目录。

两组均为 Qwen3.5-9B,在相同 F66 Program/Skill 框架、输入与执行预算下比较:
## 先读哪些文件

- **ProgSkill / `base`**:未微调 Planner,仍调用 Skill,**不是直接回答的纯 Base-LLM**。
- **DCG-SFT / `sft`**:只加载第一版 Planner SFT A;所有模型型 Skill 继续使用原始基座并禁用 adapter。
1. [完整实验协议](docs/EXPERIMENT_PROTOCOL.md):条件、数据、训练、推理、评分和可比范围。
2. [代码职责与数据流](docs/ARCHITECTURE.md):从 Planner 到执行器、模型路由和审计。
3. [运行与验证说明](REPRODUCE.md):可直接运行的 CPU 检查,以及真实复现还需要的资产。
4. [历史快照说明](docs/HISTORY.md):为什么旧 P14 不再作为第二套 non-training 主干。

共 **422 个唯一配对、844 条正式轨迹**。失败与未终止均保留在每组 422 的分母内,双方无缺失。

| 指标 | ProgSkill:未微调 Planner | DCG-SFT:第一版 Planner SFT | 提升 |
| --- | ---: | ---: | ---: |
| 类别正确率 | 79/422,18.72% | **171/422,40.52%** | +21.80 个百分点 |
| 等级正确率 | 111/422,26.30% | **230/422,54.50%** | +28.20 个百分点 |
| 类别与等级联合正确率 | 79/422,18.72% | **171/422,40.52%** | +21.80 个百分点 |
| 合法终止率 | 191/422,45.26% | **420/422,99.53%** | +54.27 个百分点 |
| 首次 Top-5 命中率 | 177/422,41.94% | **251/422,59.48%** | +17.54 个百分点 |
| 最终 Top-5 命中率 | 177/422,41.94% | **251/422,59.48%** | +17.54 个百分点 |
| 任次 Top-5 命中率 | 177/422,41.94% | **251/422,59.48%** | +17.54 个百分点 |
| 类别 Macro-F1:8 个有支持类别 | 0.18845 | **0.32218** | +0.13373 |
| 类别 Macro-F1:固定 12 类 | 0.12563 | **0.21479** | +0.08916 |
| 未合法终止 | 231 | **2** | 减少 229 条 |
| 缺失轨迹 | 0 | 0 | 无缺失 |

逐 ID 配对联合正确性:**99 条改善、7 条退步,净增加 92 条正确结果**。三种 Top-5 口径分别计算,本轮数值恰好相同。合法终止率不等于业务正确率。

| 调用与成本(422 条/组) | ProgSkill | DCG-SFT | 相对减少 |
| --- | ---: | ---: | ---: |
| 模型调用总数 | 2,897 | 1,695 | 41.49% |
| 平均模型调用数/来源 | 6.86 | 4.02 | 41.49% |
| 输入 token 总数 | 30,563,818 | 11,128,130 | 63.59% |
| 输出 token 总数 | 319,905 | 93,618 | 70.74% |
| 平均来源执行耗时 | 34.03 秒 | 11.03 秒 | 67.58% |

耗时为各来源执行 receipt 的均值,包含失败来源,不是整轮墙钟或服务时延承诺。原已验证部分精确复用,其余来源唯一补充,完整集合无重叠遗漏;没有按结果重跑或筛除。原、新两个阶段墙钟分别保存于 JSON,不能当作同一次完整运行的墙钟测量。

## 代码与结果目录

| 目录 | 内容 |
| 目录 | 主干职责 |
| --- | --- |
| `nontraining/` | 历史 non-training 执行及审计代码;历史接口不作为本表的严格配对对照 |
| `teacher/` | **百炼 `qwen3.8-2.4t-a95b`** 的教师轨迹采集代码,不是 9B 教师模型 |
| `sft/` | 第一版 Qwen3.5-9B Planner-only LoRA,200 个训练来源 |
| `evaluation/` | 原同接口评估、模型路由和控制器回放代码快照;示例数据为合成测试 fixture,不是完整真实验证数据 |
| `trajectories/` | 教师 200 条、完整验证 `base` 422 条与 `sft` 422 条,共 **1,044 条脱敏公开轨迹** |
| `tools/`、`publication_tests/` | 轨迹脱敏工具与隐私回归测试 |
| `results/` | [完整指标](results/evidence-summary.json)、[轨迹清单与 SHA](results/trajectory-export.json)、[模型角色](results/model-roles.json)、[验证说明](results/publication-verification.json) |

## 验证与隐私边界

所有服务器阶段及完整回放成功退出;本机从各自解包目录再次完整回放,并逐 SHA 核验原始证据全部成员及 844 份正式轨迹。逐 ID 指标、配对统计和两种 Macro-F1 已独立重算。聚合 JSON 保留证据 SHA 依赖,但不发布私有目录和来源 ID。

公开轨迹只保留 Program、实际步骤状态、最终类别/等级与原 trace SHA;业务元数据、原始消息、推理文本和语义证据已脱敏。两组学生使用一致的顺序公开编号;无私有 ID 映射。它们**不是训练数据,也不是完整控制器回放输入**。教师轨迹保持不变。

这是开发验证集、单 seed,仅 8/12 类有支持,且来源可能共享表;不是独立 Test 或跨领域泛化结论。教育与钢铁数据集不在本轮结果内。该更新只替换结果展示和学生公开轨迹,不修改实验代码、权重或训练设置。

真实数据集、gold、权重、凭证和实验服务器地址均不上传。clone/import 不会启动任何训练、GPU 或 API 作业。复现说明见 [REPRODUCE.md](REPRODUCE.md)。
| `teacher/` | 百炼 `qwen3.8-2.4t-a95b` 的采集、显式策略、传输重试和账本 |
| `sft/` | 真实 Planner Program JSON + EOS 的数据导出、分词和第一版 LoRA SFT |
| `evaluation/runtime/` | **唯一主干 runtime**:原版 F66 控制器、binder、Skill 与 terminal guard;两臂共享 |
| `evaluation/` | 仅 Planner 启用 adapter 的路由、执行、原调用回放、身份检查和指标 |
| `nontraining/README.md` | 未训练 Planner 条件的导航;直接指向同一 F66 runtime,没有第二套复制代码 |
| `results/`、`trajectories/` | 原聚合结果和1044条脱敏轨迹,字节不变 |
| `tools/`、`publication_tests/` | 脱敏与公开依赖验证;CPU 检查不运行真实模型 |

## 发布依赖修复(2026-10-19)
## 已发布的同协议 Val422 结果

补回历史批次审计模块与源代码/官方模型哈希清单、教师录制调用回放助手,以及评估旧后端的SHA清单工具。未改变模型、实验协议、训练参数、结果数字或公开轨迹。
每组固定422来源,合844条正式轨迹。`base` 是**未训练 Planner 调用 Skills**,不是直接回答的 Base-LLM;`sft` 只启用第一版 Planner adapter,模型型 Skill 两臂均用基座。

`pool_metadata.py` 位于 `nontraining/vendor/` 和 `evaluation/runtime/vendor/`,不是仓库根目录模块。通过 `program_loop` 导入时会初始化对应的vendor路径;若只使用该工具,请按 [REPRODUCE.md](REPRODUCE.md) 设置明确的导入路径。新增隔离进程回归覆盖批次入口、完整合成回放和请求篡改拒绝。
| 指标 | base / ProgSkill | sft / DCG-SFT |
| --- | ---: | ---: |
| 类别匹配 | 79/422(18.72%) | 171/422(40.52%) |
| 等级匹配 | 111/422(26.30%) | 230/422(54.50%) |
| 合法终止 | 191/422(45.26%) | 420/422(99.53%) |
| 实际模型调用 | 2897 | 1695 |

**代码依赖补齐不等于发布了私有数据/历史执行目录。** 历史 `teacher/collect.py`、`teacher/detached.py`、评估watcher/legacy环境身份仍要求经授权的原始配置、manifest、ledger或数据;不得直接运行它们来启动付费请求/GPU。公开CPU测试不需要这些私有资产。
逐来源有99改善、7退化。完整分母、Top5、F1、成本与阶段墙钟保存在 [evidence-summary.json](results/evidence-summary.json)。本次未重新训练、生成或评分;旧结果不是本次排版后的新实验。

Val422 是已观察开发集,只有8/12类有支持、来源可能共享业务上下文;它不提供专家 Gold 或独立业务族保证。合法终止不等于业务正确。公开轨迹脱敏有损,不能用于全量控制器回放或直接训练。M8/M9/M10、后续 Skill SFT 和其他 RL/领域实验不属于这份第一版 Planner 主干协议,不能与本表直接拼成统一对照。
83 changes: 23 additions & 60 deletions research/finance_program_v1/REPRODUCE.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,38 @@
# Reproduction and publication boundaries
# 金融主干运行与复现

## CPU tests
先读 [实验协议](docs/EXPERIMENT_PROTOCOL.md)。在 `research/finance_program_v1` 工作;Python3.11+。原公开验证环境曾用Python3.13/Torch2.9 CPU。真实9B历史环境为Torch2.9、Transformers5.10.4、PEFT0.21、Accelerate1.15;这里只说明历史环境,不在import/test时安装或下载。

Run stages in separate processes from their own directories; names such as `gate` and `io_utils` are intentionally local:
## 可直接运行:CPU测试

以下阶段使用合成/录制I/O,分别启动进程,避免同名 `gate`/`io_utils`/`program_loop` 混入另一个阶段:

```powershell
cd nontraining
python -B -m pytest tests -q -p no:cacheprovider
cd ../sft
Set-Location teacher
python -B -m pytest tests -q -p no:cacheprovider --basetemp .test-tmp
Set-Location ../sft
python -B -m unittest discover -s tests -v
cd ../evaluation
Set-Location ../evaluation
python -B -m unittest discover -s tests -v
cd ..
Set-Location runtime
python -B -m pytest tests -q -p no:cacheprovider --basetemp .test-tmp
Set-Location ../..
python -B -m unittest discover -s publication_tests -v
```

Python 3.11+ is expected. The original publication checks used Python 3.13 with Torch 2.9 CPU operations. The actual 9B experiment used Torch 2.9 / Transformers 5.10.4 / PEFT 0.21 / Accelerate 1.15. These CPU tests do not download models or start GPU or teacher API work. The result update does not alter the original experiment code or its synthetic fixtures.

`evaluation/data/study.json` is a fictional field/category fixture, **not the real Val422 dataset**. The private-data prompt integration test and private transport/deployment/download helpers are excluded. Adapter fixtures contain architecture/configuration only, with a placeholder base path.

## Full financial Val422 results

The current [aggregate result](results/evidence-summary.json) covers all 422 unique sources and 844 formal trajectories, comparing an untrained Planner and the accepted first SFT A under the same F66 Program/Skill interface. Both arms call Skills; `base` is not a direct-answer Base-LLM. Model Skills always use the original base without adapter; only the SFT Planner enables the accepted LoRA.

The already verified subset was reused byte-for-byte and all remaining sources were run once under the same frozen protocol. Original smoke trajectories are excluded from formal metrics. The source union is exact and disjoint; failures and nontermination remain in each fixed 422 denominator. Labels were used only locally after generation and replay, never uploaded or inserted into model messages. Separate generation-stage walls are recorded, not represented as one full-run wall measurement.

All remote stages, controller/tokenizer/routing replay and archive steps exited successfully. On Windows the original and supplementary archives were safely extracted and all listed member hashes rechecked; full controller replay ran from each extracted root. The local replay does not claim a local real tokenizer: it is bound to the same-SHA remote real-tokenizer proof. All 844 formal trace hashes, per-ID metrics, paired counts and Macro-F1 were independently rechecked before publication.

Full numerical reproduction requires controlled input study/registry, exact source partition and order, local-only gold, full raw traces, original model revision and accepted first LoRA. These are not public. The `evaluation/` directory retains the original evaluation/replay code snapshot; it is not a self-contained launcher with private full-dataset orchestration or production data. The public JSON and trajectory views are a result release, not a replacement deployment bundle.

For controlled real execution, create a new owned configuration/manifest with authorized assets and the prescribed resource/identity checks. Do not overwrite immutable runs, silently change budgets/labels or infer permission for GPU/API work from this publication.

## Teacher and student trajectories

The current release contains **1,044 lossy projections**: unchanged teacher 200, matched full-validation base 422 and SFT 422. The teacher is **Bailian `qwen3.8-2.4t-a95b`**, not a locally trained 9B teacher. The first student uses 200 teacher-selected sources for Planner-only Program+EOS SFT; Skill output text and evaluation labels are not supervision.

Both student files align on public IDs `val-0001` through `val-0422`. No private source-ID mapping is published. The original trace SHA identifies controlled evidence; it is not the SHA of the redacted row. [trajectory-export.json](results/trajectory-export.json) records public-file sizes, row counts and SHA values, including the unchanged teacher file.

Actual Program structure, attempts, execution statuses and final classification/grade are retained. Prompts, raw reasoning, source metadata and semantic observation values are omitted. Literal arguments are replaced by `[REDACTED]` and flagged; unparseable replies retain status/digest, not raw text. No failed row is removed. This format cannot independently establish semantic correctness and must not be used as training data or full replay input.
每次pytest使用独占临时目录或新路径;Windows上系统旧pytest临时符号链接可能产生清理权限错误,不能因此改业务代码。CPU通过只证明契约/路由/回放/监督边界,不是9B语义准确率或GPU显存证据。

The prior partial-validation result tables and standalone partial trajectory files are no longer part of the current branch tree. Original raw evidence and its cryptographic provenance remain preserved privately; the first SFT weights, teacher trajectories and experiment source code are unchanged.
## 受控真实执行的顺序

## Interpretation
1. 准备授权原始metadata、标准Registry、固定来源/分区/顺序、当前源码SHA、模型revision和逐文件身份;labels另存本地评估侧。公开 `study.json` 是合成fixture,不能替代这些资产。
2. Teacher采集使用 `teacher/collect.py`/`detached.py` 和版本化policy,密钥仅内存由调用方供给。占位config不是历史账本,不能直接复用付费额度。
3. 用 `sft/export_dataset.py`核200个来源与真实接受的Program;`token_audit.py --data ... --model ... --output ...`核无截断与响应+EOS监督。准备受控manifest、token审计和model identity后,才使用 `train_student.py --mode trial`,proof通过后fresh `--mode formal`。历史pipeline负责资源锁和实际退出;正式训练不会继承trial更新。
4. 评估使用 `evaluation/evaluate.py --cohort smoke`,然后按新的受控队列执行评估。原公开runner只提供smoke/val80接口;完整历史Val422补充协调器及私有配置未发布,不能把这个命令声称为一键422复现。两个arm均显式F66与相同study预算;只有sft的Planner开adapter。
5. 停写后运行 `evaluation/replay.py`、训练/路由身份gates,再本地评分、固定分母与独立复核。原run与manifest不可覆盖。

Val422 is a development set with eight supported classes out of twelve, one seed and potentially correlated table sources. It is not held-out Test or independent generalization. Supported-class and fixed-twelve-class Macro-F1 are reported separately; legal termination is not business correctness. Historical non-training interfaces are not interchangeable with this matched F66 comparison.

## Publication dependency repair (2026-10-19)

The public nontraining audit now includes `reviews/independent_audit_01.py`, its exact historical source SHA inventory, the public official-model file-hash inventory, and the two omitted source files needed by that inventory. This preserves the historical 121-file/109-core-file signature; it does not fabricate a historical run or ship model weights. `batch_audit.py` imports and a real-controller recorded-I/O replay with synthetic source data are covered by fresh isolated-process tests, including tampered-request rejection.

Additional restored code: `teacher/pilot_audit.py` contains only the recorded retry/I-O replay helpers used by `detached.py`, not the private-gold historical quality aggregator. The public teacher runtime resolves to the already included `evaluation/runtime` when no controlled local `teacher/runtime` is present. `evaluation/legacy/tools/freeze_revision.py` restores the original pure SHA inventory helper, not the private revision manifests or a new deployment authorization. Legacy environment-identity functions still require their controlled snapshot layout; this code snapshot is not a turnkey historical deployment.

### Import paths and CPU checks

From `research/finance_program_v1/nontraining`:

```powershell
python -B -c "import batch_audit; import program_loop; import pool_metadata; print(pool_metadata.__file__)"
```

If using only the standalone metadata helper in your own Python program, add the explicit snapshot directory before importing it:

```python
import sys
from pathlib import Path
snapshot = Path("research/finance_program_v1/nontraining").resolve()
sys.path.insert(0, str(snapshot / "vendor"))
from pool_metadata import PoolMetadata
```
真实GPU/API命令需要资产和资源门全部满足;本次整理未执行这些步骤。各脚本的 `--help` 说明保留原参数。`pipeline.py`/`watch.py`是受控运行协作者,不能把缺失私有manifest当作公开CPU示例失败。

Do not copy files between different historical snapshots or rely on another checkout's PYTHONPATH. Run the teacher synthetic suite from `teacher/` with `python -B -m pytest tests -q -p no:cacheprovider`. Run the publication checks from this directory with `python -B -m unittest discover -s publication_tests -v`; dependency checks use `-I` fresh processes so private/local import paths cannot mask missing modules.
## 结果与可复现程度

`python -B -m reviews.independent_audit_01 --help` and `python -B batch_audit.py --help` are safe CPU-only entrypoint checks. Actual audit commands need complete, authorized, unredacted recorded runs and the matching study/model manifests; redacted public trajectories cannot substitute for them. Cloning/importing/testing does not authorize or start new model downloads, API calls, training, or GPU work.
`results/evidence-summary.json`是原422/844聚合;`results/model-roles.json`绑定teacher/第一版adapter和训练数据;`results/trajectory-export.json`记录1044条公开投影的大小/SHA。原结果文件和轨迹此次字节不变。`results/publication-verification.json`是原历史发布收据,不能当作本次新的测试结果;本次整理验证记录在 `docs/curation-verification.json`。

公开轨迹隐藏了私有ID/metadata、实际prompt、语义文本及推理,保留状态、Program投影、最终类别/等级和原trace摘要。它们不是模型训练数据,也不足以全轨迹逐字回放。完整数值复现需私有输入与标签、完整原调用及权重,现有公开代码不能独立恢复这些信息。
Loading