#NPU #Ascend #Ascend910
Model: thuml/sundial-base-128m (Sundial-base, 128M, Transformer decoder + FlowLoss, ICML 2025 Oral) Revision: main (model.safetensors 513MB) Task: time-series forecasting (zero-shot probabilistic / point forecasting)
Sundial is a generative time-series foundation model pre-trained on 1 trillion time points. Architecture: PatchEmbedding (input_token_len=16) -> 12 decoder layers (hidden 768, heads 12) -> LayerNorm -> FlowLoss (diffusion steps 50). Supports variable lookback (up to 2880) and prediction lengths (output_token_lens=[720]). RevIN normalization is applied by default.
[batch, time] float32, channels=1, axis_order=[B,T]pip install -r requirements.txt
# requirements: torch, torch_npu, transformers, numpy, pandas, safetensors, accelerateDefault command (real NPU, deterministic):
python inference.pyIt loads thuml/sundial-base-128m (local working/models/sundial-base-128m if exists, otherwise HF hub via HF_ENDPOINT=https://hf-mirror.com), moves model to npu:0, runs single-step forecasting with fixed seed 123, prints device/dtype, timing and forecast sample.
Manual example:
import torch, torch_npu
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("thuml/sundial-base-128m", trust_remote_code=True)
model = model.to("npu:0")
model.eval()
seqs = torch.randn(2,512).to("npu:0") # [B, lookback]
with torch.inference_mode():
torch.npu.synchronize()
out = model(input_ids=seqs, max_output_length=96, return_dict=True).logits
torch.npu.synchronize()
print(out.shape) # [2,1,96]input_sample[0,:5]: [0.33737, -0.17777, -0.30352, -0.58801, 0.34860]
output_shape: [2, 1, 96]
output_sample[0,0,:5]: [0.19843, -0.10754, -0.12281, -0.26885, 0.16702]
output_mean: 0.0253 std: 0.4411 min: -1.3480 max: 1.0616
first run (compile+infer) ~184ms (includes patch & load)
stable avg ~75ms over 10 runs (synchronized)Full log: assets/model_result.png (xterm rendering of python inference.py stdout).
model(input_ids=seqs_cpu, max_output_length=96)model.to("npu:0"), same seqs_cpu moved to npu:0, same seed for FlowLoss noise (torch.manual_seed + torch.npu.manual_seed)working/cpu.npy and working/npu.npy (forecast tensor [2,1,96] FP32)python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu.npy --npu working/npu.npy --task forecasting --atol 1e-4 --rtol 1e-3{
"task": "forecasting",
"cpu_shape": [2, 1, 96],
"npu_shape": [2, 1, 96],
"finite": true,
"atol": 0.0001,
"rtol": 0.001,
"max_abs_error": 1.07e-06,
"mean_abs_error": 1.59e-07,
"passed": true
}Threshold FP32 1e-4/1e-3 is justified for deterministic flow sampling; stochastic variation eliminated by fixed seed. No CPU fallback.
assets/agent_workflow.png – workflow.log (inspect, check_npu, collect_env, CPU/NPU baseline, compare, benchmark)assets/npu_device_call.png – device.log (npu-smi, check_npu, model param device/dtype, input/output device)assets/model_result.png – inference.log (python inference.py real output)
Generated by scripts/render_xterm_evidence.mjs --style raw from real logs, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$.fit) not migrated; only inference on NPU