模型: NeoQuasar/WindFM-Tokenizer(revision 8f610d340e9063493926dd4402667faafb9e857b)
任务: 时间序列 Token 化(VQ 自编码重建)。将多元风电时间序列编码为离散分层 token,并从 token 解码重建原始序列。
许可证: MIT
#NPU #Ascend #Ascend910
WindFM 是首个开源的零样本风电功率预测基础模型(约 8.1M 参数),采用 "Discretize-and-Generate" 框架。WindFM-Tokenizer 是其配套的时间序列专用 VQ Tokenizer:
[batch, seq_len, d_in=6]wind_speed, wind_direction, power, density, temperature, pressure(z_pre, z_full) 两路重建序列 + 离散 token 索引(s1: 10 bits,s2: 10 bits,共 20 bit 码本)编码(encode)输出离散 token 索引,是 WindFM 自回归生成模型(WindFM-8.1M)的输入;解码(decode/forward)完成序列重建。本仓将 Tokenizer 自身完整推理流程(encode → decode 重建)适配到单卡昇腾 NPU。
[B, T, 6] float32 张量,T 为时间窗口长度(本仓演示用 T=240)。wind_speed, wind_direction, power, density, temperature, pressure,不得调换。WindFMPredictor 一致):
x = (x - mean) / (std + 1e-6),均值和标准差在时间轴上计算;[-5, 5](官方 clip=5)。seed=0),仅用于验证;业务数据请按上述契约替换。Ascend910_9362),单卡 npu:0torch 2.9.0+cpu + torch_npu 2.9.0.post1pip install numpy torch torch_npu einops safetensors权重需先下载到本地目录(snapshot_download("NeoQuasar/WindFM-Tokenizer")),再以本地路径加载,正式推理不隐式联网。
MODEL_DIR=/path/to/WindFM-Tokenizer python inference.pyinference.py 自包含完整模型架构,默认在 npu:0 完成 encode → decode 重建推理:
[WindFM-Tokenizer] device=npu:0 name=Ascend910_9362
[WindFM-Tokenizer] first_param.device=npu:0 dtype=torch.float32
[WindFM-Tokenizer] params=3958042 d_in=6 d_model=256 s1=10 s2=10
[WindFM-Tokenizer] input device=npu:0 dtype=torch.float32 shape=(1, 240, 6)
[WindFM-Tokenizer] recon_full shape=(1, 240, 6) recon_pre shape=(1, 240, 6)
[WindFM-Tokenizer] token indices s1 shape=(1, 240) s2 shape=(1, 240)
[WindFM-Tokenizer] sync time (compile+run)=285.39 ms
[WindFM-Tokenizer] MAE recon_full=0.421725 recon_pre=0.593812
[WindFM-Tokenizer] STATUS: PASS (real NPU inference on npu:0)在 npu:0(Ascend910_9362)上以同一权重与输入完成真实推理:
recon_full 形状 (1, 240, 6),MAE = 0.4217recon_pre 形状 (1, 240, 6),MAE = 0.5938(1, 240),s2 形状 (1, 240),示例 s1 tokens [534, 793, 414, 173, 345, 510, 527, 627]同一权重、同一归一化输入、同一随机种子,分别保存 CPU 与 NPU 原始输出,使用 scripts/compare_outputs.py 比较:
| 输出 | 阈值 (atol/rtol) | max_abs_error | 结果 |
|---|---|---|---|
| recon_full | 1e-4 / 1e-3 | 3.81e-06 | PASS |
| recon_pre | 1e-4 / 1e-3 | 4.17e-06 | PASS |
| enc_idx_s1 | 0 / 0(精确) | 0.0 | PASS |
| enc_idx_s2 | 0 / 0(精确) | 0.0 | PASS |
NPU 产生的离散 token 索引与 CPU 完全一致(max_abs_error=0.0),重建输出误差 < 4.3e-06,表明昇腾 NPU 算子精度与 CPU 对齐。
npu:0,batch=1,seq_len=240,d_in=6,dtype=float32,每轮前后 torch.npu.synchronize():
三张终端证据图由 xterm.js 依据本次真实日志生成(非手工绘制):
| 图 | 说明 |
|---|---|
assets/agent_workflow.png | 侦察、下载、CPU 基线、NPU 推理、一致性、校验全流程 |
assets/npu_device_call.png | npu-smi、NPU 可用性、设备名、模型参数 device/dtype |
assets/model_result.png | 默认 python inference.py 真实完整输出 |
WindFM-Tokenizer 的完整自编码重建流程(encode → decode)。完整的风电预测需要搭配 NeoQuasar/WindFM-8.1M 自回归模型与本 Tokenizer 联合使用(见官方 WindFMPredictor)。