g
gcw_coj3XaOd/davor_ayutthayaalpha-2.0-early-beta
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

davor/ayutthayaalpha-2.0-early-beta - 昇腾 NPU 推理部署

1. 模型简介

模型名称: davor/ayutthayaalpha-2.0-early-beta

模型链接: HuggingFace

模型描述: T5-based multilingual seq2seq model for text-to-text generation, including Thai language processing.

模型架构: T5 Encoder-Decoder (T5ForConditionalGeneration)

参数规模: 73,468,416 (~73M)

输入规格:

  • 类型: text (string)
  • 最大长度: 512 tokens
  • 格式: "translate English to Thai: "

输出规格:

  • 类型: text (string)
  • 最大生成长度: 512 tokens
  • 格式: generated text (decoded from token IDs)

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch-npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.57.0HuggingFace Transformers
sentencepiece>= 0.1.99Tokenizer 依赖
protobuf>= 3.20.0模型序列化依赖
numpy< 2版本兼容性
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch>=2.1.0 torch-npu>=2.1.0 transformers>=4.57.0 sentencepiece>=0.1.99 protobuf>=3.20.0 "numpy<2"

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

# HuggingFace(推荐)
huggingface-cli download davor/ayutthayaalpha-2.0-early-beta --local-dir ./weights

# AtomGit 镜像(HuggingFace 下载慢时使用)
huggingface-cli download --repo-type model https://ai.gitcode.com/hf_mirrors/davor/ayutthayaalpha-2.0-early-beta --local-dir ./weights

3.3 运行推理

# 单条推理
python3 inference.py --model-path ./weights

# 批量推理(自定义参数)
python3 inference.py --model-path ./weights --max-new-tokens 64 --device 0

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--max-new-tokensint32最大生成 token 数
--deviceint0NPU 设备编号

4. 推理成功日志

4.1 单条推理日志

[模型] davor/ayutthayaalpha-2.0-early-beta
[设备] Ascend910_9362 (npu:0)
[输入] translate English to Thai: Hello, how are you?
[输出] ลิช โต ไท โฮว ฮาร์
[耗时] 1115ms
[状态] SUCCESS

4.2 批量推理日志

[基准测试] 批量推理 (3 条):
  translate English to Thai: Hello, how are you?
    -> ลิช โต ไท โฮว ฮาร์
    [370ms]
  translate English to Thai: What is your name?
    -> ลิช โท อิส ยูเอน นาเม็ค เต
    [525ms]
  translate English to Thai: Good morning
    -> ลิช โต ไท เค. (
    [311ms]
  平均: 404ms
  最小: 311ms
  最大: 525ms

注意: 此模型为轻量级 T5 (60M参数),未经过专项翻译微调,输出为演示用途。推理失败时输出 [状态] FAILED。


5. 测试样例及输出结果

样例 1:英语到泰语翻译

运行命令:

python3 inference.py --model-path ./weights --max-new-tokens 32

输出:

[模型] davor/ayutthayaalpha-2.0-early-beta
[设备] Ascend910_9362 (npu:0)
[输入] translate English to Thai: Hello, how are you?
[输出] ลิช โต ไท โฮว ฮาร์
[耗时] 1115ms

样例 2:批量推理

运行命令:

python3 inference.py --model-path ./weights --max-new-tokens 32

输出:

[基准测试] 批量推理 (3 条):
  平均: 404ms
  最小: 311ms
  最大: 525ms

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: 人工构造英文到泰语翻译样本(3条)

评测指标:

指标结果说明
单条推理延迟~1115ms (首次) / ~370ms (缓存)首次推理包含模型加载时间
批量推理平均延迟~404ms/条3条批量推理,beam=1
NPU 显存~1.2GBT5-small 级别模型

评测命令:

python3 inference.py --model-path ./weights --max-new-tokens 32

8. NPU 配置说明

  • NPU 卡数: 1 (Ascend910_9362)
  • CANN 版本: 8.5.1
  • PyTorch 版本: 2.9.0+cpu (with torch-npu 2.9.0.post1)
  • Transformers 版本: 4.57.6
  • Tensor Parallel: 未使用(单卡推理)
  • 显存占用: ~1.2GB

9. 已知问题

  1. 生成质量: 此 T5 模型为轻量级预训练模型(~60M 参数),未经过泰语翻译专项微调,输出文本存在tokenization碎片化问题(SentencePiece subword 未正确合并为泰语单词)。这是模型本身的限制,非推理框架问题。
  2. vLLM 兼容性: vLLM-Ascend 不支持 T5 Encoder-Decoder 架构,需使用纯 transformers + torch_npu 方案。
  3. torch_dtype 警告: transformers 4.57 版本中 from_pretrained(torch_dtype=...) 参数已废弃,建议使用 dtype=。