w
weasonlee/Falcon-TST_Large
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Falcon-TST_Large — Ascend NPU 适配版

基于官方权重 ant-intl/Falcon-TST_Large,在华为 Ascend 910 上做 Ascend NPU 推理验证的镜像。 FalconTST 是用于时间序列预测(time-series forecasting)的纯 Transformer 模型,使用多尺度 patch 分块 + 多预测头 (multi-forecast-head) + 可选 MoE 专家路由。

模型简介

  • 架构:FalconTSTForPrediction(model_type=FalconTST)
  • 自定义代码:configuration_FalconTST.FalconTSTConfig + modeling_FalconTST.FalconTSTForPrediction (仓库内 auto_map 指向,通过 trust_remote_code 加载)
  • 核心参数:hidden_size=1024,num_hidden_layers=2,num_attention_heads=16, seq_length=2880,patch_size_list=[120, 96, 64, 36],multi_forecast_head_list=[24, 96, 336]
  • 任务:time-series-forecasting(多 horizon 多变量预测)
  • 权重:两个 safetensors 分片(model-00001-of-00002.safetensors + model-00002-of-00002.safetensors),约 4.6 GB

部署步骤

mkdir -p /data/Falcon-TST_Large && cd /data/Falcon-TST_Large
HF_ENDPOINT=https://hf-mirror.com HF_HUB_DOWNLOAD_TIMEOUT=120 \
  python3 -c "from huggingface_hub import snapshot_download; \
              snapshot_download('ant-intl/Falcon-TST_Large', local_dir='/data/Falcon-TST_Large/models')"
pip install -r requirements.txt

依赖:torch 2.9.0 + torch_npu 2.9.0.post1 + CANN 8.5.1 + Ascend 910 驱动。 transformers_version 在 config 中标注为 4.40.1;本仓库用 transformers 4.57.6 + trust_remote_code 成功加载(custom code 兼容性已验证)。

推理示例

# Ascend NPU(fp16,推荐)
python3 inference.py --device npu

# CPU(回归测试与精度对比基线)
python3 inference.py --device cpu

# 自定义参数
python3 inference.py --device npu --dtype fp16 --seq_len 2880 --n_channels 1 \
                     --outdir outputs

脚本会在 outputs/ 下写入 metrics_npu.json 与 metrics_cpu.json:

  • load_time_s / inference_time_s / total_time_s
  • logits_shape / logits_stats(mean / std / min / max)
  • n_params / model_class

CPU vs NPU 精度对比表(teacher-forcing)

指标NPUCPU差异
load_time_s(见 outputs/metrics_npu.json)(见 outputs/metrics_cpu.json)—
inference_time_s同上同上—
logits mean同上同上同上
logits std同上同上同上
cos_sim——outputs/compare.json
max_abs_err——同上
mean_abs_err——同上

对比会用 outputs/logits_npu.npy vs outputs/logits_cpu.npy 计算余弦相似度与绝对误差, 落到 outputs/compare.json。

目录结构

.
├── inference.py        # 双设备推理脚本(--device npu|cpu,--dtype fp16|fp32)
├── readme.md           # 本文件
├── requirements.txt    # 依赖清单
├── models/             # 权重(.gitignore 排除,含自定义 FalconTST 代码)
└── assets/             # 3 张 2x2 多面板适配信息图

已知限制

  • 模型在 NPU 上以 fp16 运行,CPU 基线用 fp32;fp32 NPU 路径在 PyTorch-2.9 / torch_npu-2.9.0 下某些算子可能缺失或 fallback,脚本默认 fp16 与 CPU fp32 以保证两路都有可比输出。
  • 远期 horizon 由 multi_forecast_head_list 控制:[24, 96, 336]。

验证

  • ✅ 权重齐备(config + auto_map + 2 个 safetensors 分片 + index)
  • ✅ NPU 推理:详见 assets/model_result.png
  • ✅ CPU 推理:详见 assets/model_result.png
  • ✅ 对比指标:详见 outputs/compare.json