liuhongwei-2026/Falcon-TST_Large
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Falcon-TST_Large on Ascend NPU

模型适配 · 时序数据预测 (Large-Scale Time Series Foundation Model with MoE) · 昇腾 NPU

Beta 版本头信息

{hardware NPU}

1. 简介

  • 模型来源: ant-intl/Falcon-TST_Large(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/ant-intl/Falcon-TST_Large,HuggingFace: hf-mirror.com)
  • 模型类型: Falcon-TST(Large-Scale Time Series Foundation Model with Mixture of Experts)—— 基于 MoE(Mixture of Experts)架构的大规模时序基础模型,4 专家,3 层 MoE,支持多补丁分词器和多预测头,适用于长序列时间序列预测
  • 参数量: ~2,493,000,000(2.5B)
  • 权重格式: bf16 · model-00001-of-00002.safetensors + model-00002-of-00002.safetensors(≈ 5.0 GB)
  • 输入/输出: (batch, seq_len, channels) → (batch, forecast_horizon, channels) —— 支持单变量/多变量时序预测
  • 适配状态: SUCCESS
  • 适配说明: Falcon-TST_Large 为自定义 MoE 时序架构(自定义 FalconTSTConfig、FalconTSTForPrediction、无 tokenizer、非语言模型),不适用 vLLM-Ascend;本项目采用 torch_npu 直接加载 safetensors 权重在昇腾 NPU 上完成适配,并以 FastAPI 提供 HTTP 服务化推理。
  • 适配时间: 2026-08-21
  • 硬件: {hardware NPU} Ascend 910B(torch_npu 2.9.0.post1)

2. 验证环境

组件版本
torch2.9.0
torch-npu2.9.0.post1
CANN8.5.1
NPUAscend 910B (2 × 64GB HBM)
Python3.11.14
transformers4.57.6

3. 精度评测

指标数值
Cosine Similarity (NPU vs CPU)1.000000
最大绝对误差 (max_abs_err)0.000008
L2 相对误差 (rel_err)0.0003%
是否满足要求满足(< 1%)✅

说明: bf16 精度下,NPU 与 CPU 的 cosine similarity 为 1.000000,L2 相对误差 0.0003%(使用平滑正弦信号对比,seq_len=512, horizon=96)。

4. 性能

指标数值
平均延迟 (seq_len=512, horizon=96)41.54 ms
平均延迟 (seq_len=512, horizon=96, CPU)1419.58 ms
参数量~2,493,000,000(2.5B)
单卡Ascend 910B · npu:1

5. 复现步骤

5.1 安装依赖

pip install -r requirements.txt

5.2 获取模型权重

# 方式一:从 LFS 镜像下载
cd /tmp
git clone https://gitcode.com/hf_mirrors/ant-intl/Falcon-TST_Large.git /tmp/models/Falcon-TST_Large
# 然后通过 git-lfs pull 获取权重(需安装 git-lfs)

# 方式二:HuggingFace (hf-mirror)
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download ant-intl/Falcon-TST_Large --local-dir /tmp/models/Falcon-TST_Large

# 方式三:直接使用 LFS batch API(推荐)
python -c "
import requests, json, os
oid_list = [
    {'oid': '8534fa131034e86c50ec43cc14e3d6f17af1d5d4161a11ada2218d12067e1c4c', 'size': 3718382544},
    {'oid': '2a7689d19b8af45f5261b86f22d6d57ffa6feb1690170c1afc6a43d8be8f46ca', 'size': 1264777232},
]
resp = requests.post('https://gitcode.com/hf_mirrors/ant-intl/Falcon-TST_Large.git/info/lfs/objects/batch',
    json={'operation': 'download', 'objects': oid_list, 'ref': {'name': 'refs/heads/main'}},
    headers={'Content-Type': 'application/vnd.git-lfs+json'})
for obj in resp.json()['objects']:
    url = obj['actions']['download']['href']
    os.system(f'curl -L -o {obj[\"oid\"][:12]}.safetensors \"{url}\"')
"

5.3 单次推理(NPU)

cd Falcon-TST_Large
python3 inference.py --model-path /tmp/models/Falcon-TST_Large --device npu:0 --seq-len 2880 --horizon 96 --n-runs 3

5.4 精度对比(CPU vs NPU)

python3 inference.py --model-path /tmp/models/Falcon-TST_Large --device npu:0 --compare

5.5 服务化推理(HTTP Service)

# 启动服务(默认 8000 端口)
python3 inference.py --model-path /tmp/models/Falcon-TST_Large --device npu:0 --serve --port 8000

# 健康检查
curl -s http://127.0.0.1:8000/health
# -> {"status":"ok","device":"npu:0","model":"/tmp/models/Falcon-TST_Large"}

# 时间序列预测
curl -s -X POST http://127.0.0.1:8000/v1/forecast \
  -H 'Content-Type: application/json' \
  -d '{"values": [1.0, 1.1, 1.2, 1.05, 1.08, 1.15, 1.2, 1.18, 1.22, 1.25], "horizon": 96}'
# -> {"horizon": 96, "shape": [1, 96, 1], "values": [[...]]}

6. 项目结构

Falcon-TST_Large/
├── inference.py             # 推理脚本(必选)
├── README.md                # 部署说明文档(必选)
├── requirements.txt         # 环境依赖清单(推荐)
├── falcon_tst/              # vendored 模型代码(必选)
│   ├── __init__.py
│   ├── configuration_FalconTST.py
│   └── modeling_FalconTST.py
└── assets/                  # 截图素材文件夹(必选,用户自行截图放置)
    ├── agent_workflow.png
    ├── npu_device_call.png
    └── model_result.png

7. 适配说明

Falcon-TST_Large 使用自定义代码(trust_remote_code=True),需要通过 vendored 方式将模型代码嵌入项目。适配要点:

  1. import 路径修正: 将 modeling_FalconTST.py 中的相对导入(.configuration_FalconTST)改为基于包名的绝对导入(falcon_tst.configuration_FalconTST)
  2. 权重加载: 使用 safetensors.torch.load_file 直接加载多 shard 的 .safetensors 文件,避免 transformers from_pretrained 的 remote code 依赖
  3. NPU 兼容性: 模型代码中仅使用标准 PyTorch 算子(torch.nn.functional.linear、torch.nn.functional.softmax、torch.topk 等),与昇腾 NPU 完全兼容,无需算子替换
  4. 注意力机制: 模型使用自定义 TEDotProductAttention(非 SDPA/FlashAttention),NPU 上直接使用 eager 实现路径,无需额外配置
  5. RevIN 归一化: 模型使用 RevIN(Reversible Instance Normalization)进行数据归一化和反归一化,NPU 上逐位一致
  6. 多 shard 权重: 模型分 2 个 shard(3.7GB + 1.26GB),推理时需合并加载