AutonLab/MOMENT-1-large 是 MOMENT 时序基础模型家族的 Large 版本,基于 google/flan-t5-large (T5 encoder, 24层, d_model 1024, d_ff 2816, 16 heads) 的 encoder-only 架构,权重 model.safetensors 1.39 GB、约 347.5M 参数(encoder only),支持通用的时序分析(forecasting, classification, anomaly detection 等)。本仓适配 forecasting 任务,context 512 / patch 8 / stride 8 / horizon 96,运行于 Ascend 910B (npu:0) 的真实 NPU 推理并通过 CPU 一致性验证。
ca58581bc7bea2ebed4e80dc0a3e4b8b609c6eccmodel.safetensors 1.39 GB, ~347.5M params, FP32, MOMENTPipelineconfig.json seq_len 512 patch_len 8 patch_stride_len 8 transformer_type encoder_only backbone flan-t5-large, t5_config d_model 1024 num_layers 24 num_heads 16 d_ff 2816ForecastingHead (d_model*num_patches -> horizon),注意官方提示仅 reconstruction 头为预训练,forecasting 头需微调但本仓以随机初始化头做 deterministic 验证(seed 123)任务路由: 时序点预测 (forecasting) — 输入
[B, C, T]历史窗口 → 输出[B, C, horizon]预测。分类/回归 logits 比较不适用,本仓以 forecast tensor 的 MAE/一致性为验证。
x_enc 张量 [batch, n_channels, seq_len] + input_mask [batch, seq_len],本示例 batch=1, seq_len=512, n_channels=3,dtype float32,time 维度无显式时间戳,通道为合成随机游走forecast [batch, n_channels, forecast_horizon],本例 [1,3,96],已做 RevIN denorm(与输入同量纲),finite 验证通过rng.randn(512)*scale + base 其中 base/scale = [50/2, 35/1, 99/4],累计和 random walk,类似真实时序channel_0 mean 47.49, channel_1 34.50, channel_2 175.61,无缺失,input_mask 全 1[channel_0, channel_1, channel_2],不可调换RevIN 按 x_enc 与 input_mask 做 norm/denorm,外部无需额外 StandardScaler,输入原始 float32 即可[B,C,T],禁止 [B,T,C] 转置;缺失值通过 input_mask 标记(本例全观测)torch.npu.is_available()==True, device_count=2, torch.npu.get_device_name(0)=Ascend910_9362requirements.txtpip install -r requirements.txt
# momentfm 已在 PyPI: pip install momentfm --no-deps(如遇依赖冲突加 --no-deps)
# 或本地安装: pip install momentfmpython inference.py关键日志(npu:0 真实执行):
============================================================
Model: AutonLab/MOMENT-1-large (revision ca58581bc7bea2ebed4e80dc0a3e4b8b609c6ecc)
Task: time-series forecasting (MOMENT point forecast)
Backend: torch + torch_npu
Device: npu:0
Context: 512, Horizon: 96, Channels: 3
============================================================
[ENV] torch 2.9.0+cpu torch_npu 2.9.0.post1+gitee7ba04
[ENV] npu_available=True device_count=2 device_name=Ascend910_9362
...
[DEVICE] Set NPU device 0, current device 0
[VERIFY] Dummy tensor device: npu:0
[DATA] x_enc shape (1, 3, 512) dtype torch.float32 mean 85.8747
[LOAD] cfg seq_len=512 patch_len=8 backbone=google/flan-t5-large d_model=1024
[LOAD] model first param device: npu:0 dtype torch.float32
[LOAD] model param count 347.53M
[INPUT] past tensor shape (1, 3, 512) device npu:0 dtype torch.float32
[INFER] Completed in 0.1342s (sync timed)
[RESULT] Forecast tensor shape (1, 3, 96) device npu:0 dtype torch.float32 finite True
[RESULT] forecast mean 86.0615
[RESULT] channel_0 head [46.19, 49.15, 46.94] tail [48.00, 47.60, 48.56]
[RESULT] channel_1 head [33.53, 36.08, 33.80] tail [34.34, 34.92, 35.20]
[RESULT] channel_2 head [174.77, 180.54, 171.96] tail [176.54, 176.33, 179.33]
[VERIFY] Model param device after inference: npu:0
[STATUS] NPU inference SUCCESS on npu:0, elapsed 0.1342schannel_0 47.49, channel_1 34.50, channel_2 175.61[1,3,96] 已 RevIN denorm,量纲与输入一致,可直接业务使用:
[46.1916, 49.1527, 46.9499] tail [48.0051, 47.6051, 48.5684][33.5387, 36.0815, 33.8066] tail [34.3417, 34.9211, 35.2083][174.7733, 180.5453, 171.9651] tail [176.5493, 176.3351, 179.3373].npy,运行 compare_outputs.py --task forecastingcpu shape [1,3,96] npu shape [1,3,96] finite True max_abs 4.577e-05 mean_abs 7.19e-06 allclose True (atol 1e-4 rtol 1e-3)torch.npu.synchronize()图片由 xterm.js 根据本次真实日志生成(非截图):
assets/agent_workflow.png — 侦察、下载、加载、NPU 推理、一致性、benchmark 与校验的完整工作流assets/npu_device_call.png — npu-smi、NPU 可用性、设备名、模型参数 device/dtype、输入与输出 Tensor deviceassets/model_result.png — 默认 python inference.py 的真实完整输出(含 schema/窗口摘要、真实预测、同步耗时和状态)

momentfm 的 T5 encoder,部分算子在 NPU 上为 FP32 回退已记录但无 CPU fallback