AutonLab/MOMENT-1-small 是 MOMENT 时序基础模型家族的 Small 版本,基于 google/flan-t5-small (T5 encoder-only, 8 layers, d_model=512, num_heads=6, d_ff=1024) ,支持 forecasting、classification、anomaly detection、imputation 和 embedding 等任务。本次适配验证 reconstruction (预训练头, patch_len=8, seq_len=512) 在单卡 npu:0 的真实推理与 CPU 一致性。
model.safetensors 145 MB (+ pytorch_model.bin 145 MB 同权重), FP32, ~82M 参数, 估算峰值显存 < 2GB[batch, n_channels, seq_len] float32, batch=2, n_channels=1, seq_len=512 (默认), patch_len=8 -> 64 patchessin(2πt/50)+0.01t+randn*0.1), seed 42, 无缺失, 已做 RevIN norm (模型内)[B,C,T] 严格保持, 通道与时间维不转置; input_mask 为 [B, seq_len] 全 1reconstruction [B,C,seq_len] float32, embeddings [B, d_model] 当 reduction=meanRevIN norm -> Patching(patch_len=8,stride=8) -> PatchEmbedding -> T5Encoder -> PretrainHead -> RevIN denormx[0,0,0:5]=[0.0497,0.1215,0.3335,0.5504,0.4983] mean 2.3777 std 1.5178, 来自合成数据 seed 42, 可复现npu:0, CANN 8.5.1, npu-smi 可用设备数 2torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)==Ascend910_9362, first_param device npu:0, 输入/输出 Tensor device npu:0, 计时前后 torch.npu.synchronize()pip install -r requirements.txt
# requirements 包含 torch, torch_npu, transformers, momentfm, safetensors 等默认命令 (已在 npu:0 验证通过, 退出码 0):
python inference.pyworking/MOMENT-1-small (若存在) 或 Hugging Face AutonLab/MOMENT-1-small 加载权重, 显式 .to("npu:0")执行 python inference.py (npu:0, FP32, batch2, seq512, n_channels1):
[INFO] model source: working/MOMENT-1-small
[INFO] NPU available: True device_count=2 device_name=Ascend910_9362
[INFO] selected device: npu:0
[INFO] first_param device after to(device): npu:0
[INFO] input x shape=(2, 1, 512) sample x[0,0,0:5]=[0.0497, 0.1215, 0.3335, 0.5504, 0.4983]
[RESULT] reconstruction shape (2, 1, 512) sample [0,0,0:5]=[2.9151, 2.0822, 2.0386, 4.4080, 3.0305]
[RESULT] recon mean 2.488152 mse_vs_input 3.105179
[PERF] first run latency 9.72 ms
[RESULT] embedding shape (2, 512) sample [-0.05424, 0.14007, -0.01814, -0.07896, -0.01091]
[PERF] stable avg 9.33 ms windows/s 214.3
[DONE] NPU inference completed successfully device=npu:0同一权重、输入、预处理、dtype(FP32)、seed 42 下 CPU vs NPU 对比 (scripts/compare_outputs.py --task regression --atol 1e-4 --rtol 1e-3):
cpu_output.npy vs npu_output.npy (reconstruction [2,1,512] FP32)npu:0 FP32, batch=2, seq_len=512, n_channels=1, patch_len=8 (64 patches)torch.npu.synchronize() 前后同步, 预热 2 次, 正式 10 次, 不含 CSV 读取 (合成输入)三图由 xterm.js 根据本次真实日志生成 (非手工绘图, 非 Pillow 模拟), 深灰背景白色等宽字体, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 仅为展示标签:

agent_workflow.png: 侦察、环境、下载、加载、NPU 推理、一致性、benchmarknpu_device_call.png: npu-smi info + torch.npu.is_available() + 参数/输入/输出 devicemodel_result.png: python inference.py 默认推理真实输出