Skip to content

TimesNet 调试形参

Abstract

这篇保存用于学习 TimesNet 代码运行流程的最小 rolling forecast 参数。目标是让 TimesBlocktop_k 周期循环和 Inception_Block_V1 的多 kernel 循环都至少执行一次。


1. PyCharm 配置

Script path

text
D:\1sudyta\1ai-self\aistyle\TFB\scripts\run_benchmark.py

Working directory

text
D:\1sudyta\1ai-self\aistyle\TFB

Environment variables

text
KMP_DUPLICATE_LIB_OK=TRUE

2. Parameters

直接复制下面这一整行到 PyCharm 的 Parameters

text
--config-path rolling_forecast_config.json --data-name-list cif_2016_dataset_1.csv --model-name time_series_library.TimesNet --adapter transformer_adapter --model-hyper-params "{\"batch_size\":4,\"d_model\":32,\"d_ff\":64,\"e_layers\":1,\"horizon\":6,\"seq_len\":24,\"top_k\":2,\"num_kernels\":3,\"dropout\":0.0,\"lr\":0.0001,\"num_epochs\":1,\"num_workers\":0,\"norm\":true}" --strategy-args "{\"horizon\":6,\"tv_ratio\":0.8,\"train_ratio_in_tv\":0.75,\"stride\":6,\"num_rollings\":2}" --num-workers 1 --timeout 600 --save-path debug\cif1_TimesNet_rolling_min

2.1 VSCode 调试配置

先在 VSCode 里执行:

text
Ctrl+Shift+P
-> Python: Select Interpreter
-> 选择 D:\Anaconda\envs\tfb\python.exe

然后在仓库根目录创建或修改:

text
D:\1sudyta\1ai-self\aistyle\TFB\.vscode\launch.json

加入下面配置:

json
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "TFB TimesNet rolling debug",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}\\scripts\\run_benchmark.py",
      "cwd": "${workspaceFolder}",
      "console": "integratedTerminal",
      "env": {
        "KMP_DUPLICATE_LIB_OK": "TRUE"
      },
      "args": [
        "--config-path", "rolling_forecast_config.json",
        "--data-name-list", "cif_2016_dataset_1.csv",
        "--model-name", "time_series_library.TimesNet",
        "--adapter", "transformer_adapter",
        "--model-hyper-params", "{\"batch_size\":4,\"d_model\":32,\"d_ff\":64,\"e_layers\":1,\"horizon\":6,\"seq_len\":24,\"top_k\":2,\"num_kernels\":3,\"dropout\":0.0,\"lr\":0.0001,\"num_epochs\":1,\"num_workers\":0,\"norm\":true}",
        "--strategy-args", "{\"horizon\":6,\"tv_ratio\":0.8,\"train_ratio_in_tv\":0.75,\"stride\":6,\"num_rollings\":2}",
        "--num-workers", "1",
        "--timeout", "600",
        "--save-path", "debug\\cif1_TimesNet_rolling_min"
      ]
    }
  ]
}

3. 参数含义

参数当前值作用
seq_len24输入历史长度
horizon6会映射成 pred_len=6
d_model32embedding 后隐藏维度
d_ff64Inception 中间通道
e_layers1只跑一个 TimesBlock,先降低复杂度
top_k2for i in range(self.k) 至少跑两次
num_kernels3Inception 里跑 kernel_size=1,3,5
dropout0.0关闭随机 dropout,方便断点对比
num_epochs1只训练一轮
num_rollings2只滚动两次
norm=true 的位置

normtransformer_adapter 的 required arg 之一,用于和 TFB 的模型工厂接口对齐;当前 TimesNet.py 的 forecast 主链没有读取 configs.norm 作为开关。TimesNet 内部实际执行的归一化是 forecast() 里的 means/stdev 代码。

调试参数和文档 toy 是两套尺度

本文档集的精读 toy 使用 seq_len=8, pred_len=5, C=4, d_model=6,用于手算。这里的 PyCharm/VSCode 参数使用 seq_len=24, horizon=6, d_model=32,用于真实跑通代码。两者流程相同,数值规模不同。


4. 断点顺序

第一轮只看 TimesNet 主链:

text
TransformerAdapter._process
-> TimesNet.forward
-> TimesNet.forecast
-> DataEmbedding.forward
-> TimesBlock.forward
-> FFT_for_Period
-> Inception_Block_V1.forward
-> projection

关键断点:

文件函数看什么
adapters_for_transformers.py_processadapter 给 TimesNet 的四个输入
TimesNet.pyforwardforecast 分支
TimesNet.pyforecastnormalize、embedding、predict_linear、TimesBlock、projection
TimesNet.pyFFT_for_Periodrfft -> topk -> period
TimesNet.pyTimesBlock.forwardpadding、1D→2D、stack、period_weight
Conv_Blocks.pyInception_Block_V1.forward多个 Conv2d kernel 并行

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