main (config.json: 2026-08-22, model.safetensors 1.385 GB)MOMENT + T5 Encoder (google/flan-t5-large, d_model=1024, 24 layers, 16 heads, seq_len=512, patch_len=8, stride=8, n_patches=64)model.safetensors 1.385 GB, 无需 trust_remote_code, 使用 momentfm==0.1.5 + transformers.T5EncoderModelMOMENT 是 AutonLab 提出的时间序列基础模型,支持 forecasting (点预测)、classification、anomaly detection、imputation 和 embedding。MOMENT-1-large 以 google/flan-t5-large 为骨干,Encoder-only,输入为 [batch, channels, seq_len],输出根据任务为 forecast [B,C,H]、reconstruction [B,C,T] 或 embeddings [B,D]。
x_enc: torch.Tensor [batch, n_channels, seq_len] + input_mask: [batch, seq_len] (1=有效, 0=mask)[B, C, T],禁止转置,通道维独立归一化 (RevIN, affine=False)seq_len=512, patch_len=8, stride=8, n_patches=64, d_model=1024forecast_horizon=96 (可配置 1~512),输出 [B,C,96][B,C,512],与输入同形,用于重构/异常检测batch=2, channels=3, seq_len=512, seed=0 正态分布,SHA256 可追溯 (working/cpu_forecasting.npy)Ascend910_9362), torch_npu 2.9.0.post1, CANN 8.5.1, npu-smi 25.5.5torch 2.9.0+cpu, transformers 4.57.6, numpy 1.26.4, huggingface_hub (hf-mirror)SOC_VERSION=ascend910_9391, TASK_QUEUE_ENABLE=1torch.npu.is_available()==True, device_count=2, 目标 npu:0 (Bus 0000:0A:00.0)pip install -r requirements.txt
# 或手动安装核心依赖
pip install torch torch_npu transformers safetensors huggingface_hub
pip install git+https://github.com/moment-timeseries-foundation-model/moment.git权重下载 (本地优先,失败则联网):
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download AutonLab/MOMENT-1-large --local-dir ./models/MOMENT-1-large --local-dir-use-symlinks False
# 或让 inference.py 自动处理默认命令 (真实 NPU 推理,含 warmup 编译):
python inference.py
# 等价指定:
python inference.py --task forecasting --forecast-horizon 96 --batch 2 --channels 3 --seq-len 512
# 其他任务:
python inference.py --task reconstruction
python inference.py --task embedding关键日志 (stdout 截选):
[INFO] model: AutonLab/MOMENT-1-large task: forecasting seq_len: 512 n_patches: 64 horizon: 96
[INFO] npu device count: 2 name: Ascend910_9362
[INFO] selected device: npu:0
[INFO] using local model dir: ../models/MOMENT-1-large
[INFO] first param device: npu:0 dtype: torch.float32
[INFO] input shape: torch.Size([2, 3, 512]) mean -0.0017 std 1.00
[INFO] warmup 1: 262 ms (compile) | 2: 21 ms | 3: 21 ms
[INFO] sync inference time: 20.4 ms
[INFO] output forecast shape: torch.Size([2, 3, 96]) device: npu:0
[INFO] forecast sample [0,0,:5]: [0.11, 0.04, 0.03, -0.01, -0.07]
[INFO] NPU inference completed successfully PASSbatch=2, channels=3, seq_len=512 合成正态 (seed 0)horizon 96): 输出 [2,3,96], 均值 ~0.005, std ~0.09, 示例 [0.11,0.04,0.03,-0.01,-0.07] (NPU)[2,3,512], 均值 ~0.041, 示例 [0.258,0.315,0.588,0.216,0.221] (与 CPU 对齐,见一致性)[2,1024], 均值 ~0.0026同一权重、输入、预处理、seed、eval、dtype (float32) 下比较原始张量:
python scripts/compare_outputs.py --cpu working/cpu_forecasting.npy --npu working/npu_forecasting.npy --task forecasting --atol 1e-4 --rtol 1e-3| 任务 | CPU shape | NPU shape | max_abs | mean_abs | passed (atol 1e-4) |
|---|---|---|---|---|---|
| forecasting | [2,3,96] | [2,3,96] | 1.64e-06 | 2.64e-07 | ✅ |
| reconstruction | [2,3,512] | [2,3,512] | 1.73e-06 | 2.77e-07 | ✅ |
| embedding | [2,1024] | [2,1024] | 1.79e-07 | 2.26e-08 | ✅ |
torch.npu.synchronize()前后计时,无 CPU fallback (首参 device=npu:0, 输出 device=npu:0)。阈值按 FP32 严格 1e-4,实际误差 <2e-06,满足。分类场景会额外检查 argmax 一致率,此模型为回归/预测故以数值为主。
设备 npu:0, dtype float32, batch=2, channels=3, seq_len=512, horizon=96, 计时含 torch.npu.synchronize(),不含数据生成,预处理包含在模型内。
| 阶段 | 值 |
|---|---|
| compile / first-run | 262 ms (含图编译+缓存) |
| 稳定 avg (10 runs) | 20.41 ms |
| min / max | 20.07 / 21.44 ms |
| p50 / p90 / p95 | 20.28 / 20.91 / 21.17 ms |
| reconstruction avg | 20.71 ms |
| 吞吐 | ~98 windows/s (2 windows / 0.0204 s) / ~49 series/s |
| 峰值 HBM | ~3.9 GB (npu-smi) / 64 GB 总量 |
| 电源 | 170 W (npu-smi) |
表格模型 rows/s 口径对应时间序列 windows/s。
三图由 scripts/render_xterm_evidence.mjs --style raw 根据真实日志生成 (深灰 #282828, 白色等宽, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$),README 仅引用图片。
assets/agent_workflow.png — 侦察、环境、下载、加载、NPU推理、一致性、benchmark、提交校验assets/npu_device_call.png — npu-smi info, torch.npu.is_available(), 设备名、参数 device/dtype、输入/输出 Tensor deviceassets/model_result.png — python inference.py 完整输出 (输入摘要、输出摘要、同步耗时、PASS)

npu:0 单卡,npu:1 未测ArgSort 在 AiCPU 回退 (warning),不影响精度但可优化为 float32NPU, Ascend, Ascend910, time-series, forecasting, moment, t5, foundation-model