liucu/AutonLab-MOMENT-1-small-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

AutonLab/MOMENT-1-small NPU Adapted #NPU

Model Introduction

MOMENT-1-small is a time-series foundation model (385K params, 145M weight file) developed by Carnegie Mellon Auton Lab. It is a T5 encoder-based (flan-t5-small, d_model=512, 8 layers, 6 heads) foundation model trained on TimeSeries-PILE for general-purpose time-series analysis. This repository provides Ascend 910 NPU adaptation (910B, npu:0) validated for reconstruction (pre-training / imputation / anomaly detection) with seq_len=512, patch_len=8, patch_stride=8. The checkpoint contains model.safetensors (145MB) and pytorch_model.bin (145MB) plus config.json with T5 config. Licence MIT. Paper: https://arxiv.org/pdf/2402.03885.pdf .

Original weight URL: https://huggingface.co/AutonLab/MOMENT-1-small

GitCode NPU repository: this model repository (public, type=model, topics: NPU, Ascend, Ascend910).

Data Contract

  • Task: reconstruction (also supports forecasting/classification/anomaly via MOMENTPipeline, NPU verified for reconstruction).
  • Input: [batch, n_channels, seq_len] float32, seq_len=512, n_channels=3 (validated, flexible 1~3), input_mask [batch, seq_len] with 1=valid, 0=masked.
  • Time series generation: deterministic synthetic sinusoids (validated):
    • ch0: sin(52πt/512)+0.5cos(2*2πt/512)+noise
    • ch1: 0.01t + sin(32πt/512)*0.8 + noise
    • ch2: sin(8*2πt/512)0.6 + sin(122πt/512)*0.4 where t=0..511, seed 42. This provides realistic periodic patterns vs random noise.
  • Axis order: [B, C, T] strictly; no permutation to [B,T,C] without code change.
  • Frequency/time features: not required; RevIN normalization applied internally.
  • Output: reconstruction [B, C, T] float32, de-normalized (RevIN denorm), same shape as input.
  • Pre-processing: RevIN norm (affine=False by default), nan_to_num, patching (Patching + PatchEmbedding with positional embedding). Same fitted state reused for CPU/NPU.
  • No missing steps, no column mapping needed (time-series not tabular DataFrame).
  • Validation used batch=2, seq_len=512, n_channels=3.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 4.57.6, momentfm 0.1.4, numpy 1.26.4, huggingface_hub 0.36.2
  • Ascend CANN 8.5.1, torch.npu.is_available()==True, device npu:0 Ascend910_9362, device count 2
  • HF_ENDPOINT=https://hf-mirror.com (domestic mirror), proxy via env (no manual http_proxy override)
  • Weight load: MOMENTPipeline.from_pretrained(local_dir, model_kwargs={"task_name":"reconstruction"}) then model.to("npu:0"), all tensors explicitly moved to npu:0, torch.npu.synchronize() before/after timing.

Installation

pip install -r requirements.txt
# requirements cover: torch, torch_npu, transformers, huggingface_hub, numpy, momentfm, safetensors

NPU Inference

Default command (verified on 910B):

python inference.py
  • Resolves local weight at working/models/MOMENT-1-small if exists, otherwise downloads from AutonLab/MOMENT-1-small via snapshot_download (requires HF_ENDPOINT).
  • Moves model and all compute tensors to npu:0, synchronizes.
  • Logs: model_name, task_type, backend, device, dtype, first param device, input summary (shape/dtype/preview), output summary (shape/device/dtype/mean/std), synchronized elapsed time, final SUCCESS with device id.
  • Exit code 0 on success, non-zero on NPU missing or fallback.

Real Results (NPU npu:0, batch=2, C=3, T=512)

  • Output shape: (2, 3, 512) device npu:0
  • Input preview ch0 first5: [0.5248, 0.5543, 0.6542, 0.7578, 0.7289]
  • NPU reconstruction preview ch0 first5: [-0.07252, -0.10288, -0.13895, 0.60960, -0.13686] (CPU identical within 1.7e-06)
  • NPU inference synchronized time: ~0.0090s (warmup 2, avg 8.83ms stable over 10 runs)
  • Weight bytes: ~303MB (145MB*2), param dtype float32, param device npu:0
  • Input device npu:0, output device npu:0, fallback_detected: False

Consistency

  • CPU vs NPU with identical weight/input/seed/dtype (float32) on same synthetic batch:
    • python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_recon.npy --npu working/npu_recon.npy --task regression --atol 1e-4 --rtol 1e-3
    • Result: shape [2,3,512] both, finite true, max_abs_error 1.669e-06, mean_abs_error 1.69e-07, passed true
    • Threshold rationale: FP32, atol 1e-4 rtol 1e-3 generous; observed errors ~1e-06 far below.
    • Single-window smoke consistency (batch=2) not full dataset benchmark; no argmax needed (regression).

Performance

  • After 3 warmup, 10 timed runs (torch.npu.synchronize() each side):
    • avg 8.83 ms, min 8.38 ms, max 9.07 ms, p50 8.92 ms, p90 9.00 ms, p95 9.03 ms
    • Throughput: 226.58 windows/s (batch 2 => 113 series/s), batch=2 windows per inference
    • First-run after compile already included in warmup; stable timing reported.
    • Peak memory: allocated 144.9 MB, max 161.4 MB (torch.npu.memory_allocated).
    • dtype float32, context 512, patch 8, horizon reconstruction full length.
    • Pre-processing timed inside inference (RevIN+patching), not excluded.

Evidence Graphs

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

  • assets/agent_workflow.png – workflow (env check, model fetch, NPU inference, consistency, benchmark).
  • assets/npu_device_call.png – npu-smi info + check_npu.py + param device logs, proving calls on npu:0.
  • assets/model_result.png – default python inference.py full stdout (input/output preview, sync timing, SUCCESS). Images are xterm.js rendered from logs; not simulated via Pillow/Matplotlib.

agent workflow npu device call model result

Limitations

  • Forecasting/classification heads are randomly initialized (warning: only reconstruction head pre-trained); those tasks require fine-tuning.
  • CANN ArgSort fallback to AICPU (warning) observed but not failing; timing includes it.
  • Single NPU npu:0 only; multi-NPU not tested.
  • BF16/FP16 not verified; FP32 only.
  • Smoke consistency only (2 windows), not full Timeseries-PILE evaluation.