JeffDing/ayutthayaalpha-2.0-early-beta-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

AyutthayaAlpha 2.0 Early Beta 昇腾NPU部署文档

1. 模型简介

模型名称: ayutthayaalpha-2.0-early-beta
模型链接: davor/ayutthayaalpha-2.0-early-beta
模型描述: AyutthayaAlpha 2.0 是一个泰语–拉丁字母音译 Transformer,用于人名/机构名的双向音译。给定一个源语言名字,模型输出按发音相似度和文化习惯排序的候选拉丁/泰语写法。
模型架构: T5-style encoder–decoder(6 encoder layers + 6 decoder layers,d_model=512,d_ff=2048,8 heads,relative attention)。
参数规模: 基于本地 model.safetensors 与 config.json 推断的 T5-small/medium 级 Encoder-Decoder 结构。

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch2.1.0+当前环境:2.9.0+cpu
torch_npu随 CANN 安装当前环境:2.9.0.post1
transformers>= 4.45.0HuggingFace 库
sentencepiece按需安装T5 tokenizer 依赖
昇腾驱动CANN 8.5.1当前环境:8.5.1
NPU 设备Ascend 910 / 910B / 910C需驱动正常加载

安装命令:

# torch / torch_npu 由 CANN 提供,不要通过 pip 覆盖
pip install transformers sentencepiece numpy

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 确认 torch_npu 可用
python3 -c "import torch_npu, torch; print(torch.npu.is_available())"

3.2 运行推理

# 泰语 -> 拉丁音译
python3 inference.py \
  --model_path /tmp/ayutthayaalpha-2.0-early-beta \
  --input "สมชาย" \
  --max_length 32

# 拉丁 -> 泰语回译
python3 inference.py \
  --model_path /tmp/ayutthayaalpha-2.0-early-beta \
  --input "Somchai" \
  --max_length 32

3.3 推理参数说明

参数类型默认值说明
--inputstr-单条输入文本
--input_filestr-批量输入文件,每行一个样例
--model_pathstr/tmp/ayutthayaalpha-2.0-early-beta本地模型目录
--max_lengthint32最大生成长度

4. 测试样例及输出结果

样例 1:泰语 -> 拉丁音译

输入:

สมชาย

输出:

somchai

样例 2:拉丁 -> 泰语回译

输入:

khlai khampraphan

输出:

คล้าย คำประพันธ์

说明: 推理脚本使用 transformers.T5ForConditionalGeneration 加载模型,并通过 torch_npu 在 npu:0 上执行 beam search 解码。

5. Agent适配截图

5.1 Agent适配全过程截图

Agent 适配流程

5.2 NPU设备调用截图

NPU 设备调用

5.3 模型适配结果截图

模型适配结果

6. NPU运行验证信息

测试项结果
推理设备npu:0
模型加载成功
泰语->拉丁推理成功
生成耗时0.4055s / 样例 1

验证结论: 本模型已基于 torch_npu + transformers 在昇腾 NPU 上完成推理验证,可正常加载权重并执行泰语/拉丁双向音译。

7. 注意事项

  • 推理脚本使用 torch_npu 作为 NPU 引擎,设备检测顺序为 NPU → CPU 降级。
  • 输入必须带方向前缀:<latn> 表示泰语转拉丁,<thai> 表示拉丁转泰语。
  • 当前适配使用 model.safetensors,未使用其他权重格式。
  • 根据最新规则,本适配不强制精度 1% 对比;如需要,可额外增加 CPU/NPU 输出一致性校验。