#NPU 时间序列预测模型 TimeMoE-200M 昇腾 NPU 适配仓
TimeMoE-200M 是基于 Mixture-of-Experts 的时间序列基础模型(Time-MoE: Billion-Scale Time Series Foundation Models with Mixture of Experts, arXiv:2409.16040)。本仓将该模型真实运行在单卡昇腾 Ascend910(npu:0)上,完成单变量多步时间序列点预测,并提供 CPU/NPU 一致性验证与性能基准。
Maple728/TimeMoE-200M(time_moe 架构,TimeMoeForPrediction,MoE:8 experts / top-2,200M active / 453M total 参数)794591bfeb1225fdf742cec0f4c71f20c3f3b87etransformers(trust_remote_code=True 加载模型自带 modeling_time_moe.py)npu:0(Ascend910,Ascend910_9362)使用公开可追溯的经典月度国际航空旅客数据集(Airline Passengers, Box & Jenkins, 1949-1960,公有领域),共 144 个等间隔月度观测,单变量。
[T]pip install torch torch_npu transformers==4.40.1 numpy
python -c "import torch, torch_npu; print(torch.npu.is_available())" # 应输出 True模型权重需先下载到本地(本仓不提交权重):
from huggingface_hub import snapshot_download
snapshot_download("Maple728/TimeMoE-200M", revision="794591bfeb1225fdf742cec0f4c71f20c3f3b87e",
local_dir="models/TimeMoE-200M")默认运行真实 npu:0 推理,context=96、horizon=32:
python inference.py
# 或指定模型目录
TIMEMOE_MODEL_DIR=/path/to/TimeMoE-200M python inference.pyinference.py 内部检查 torch.npu.is_available(),将模型与输入 Tensor 显式迁移到 npu:0,使用 model.generate(..., max_new_tokens=32, do_sample=False) 做确定性点预测,并在计时前后调用 torch.npu.synchronize()。
n=144, context=96, horizon=32, scale=622.0[472.0, 535.0, 622.0, 606.0, 508.0, 461.0, 390.0, 432.0][444.43, 435.91, 483.26, 478.44, 502.00, 554.37, 610.67, 602.27][399.70, 387.22, 437.01, 426.71, 443.06, 490.24, 539.92, 524.30]相同权重、相同输入、相同 dtype(float32)、相同 seed、eval 模式下分别运行 CPU 与 NPU 推理,保存原始输出数组并对比:
python scripts/compare_outputs.py --cpu cpu_forecast.npy --npu npu_forecast.npy \
--task forecasting --atol 1e-2 --rtol 1e-2结果:passed=true, max_abs_error=1.50e-3, mean_abs_error=6.29e-4(阈值按 float32 与输出尺度确定,见 references/validation.md)。
NPU 上预热 3 次、正式测试 10 次(每次前后 torch.npu.synchronize()):
三张证据图由 xterm.js 根据本次真实日志渲染生成(非桌面截图):
assets/agent_workflow.png:侦察、数据检查、下载、加载、NPU 推理、一致性、benchmark 与提交校验全流程assets/npu_device_call.png:npu-smi、torch.npu.is_available()、设备名、模型参数 device/dtype、输入输出 Tensor deviceassets/model_result.png:默认 python inference.py 的真实完整输出(数据摘要、真实预测、同步耗时、状态)modeling_time_moe.py 等)要求 trust_remote_code=True,已在本地审查,无网络/子进程行为。npu:0;多卡并行未验证。License: Apache-2.0