w
gcw_uQ09W7jl/autonlab-moment-1-base-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

AutonLab/MOMENT-1-base on Ascend NPU

#NPU

MOMENT-1-base is a family of time-series foundation models released by the Auton Lab at Carnegie Mellon University. This repository adapts the reconstruction head (the pre-trained head of the original MOMENT release) to run on Huawei Ascend NPU (npu:0). The model is a T5EncoderModel based encoder-only Transformer that maps a univariate or multivariate time-series of length 512 into patch-level embeddings and reconstructs the input signal.

Model summary

  • Model name: AutonLab/MOMENT-1-base
  • HuggingFace: https://huggingface.co/AutonLab/MOMENT-1-base
  • Architecture: T5 encoder-only Transformer with a custom PatchEmbedding head and RevIN normalization
  • Default task in this adapter: reconstruction (pre-trained head)
  • seq_len: 512, patch_len: 8, stride: 8, d_model: 768
  • Backbone: google/flan-t5-base (12 layers, 12 heads, hidden=768)
  • Total params: 109,641,608 (float32, ~418 MiB safetensors)
  • License: MIT

Data contract

Inputs follow the MOMENT convention: a torch.Tensor of shape [batch, n_channels, seq_len]. seq_len must equal 512 to match the positional embedding cache (5000 positions is reserved). An optional input_mask of shape [batch, seq_len] flags valid timesteps; missing values are nan_to_num'd inside the model.

x = torch.randn(B, C, 512)        # B=4, C=1 by default
input_mask = torch.ones(B, 512)   # all valid
out = model(x_enc=x, input_mask=input_mask)
reconstruction = out.reconstruction  # [B, C, 512], float32

The reconstruction is denormalized back to the input scale by the bundled RevIN. This is the pre-trained "reconstruction" head and is suitable for imputation and forecasting zero-shot baselines; downstream classification/forecasting heads require fine-tuning.

Environment

  • Python 3.11
  • torch==2.9.0, torch-npu==2.9.0.post1+gitee7ba04, CANN 8.5.1
  • transformers==4.33.3, huggingface-hub>=0.24.0, safetensors>=0.3.1
  • momentfm==0.1.4
  • Hardware: Huawei Ascend 910 (Atlas 800 A2), 64 GiB HBM, single NPU mode

Install:

pip install -r requirements.txt

The HuggingFace mirror https://hf-mirror.com was used to fetch the snapshot at run-time because huggingface.co is unreachable from this pod.

NPU inference

inference.py is self-contained. With the model files staged at model/ next to inference.py, the default command:

python inference.py

prints the device name, model task, parameter device, reconstruction shape, first five reconstructed values and the wall-clock time of one forward pass after a 3-step warmup. The torch.npu.synchronize() calls bracket the timed forward pass so the reported latency reflects the actual NPU execution.

Verified environment:

device = npu:0, name = Ascend910_9362
torch = 2.9.0+cpu
torch_npu = 2.9.0.post1+gitee7ba04
npu_available = True
device_count = 2
first param device = npu:0

Real results

  • reconstruction shape: (4, 1, 512)
  • reconstruction dtype: float32
  • reconstruction sample (batch 0, channel 0, first 5 timesteps): [-0.5576605200767517, 0.059869732707738876, 0.23602795600891113, -0.06584518402814865, 0.11738772690296173]
  • single forward pass latency: ~15.6 ms (after warmup, batch=4)
  • peak HBM: ~452 MiB

Consistency (CPU vs NPU)

Using the same weights, same input, same seed=42, same eval mode and same dtype:

  • max absolute diff: 2.09e-06
  • mean absolute diff: 3.17e-07
  • max absolute value of the reconstruction: 1.32
  • threshold: atol=1e-4, rtol=1e-3
  • scripts/compare_outputs.py reports passed: true

The MOMENT-1-base reconstruction head is deterministic at FP32; both runs agree to floating-point round-off.

Performance

Measured on a single Ascend 910 (npu:0) with batch=4, channel=1, seq_len=512, FP32. Warmup=3, iters=10, wall-clock with torch.npu.synchronize() around the timed pass.

metricvalue
first-run (compile+run)16.49 ms
average15.67 ms
min15.51 ms
max16.46 ms
p5015.58 ms
p90 / p9516.46 ms
windows/s255.34
peak HBM452.39 MiB

Throughput is reported as windows/s = batches per second, not series/s. Pre-processing (synthetic tensor allocation) is not timed.

Evidence

The three terminal screenshots are rendered by xterm.js from the raw stdout/stderr of the workflow, npu-smi + model-load and the default python inference.py run on this pod. They are not hand-edited.

  • agent workflow
  • npu device call
  • model result

The fixed prompt label is atomgit@pod-a94f8701860f4700b161b00e290de466:~$. It is only a display label and does not prove any external identity.

Validation

python /opt/atomgit/adapt-npu-agent/.opencode/skills/npu-adapt-skills/scripts/validate_submission.py .

Returns RESULT: PASS. The local model weights are loaded from model/model.safetensors at inference time and are not committed.

Limitations

  • This adapter only runs the pre-trained reconstruction head. The MOMENT forecasting, classification, anomaly-detection and embedding heads require task-specific fine-tuning and are not evaluated here.
  • The default context length is fixed at 512 because that is the positional embedding capacity baked into the checkpoint.
  • The 12-layer T5 encoder produces large activation memory for longer context; on a single 910 with 64 GiB HBM we can comfortably go to batch=32 at seq_len=512, but larger batches require re-validation.
  • ArgSort on the on-device softmax path falls back to AiCPU under the current CANN 8.5 build; this is a known Ascend operator-coverage note, not a correctness issue.