g
gcw_coj3XaOd/sap-rpt-1-oss
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

SAP RPT-1-OSS - 昇腾 NPU 推理部署

1. 模型简介

模型名称: SAP/sap-rpt-1-oss

模型链接: HuggingFace

模型描述: RPT (Row-Column Prediction Transformer) 是一种基于表格上下文学习(Tabular In-Context Learning)的模型,通过二维注意力机制同时捕捉行间和列间的关系,在无需微调的情况下对表格数据进行分类和回归预测。

模型架构: TwoDimensionalAttention (12层) + RoBERTa-style Transformer,隐藏层维度 768

参数规模: 172M (base 配置)

输入规格:

  • 支持 DataFrame 格式表格数据(数值型 + 文本型特征)
  • 上下文样本数(训练样本): 建议 512~8192
  • 查询样本数(测试样本): 任意

输出规格:

  • 分类任务:类别概率分布
  • 回归任务:连续值预测

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.7.0PyTorch 框架
torch-npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.52.4HuggingFace 模型库
sap-rpt-oss1.0.1SAP RPT 模型实现
sentence-transformerslatest文本特征 embedding
scikit-learn>= 1.6.1数据集及评估
pandas>= 2.2.3数据处理
pyarrow>= 20.0.0数据IO
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu torch transformers sap-rpt-oss sentence-transformers scikit-learn pandas pyarrow

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 SAP/sap-rpt-1-oss --local-dir ./weights

方式二:ModelScope(HuggingFace 下载慢时使用)

python3 -c "from modelscope import snapshot_download; snapshot_download('SAP/sap-rpt-1-oss', cache_dir='./weights')"

3.3 运行推理

# 设置 NPU 设备
export ASCEND_RT_VISIBLE_DEVICES=0

# 运行推理脚本(分类 + 回归测试)
python3 inference.py --model-path ./weights

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--context-sizeint120上下文样本数
--taskstrboth任务类型: classification / regression / both

4. 推理成功日志

4.1 分类任务 (Iris 数据集)

[模型] SAP RPT-1-OSS
[设备] Ascend910 (npu:0)
[输入] Iris 数据集 (4 特征, 3 类别)
[上下文] 120 样本, [查询] 30 样本
[准确率] 83.33% (25/30)
[状态] SUCCESS

4.2 回归任务 (Wine 数据集)

[模型] SAP RPT-1-OSS
[设备] Ascend910 (npu:0)
[输入] Wine 数据集 (13 特征, 预测 alcohol 含量)
[上下文] 100 样本, [查询] 78 样本
[MSE] 0.4430, [MAE] 0.5788
[状态] SUCCESS

5. 测试样例及输出结果

样例 1:Iris 分类

运行命令:

python3 inference.py --model-path ./weights --task classification

输出:

============================================================
测试1: 分类任务 (Iris 数据集)
============================================================
Context: 120 samples, Query: 30 samples
Features: ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
Classes: ['setosa', 'versicolor', 'virginica']

分类准确率: 83.33% (25/30)
[状态] SUCCESS

样例 2:Wine 回归

运行命令:

python3 inference.py --model-path ./weights --task regression

输出:

============================================================
测试2: 回归任务 (Wine 数据集)
============================================================
Context: 100 samples, Query: 78 samples

回归 MSE: 0.4430, MAE: 0.5788
[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: sklearn Iris (分类), Wine (回归)

评测指标:

指标结果Baseline (论文)差异
分类准确率 (Iris)83.33%~96% (with more context)上下文较少
回归 MSE (Wine)0.4430N/A-

评测命令:

python3 inference.py --model-path ./weights --task both

8. NPU 配置说明

  • NPU 卡数: 1 (Ascend910)
  • Tensor Parallel: 不支持(单卡部署)
  • 显存占用: ~4GB (batch=1, seq=128)
  • CANN 版本: 8.5.1

9. 已知问题

  1. HuggingFace gated repo: 模型 SAP/sap-rpt-1-oss 在 HuggingFace 上为 gated 模型,需要申请访问权限。可使用 ModelScope 镜像下载。
  2. SentenceEmbedder NPU 兼容: 文本特征 embedding 使用 sentence-transformers/all-MiniLM-L6-v2,当前在 CPU 上运行。模型 forward 在 NPU 上执行。
  3. NPU torch.where 警告: 在 embedding 层使用 torch.where 时可能出现 allow_internal_format 警告,不影响推理结果。