本项目完成蚂蚁集团开源时序基础模型 Falcon-TST_Large(ant-intl/Falcon-TST_Large)在昇腾 Ascend910 NPU 上的服务化推理适配。模型权重来自 GitCode 镜像(https://ai.gitcode.com/hf_mirrors/ant-intl/Falcon-TST_Large),经 vLLM-Ascend 部署,对外提供 OpenAI 兼容的 /v1/embeddings 推理端点。
Falcon-TST 是专为高效时间序列预测设计的大规模基础模型。与常规 LLM 不同,它采用 MoE(Mixture-of-Experts) 解码器:4 路局部专家各自使用独立的 patch 尺寸(120/96/64/36)对输入序列分块,配合一路 patch=32 的共享专家,再由自回归多尺度预测头([24,96,336])产出逐步递进的未来预测。模型共约 24.9 亿参数(权重 fp32 约 9.28GB),回看窗口 2880 步。
模型的核心特点:
[B, 2880] 原始观测,patch embedding 是作用于浮点分块上的线性层,无需文本 tokenizer。TopKRouter 用 softmax 打分 + top-1 路由,将不同样本分派给最匹配的专家。einsum 实现(TEDotProductAttention),昇腾算子原生可跑。本适配的核心价值:
/vllm-workspace 只读源码。is_attention_free + is_causal=False 令 vLLM 正确识别为无 KV cache 模型,规避 HybridKV 断言。| 项目 | 版本/配置 |
|---|---|
| NPU | 昇腾 Ascend910(64GB HBM 单卡) |
| 驱动 / CANN | npu-smi 25.5.5 / CANN 8.5.1 |
| Python | 3.11.14 |
| torch | 2.9.0(CPU torch + torch_npu 后端) |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| vLLM | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| transformers | 4.57.6 |
| 模型权重 | safetensors 2 分片(3.72GB + 1.26GB),fp32 加载约 9.28GB |
设备选择:本机 NPU3 双芯片,本服务绑定 chip1(ASCEND_RT_VISIBLE_DEVICES=1),与 chip0 上的其他推理进程隔离。
mkdir -p /opt/atomgit/models/ant-intl/Falcon-TST_Large
# 权重清单:config.json / configuration_FalconTST.py / modeling_FalconTST.py /
# model.safetensors.index.json / model-00001-of-00002.safetensors /
# model-00002-of-00002.safetensors
# 从 GitCode resolve 端点逐文件拉取cd /opt/atomgit/adapt/falcontst_ascend
pip install -e . --no-build-isolation
python3 -c "from vllm.model_executor.models.registry import ModelRegistry; \
print('FalconTSTForPrediction' in ModelRegistry.get_supported_archs())"
# => True模型无文本词表,tokenizer 仅用于承载 vLLM 启动元数据与 pad token(编码为掩码值):
python3 build_falcon_tokenizer.py # 输出到 /opt/atomgit/adapt/falcontst_tokenizerexport ASCEND_RT_VISIBLE_DEVICES=1
export TORCHDYNAMO_DISABLE=1
python3 -m vllm.entrypoints.openai.api_server \
--model /opt/atomgit/models/ant-intl/Falcon-TST_Large \
--tokenizer /opt/atomgit/adapt/falcontst_tokenizer \
--load-format safetensors --dtype float32 \
--max-model-len 2880 --max-num-seqs 4 \
--port 8035 --host 127.0.0.1 --enforce-eager \
--runner pooling --convert embed \
--tensor-parallel-size 1 --gpu-memory-utilization 0.25 \
--trust-remote-code启动成功后日志应出现:
Resolved architecture: FalconTSTForPrediction
Disabling chunked prefill for model without KVCache
Application startup complete.curl -s http://127.0.0.1:8035/v1/models | head -c 300
# => {"object":"list","data":[{"id":"/opt/atomgit/models/ant-intl/Falcon-TST_Large",...}]}python3 inference.py --server http://127.0.0.1:8035 --batch 2 --kind noisy预期输出片段:
server : http://127.0.0.1:8035
model : /opt/atomgit/models/ant-intl/Falcon-TST_Large
forecast horizon : 96
elapsed : 0.0882 s
--- series 0 ---
input[:8] : [0.038, 4.095, 7.785, 9.909, 10.64, 10.644, 9.958, 8.841]
forecast[:8] : [-0.551, 2.263, 5.862, 8.577, 8.611, 8.743, 9.863, 8.609]python3 - << 'EOF'
import requests, numpy as np
SCALE, OFFSET = 1000.0, 1_000_000
t = np.arange(2880)
x = 10*np.sin(2*np.pi*t/288)
ids = (np.round(x*SCALE).astype(np.int64)+int(OFFSET)).tolist()
r = requests.post("http://127.0.0.1:8035/v1/embeddings",
json={"model":"/opt/atomgit/models/ant-intl/Falcon-TST_Large","input":ids})
print(r.json()["data"][0]["embedding"][:6])
EOFAscend910 单卡、--enforce-eager、fp32 实测:
| 指标 | 数值 |
|---|---|
| 权重加载 | 5.33s(2 shards) |
| 模型显存 | ~11.1GB(VLLMEngineCor 进程) |
| HBM 占用 | 13960MB / 65536MB(21.3%) |
| 单次推理(预热后) | ~84ms |
| 推理峰值 AICore | 66% |
| 持续负载 | 40s 内 796 次请求 |
说明:模型为 attention-free,无 KV cache 分配;eager 模式不启用编译,如需更高吞吐可进一步开启编译优化。
以 CPU(官方 modeling_FalconTST.py)为参考基准,对同一批输入序列做逐点对比:
| 指标 | 序列 A | 序列 B |
|---|---|---|
| 最大绝对误差 | 0.000130 | 0.000273 |
| 平均绝对误差 | 0.000038 | 0.000066 |
| 相关系数 | 1.000000 | 1.000000 |
结论:NPU 输出与 CPU 官方实现相关系数为 1.000000。微小绝对误差来自输入「定标整数」传输的量化(SCALE=1000,量化步长 0.001),模型计算本身与 CPU 逐位一致。
token_id = round(v*1000)+1000000 编码;服务端 forward 会按同规则解码。is_causal=False 必设:否则 vLLM 默认按 decoder 处理,触发 HybridKVCacheCoordinator requires at least two attention groups 崩溃。vocab_size 放大:config 中 vocab_size=4000000,使定标整数 token id 能通过 vLLM 的 OOV 校验(max_input_id 上限判定)。transformers<5,勿升级;建模代码拷贝自官方并做 import 归一化。vllm.general_plugins OOT 插件机制,避免侵入框架源码。ASCEND_RT_VISIBLE_DEVICES 控制实际物理卡,请避开其他进程已占用的芯片。/v1/embeddings(--convert embed),非 /v1/completions 或 /v1/chat/completions。falcontst-large-20260822/
├── inference.py # 推理客户端(requests 版)
├── README.md # 本文件
├── requirements.txt # Python 依赖
└── assets/
└── README.md # 模型卡 / 补充说明模型权重遵循 Apache-2.0(模型原始许可)。本适配代码以 Apache-2.0 发布。