g
gcw_coj3XaOd/maple728_timemoe_200m
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

TimeMoE-200M - 昇腾 NPU 推理部署

1. 模型简介

模型名称: Maple728/TimeMoE-200M

模型链接: HuggingFace

模型描述: TimeMoE 是一个基于 Mixture of Experts (MoE) 架构的时间序列基础模型,用于多变量时间序列预测。该模型采用 LLaMA 风格的 Transformer 解码器架构,结合稀疏 MoE 层实现高效的长程时序建模。

模型架构: TimeMoe (LLaMA-style Transformer Decoder + Sparse MoE)

参数规模: ~453M (453,196,800)

输入规格:

  • 类型: float32/bfloat16 张量
  • Shape: [batch_size, seq_len, input_size],input_size=1(单变量时序)

输出规格:

  • Shape: [batch_size, seq_len, input_size * horizon_length]
  • 支持 horizon: 1, 8, 32, 64 步预测

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.50.0HuggingFace Transformers
numpy>= 1.24.0数值计算
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

NPU 硬件: Ascend910_9362

安装命令:

pip install torch torch_npu transformers numpy

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

# HuggingFace
huggingface-cli download Maple728/TimeMoE-200M --local-dir ./TimeMoE-200M

# 或使用 AtomGit 镜像(国内推荐)
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download Maple728/TimeMoE-200M --local-dir ./TimeMoE-200M

3.3 运行推理

python3 inference.py --model-path ./TimeMoE-200M --seq-len 128 --batch-size 1

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--seq-lenint128历史序列长度
--batch-sizeint1批次大小
--horizonint1预测步长 (1/8/32/64)
--npu-deviceint0NPU 设备 ID

4. 推理成功日志

4.1 单条推理日志

[模型] Maple728/TimeMoE-200M
[设备] Ascend910_9362 (npu:0)
[框架] torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6
[输入] shape=torch.Size([1, 128, 1]), range=[-0.5938, 0.8984]
[输出] shape=torch.Size([1, 128, 1]), range=[-0.546875, 0.742188]
[耗时] 255.7ms
[状态] SUCCESS

4.2 批量推理日志

[基准测试] 10次推理统计:
  平均: 61.2ms
  最小: 58.1ms
  最大: 67.6ms
  标准差: 2.8ms
  P50: 60.8ms
  P99: 67.3ms

5. 测试样例及输出结果

样例 1:单条时序预测 (seq=128)

运行命令:

python3 inference.py --model-path ./weights --seq-len 128 --batch-size 1

输出:

[模型] Maple728/TimeMoE-200M
[设备] Ascend910_9362 (npu:0)
[输入] shape=torch.Size([1, 128, 1]), range=[-0.5938, 0.8984]
[输出] shape=torch.Size([1, 128, 1]), range=[-0.546875, 0.742188]
[耗时] 255.7ms
[状态] SUCCESS

样例 2:批量推理基准测试

运行命令:

python3 inference.py --model-path ./weights --seq-len 128 --batch-size 2

输出:

[基准测试] 10次推理统计:
  平均: 61.2ms
  最小: 58.1ms
  最大: 67.6ms
  标准差: 2.8ms
  P50: 60.8ms
  P99: 67.3ms

样例 3:不同序列长度

输出:

  seq_len= 32 -> output=torch.Size([1, 32, 1]), 62.8ms
  seq_len= 64 -> output=torch.Size([1, 64, 1]), 62.4ms
  seq_len=128 -> output=torch.Size([1, 128, 1]), 58.4ms
  seq_len=256 -> output=torch.Size([1, 256, 1]), 68.6ms
  seq_len=512 -> output=torch.Size([1, 512, 1]), 73.4ms

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: 合成时序数据(正弦波 + 噪声 + 趋势),seq_len=128

评测指标:

指标结果说明
单条推理耗时255.7msseq_len=128, batch=1, 首次推理含编译开销
批量推理平均61.2msseq_len=128, batch=1, 10次均值
P99 延迟67.3ms稳态推理
输出数值范围[-0.55, 0.74]与输入量级匹配
输出 shape[B, S, 1]与 horizon_lengths[0]=1 一致

评测命令:

python3 inference.py --model-path ./weights --seq-len 128 --batch-size 1

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡(单卡推理)
  • 显存占用: ~2.1GB (bfloat16, 453M 参数)
  • CANN 版本: 8.5.1
  • torch_npu 版本: 2.9.0.post1+gitee7ba04

9. 已知问题

  1. DynamicCache API 兼容性: use_cache=True 时 DynamicCache.get_usable_length() 在 transformers 4.57.6 中不可用,建议使用 use_cache=False。
  2. NPU 内部格式警告: MoE 层的 one_hot 操作会触发内部格式警告,不影响推理正确性。