Appearance
TimesNet 调试形参
Abstract
这篇保存用于学习 TimesNet 代码运行流程的最小 rolling forecast 参数。目标是让
TimesBlock的top_k周期循环和Inception_Block_V1的多 kernel 循环都至少执行一次。
1. PyCharm 配置
Script path
text
D:\1sudyta\1ai-self\aistyle\TFB\scripts\run_benchmark.pyWorking directory
text
D:\1sudyta\1ai-self\aistyle\TFBEnvironment variables
text
KMP_DUPLICATE_LIB_OK=TRUE2. 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_min2.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_len | 24 | 输入历史长度 |
horizon | 6 | 会映射成 pred_len=6 |
d_model | 32 | embedding 后隐藏维度 |
d_ff | 64 | Inception 中间通道 |
e_layers | 1 | 只跑一个 TimesBlock,先降低复杂度 |
top_k | 2 | for i in range(self.k) 至少跑两次 |
num_kernels | 3 | Inception 里跑 kernel_size=1,3,5 |
dropout | 0.0 | 关闭随机 dropout,方便断点对比 |
num_epochs | 1 | 只训练一轮 |
num_rollings | 2 | 只滚动两次 |
norm=true 的位置
norm=true 的位置
norm是transformer_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 | _process | adapter 给 TimesNet 的四个输入 |
TimesNet.py | forward | forecast 分支 |
TimesNet.py | forecast | normalize、embedding、predict_linear、TimesBlock、projection |
TimesNet.py | FFT_for_Period | rfft -> topk -> period |
TimesNet.py | TimesBlock.forward | padding、1D→2D、stack、period_weight |
Conv_Blocks.py | Inception_Block_V1.forward | 多个 Conv2d kernel 并行 |