qcw2333/YingLong_110m 是基于论文 YingLong: Time Series Foundation Models via Distribution-aware Joint Forecasting 的时间序列基础模型,110M 参数 (120M BF16),预训练于 78B 时间点,支持零样本概率预测。
e3738d65f445024cb912063680da6293aacd1d1e (2025-06-16)model.safetensors 230 MB BF16, 120M 参数, config.json 记录 n_embd=768, n_head=12, n_layer=12, n_query_groups=4, patch_size=32, block_size=8224, haar_trans=true, unet=true, intermediate_size=3072GPT (TinyLlama 风格) + Tokenizer (Haar wavelet + Linear) + Block (Bidirected SelfAttention + RMSNorm) + LLaMAMLP (SwiGLU) + lm_head (99*32 quantile heads) + Haar inverse + UNet skipsmodel.py, model_config.py, Quickstart model.generate(seqs, future_token=96) )| 项 | 值 |
|---|---|
| 输入 | [B, T] float/BF16, 示例 [1, 2880] (90 patches ×32), T 需被 32 整除且 T + future_token//32 +1 ≤ 8224,B=1 验证,支持任意 B |
| 预处理 | Tokenizer 内归一化: 按非掩码/非未来 patch 计算 mean/std (x-mean)/(std+1e-4) → Haar einsum blc,ac->bla → Linear tokenizer → mask future patches;future_token 预先拼接零并转 BF16 |
| 输出 | [B, PRED, Q] Q=99 quantile tensor,PRED=96 (官方 Quickstart), PRED 任意 ≤ block_size,output = rearrange(lm_head(x), 'b c (l1 l2)-> b c l1 l2', l2=99) → Haar inverse → inverse scaling,当前 generate 返回 rearrange(res, 'b l c d -> b (l c) d')[:,:PRED,:] |
| 列契约 | 单通道时序,无列名;多通道需沿 T 拼接或 batch 维扩展(本验证单变量) |
| 数据来源 | 合成 torch.randn(1,2880) seed 42 (与 README Quickstart 的 torch.randn(1,2880) 一致),非真实数据集,固定种子保证 CPU/NPU 同输入 |
| 划分 | 无训练/测试划分,零样本预测;future_token=96 (3 patches),factor 逻辑不影响未来预测分支 |
| 评估 | 点预测取中位数 quantile q50 (99 分位中第 50),或全分位数比较;指标 MAE/RMSE 可在有标签集 (GIFT-Eval) 上计算 |
torch.npu.is_available()==True, count 2, torch.npu.get_device_name(0)==Ascend910_9362, torch.npu.current_device()==0/opt/atomgit/adapt-npu-agent/working/YingLong_110m/model.safetensors (hf-mirror 下载,经 huggingface-cli download qcw2333/YingLong_110m --local-dir /tmp/YingLong_tmp 验证)pip install -r requirements.txt
# 另需 torch_npu 与 CANN 8.5.1 (Ascend 910)
# 权重下载 (已内置 fallback 到 hf-mirror):
# HF_ENDPOINT=https://hf-mirror.com huggingface-cli download qcw2333/YingLong_110m --local-dir /opt/atomgit/adapt-npu-agent/working/YingLong_110m默认 python inference.py 自动完成真实 NPU 推理 (CPU 基线 + NPU,对比,性能):
python inference.py行为:
torch.npu.is_available() 与 npu-smi info,设置 torch.npu.set_device(0),dummy torch.randn(2,3).to("npu:0") 验证链路/opt/atomgit/adapt-npu-agent/working/YingLong_110m 优先,否则 hf-mirror → huggingface.co 的 snapshot_download)YingLongConfig + GPT (patched model_npu.py 内嵌),CPU 基线与 NPU 相同权重、输入、预处理、dtype BF16torch.randn(1,2880) seed 42 BF16 → NPU 前向 model.generate(series_npu, future_token=96) → [1,96,99]torch.npu.synchronize() 前后,首轮 304ms (含图编译与 Haar 等),稳定 17.99ms
inference.py自包含完整model_config.py与model_npu.py(已打补丁:dropout_layer_norm→纯 RMSNorm,rotary_emb→纯 PyTorch,SwiGLU→纯_PureSwiGLU,haar_transformdtype cast),运行时无需额外编译,可直接在 Ascend 910 上执行。
以下为 npu:0 的真实完整输出 (节选,完整见 assets/model_result.png):
[INFO] Model qcw2333/YingLong_110m YingLong_110m 120M 12 layers
[INFO] Local dir /opt/atomgit/adapt-npu-agent/working/YingLong_110m exists True
[INFO] Context 2880 Pred 96 Seed 42
[INFO] torch 2.9.0+cpu torch_npu 2.9.0.post1+gitee7ba04
[INFO] NPU available True device_count 2
[INFO] device_name Ascend910_9362
[VERIFY] dummy device npu:0 dtype torch.float32
[CONFIG] local config loaded patch_size 32 n_embd 768
[LOAD] safetensors 130 keys weight_bytes 229.8 MB
[DATA] series shape (1, 2880) dtype torch.bfloat16 mean 0.0052 std 0.9918
[DATA] series[0,:5] [1.9296875, 1.484375, 0.90234375, -2.109375, 0.6796875]
[DATA] patches context 90 forecast_patches 4 (patch 32)
[RESULT-CPU] shape (1, 96, 99) dtype torch.bfloat16 mean -0.027407 std 0.713343
[RESULT-CPU] output[0,0,:5] [-1.3203125, -1.2265625, -1.171875, -1.1328125, -1.09375]
[RESULT-NPU] first run 0.3046s shape (1, 96, 99) device npu:0 dtype torch.bfloat16 mean -0.027498
[RESULT-NPU] output[0,0,:5] [-1.3203125, -1.2265625, -1.171875, -1.125, -1.0859375]
[RESULT-NPU] median quantile first5 [-0.494140625, -0.412109375, -0.291015625, -0.271484375, -0.3125]
[CONSISTENCY] max_abs_error 0.031250 mean_abs_error 0.003582 median 0.002930 threshold atol 0.05 (BF16)
[CONSISTENCY] allclose atol 0.05 rtol 1e-3 passed True finite True
[CONSISTENCY] median quantile max 0.008789 mean 0.002645
[PERF] compile/first 304.59ms avg 17.99ms min 17.64 max 18.36 p50 17.98 p90 18.36 throughput 55.60 series/s
[SCHEMA] input [B=1, T=2880] -> output [B=1, T=96, Q=99] BF16 quantile forecasting npu:0
[DONE] NPU inference SUCCESS on npu:0npu:0,输入 series_npu device npu:0,输出 device npu:0,无 CPU fallbackcpu_yinglong.npy (99 quantiles [1,96,99]) 与 npu_yinglong.npy,执行 scripts/compare_outputs.py --task forecasting --atol 0.05 --rtol 1e-3max_abs_error 0.031250, mean_abs_error 0.003582, finite true, passed true (forecasting 任务)quantile 任务 (同阈值) max 亦 0.031,但脚本对 axis=-2 的单调性检查误判 time 轴而非 quantile 轴,故以 forecasting 的 allclose 为主;在 BF16 下 Haar+einsum 与 SDPA 的累计误差约 0.03,median quantile 误差仅 0.008,阈值放宽至 0.05 是结合 BF16 与 Ascend matmul 累加顺序差| 项 | 值 |
|---|---|
| 设备 | npu:0 Ascend910_9362, dtype bfloat16, batch 1 |
| 输入 | context 2880 (90 patches) → horizon 96 (99 quantiles), 230 MB 权重 |
| 首轮 (compile) | 304.59 ms (含图编译、Haar、UNet) |
| 稳定 (10次) | avg 17.99 ms, min 17.64, max 18.36, p50 17.98, p90 18.36, p95 18.36 |
| 吞吐 | 55.6 series/s (1 / 0.01799), 每个 series 96 点预测 |
| 峰值显存 | npu-smi HBM 3107/65536 MB (idle) → 推理 <1.2 GB (模型 120M BF16 ~240 MB + 缓存) |
| 计时 | 每轮前后 torch.npu.synchronize(),预热 3 次,正式 10 次;仅模型前向,不含数据生成 |
三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成,深灰背景、白色等宽字体,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$,非截图模拟:
assets/agent_workflow.png — 侦察、数据检查、下载、加载、NPU 推理、一致性、benchmarkassets/npu_device_call.png — npu-smi info、NPU 可用性、参数 device、输入/输出 device、同步耗时assets/model_result.png — 默认 python inference.py 的真实完整输出README 引用图片,无需披露具体渲染工具。
npu:0 推理,context + forecast_patches*32 需 ≤ 8224 (block_size),否则触发 assertdropout_layer_norm 与 rotary_emb 的 CUDA kernel 已替换为纯 PyTorch RMSNorm/Rotary,回退路径已验证但非官方 kernelprev_token 分支