模型适配 · 表格/时序数据预测 (Time Series Foundation Model with MoE) · 昇腾 NPU
Beta 版本头信息
{hardware NPU}model.safetensors(≈ 865 MB)TimeMoeConfig、TimeMoeForPrediction、无 tokenizer、非语言模型),不适用 vLLM-Ascend;本项目采用 torch_npu 直接加载 safetensors 权重在昇腾 NPU 上完成适配,并以 FastAPI 提供 HTTP 服务化推理。{hardware NPU} Ascend 910B(torch_npu 2.9.0.post1)| 组件 | 版本 |
|---|---|
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| NPU | Ascend 910B (2 × 64GB HBM) |
| Python | 3.11.14 |
| transformers | 4.57.6 |
| 指标 | 数值 |
|---|---|
| Cosine Similarity (NPU vs CPU) | 0.999983 |
| 最大绝对误差 (max_abs_err) | 0.15625 |
| L2 相对误差 (rel_err) | 0.64% |
| 是否满足要求 | 满足(< 1%)✅ |
说明: bf16 精度下,NPU 与 CPU 的 cosine similarity 约 0.999983,L2 相对误差 0.64%(使用平滑正弦信号对比),在 bf16 数值精度预期范围内。
| 指标 | 数值 |
|---|---|
| 平均延迟 (seq_len=512, horizon=1) | 120.3 ms |
| 平均延迟 (seq_len=512, batch=4, horizon=1) | 206.4 ms |
| 平均延迟 (seq_len=512, horizon=64) | 117.8 ms |
| 峰值 HBM | 0.89 GB |
| 参数量 | 200,737,028(200M) |
| 单卡 | Ascend 910B · npu:0 |
pip install -r requirements.txt# 方式一:ModelScope
python -c "from modelscope import snapshot_download; snapshot_download('Maple728/TimeMoE-200M', local_dir='/models/TimeMoE-200M')"
# 方式二:HuggingFace (hf-mirror)
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download Maple728/TimeMoE-200M --local-dir /models/TimeMoE-200M
# 方式三:AtomGit 镜像仓
git clone https://ai.gitcode.com/hf_mirrors/Maple728/TimeMoE-200M.git /models/TimeMoE-200Mcd TimeMoE-200M
python3 inference.py --model-path /models/TimeMoE-200M --device npu:0 --seq-len 512 --horizon 64 --n-runs 3python3 inference.py --model-path /models/TimeMoE-200M --device npu:0 --compare# 启动服务(默认 8000 端口)
python3 inference.py --model-path /models/TimeMoE-200M --device npu:0 --serve --port 8000
# 健康检查
curl -s http://127.0.0.1:8000/health
# -> {"status":"ok","device":"npu:0","model":"/models/TimeMoE-200M"}
# 时间序列预测
curl -s http://127.0.0.1:8000/v1/forecast \
-H 'Content-Type: application/json' \
-d '{"values": [1.0, 1.1, 1.2, 1.05, ...], "horizon": 64}'
# -> {"horizon": 64, "shape": [1, 512, 64], "values": [[...]]}TimeMoE-200M/
├── inference.py # 推理脚本(必选)
├── README.md # 部署说明文档(必选)
├── requirements.txt # 环境依赖清单(推荐)
├── time_moe/ # vendored 模型代码(必选)
│ ├── __init__.py
│ ├── configuration_time_moe.py
│ ├── modeling_time_moe.py
│ └── ts_generation_mixin.py
└── assets/ # 截图素材文件夹(必选,用户自行截图放置)
├── agent_workflow.png
├── npu_device_call.png
└── model_result.pngTimeMoE-200M 使用自定义代码(trust_remote_code=True),需要通过 vendored 方式将模型代码嵌入项目。适配要点:
modeling_time_moe.py 中的相对导入(.configuration_time_moe、.ts_generation_mixin)改为基于包名的绝对导入(time_moe.configuration_time_moe、time_moe.ts_generation_mixin)safetensors.torch.load_file 直接加载 model.safetensors,避免 transformers from_pretrained 的 config 参数冲突torch.nn.functional.linear、torch.nn.functional.softmax、torch.topk 等),与昇腾 NPU 完全兼容,无需算子替换eager 注意力路径(_supports_sdpa=False,_supports_flash_attn_2=True 但未启用),NPU 上自动走标准实现