Skip to content

Level 1 run_benchmark 总顺序

Abstract

入口:

python
if __name__ == "__main__":

这一层只解释一件事:

run_benchmark.py 在最高层顺序上怎样把命令行运行,变成一次完整 benchmark。

1. 上一层与当前层位置

上一层是:

当前层是:

  • Level 1:只看 run_benchmark.py 自己的顺序,不下钻 pipeline(...) 内部。

当前层对应上一层中的具体位置是:

2. 当前层第一性

run_benchmark.py 的第一性是:

把“命令行参数 + JSON 配置文件”变成“可执行 benchmark 配置”,再把 pipeline(...) 产生的日志文件交给 report(...)

这意味着它的职责不是:

  • 读 CSV 细节
  • 训练模型
  • 做 rolling 预测

而是:

  1. 解析输入
  2. 组装配置
  3. 调用主执行入口 pipeline(...)
  4. 调用结果展示入口 report(...)

3. 当前命令的最小例子

这一层以下文这条命令作为具体例子:

text
python scripts/run_benchmark.py
--config-path rolling_forecast_config.json
--data-name-list ETTh1.csv
--model-name time_series_library.DLinear
--adapter transformer_adapter
--model-hyper-params {"batch_size":4,"d_model":32,"d_ff":128,"moving_avg":25,"dropout":0.0,"lr":0.0001,"num_epochs":1,"num_workers":0,"seq_len":96,"horizon":24}
--strategy-args {"horizon":24,"tv_ratio":0.8,"train_ratio_in_tv":0.75,"stride":24,"num_rollings":48}
--num-workers 1
--timeout 600
--save-path debug\\ETTh1_DLinear_rolling_min_allmetrics

4. Level 1 顺序图

5. 抽象索引树

这棵树不是执行顺序图,而是:

为了让人脑快速索引 run_benchmark.py 的四个逻辑分块。

6. 职责树

6.1 输入解析

负责生成:

  • args
  • config_data

6.2 配置组装

负责生成:

  • data_config
  • model_config
  • evaluation_config
  • report_config

6.3 执行 benchmark

负责调用:

  • pipeline(data_config, model_config, evaluation_config)

返回:

  • log_filenames

6.4 结果展示

负责调用:

  • report(report_config, report_method=args.report_method)

7. 输入输出接口

7.1 关键输入

  • args
    • 来自 argparse
  • config_data
    • 来自 json.load(...)

7.2 关键中间变量

  • data_config
  • model_config
  • evaluation_config
  • report_config

7.3 关键输出

  • log_filenames
    • 类型:List[str]
    • 语义:本次 benchmark 产出的日志文件路径列表

8. 函数 / 文件关系图

9. 这一层对当前例子的具体落地

在这条命令下,run_benchmark.py 这一层真正做的是:

  1. 读取 rolling_forecast_config.json
  2. 用命令行覆盖默认值
  3. 得到:
    • data_config 里有 ETTh1.csv
    • model_config 里有 time_series_library.DLinear
    • evaluation_config 里有 rolling_forecasthorizon=24
  4. pipeline(...)
  5. 拿到日志文件列表
  6. 再把这些日志交给 report(...)

10. 下一层入口

下一层要 BFS 细分的是:

python
pipeline(
    data_config,
    model_config,
    evaluation_config,
)

对应:

11. 只留一句

Level 1 只看 run_benchmark.py 怎样把“命令行运行”变成“pipeline(...) + report(...)”。

*记录并在线阅读我的笔记*