gcw_6a3w2yXz/ant-intl-Falcon-TST_Large-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ant-intl/Falcon-TST_Large NPU 适配

#NPU

本仓库将 HuggingFace 上的 ant-intl/Falcon-TST_Large(Falcon-TST 时间序列基础模型,MoE 异构多 patch 架构,hidden 1024,2 层 MoE,4 专家 + shared expert,seq_len 2880,多预测头 24/96/336)适配为可在单卡昇腾 Ascend 910B(npu:0)上真实运行的 GitCode AI model 仓库。支持单变量/多变量时序的零样本点预测,支持任意 horizon 的自回归多头推理。

  • 模型原始仓库:https://huggingface.co/ant-intl/Falcon-TST_Large
  • 权重:model-00001-of-00002.safetensors 3.72 GB + model-00002-of-00002.safetensors 1.26 GB,合计约 4.98 GB(fp32/bf16 混合),config.json seq_length 2880, hidden 1024, patch_list [120,96,64,36], shared 32, heads [24,96,336]
  • Revision:344bb5c86c1b3e7d68b331dad236bfd33f869ba2(main)
  • 源实现:https://github.com/ant-intl/Falcon-TST(modeling_FalconTST.py, configuration_FalconTST.py, trust_remote_code=True)

任务与路由

项值
模型ant-intl/Falcon-TST_Large(2.49B params, hidden 1024, 2 MoE layers, 4 local experts + 1 shared, expert_layers 4, heads 24/96/336)
架构FalconTSTBlock -> FalconTSTMoELayer (TopKRouter topk=1) -> SequentialFalconTST / FalconTSTExpert (PatchEmbedding MLP + TransformerLayer + RMSNorm) + RevIN + RoPE
任务时间序列点预测 point forecasting(通过 predict 自回归,支持 24/96/336 及任意 horizon)
输入time_series shape [batch, seq_len, channels](本仓 batch 1, seq_len 2880, channels 7;也支持 [batch, seq_len] 单变量),dtype float32,mask_pad 255.0 表示缺失,RevIN 按通道归一
输出forecast shape [batch, horizon, channels](本例 [1,96,7]),float32;长 horizon 经 multi_head 从长到短自回归拼接
数据契约轴顺序 [batch, time, channel] 输入 -> [batch, horizon, channel] 输出;context 2880(不足时左侧 pad 255.0,超出时截断最后 2880),horizon 96(本基准)/336(扩展),通道 7,缩放 RevIN(per-sample mean/std + inverse),patch 120/96/64/36 + shared 32,频率隐式
路由time-series 点预测(非概率预测,输出 deterministic forecast,需校验 max_abs/mean_abs)

环境

  • 操作系统:Linux aarch64,昇腾 910B(Ascend910_9362),CANN 8.5.1
  • Python 3.11,torch 2.9.0+cpu + torch_npu 2.9.0.post1,transformers 4.57.6,einops 0.8.2,safetensors,numpy 1.26.4
  • 依赖见 requirements.txt:torch、torch_npu、transformers、safetensors、einops、huggingface_hub、numpy

安装

pip install -r requirements.txt
# 昇腾 NPU 需确保 torch 与 torch_npu 版本匹配,并已加载 Ascend 驱动/固件
# 权重已缓存在 models/Falcon-TST_Large(约 4.98 GB),无需重复下载;缺失时自动从 HuggingFace 拉取(HF_ENDPOINT=https://hf-mirror.com)

NPU 推理

inference.py 为自包含脚本,默认使用合成可复现时序(seed 0)在 npu:0 上完成 CPU 基线、NPU 推理、一致性与性能基准。所有参数与输入 Tensor 显式位于 npu:0(见 npu_device_call.png 与 model_result.png)。计时前后均调用 torch.npu.synchronize()。

# 权重已缓存在本地(离线,推荐)
python inference.py

# 指定本地权重目录
MODEL_DIR=/path/to/Falcon-TST_Large python inference.py

# 自动从 HuggingFace 下载(需联网,首次约 4.98 GB)
HF_ENDPOINT=https://hf-mirror.com python inference.py

设备固定为 npu:0(可用时),通过 copy.deepcopy 保持 CPU/NPU 权重一致,避免随机差异。输入通过 RevIN 后 patch 嵌入,MoE router 按样本分发到 4 专家 + shared,输出经 inverse RevIN。

真实结果(Ascend 910B 单卡,npu:0)

