#NPU
| Component | Config |
|---|---|
| Model | hidden_size=384, num_hidden_layers=12, num_attention_heads=12, num_key_value_heads=12, intermediate_size=1536, hidden_act=silu, num_experts=8, num_experts_per_tok=2, rms_norm_eps=1e-6, rope_theta=10000, attention_dropout=0.0, use_cache=True, tie_word_embeddings=False |
| Input | input_size=1 (univariate, channel-independent), max_position_embeddings=4096 |
| Output | TimeMoeOutputLayer per horizon (1/8/32/64) -> Linear hidden->input*horizon |
| Generation | TSGenerationMixin._greedy_search (autoregressive, picks lm_head that matches remaining max_new_tokens) |
| Device | npu:0 (Ascend910_9362) |
| Precision | float32 baseline (verified), bfloat16 native (config torch_dtype=bfloat16) |
| Context | 400 used (configurable, max 4096 - pred_len) |
working/sample_data.csv (synthesized fallback uses same schema), SHA c389b492a121af65d1c6f502c8e7c3044f0d01ba1da16fc20062b07d953e0b6f, 599 rows, 35683 bytestimestamps, open, high, low, close, volume, amountclose univariate series (input_size=1). Other columns ignored for TimeMoE (channel-independent). Full schema preserved for generic time-series datasets.normed = (x - mean) / std where mean/std computed on context window (400). mean=10.960475, std=0.176887 for the default window.[1, 400] float32, [Batch, Time] (unsqueezed internally to [B,T,1]).model.generate(normed_context, max_new_tokens=64) -> normed_pred = output[0,-64:] -> pred = normed_pred * std + mean[Batch, Time] input, [Batch, Time+Pred] output; multivariate case would be channel-independent per seriesData privacy: no private data submitted; logs only show schema statistics and close forecasts.
| Item | Version |
|---|---|
| Python | 3.11.14 |
| Torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| Transformers | 4.40.1 (required; 4.57 incompatible without patch) |
| Accelerate | 1.14.0 |
| Pandas | 3.0.2 |
| Numpy | 1.26.4 |
| Huggingface_hub | 0.36.2 |
| Safetensors | 0.7.0 |
| Ascend Toolkit | /usr/local/Ascend/cann-8.5.1 (SOC ascend910_9391) |
| NPU | Ascend910_9362, 2 devices, visible 4,5 |
| CANN | 8.5.1 |
NPU check:
torch.npu.is_available()==True, device_count=2, device_name=Ascend910_9362
npu-smi info OKPeak memory for TimeMoE-50M on npu:0: ~500 MB (weights 217MB + KV cache + activations for 400+64 length; well within 64GB).
pip install -r requirements.txt
# For Chinese mirror: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txtRequirements (pinned for reproducibility):
torch==2.9.0
torch_npu==2.9.0.post1
transformers==4.40.1
accelerate==1.14.0
huggingface_hub
safetensors
pandas==3.0.2
numpy==1.26.4
tqdm
scikit-learnModel download (first run, then cached):
export HF_ENDPOINT=https://hf-mirror.com
export HF_HUB_DISABLE_XET=1
# model will be auto-downloaded to working/models/TimeMoE-50M or huggingface cacheDefault command (verified on Ascend 910B, npu:0):
python inference.pyWhat it does:
torch.npu.is_available() and npu-smi infotorch.npu.set_device(0)working/models/TimeMoE-50M or downloads from HF hub with revision pinned (446753...)npu:0 via .to("npu:0")model.generate(normed_context, max_new_tokens=64) under torch.no_grad() and torch.npu.synchronize() timingExpected output excerpt:
[LOAD] model first param device: npu:0
[INFER] Completed in 0.3166s (sync timed)
[RESULT] Forecast tensor shape (64,), finite True
[RESULT] pred head (first 5): [10.815929 10.811933 10.808162 10.80629 10.805475]
[STATUS] NPU inference SUCCESS on npu:0, elapsed 0.3166sDummy tensor verification:
[VERIFY] Dummy tensor device: npu:0
[VERIFY] Model param device after inference: npu:0No CPU fallback: explicit device="npu:0" and torch.npu.synchronize(); if NPU unavailable, script exits non-zero. Model params remain on npu:0 throughout; next(model.parameters()).device == npu:0.
Real NPU inference on Ascend910_9362 (context 400 -> pred 64, batch 1, FP32, seed 42, deterministic greedy):
| Metric | Value |
|---|---|
| Context mean/std | 10.960475 / 0.176887 |
| First forecast close | 10.815929 |
| Fifth forecast close | 10.805475 |
| Last forecast close | 10.817074 |
| Forecast mean close | 10.7944 |
| Forecast std close | 0.0135 |
| Forecast min / max | 10.7712 / 10.8171 |
| Elapsed (first compile) | 0.3057s |
| Second run | 0.0587s |
| Stable avg (10 runs) | 0.0603s |
| Finite | True |
| Ground truth MAE (next 64 closes) | 0.067848 |
Full forecast head (first 5, denormalized):
[10.815929 10.811933 10.808162 10.80629 10.805475]Normed head:
[-0.81716263 -0.83976007 -0.86107695 -0.87165713 -0.87626255]Tail (last 5):
[10.811561 10.815245 10.815043 10.816345 10.817074]Ground truth future close head (for reference, zero-shot):
[10.82 10.81 10.78 10.76 10.75] # from sample_data.csv rows 400-404CPU vs NPU on identical weights, data, preprocessing, seed=42, dtype float32, eval mode, greedy:
torch.manual_seed(42) on cpu, AutoModelForCausalLM.from_pretrained(..., torch_dtype=torch.float32, device_map="cpu")torch.npu.set_device(0) + same seed, same model.generate(normed_context, max_new_tokens=64) with same normalizationunsqueeze_ mutation side-effect)Outputs saved as .npy (forecast tensor shape [64] float32):
working/cpu_output.npy (and cpu_normed.npy)working/npu_output.npyCompare via scripts/compare_outputs.py --task regression --atol 1e-4 --rtol 1e-3:
{
"task": "regression",
"cpu_shape": [64],
"npu_shape": [64],
"finite": true,
"atol": 0.0001,
"rtol": 0.001,
"max_abs_error": 9.5367431640625e-07,
"mean_abs_error": 6.407499313354492e-07,
"passed": true
}Max abs error 9.5e-07 on close price scale ~10.96, relative ~8.7e-08, far within tolerance. Normed space max diff 5.48e-06. Smoke consistency only (single window 400->64), not full dataset benchmark.
No CPU fallback observed; model params remain on npu:0 throughout (next(model.parameters()).device == npu:0, dummy tensor on npu:0). Second run 0.0587s confirms stable NPU execution after compile.
Measured on npu:0, float32, batch=1, context=400, pred=64, input_size=1, horizon [1,8,32,64] (single step 64 via horizon 64):
model.generate (includes embed, 12 decoder layers with MoE, RoPE, output head). CSV I/O and normalization outside timed region. torch.npu.synchronize() before and after.Detailed perf.json:
{
"context_length": 400,
"prediction_length": 64,
"max_position_embeddings": 4096,
"first_run_sec": 0.3056674003601074,
"second_run_sec": 0.05869007110595703,
"stable_avg_sec": 0.0603276252746582,
"min_sec": 0.05998039245605469,
"max_sec": 0.06069016456604004,
"p50": 0.06035566329956055,
"p90": 0.060616135597229004,
"p95": 0.06065315008163452,
"dtype": "torch.float32",
"batch": 1,
"device": "npu:0"
}Three PNGs generated via scripts/render_xterm_evidence.mjs --style raw from real logs (fixed prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$):
assets/agent_workflow.png - full adaptation workflow: inspect, data check, download, load, NPU inference, consistency, benchmark, validationassets/npu_device_call.png - npu-smi and NPU device calls (model param device npu:0, dummy tensor npu:0)assets/model_result.png - default python inference.py output (forecast head, timing, SUCCESS)Rendered with xterm.js raw style, dark grey background, white monospace. Logs sanitized for tokens.

Evidence generated by xterm.js from real stdout/stderr, UTC timestamps, exit codes preserved.
max_new_tokens with argmax); stochastic sampling not tested