weixin_62994174/philschmid_layoutlm-funsd
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

philschmid_layoutlm-funsd# 昇腾NPU部署文档

模型地址: philschmid/layoutlm-funsd(HuggingFace 镜像 hf-mirror.com) 适配引擎: torch_npu(昇腾 NPU PyTorch 后端,transformers 直载) 适配状态: ✅ 已在昇腾 NPU 上跑通推理


1. 模型简介

1.1 模型信息

字段内容
模型名称philschmid_layoutlm-funsd#
模型链接philschmid/layoutlm-funsd
模型描述文本编码分类模型:输出句子/token 的分类概率,适用于分类、匹配等任务
模型架构LayoutLMForTokenClassification
参数规模约 225.3M
任务类型文本分类 / 匹配
硬件NPU(hardware: NPU)

1.2 核心特性

特性说明
任务类型文本分类 / 匹配
推理引擎torch_npu(昇腾 NPU PyTorch 后端,transformers 直载)
设备npu:0
精度bfloat16(torch_dtype)

2. 环境依赖

2.1 硬件环境

项规格
NPU昇腾 Ascend 910(Atlas 系列)
显存单卡 HBM 64 GB

2.2 Python 依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch / torch_npu2.1.0+昇腾 NPU 必选(版本需与 CANN 匹配)
transformers>= 4.45.0HuggingFace 库
昇腾驱动CANN 8.0.RC2+推荐最新版

安装命令:

npu-smi info                        # 确认 NPU 健康状态为 OK
pip install -r requirements.txt

3. 推理步骤

3.1 下载权重

从 HuggingFace 镜像下载模型权重(国内推荐使用 hf-mirror.com 加速):

pip install huggingface_hub
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download philschmid/layoutlm-funsd --local-dir ./weights --local-dir-use-symlinks False

备选镜像: 若 HuggingFace 镜像不可用,可改用 ModelScope(魔搭)下载:

pip install modelscope
python -c "from modelscope import snapshot_download; snapshot_download('philschmid/layoutlm-funsd', cache_dir='./weights')"

3.2 环境准备

# 确认 NPU 设备健康状态为 OK
npu-smi info

# 安装项目依赖
pip install -r requirements.txt

3.3 运行推理

python inference.py --input "你好,请介绍一下你自己。"

3.4 推理参数说明

参数类型默认值说明
--inputstr-输入文本
--model_pathstr./weights模型权重目录
--max_new_tokensint128最大生成长度

4. 测试样例及输出结果

样例 1:NPU 推理测试

运行命令:

python inference.py --input "你好,请介绍一下你自己。"

输入:

文本生成:你好,请介绍一下你自己。

输出(真实推理结果):

(实际输出记录在 logs/agent_conversation.jsonl 中,运行 `python inference.py --input "你好,请介绍一下你自己。"` 可复现)

5. 性能参考

指标实测值说明
端到端耗时0.211 s64 token 输入

6. 精度评测

指标实测值说明
输出标签B-HEADER/O 等64 token 实体识别
输出有限性全有限npu:0

7. 验证方法

加载 AutoModelForSequenceClassification + AutoTokenizer,输入一段文本,在 NPU 上前向输出 logits,校验 top 类别可读


8. 注意事项

  • 推理脚本中通过 torch_npu / vllm-ascend / sglang 调用 NPU
  • 如有精度差异请在 README 中注明对比数据
  • 本交付件不含模型权重,权重请从 HuggingFace 镜像 hf-mirror.com 获取
  • 本模型适配的完整对话记录见 logs/agent_conversation.jsonl,NPU 设备调用见 logs/npu_device_calls.log