Appearance
Non-stationary Transformer 总览
一、论文动机
Phase 1 因果链中的位置:Informer 解决了
归一化后,模型看到的是一个"去趋势、去波动"的序列。均值
解决方案:不拒绝归一化(归一化对训练稳定性是必要的),而是用可学习的 Projector 从原始信号的统计量中提取两个因子,在注意力计算时把非平稳信息重新注入:
(tau):调整注意力的集中程度(温度因子) (delta):为每个 key 位置引入可学习偏置(位置偏移因子)
二、核心创新:DSAttention
标准 Attention 与 DSAttention 的公式差别:
标准:
score = QK^T
A = softmax(score / sqrt(E))
DSAttention:
score = QK^T · τ + δ
A = softmax(score / sqrt(E))
↑ ↑
tau 缩放整体 delta 按 key 位置偏移两个因子由同一结构的 Projector 从 (x_raw, stats) 中学出,x_raw 是归一化前的原始信号。
跨模型对比:
| 维度 | Informer | Autoformer | FEDformer | Non-stationary |
|---|---|---|---|---|
| 注意力类型 | ProbSparse | Auto-Correlation(FFT) | 频域稀疏 | DSAttention(全局,加 τ/δ) |
| 归一化处理 | Instance Norm | 序列分解 | 序列分解 | Instance Norm + 统计量恢复 |
| 非平稳信息 | 丢失 | 丢失(趋势由 decomp 保留) | 丢失 | 由 τ/δ 恢复到 Attention |
| 新增参数 | — | — | — | 2 个 Projector(MLP + Conv1d) |
| Encoder 骨架 | 标准 Transformer | 无 distilling | 频域 | 标准 Transformer |
| token 语义 | 时间步 | 时间步 | 时间步 | 时间步 |
| 复杂度 |
三、架构图(论文原理层)
四、TFB 调用链
五、文档 BFS 树形索引
六、论文组件 → 代码对应表
| 论文组件 | 代码位置 | 精读文档 |
|---|---|---|
| Instance Normalization | forecast() L171–176 | [[02-Layer1-forecast主链]] |
| Projector(τ learner) | Projector.__init__ / forward | [[03A-Layer2A-Projector]] |
| Projector(δ learner) | 同上,output_dim=seq_len | [[03A-Layer2A-Projector]] |
| De-stationary Attention | DSAttention.forward | [[03B-Layer2B-DSAttention]] |
| AttentionLayer(Q/K/V 投影) | AttentionLayer.forward | [[03B-Layer2B-DSAttention]] |
| Encoder(标准,无 distilling) | Encoder.forward(conv_layers=None) | [[02-Layer1-forecast主链]] |
| Decoder(标准) | Decoder.forward | [[02-Layer1-forecast主链]] |
| DataEmbedding | DataEmbedding(含 PositionalEmbedding) | 参见 [[Informer]] 文档 |
| De-normalization | forecast() L201 | [[02-Layer1-forecast主链]] |
七、全局 Toy 参数
| 参数 | 值 | 含义 |
|---|---|---|
| B | 2 | batch size |
| seq_len | 12 | encoder 输入长度 |
| label_len | 6 | decoder 历史前缀 |
| pred_len | 4 | 预测步数 |
| dec_len | 10 | = label_len + pred_len |
| enc_in = dec_in = c_out | 5 | 变量数 N |
| d_model | 8 | 隐层维度 |
| n_heads | 4 | 注意力头数 |
| d_keys = d_values | 2 | = d_model / n_heads |
| d_ff | 16 | FFN 隐层 |
| e_layers | 2 | Encoder 层数 |
| d_layers | 1 | Decoder 层数 |
| time_dims | 4 | 时间标记维度(ETTh1:hour/day/weekday/month) |
| p_hidden_dims | [32] | Projector MLP 隐层维度 |
| p_hidden_layers | 1 | Projector MLP 层数 |
维度唯一性说明:主要语义维度 seq_len(12) / label_len(6) / pred_len(4) / dec_len(10) / enc_in(5) / d_model(8) / d_ff(16) 互不相同。d_keys=2 与 B=2 数值相同,但语义和张量位置完全不同,不会造成追踪混淆。
八、推荐阅读路径
快速了解直觉:本文 §一~§二 + [[03B-Layer2B-DSAttention]] §5.1 宏观逻辑
完整代码精读:
- [[01-Layer0-接入界面]] — 了解 TFB 如何传参、p_hidden_dims 从哪来
- [[02-Layer1-forecast主链]] — 归一化/反归一化 + tau/delta 注入流程
- [[03A-Layer2A-Projector]] — Conv1d 聚合时序信息的非常规用法
- [[03B-Layer2B-DSAttention]] — 实际代码与公式的对应
- [[04-收束]] — 端到端 shape 汇总 + 与已学模型对比