liuhongwei-2026/ayutthayaalpha-2.0-early-beta
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ayutthayaalpha-2.0-early-beta(昇腾 NPU 适配)

将 HuggingFace 模型 davor/ayutthayaalpha-2.0-early-beta 适配部署到国产昇腾(Ascend)NPU 上,并提供 OpenAI 兼容的服务化推理接口。

  • 原模型:https://huggingface.co/davor/ayutthayaalpha-2.0-early-beta
  • 镜像源:https://ai.gitcode.com/hf_mirrors/davor/ayutthayaalpha-2.0-early-beta
  • 本文档适配环境:torch 2.9.0 (+torch_npu 2.9.0.post1) + CANN 8.5.1 + Ascend 910

模型简介

项目值
架构T5ForConditionalGeneration(encoder-decoder)
参数量~73.5M(d_model=512,6 层,8 头)
词表大小32868
dtype 原配置float32(推理按 bfloat16 亦可行)
语言泰语(ไทย)为主,兼顾英文

AyutthayaAlpha 为泰语文本生成模型(命名取自泰国古都「大城府」)。

适配要点

该模型是 encoder-decoder(T5) 架构,而 vLLM-Ascend 仅支持 decoder-only 的 CausalLM 架构,registry 中不含 T5ForConditionalGeneration。因此本项目不走 vLLM-Ascend 服务化,改为:

  1. 用 transformers 直接以 torch_npu 在昇腾 NPU 上加载权重;
  2. 通过 FastAPI 暴露 OpenAI 兼容接口(/v1/models、/v1/chat/completions、/v1/completions)实现服务化推理。

全程无任何 CUDA 算子,T5 算子均为 torch 原生算子,在 NPU 上可直接运行,无需改动模型源码。

环境依赖

见 requirements.txt。核心版本:

  • torch>=2.1、torch_npu==2.9.0.post1(对应 CANN 8.5.1)
  • transformers>=4.40
  • fastapi、uvicorn

安装依赖(昇腾环境已就绪时):

pip install -i https://mirrors.aliyun.com/pypi/simple/ \
    transformers "fastapi" "uvicorn"

权重准备

权重下载(优先级:本地目录 > ModelScope > HF-mirror > gitcode LFS):

mkdir -p /opt/atomgit/models/ayutthayaalpha-2.0-early-beta
export HF_ENDPOINT=https://hf-mirror.com
python -c "from huggingface_hub import snapshot_download; snapshot_download('davor/ayutthayaalpha-2.0-early-beta', local_dir='/opt/atomgit/models/ayutthayaalpha-2.0-early-beta')"

模型仅含一个 model.safetensors(约 294MB)。

CLI 推理

python inference.py --prompt "สวัสดีครับ แนะนำตัวหน่อย" \
    --model-dir /opt/atomgit/models/ayutthayaalpha-2.0-early-beta \
    --device npu:0

服务化推理(OpenAI 兼容)

PORT=8010 DEVICE=npu:0 python inference.py --serve --port 8010

就绪检查

curl -sf http://127.0.0.1:8010/v1/models

Chat 补全

curl -s http://127.0.0.1:8010/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"ayutthayaalpha-2.0-early-beta",
       "messages":[{"role":"user","content":"What is the capital of Thailand?"}],
       "max_tokens":48}'

文本补全

curl -s http://127.0.0.1:8010/v1/completions \
  -X POST -H 'Content-Type: application/json' \
  -d '{"prompt":"สวัสดี","max_tokens":16}'

验证结果(昇腾 NPU,单卡)

检查项结果
NPU 权重加载from_pretrained(...).to('npu:0') 成功,无缺失键
CLI 推理成功,正常生成泰语文本
GET /v1/modelsHTTP 200
POST /v1/chat/completionsHTTP 200
POST /v1/completionsHTTP 200
dtypebfloat16 / 原生 float32 均可运行