本项目将 Maple728/TimeMoE-200M(Time-MoE 200M,基于混合专家 MoE 的 decoder-only 时序基础模型)在华为昇腾 NPU 上完成部署与推理验证。
time-series-forecastingtorch_npunpu:1(Ascend 910B4-1,CANN 8.5.1)TimeMoeForPrediction(MoE 解码器,8 experts / top-2)torch_npuTime-MoE 是首个将时序基础模型扩展到十亿级参数的工作(论文 Time-MoE: Billion-Scale Time Series Foundation Models with Mixture of Experts, ICLR 2025 Spotlight)。TimeMoE-200M 是其中的 large 版本,采用 decoder-only 自回归架构,通过混合专家(MoE)提升容量,支持任意预测长度与最长 4096 的 上下文。
本交付使用官方实现源码(固定 revision
915bfda4c78a544d62a2bec6ab22948423059236,文件
time_moe/models/modeling_time_moe.py 中的真实 TimeMoeForPrediction),
加载本地固定模型权重 model.safetensors(HF 仓库 revision
794591bfeb1225fdf742cec0f4c71f20c3f3b87e,字节数 906450104),
在昇腾 NPU npu:1 上完成端到端时序预测。推理过程中不做 CPU 回退,
NPU 初始化、张量放置或执行失败时以非零退出码失败。
模型关键配置(config.json):
| 配置项 | 值 |
|---|---|
| hidden_size | 768 |
| intermediate_size | 3072 |
| num_hidden_layers | 12 |
| num_attention_heads / kv_heads | 12 / 12 |
| num_experts / num_experts_per_tok | 8 / 2 |
| horizon_lengths | [1, 8, 32, 64] |
| max_position_embeddings | 4096 |
| torch_dtype | bfloat16 |
容器已提供匹配的 torch==2.9.0+cpu 与 torch_npu==2.9.0,严禁重新安装
或用普通 PyPI wheel 替换。其余依赖仅从
https://mirrors.aliyun.com/pypi/simple/ 安装。
| 组件 | 版本 | 说明 |
|---|---|---|
| 操作系统 | openEuler (aarch64) | 容器环境 |
| NPU 硬件 | Ascend 910B4-1 × 8 | 分配设备 npu:1 |
| CANN | 8.5.1(cann-8.5.1) | /usr/local/Ascend |
| npu-smi | 25.5.1 | 设备监控 |
| Python | 3.11.14 | 容器自带 |
| torch | 2.9.0+cpu | 容器提供,勿替换 |
| torch_npu | 2.9.0 | 容器提供,勿替换 |
| transformers | 4.57.6 | 与官方实现兼容(>=4.57.0) |
| safetensors | 0.8.0 | 权重加载 |
| numpy | 1.26.4 | 数值处理 |
| Pillow | 12.3.0 | 截图渲染(交付工具) |
requirements.txt 仅固定顶层非 torch 依赖;torch/torch_npu 由容器提供。
source /usr/local/Ascend/ascend-toolkit/set_env.shpython3 -m venv --system-site-packages /work/pipeline/runtime/venvs-tabular16/timemoe-200m-npu
export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
/work/pipeline/runtime/venvs-tabular16/timemoe-200m-npu/bin/pip install -r requirements.txt使用
--system-site-packages以复用容器匹配的 torch/torch_npu,仅在 venv 内安装其余依赖。
cd /work/pipeline/jobs/tabular16/timemoe-200m/timemoe-200m-npu
bash scripts/run_inference.sh该脚本会:
npu-smi info + npu-smi info -t proc-mem 监控进程,
把每个采样写入 logs/npu_device_call.log;npu:1 上运行 inference.py(context=32,prediction=8,batch=2),
原始输出写入 logs/npu_inference.log;logs/npu_result.json(pid 为 npu-smi 可见的 host PID,
另记录 container_pid);logs/npu_inference.sanitized.log 与
logs/npu_device_call.sanitized.log。也可以直接运行:
/work/pipeline/runtime/venvs-tabular16/timemoe-200m-npu/bin/python inference.py \
--device npu:1 --context-length 32 --prediction-length 8 --batch-size 2 \
--output logs/npu_result.json/work/pipeline/runtime/venvs-tabular16/timemoe-200m-npu/bin/python scripts/render_assets.py截图全部从真实脱敏日志渲染,不写入任何手工构造的数值。
测试输入为自生成的确定性 CC0 时序数据(无外部数据集、不使用随机数):
y(t) = 0.2·t + amp·sin(2π·t/12 + φ) + 1.5·sin(2π·t/7 + 0.5b),
其中 batch=2,context_length=32,prediction_length=8。
运行命令(真实执行):
bash scripts/run_inference.sh关键日志(logs/npu_inference.log,真实输出;pid/start_time/load_s/latency_s
随运行略有变化,数值字段确定不变):
[corr] baseline_pids=[]
[env] pid=121454
[env] start_time=2026-08-22T16:25:57.520001Z
[env] torch=2.9.0+cpu
[env] torch_npu=2.9.0
[env] transformers=4.57.6
[env] npu_available=True npu_count=8 npu_device_name=Ascend910B4-1
[env] cann=cann-8.5.1
[env] assigned_device=npu:1
[weights] source_revision=794591bfeb1225fdf742cec0f4c71f20c3f3b87e
[weights] impl_revision=915bfda4c78a544d62a2bec6ab22948423059236
[weights] weight=model.safetensors bytes=906450104 sha256=28d1cbf480c1f63d4ad56d8b7649d9860b9afa9f31abeedff9decea48d9aee57 sha_time=0.67s
[input] source=self-authored-CC0-deterministic-series license=CC0 shape=(2,32) raw_mean=3.697878
[input] input_device=npu:1 input_dtype=torch.bfloat16
[model] load_s=3.87 strict_local_safetensors=True
[model] npu_resident_hold_s=2.0
[corr] container_pid=121454 host_pid=2075412 samples=5 new_pids={"2075412": [1050.0, 1050.0, 1050.0, 1050.0, 1050.0]}
[model] num_params=453196800 model_device=npu:1 dtype=torch.bfloat16
[inference] output_device=npu:1 output_shape=[2, 40] latency_s=0.5688
[forecast] shape=[2, 8] stats={"min": -1.933887243270874, "max": 6.564408779144287, "mean": 2.034532070159912, "std": 2.768984079360962}
[forecast] sample=[1.790663, 0.5791, 0.395065, 1.238559, 2.549808, 4.029756, 5.202978, 6.268847]
[forecast] finite=True num_values=16
[router] num_experts=8 topk=2 total_tokens=64
[router] aggregate_expert_selection_counts=[200, 192, 245, 158, 202, 150, 121, 268]
[mem] peak_npu_memory_mb=930.421875
[result] wrote .../logs/npu_result.json
[exit] code=0 pid=2075412Ascend910B4-1(npu_device_name)794591bfeb1225fdf742cec0f4c71f20c3f3b87e
(source_revision)pid=2075412(npu-smi 可见的 host PID)、container_pid=121454npu:1npu:1(453,196,800 参数,bfloat16)npu:1[2, 40](32 上下文 + 8 预测),预测切片 [2, 8]0.5688 s930.42 MB[1.7907, 0.5791, 0.3951, 1.2386, 2.5498, 4.0298, 5.2030, 6.2688][200, 192, 245, 158, 202, 150, 121, 268]并发 npu-smi info / npu-smi info -t proc-mem 监控
(logs/npu_device_call.log)在推理期间捕获到推理进程(host PID 2075412,
container PID 121454)附着于 NPU 1,进程内存最高 1100 MB;同时
NPU 1 HBM 从基线约 3400 MB 升至峰值 4396 MB(+996 MB)。
npu_result.json 中的 pid 与 npu-smi 进程表行一一对应
(PID_CORRELATION ... MATCH),证明推理进程确实运行于分配的 NPU。
结构化结果:logs/npu_result.json(含 engine、exit code、NPU 可用性/名称/数量、
分配设备、输入/模型/输出设备、输出形状、时延、峰值内存、预测统计、路由统计、
权重 SHA256、pid/container_pid/start_time/end_time、strict_load、
checkpoint 与顶层 output 对象等)。
| 文件 | 说明 |
|---|---|
inference.py | 推理主脚本(torch_npu,npu:1) |
requirements.txt | 顶层依赖固定(Aliyun 镜像) |
scripts/run_inference.sh | 可复现运行脚本(含并发 npu-smi 监控与 PID 关联) |
scripts/render_assets.py | 截图渲染脚本(从真实日志) |
scripts/validate_delivery.py | 交付校验脚本 |
logs/npu_inference.log | 原始推理日志 |
logs/npu_inference.sanitized.log | 脱敏推理日志 |
logs/npu_device_call.log | 原始 npu-smi 监控日志(含 proc-mem) |
logs/npu_device_call.sanitized.log | 脱敏 npu-smi 监控日志 |
logs/npu_result.json | 结构化结果 |
assets/agent_workflow.png | 工作流截图(真实日志渲染) |
assets/modelagent_live_session.png | ModelAgent 现场会话截图 |
assets/npu_device_call.png | npu-smi 监控截图(真实日志渲染) |
assets/model_result.png | 推理结果截图(真实日志渲染) |
| 项目 | 值 |
|---|---|
| HF 模型仓库 | Maple728/TimeMoE-200M |
| 模型 revision(固定) | 794591bfeb1225fdf742cec0f4c71f20c3f3b87e |
| 官方实现仓库 revision(固定) | 915bfda4c78a544d62a2bec6ab22948423059236 |
| 权重文件 | model.safetensors |
| 权重字节数 | 906450104 |
| 权重 SHA256 | 28d1cbf480c1f63d4ad56d8b7649d9860b9afa9f31abeedff9decea48d9aee57 |
权重 SHA256 由本交付在推理前实时计算并与清单字节数校验,未改动任何权重。
| 现象 | 可能原因 | 处理 |
|---|---|---|
torch.npu.is_available() is False | CANN 环境未加载 | source /usr/local/Ascend/ascend-toolkit/set_env.sh |
No module named 'torch_npu' | torch_npu 未安装或被覆盖 | 使用容器自带 Python/venv,勿重装 torch 对 |
| 设备越界 | --device 超出 npu_count | 使用 npu:1(本机 8 卡) |
算子报 not supported on NPU | 依赖了 CUDA 专属算子 | 本模型官方源码已使用标准 PyTorch/torch_npu 算子 |
日志尾部出现 path string is NULL | torch_npu 运行时的良性提示 | 已在下游脚本中从脱敏日志剥离,不影响结果 |
| 输出含非有限值 | 输入含 NaN/Inf | 检查输入序列;本交付输入为确定性有限序列 |
max_position_embeddings(4096),
超出需按官方说明微调。npu:1。ASCEND_GLOBAL_LOG_LEVEL=3 仅保留 ERROR 级 CANN 日志以保持日志脱敏简洁。Maple728/TimeMoE-200M 声明许可证:Apache-2.0。.gitignore)。


