Bingggooo/Maple728-TimeMoE-200M-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Maple728/TimeMoE-200M-NPU

#NPU Ascend 910B Time-Series Forecasting Adaptation

Model adapted from Maple728/TimeMoE-200M (200M MoE) weights model.safetensors 906M.

  • Source model: Maple728/TimeMoE-200M (time_moe, 12 layers, hidden 768, 12 heads, 8 experts top-2, horizon_lengths [1,8,32,64])
  • Task: time-series-forecasting univariate point forecasting. Route: 点预测 (forecast tensor, no quantiles)
  • Adaptation device: npu:0 Ascend910_9362 (2 devices, CANN 8.5.1, torch_npu 2.9.0.post1, torch 2.9.0+cpu, transformers 4.40.1)
  • Precision: float32, deterministic generation (greedy, no sampling), trust_remote_code
  • Revision: local snapshot /tmp/TimeMoE-200M (config.json + model.safetensors, 865M after download)

Data Contract

Synthetic univariate series mirroring ETTh/Electricity trend+seasonality, seed=42, 600 timesteps, traceable via SHA256.

  • File source: Generated locally via numpy.random.RandomState(42); SHA256(inp_norm prefix) = 3d0869b35ae00ea8
  • Schema: 1 channel univariate float32, time index 0..599, values derived from 0.5*sin(2πt/24)+0.3*sin(2πt/96)+0.01*t+ N(0,0.1)
  • Columns / dtype: single series float32; time not tokenized
  • Missing / preprocessing: No NaN; z-score per window: (x-mean)/(std+1e-5) where mean/std computed on context window (512); inverse transform forecast*std+mean for denorm output
  • Scaling: Per-window z-score clipped none; report both normalized and denorm forecasts
  • Split: context=512 (input), pred_len=32 (forecast), max_length=544; same slice used for CPU and NPU (last 512 before horizon)
  • Input shape: [batch=1, seq_len=512] (model unsqueezes to [B,T,1] internally)
  • Output shape: [batch=1, seq_len=544] full including input copy + [32] forecast horizon
  • Privacy: Synthetic only, no PII.

Environment

python 3.11.14
torch 2.9.0+cpu
torch_npu 2.9.0.post1+gitee7ba04
transformers 4.40.1
numpy 1.26.4, pandas 3.0.2
Ascend CANN 8.5.1, Ascend910_9362 x2, HBM 3105/65536 MB (npu:0), 2873/65536 MB (npu:1)
npu-smi driver 25.5.5

Collect via python scripts/collect_env.py --output working/env.json and python scripts/check_npu.py (see assets/npu_device_call.png).

Installation

pip install -r requirements.txt
# Ensure Ascend CANN 8.5.1 and torch_npu installed (Ascend910B)
# Model weights downloaded once to /tmp/TimeMoE-200M via:
#   huggingface-cli download Maple728/TimeMoE-200M --local-dir /tmp/TimeMoE-200M --local-dir-use-symlinks False

requirements.txt pins torch, torch_npu, transformers, numpy, safetensors, huggingface_hub. No internet download at inference beyond first snapshot (cached).

NPU Inference

Default command (uses NPU if available, otherwise CPU):

python inference.py
python inference.py --device npu:0 --context 512 --pred-len 32
python inference.py --device cpu --context 512 --pred-len 32

Key logs prove NPU call:

  • npu-smi info shows 2x Ascend910
  • scripts/check_npu.py => {"torch_npu_available": true, "npu_available": true, "device_count": 2, "device_name": "Ascend910_9362"}
  • inference.py prints Model param device: npu:0, dtype: torch.float32 and params on npu: 463/463, No CPU fallback, inputs/outputs on npu:0, and synchronizes via torch.npu.synchronize() before/after timing
  • No CPU fallback: explicit model.to(device) and seq.to(device), assert out.device.type=='npu'

Real Results (NPU)

Captured from python inference.py --device npu:0 (2026-08-20, float32, seed 42):

