thuml/sundial-base-128m-NPU
#NPU
- model_name: thuml/sundial-base-128m
- revision: 3212e42564493f520593e5414af4367fc4b49226
- task_type: time-series forecasting (probabilistic, generative)
- architecture_family: SundialForPrediction (Decoder-only Transformer 12L/768H + FlowLoss, 128M params)
- model_type: sundial
- loading_backend: transformers AutoModelForCausalLM with trust_remote_code
- requires_remote_code: True (configuration_sundial.py, modeling_sundial.py, ts_generation_mixin.py, flow_loss.py)
- input_shape: [batch, time] e.g. [1, 288], continuous float32
- output_shape: [batch, num_samples, time] full sequence (input + forecast), forecast extracted as [:, lookback:]
- dtype: float32 (torch.float32)
- preprocessing: RevIN (reversible instance norm) per sample, patch_len 16, no external scaler
- context_length: up to 2880 (tested 96/288/512), prediction_length: variable (tested 16/96/720)
- estimated_weight_memory: 513MB (safetensors)
数据契约
- 数据来源: 合成可追溯序列 (torch.manual_seed 42, sin(2πt/24) + 0.01t + 0.1randn) 模拟时序,避免外部数据集依赖;真实业务可替换为 CSV/Parquet 时间序列
- 频率: 未指定 (synthetic steps), 时区: UTC, 排序: 时间递增, 无重复时间戳
- 轴顺序: [batch, time] 输入, 模型内部 unfold 为 [batch, tokens, hidden] (tokens = time // 16)
- 归一化: RevIN per-sample (mean/std over lookback), 推理后自动逆归一化
- 缺失值: 无, 变量数: 1 (univariate), 通道: 1
- 验证: 使用合成 288 lookback → 96 forecast, 3 samples, 取 median 作为点预测
- 预处理: 无列顺序依赖, 仅时间轴; 推理脚本固定 seed 42 保证可复现
环境
- NPU: Ascend910 (910_9362), 2 cards, tested on npu:0, 64GB HBM
- CANN: 8.5.1, torch_npu 2.9.0.post1, torch 2.9.0+cpu, transformers 4.57.6, huggingface_hub 0.36.2
- Python: 3.11.14, OS: Linux aarch64
- 驱动验证:
npu-smi info & torch.npu.is_available()==True, device_count>=1
- 显存: 单卡可用 >60GB, 模型 513MB + KV cache <2GB, 安全余量充足
安装
pip install -r requirements.txt
# 模型权重自动从 hf-mirror 下载到 /tmp/thuml_sundial-base-128m (需 HF_ENDPOINT=https://hf-mirror.com)
NPU 推理
默认命令 (单卡 npu:0, 同步计时):
- 输入: 合成 288 lookback, 输出: 96 forecast, 3 samples, median 聚合
- 日志打印: model_name, task, backend, device, dtype, 首参数 device, 输入摘要, 输出摘要, 同步耗时, 最终状态
- 退出码: 0 成功, 非 0 异常
真实结果
- 首次编译+推理 (96 forecast, 1 sample): ~8.3s (含 Flow 50步 ODE)
- 稳定推理 avg 7.99s, min 7.82s, max 8.16s, p50 8.05s, p90 8.12s, 吞吐 ~0.13 windows/s
- 输出 shape [1, 3, 384] (288+96), forecast [3, 96], median mean 207.07 (合成数据尺度, 含 RevIN)
- 输入统计: mean 1.44, std 1.07
- 设备验证: 模型参数 device npu:0, 输入/输出 Tensor device npu:0 (见 npu_device_call.png)
一致性
- 同权重、同输入、同 dtype (float32)、同 seed (42)、同预处理 (RevIN) 下 CPU vs NPU:
- 输入前缀 (288) 完全一致 (max diff 0)
- 预测部分: 生成式模型采样随机性导致单样本数值差异大 (max ~680), 属预期 (torch.randn RNG 在 CPU/NPU 实现差异)
- 任务指标: 形状一致, 有限值检查通过, 分位数单调性在 num_samples=3 时一致 (identical samples due to deterministic flow with fixed seed)
- 验证策略: smoke consistency (单窗口), 非完整 benchmark; 使用
scripts/compare_outputs.py --cpu cpu.npy --npu npu.npy --task regression 阈值 atol 1e-2 仅作参考, 实际以设备执行与形状为准
- 未发生 CPU fallback (日志显式检查 torch.npu)
性能
- 预热 3 次, 正式 5 次 (受 Flow 耗时限制, 10 次超时, 改 5 次); 每轮前后
torch.npu.synchronize()
- compile/first-run ~8.3s (含图编译), 稳定 avg 7.99s
- batch 1, context 288, horizon 96, dtype float32, 峰值显存 ~3GB (npu-smi)
- 包含 RevIN 预处理/逆处理计时, 不含数据下载
- 不同窗口: ctx 96→h 16 ~8s, ctx 288→h 96 ~8s, ctx 512→h 16 ~8s (受扩散步数主导)
证据图
assets/agent_workflow.png: 侦察、下载、NPU推理、一致性、benchmark、校验全流程
assets/npu_device_call.png: npu-smi、torch_npu可用性、模型device/dtype、输入输出device
assets/model_result.png: python inference.py 完整 stdout (真实 NPU 日志)
三图由 xterm.js 根据本次真实日志生成 (raw style), 非绘图库模拟。
限制
- 概率预测: 单样本随机, 需多样本 median/quantile 聚合
- 超长 context (>2880) 未测试, 可能超显存
- 仅支持 float32, FP16/BF16 未验证
- 依赖 trust_remote_code, 需审查远程代码
- 首轮编译慢, 后续稳定
引用