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

davor/ayutthayaalpha-2.0-early-beta on Ascend NPU

1. 模型简介

AyutthayaAlpha 2.0 Early Beta 是一个 Thai–Latin 人名/机构名转写(transliteration)Transformer。 架构为自定义 T5 风格 encoder-decoder(T5ForConditionalGeneration):6 层 encoder、6 层 decoder、 hidden size 512、FFN 2048、8 头注意力,tied embeddings,共 73,468,416 参数,权重约 294MB(fp32)。

任务为 seq2seq:输入 <latn> 前缀 + 泰语人名 → 输出拉丁转写(romanization);输入 <thai> 前缀 + 拉丁人名 → 输出泰语重建。

  • Model: davor/ayutthayaalpha-2.0-early-beta
  • Architecture: T5ForConditionalGeneration (6+6, d_model=512, d_ff=2048, 8 heads)
  • Tokenizer: PreTrainedTokenizerFast,32k SentencePiece BPE(泰语偏置)
  • Task: seq2seq 转写(<latn> / <thai> 方向前缀)
  • Revision: 89d9779dea3f33a9eb9a43d6c7c188d8911bd2e5

2. 验证环境

  • NPU: Ascend910 单卡 npu:0(Ascend910_9362,HBM 61.27GiB)
  • 软件: Python 3.11.14、torch 2.9.0+cpu、torch_npu(CANN 8.5.1)、transformers 4.57.6
  • 数据流: 权重经 HuggingFace 镜像 snapshot_download 下载后本地加载,禁止 runtime 隐式下载
  • 设备证明: next(model.parameters()).device == npu:0、input_ids.device == npu:0、生成输出 npu:0

3. 安装依赖

pip install -r requirements.txt
# requirements: transformers>=4.45 torch>=2.5 torch-npu>=2.5 huggingface-hub>=0.23 safetensors>=0.4 numpy>=1.24

4. NPU 推理

python inference.py            # 默认:真实 npu:0 推理 + 转写结果 + 延迟 + PASS/FAIL
python inference.py --mode validate    # CPU vs NPU 一致性(token ids / logits max diff)
python inference.py --mode benchmark --reps 10   # 同步后稳定吞吐 tokens/s

模型目录优先取环境变量 AYUTTHAYA_MODEL_DIR,默认指向本机已下载的真实权重目录。

5. 真实推理结果(npu:0)

thai->latin:สมชาย        -> somchai
thai->latin:ทิพามณี       -> thiphamani
thai->latin:สุรศักดิ์      -> surasak
thai->latin:กรุงเทพมหานคร -> krungthepmahanakhon
latin->thai:somchai        -> สมชาย
latin->thai:khlai khampraphan -> คล้าย คำประพันธ์
latin->thai:surasak        -> สุรศักดิ์
latin->thai:bangkok        -> บางกอก
latency: avg 113.22 ms/translation (beam=5, synchronized, after warmup)
RESULT: PASS

输入为模型 README Quickstart 中的真实泰/英人名样例,固定 tokenizer 契约;生成使用 num_beams=5, do_sample=False 保证确定性。

6. CPU-NPU 一致性验证

同一输入 <latn>ทิพามณี、同一权重、beam=5 贪心确定性生成,只比较生成阶段:

cpu seq: thiphamani
npu seq: thiphamani
token_ids_equal=True
logits_max_diff=1.8120e-05   (阈值 ≤ 1e-2,fp32 下远超通过标准)
cpu_npu_consistency=PASS

说明:本验证为固定样例一致性检查(smoke consistency),非完整数据集评测。

7. 性能测试

首次 NPU 推理包含算子编译,已与稳定推理分开;计时前后调用 torch.npu.synchronize()。

  • 单次转写延迟(预热 3 次后,n=20,beam=5,批大小 1):avg 113.22 ms/translation
  • 稳定解码吞吐(reps=10,beam=5,max_length=32):74.18 tokens/s
  • 设备占用:单卡 HBM 使用约 3 GB(61.27 GiB 总量远充足)

8. 自验证截图

  • agent_workflow
  • npu_device_call
  • model_result

9. 已知限制

  • Early beta checkpoint,超参/数据过滤仍在调整;官方称人名领域优化,通用短语性能可能下降。
  • 转写反映训练数据中的混合转写惯例,不强制 RTGS 标准。
  • 本仓仅验证单卡 npu:0 FP32 seq2seq 转写任务,未做多卡推理。

10. 标签

NPU, Ascend, Ascend910, transl-iteration, thai, proper-names, text2text-generation, t5