Skip to content

Informer 调试流程图

Abstract

这份笔记对应 debug_informer.py。 目标不是跑 benchmark,而是把 输入数据 -> embedding -> encoder -> decoder -> 输出 这条链路和每一步张量 shape 对上。

1. 整体流程图

2. 一步一步看 tensor

阶段张量名shape含义
输入x_enc[2, 96, 7]encoder 看到的历史序列
输入x_mark_enc[2, 96, 4]历史时间特征,h 频率下对应 4 维
输入x_dec[2, 72, 7]decoder 输入,前 48 步是真实历史尾部,后 24 步是 0
输入x_mark_dec[2, 72, 4]decoder 这 72 步对应的时间特征
归一化mean_enc[2, 1, 7]每个 batch、每个变量在时间维上的均值
归一化std_enc[2, 1, 7]每个 batch、每个变量在时间维上的标准差
编码嵌入enc_out[2, 96, 32]数值 embedding + 时间 embedding + 位置 embedding 之和
编码器中间EncoderLayer #1 输出[2, 96, 32]注意力后长度不变
编码器中间ConvLayer 输出[2, 49, 32]distil=True 时做降采样
编码器输出enc_out_final[2, 49, 32]给 decoder 做 cross-attention 的 memory
解码嵌入dec_out[2, 72, 32]decoder 输入经过 embedding
解码器输出decoder output[2, 72, 7]线性投影回变量维度
最终输出output[2, 24, 7]只保留最后 pred_len

3. 模块参数表

模块参数当前值作用
输入 batchB2batch size
输入窗口seq_len96encoder 输入长度
decoder 历史段label_len48decoder 可以看到的历史长度
预测窗口pred_len24最终要输出的未来步数
变量维C7多变量时间序列里的变量数
embeddingd_model32每个时间步映射后的隐藏维度
FFNd_ff128Transformer 中前馈网络的隐藏层维度
注意力n_heads4多头注意力头数
编码器e_layers2encoder layer 数量
解码器d_layers1decoder layer 数量
ProbSparsefactor3稀疏注意力的采样因子
Dropoutdropout0.0dropout 比例
时间编码embedtimeF使用线性时间特征编码
时间频率freqh小时级频率,时间特征维数为 4
激活函数activationgeluFFN 激活函数
注意力输出output_attentionFalse是否额外返回 attention map
编码器降采样distilTrue是否启用 Informer 的 distilling
任务类型task_nameshort_term_forecast决定走 short_forecast() 分支

4. 参数名到底从哪来

这是你现在最容易混的地方。这里分成两套来源看。

4.1 在 debug_informer.py

这里的参数名全部是你手工塞进 SimpleNamespace 里的:

python
configs = SimpleNamespace(
    seq_len=96,
    label_len=48,
    pred_len=24,
    enc_in=7,
    dec_in=7,
    c_out=7,
    d_model=32,
    ...
)

也就是说,在这个调试脚本里:

  • 参数来源不是 TFB 配置系统
  • 参数来源不是数据集自动推断
  • 参数来源就是你手写的 configs.xxx

所以这份脚本更适合看“模型内部怎么流”,不适合拿来理解“TFB 框架怎么给参数”。

4.2 在真实 TFB 运行里

真实 TFB 里,参数来源是分层叠加的:

真实路径里比较关键的几个来源:

参数名debug_informer.py在真实 TFB 里
seq_len手写adapter 自动需求参数,通常来自 benchmark 的 input_chunk_length
pred_len手写实际上常由 horizon 同步过来
label_len手写常在 DeepForecastingModelBase 里自动设成 seq_len // 2
enc_in/dec_in/c_out手写会根据数据列数自动推出来
freq手写为 h会根据时间索引频率自动推出来
norm这个脚本没显式用benchmark 配置里决定是否归一化
batch_size/lr/num_epochs这个脚本里没用到训练真实训练时来自 adapter 默认值或命令行覆盖

5. 哪些参数是 Informer 真正直接用到的

不是所有参数名都会被 Informer 本体用到。

参数名Informer 直接使用备注
seq_len主要在别的任务分支或外层数据构造中重要
label_lendecoder 历史段长度
pred_len最终输出长度
enc_inencoder 输入通道数
dec_indecoder 输入通道数
c_outprojection 输出通道数
d_modelembedding 和 Transformer 主维度
n_heads多头注意力头数
e_layersencoder 层数
d_layersdecoder 层数
d_ffFFN 隐藏层维度
factorProbSparse 注意力因子
dropoutdropout 比例
embed时间 embedding 类型
freq时间 embedding 输入维度依赖它
activationFFN 激活函数
output_attention是否输出 attention
distil是否插入 ConvLayer 下采样
task_name决定走 short_forecast() 还是别的分支
moving_avg这个是共享参数,Informer 本体没直接用
num_kernels这个是共享参数,Informer 本体没直接用

6. 论文术语到代码对象的映射

论文里的词代码里对应什么
Input Time Seriesx_enc
Time Featuresx_mark_enc, x_mark_dec
Value EmbeddingTokenEmbedding
Temporal EmbeddingTimeFeatureEmbeddingTemporalEmbedding
Positional EmbeddingPositionalEmbedding
ProbSparse Self-AttentionProbAttention
Encoder StackEncoder([...])
DistillingConvLayer
Decoder Inputx_dec
Self-Attention in DecoderDecoderLayer.self_attention
Cross-AttentionDecoderLayer.cross_attention
Final Projectionnn.Linear(d_model, c_out)

7. 你现在最该打的断点

按顺序打,不要一上来乱钻。

  1. debug_informer.py 断在 output = model(...)

  2. Informer.py 断在 forward()

  3. Informer.py 断在 short_forecast() 里归一化后

  4. Embed.py 断在 DataEmbedding.forward()

  5. Transformer_EncDec.py 断在 Encoder.forward()Decoder.forward()

8. 一句话总结

你现在最该形成的不是“Informer 很复杂”的印象,而是下面这个稳定映射:

原始序列 [B,L,C] -> embedding [B,L,d_model] -> encoder memory [B,L',d_model] -> decoder hidden [B,L_dec,d_model] -> projection [B,L_dec,C] -> 最后截取 pred_len

只要这条链你能复述出来,后面你再去看真实 TFB batch、adapter、训练循环,就不会再散。

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