Bingggooo/AutonLab-MOMENT-1-base-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MOMENT-1-base NPU Adaptation #NPU

AutonLab/MOMENT-1-base on Ascend 910B npu:0 – time-series foundation model (T5-base backbone, seq_len 512, patch 8, d_model 768, 12 layers/12 heads, ~113M params, 115 param groups) for reconstruction/anomaly-detection and zero-shot forecasting.

  • Model weight URL: https://huggingface.co/AutonLab/MOMENT-1-base
  • Architecture: MOMENTPipeline + T5EncoderModel (google/flan-t5-base, 12 layers, 12 heads, d_ff 2048, gated-gelu), RevIN, Patching(8/8), PatchEmbedding(768), T5 encoder, PretrainHead/ForecastingHead
  • Task: Time-series reconstruction (pretrained) and forecasting (96 horizon); classification/embedding also supported; tabular treated as univariate windows
  • Revision: snapshot 5e44b0ea26376a176360f87831124e018f876d96, config seq_len 512 patch_len 8 patch_stride 8 transformer_type encoder_only
  • License: mit
  • Precision: FP32, also stable in FP16/BF16 on NPU
  • Max context: 512 (patched to 64 tokens), horizon 96 (forecasting head)

Data Contract

  • Input source: Synthetic univariate series seed 123, batch 1, n_channels 1, seq_len 512, 5min frequency synthetic. SHA256 of generation deterministic via seed; no personal data.
  • Axis order: [batch, n_channels, seq_len] strictly; model tokenizer expects [B, C, T] then patches [B*C, n_patches, d_model]. Input is not [B,T,C]. Channel=1 univariate; multivariate would be n_channels>1 same layout.
  • Time contract: ascending, no duplicate timestamps, no missing steps, gaps must be imputed before feeding; frequency informational only.
  • Preprocessing: Raw float32, no external scaling – model applies RevIN per sequence (mean/std over masked positions, affine False) internally for norm/denorm. torch.nan_to_num guards NaN/inf.
  • Target: reconstruction: output [1,1,512] same shape as input (pretrain head Linear 768->8 flatten). forecasting: [1,1,96] horizon 96. embedding: [batch, d_model] or [batch, n_patches, d_model] reduction mean.
  • Splits: single window synthetic; no train/test leakage; seed fixed 123 for comparability; forecasting head random but fixed seed 42 for deterministic CPU-NPU compare.
  • Schema validation: inference.py checks shape [B,C,T], T==512, finite, rejects mismatch.
  • Privacy: only synthetic stats and schema logged; no raw data submitted.

Environment

  • NPU: Ascend910_9362, 2 devices, tested on npu:0, HBM 65536 MB, SOC 910_9391, CANN 8.5.1, driver 25.5.5, npu-smi OK temp 44-45C
  • Python: 3.11.14, Torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, Transformers 5.15.1, Numpy 1.26.4, huggingface_hub 0.36.2, safetensors, momentfm 0.1.5 (vendored from github, tsfm_public 0.1.dev1)
  • HF cache: snapshot_download local_dir_use_symlinks False, trust_remote_code false (MOMENT pure python)
  • Device validation: torch.npu.is_available()==True, device_count==2, get_device_name(0)==Ascend910_9362, all 115 param groups on npu:0, no CPU fallback (ArgSort runs on AI CPU but expected, no fallback for model ops)

Installation

pip install -r requirements.txt
# requires CANN toolkit at /usr/local/Ascend/cann-8.5.1 and torch_npu
# momentfm is vendored: cp -r /tmp/moment_repo2/momentfm to site-packages or pip install git+https://github.com/moment-timeseries-foundation-model/moment.git

NPU Inference

python inference.py
# defaults: --task reconstruction --seq-len 512 --seed 123 --device npu:0
python inference.py --task forecasting
python inference.py --task embedding
python inference.py --benchmark   # warmup 3 + test 10
  • Loading: MOMENTPipeline.from_pretrained(local_path, model_kwargs={task_name}) then .init() then .to("npu:0"), verify next(param).device==npu:0, print dtype and device
  • Compute: direct model(x_enc, input_mask) for reconstruction/forecast, model.embed(...) for embedding, with torch.npu.synchronize() before/after timing, RevIN inside.
  • Output: stats, sample, median, elapsed, SUCCESS, exit 0 else non-zero. Forecasting head warning is expected (random head - fixed seed 42 ensures deterministic).
  • Edge: ArgSort warning on NPU is expected (int kernel on AiCpu), not a fallback failure; no other CPU fallback.