以合成时序 seq_len=2880, batch=1, channels=7, horizon=96 为例(seed 0,torch.randn,float32):

  • 输入:time_series shape (1,2880,7),均值 -0.0120,标准差 1.0042,范围 [-4.34, 4.10]
  • CPU 基线:forecast shape (1,96,7) 均值 0.010879,标准差 0.072301,最值 [-0.191888, 0.240055],样例 channel0 前5 [-0.191888, -0.116163, -0.177874, -0.083044, -0.097190],channel3 前5 [-0.006824, 0.013052, 0.011642, 0.011840, 0.061786]
  • NPU 输出:相同输入在 npu:0 上 forecast shape (1,96,7) 均值 0.010879,标准差 0.072247,最值 [-0.191882, 0.240053],样例 channel0 前5 [-0.191882, -0.116161, -0.177874, -0.083042, -0.097188]
  • 推理状态:[STATUS] SUCCESS - NPU inference completed without CPU fallback

扩展 horizon 336 在同输入单通道下 shape (1,336,1) max_abs 1.07e-05 亦一致。完整输出见 model_result.png。同权重、同输入、同预处理、同 dtype (float32)、同随机种子、eval 模式下对比。

CPU-NPU 一致性

使用相同权重(deepcopy)、相同数据切片(seed 0)、相同预处理(RevIN + patch)、相同种子与 float32,分别在 CPU 与 npu:0 保存原始输出,用 scripts/compare_outputs.py 比较:

python scripts/compare_outputs.py --cpu /tmp/falcon_cpu.npy --npu /tmp/falcon_npu.npy --task forecasting --atol 1e-4 --rtol 1e-3
  • 点预测(forecast):shape (1,96,7) 一致,max_abs 2.31e-05,mean_abs 2.26e-06,atol=1e-4 rtol=1e-3 PASS(另 horizon 336 单通道 max_abs 1.07e-05)
  • 有限值:CPU 与 NPU 均 all_finite True
  • 阈值:atol=1e-4 rtol=1e-3(FP32 跨硬件 LayerNorm/attention/RoPE 正常波动,MoE 误差远低于阈值)

结果:PASS。

性能基准

在 npu:0、float32 下,预热 3 次后正式计时 10 次(batch=1, seq_len=2880, channels=7, horizon=96):

指标值
compile/first-run~496 ms(首次含图编译,2 层 MoE + 4 专家 ×4 层) / ~79.89 ms(首轮计时 after warmup)
avg / min / max81.19 ms / 79.89 ms / 82.65 ms
p50 / p90 / p9581.14 ms / 82.33 ms / 82.49 ms
throughput12.32 windows/s (batch 1, seq 2880) 或 1182 forecast_rows/s
dtypefloat32,batch 1, seq 2880, horizon 96, channels 7
权重显存~9.28 GB fp32 统计(含 2.49B params)实际 HBM 占用 ~4-5 GB + 激活 ~1 GB,64 GB 未超限(npu-smi HBM 3513 MB 稳态)
预处理计时含 RevIN + patchify + routing,已计入 forward;不含合成数据生成

首轮编译与稳定推理分开报告,计时前后均调用 torch.npu.synchronize()。长 horizon 336 需多轮自回归,耗时与 horizon 线性增长。

证据图

三张 PNG 由 xterm.js 根据本次真实日志生成(非手工绘图),深灰背景、白色等宽字体,固定提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$(仅展示标签,不证明服务器身份):

  • assets/agent_workflow.png:侦察、环境检查、下载、加载、NPU 推理、一致性、benchmark 和提交校验的流水日志
  • assets/npu_device_call.png:npu-smi info、NPU 可用性、设备名、模型参数 device/dtype、输入与输出 Tensor device
  • assets/model_result.png:默认 python inference.py 的完整输出,包括 schema、真实 forecast、同步耗时和状态

agent workflow npu device model result

图片由 scripts/render_xterm_evidence.mjs --style raw 渲染,源日志经 ANSI 清理并脱敏后生成。

限制

  • 点预测输出 deterministic forecast,未包含概率分位数采样;长 horizon 经从长到短头自回归,误差随步累积。
  • 仅验证 seq_len 2880 + horizon 96/336,channels 7 的路径;更长 horizon 或更大 batch 会增加显存与编译时间,单卡 64 GB 需评估;模型总权重 4.98 GB,float32 加载时显存峰值约 9 GB 统计值。
  • 单样本 smoke consistency,不能称为完整数据集精度评测;完整评测需在 ETT、Weather 等上以 MAE/MSE 评估。
  • NPU 仅验证 Ascend 910B 单卡 npu:0,float32;未验证 910A/C、多卡或量化(int8)路径。
  • 若模型需对数据执行 fit(),本仓仅适配推理,不声称训练已完成 NPU 适配。

复现

见 inference.py 与本 README。权重从 models/Falcon-TST_Large 本地加载,若缺失会从 HF 缓存自动定位,无需联网。