[INFO] Model: Maple728/TimeMoE-200M
[INFO] NPU device name: Ascend910_9362, count: 2
[DATA] inp mean 3.100524 std 1.538619 sha256 prefix 3d0869b35ae00ea8
[DATA] inp_norm mean 0.000000 std 0.999993
[LOAD] Model param device after move: npu:0, dtype torch.float32
[CHECK] params on npu: 463/463
[OUTPUT] output shape torch.Size([1, 544]), device npu:0
[OUTPUT] forecast normalized full: [1.1353217363357544, 1.129515528678894, 1.129783034324646, 1.0987622737884521, 1.115885853767395, 1.17235267162323, 1.2253246307373047, 1.3212476968765259, 1.4092044830322266, 1.4990017414093018, 1.5927329063415527, 1.6473511457443237, 1.6993191242218018, 1.7142565250396729, 1.7313669919967651, 1.718336582183838, 1.6956920623779297, 1.6466922760009766, 1.5589796304702759, 1.4523346424102783, 1.3398641347885132, 1.2228366136550903, 1.1338753700256348, 1.068324327468872, 0.9837856292724609, 0.9675366282463074, 0.9717206358909607, 0.95228111743927, 0.9697256684303284, 1.0113574266433716, 1.0698736906051636, 1.1581742763519287]
[OUTPUT] forecast denorm full: [4.847352027893066, 4.838418483734131, 4.83882999420166, 4.791100978851318, 4.817447662353516, 4.904328346252441, 4.985832214355469, 5.133420944213867, 5.2687530517578125, 5.406917095184326, 5.551133632659912, 5.6351704597473145, 5.715129375457764, 5.738112449645996, 5.764438629150391, 5.74439001083374, 5.7095489501953125, 5.634156703948975, 5.499200344085693, 5.335114479064941, 5.162064552307129, 4.982004165649414, 4.845126628875732, 4.744268417358398, 4.614195823669434, 4.589194297790527, 4.595632076263428, 4.5657219886779785, 4.592562675476074, 4.656618118286133, 4.746652603149414, 4.882513523101807]
[OUTPUT] forecast normalized stats mean 1.298213 std 0.267647 min 0.952281 max 1.731367
[TIMING] synchronized elapsed 0.3205s (device npu:0)
[TIMING] second stable run 0.0630s, throughput 15.86 windows/s
[STATUS] SUCCESS

Full forecast head: [1.1353, 1.1295, 1.1297, 1.0987, 1.1158] tail [0.9522, 0.9697, 1.0113, 1.0698, 1.1581] (normalized).

CPU same forecast tail [0.9522808790206909, 0.9697253704071045, 1.0113576650619507, 1.0698736906051636, 1.1581764221191406] - difference max 4.6e-06.

Consistency

Saved CPU/NPU arrays and compared via scripts/compare_outputs.py:

python scripts/compare_outputs.py --cpu working/timemoe/cpu_forecast.npy --npu working/timemoe/npu_forecast.npy --task forecasting --atol 1e-4 --rtol 1e-3

Result:

{
  "task": "forecasting",
  "cpu_shape": [32],
  "npu_shape": [32],
  "finite": true,
  "atol": 0.0001,
  "rtol": 0.001,
  "max_abs_error": 4.649162292480469e-06,
  "mean_abs_error": 1.1622905731201172e-06,
  "passed": true
}

Additional full output (544 length) max_abs 4.65e-06, mean 6.8e-08. Threshold chosen for FP32 MoE (router top-k, one_hot). Strict pass.

Same weight, input, preprocessing, dtype (float32), seed (42), eval mode. No CPU fallback - output device verified npu:0 and param count 463/463 on NPU.

Single-sample smoke consistency (not full benchmark). No sampling variance.

Performance

Measured with torch.npu.synchronize() around each model.generate.

  • First compile: 0.3154s (warmup1 includes graph compile + MoE routing)
  • Second run: 0.0616s / third 0.0610s (stable after compile)
  • Benchmark 10 runs avg: 0.0626s, min 0.0597s, max 0.0660s, p50 0.0625s, p90 0.0660s, p95 0.0660s, throughput 15.96 windows/s, batch 1, dtype float32, shape [1,512]→[1,544]
  • Fresh model first run: 0.0600s after cache? (second stable 0.0592s) - cache warms quickly
  • CPU reference: 3.90s (same input) → NPU speedup ~60x stable, ~12x including compile
  • HBM: npu:0 5166/65536 MB peak during benchmark (from 3105 idle), npu:1 idle 2873 MB
  • Excludes CSV read and denorm (timed only model.generate)

Warmup 3, test 10, as required. Preprocessing not timed.

Evidence

Three PNGs generated by xterm.js from real logs via scripts/render_xterm_evidence.mjs --style raw (dark background, white mono, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$):

  • assets/agent_workflow.png - workflow: inspect, env, download, comparison, benchmark, inference, validate
  • assets/npu_device_call.png - npu-smi + check_npu + model param device/dtype + input/output device
  • assets/model_result.png - default python inference.py full output

README references assets/agent_workflow.png, assets/npu_device_call.png, assets/model_result.png. Images only via xterm.js, not Pillow/matplotlib.

Limitations

  • Only univariate (input_size=1) forecasting; multivariate not supported (model config fixed)
  • Supported horizons are [1,8,32,64]; other pred_len will snap to nearest lower horizon (e.g., 20→8, 50→32) per model logic; tested 32 which maps exactly
  • Max context 4096 (model max_position_embeddings), tested 512 (typical ETTh)
  • FP32 only for strict consistency; BF16 would need looser atol
  • MoE warning Cannot create tensor with interal format is benign (one_hot internal format) - does not indicate fallback
  • Single synthetic dataset smoke test; not a full benchmark (M4/ETTh etc.) - for full evaluation run official TimeMoE eval suite