Real Results (NPU)

  • Input: batch 1, n_channels 1, seq_len 512, mean -0.0153, std 1.0007, preview [0.3373, -0.1777, -0.3035, -0.5880, 0.3486]
  • Reconstruction (pretrained head, npu:0, seed 123): shape [1,1,512], mean -0.039223, std 0.4387, preview [-0.3322, -0.0482, -0.0177, -0.1717, -0.1311], min -0.8746 max 1.1996, elapsed first run 0.2554s (incl compile), second stable 0.0125s
  • Device evidence: First param device: npu:0, NPU device name: Ascend910_9362, Input device: npu:0, Output device: npu:0, 115/115 params on NPU, torch.npu.synchronize() used
  • HBM baseline: 3108 MB idle, model ~453 MB weights (model.safetensors + duplicate bin) + encoder ~200 MB resident, within 64GB

Consistency

  • CPU vs NPU (same weights, seed 42 model init, seed 123 data, reconstruction): saved cpu_output.npy/npu_output.npy [1,1,512] float32
  • Result: max_abs_error 1.67e-06, mean_abs_error 3.03e-07, finite true, shape equal
  • Command: python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working_moment_base/cpu_output.npy --npu working_moment_base/npu_output.npy --task forecasting --atol 1e-4 --rtol 1e-3 → PASSED (forecasting task flag used for generic float compare)
  • Threshold rationale: FP32 atol 1e-4 rtol 1e-3 standard for time-series; observed 1e-6 << threshold proves no fallback and deterministic.
  • Reproducibility: same preprocessing (RevIN internal), dtype float32, eval mode, seeds fixed, sync timing. ArgSort AiCpu warning does not affect correctness.

Performance

  • Method: torch.npu.synchronize() before/after each forward; warmup 3, test 10
  • Compile/first-run: 0.2495s warmup1 (compile) vs 0.0125s stable (compile amortized). First-run fresh load 0.0138s after cache (compilation cached)
  • Stable: avg 0.0127s, min 0.0122s, max 0.0134s, p50 0.0126s, p90 0.0132s, p95 0.0133s, throughput 78.67 windows/s (batch1, 512->512 reconstruction, FP32)
  • Peak HBM: ~4200 MB after load, well within 65536 MB
  • Preprocessing: not included (synthetic ~0.001s); timing only model forward + head (synchronized)
  • Metric: windows/s for time-series (seq_len 512 patches 64); rows/s would be 512/0.0127=40314 rows/s but reported as windows

Evidence Images

All three PNGs generated by scripts/render_xterm_evidence.mjs --style raw from real logs (xterm.js white on dark gray, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$ display-only).

  • Agent Workflow – inspect, env, download, cpu baseline, npu inference, compare, benchmark, validate.
  • NPU Device Call – npu-smi, check_npu, device name, param dtype/device, input/output device.
  • Model Result – python inference.py full output, schema, forecast/reconstruction, timing, SUCCESS.

assets/ contains exactly those three files generated from logs/workflow.log, logs/device.log, logs/inference.log via manifest.

Limitations

  • Pretrained head only reconstruction; forecasting/classification heads are random before fine-tuning – zero-shot forecasting values are not production-grade, consistency still validated with fixed seed.
  • Univariate focus; multivariate n_channels>1 supported but not benchmarked extensive.
  • Seq_len 512 fixed patch 8; other lengths not tested for performance.
  • Training (fit) not migrated – only inference; gradient checkpointing enabled but not tested on NPU training.
  • Requires torch_npu and CANN 8.5.1; ArgSort int kernel runs on AiCpu by design (not considered fallback).
  • Single NPU npu:0 only; multi-NPU not benchmarked.

Repository Structure

.
├── inference.py
├── readme.md
├── requirements.txt
└── assets/
    ├── agent_workflow.png
    ├── npu_device_call.png
    └── model_result.png