sap-rpt-1-oss (formerly ConTextTab) 是来自论文 ConTextTab: A Semantics-Aware Tabular In-Context Learner 的表格数据上下文学习模型。
该模型结合了语义理解和表格数据结构的优势,在大规模真实世界表格数据上训练,可在多种表格预测任务上达到 SOTA 性能。
| 属性 | 值 |
|---|---|
| 模型类型 | RPT (Recursive Percolation Transformer) |
| 参数量 | 172.07M |
| 隐藏层维度 | 768 |
| Encoder 层数 | 12 |
| Attention 头数 | 12 |
| 注意力机制 | 2D Attention (行+列) |
| 文本嵌入模型 | sentence-transformers/all-MiniLM-L6-v2 (384维) |
| 支持任务 | 分类 / 回归 |
| Checkpoint | l2/base.pt (~62MB) |
(n_samples, n_features) 的特征矩阵 + 类别标签(n_samples, n_features) 的特征矩阵 + 连续目标值| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.10 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| sentence-transformers | 5.7.0+ | 文本嵌入模型 |
| scikit-learn | 1.5.0+ | 数据处理 |
| pandas | 1.5+ | 表格数据处理 |
| numpy | 1.21+ | 数值计算 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 安装 sap-rpt-oss(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -e /workspace/agent/sap-rpt-1-oss/
# 3) 安装 Sentence Transformer(使用 HF 镜像)
export HF_ENDPOINT=https://hf-mirror.com
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple sentence-transformers
# 4) 验证环境
python -c "
import torch, torch_npu
from sentence_transformers import SentenceTransformer
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent/sap-rpt-1-oss-ascend
# 确认上游权重存在
ls -la /workspace/agent/sap-rpt-1-oss/
# 期望输出:config.json l2/base.pt (~62MB) ...# 设置 HF 镜像以加速下载
export HF_ENDPOINT=https://hf-mirror.com# 分类任务(默认)
python inference.py --device npu:0
# 分类任务 + 查看 NPU 显存
python inference.py --device npu:0 --show_npu_memory
# 回归任务
python inference.py --device npu:0 --task regression
# 指定其他 NPU 卡
python inference.py --device npu:1conda activate pt2100
export HF_ENDPOINT=https://hf-mirror.com
cd /workspace/agent/sap-rpt-1-oss-ascend
python inference.py --device npu:0 --show_npu_memory --task classification实际输出:
[W819 01:58:18.842643600 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W819 01:58:33.130696370 NPUCachingAllocator.cpp:198] Warning: The current CANN and Soc Version require processing for 32 padding size...
[设备] npu:0
NPU设备数量: 1
设备 0: Ascend910B2
[模型加载] checkpoint: /workspace/agent/sap-rpt-1-oss/l2/base.pt
[任务类型] classification
Loading weights: 100%|██████████| 103/103 [00:00<00:00, 6831.44it/s]
[模型] sap-rpt-1-oss (classification)
[参数量] 172.07M
[模型] 已迁移至 npu:0
[NPU显存 · 模型加载后] 总显存=61.0GB | 已分配=656.6MB | 缓存=742.00MB | 峰值=656.6MB
[数据集] Breast Cancer (训练: (300, 30), 测试: (269, 30))
训练模型...
[训练耗时] 0.07s
预测...
==============================================================================
输出摘要
==============================================================================
模型: sap-rpt-1-oss (分类)
预测数量: 269
预测耗时: 0.96s
预测类别: [0 1]
预测分布: {0: 70, 1: 199}
[NPU显存 · 推理完成后] 总显存=61.0GB | 已分配=656.6MB | 缓存=2648.00MB | 峰值=2174.5MB✅ 验证要点:
conda activate pt2100
export HF_ENDPOINT=https://hf-mirror.com
cd /workspace/agent/sap-rpt-1-oss-ascend
python inference.py --device npu:0 --show_npu_memory --task regression实际输出:
[设备] npu:0
[模型加载] checkpoint: /workspace/agent/sap-rpt-1-oss/l2/base.pt
[任务类型] regression
[模型] sap-rpt-1-oss (regression)
[参数量] 172.07M
[模型] 已迁移至 npu:0
[NPU显存 · 模型加载后] 总显存=61.0GB | 已分配=656.6MB | 缓存=742.00MB | 峰值=656.6MB
[数据集] Boston (训练: (253, 13), 测试: (253, 13))
训练模型...
[训练耗时] 0.00s
预测...
==============================================================================
输出摘要
==============================================================================
模型: sap-rpt-1-oss (回归)
预测形状: (253,)
预测耗时: 0.77s
预测范围: [7.0773, 49.4948]
预测均值: 22.1474
[NPU显存 · 推理完成后] 总显存=61.0GB | 已分配=656.6MB | 缓存=1400.00MB | 峰值=1219.1MB✅ 验证要点:
解决方案:模型 checkpoint 已本地存储在 /workspace/agent/sap-rpt-1-oss/l2/base.pt。脚本会自动使用本地 checkpoint,无需访问 HuggingFace。
解决方案:首次运行需要下载 Sentence Transformer 模型。请设置 HF 镜像:
export HF_ENDPOINT=https://hf-mirror.com
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple sentence-transformers解决方案:支持 CUDA GPU 和 NPU。脚本会自动检测可用设备,优先使用 NPU。
解决方案:
max_context_size 参数(如从 8192 降至 2048)bagging 参数(如从 8 降至 1)解决方案:当前脚本支持 sklearn 风格的 fit/predict 接口,可直接对整个测试集预测。
sap-rpt-1-oss-ascend/
├── inference.py # 推理脚本(torch_npu 推理)
├── README.md # 本文档
├── requirements.txt # 依赖列表
└── assets/ # 资源占位目录上游权重目录(只读,未被修改):
/workspace/agent/sap-rpt-1-oss/
├── l2/base.pt # 权重(172.07M, ~62MB)
├── 2025-11-04_sap-rpt-one-oss.pt # 原始格式权重
├── configuration.json # 模型配置
├── README.md # 原始文档
└── ...# sap-rpt-1-oss 昇腾 NPU 推理环境依赖
# 核心依赖(必须)
torch>=2.0.0
torch_npu>=2.0.0
sentence-transformers>=5.7.0
scikit-learn>=1.5.0
pandas>=1.5.0
numpy>=1.21.0
pyarrow>=10.0.0
huggingface_hub>=0.20.0使用方式:
# 激活环境
conda activate pt2100
# 设置 HF 镜像
export HF_ENDPOINT=https://hf-mirror.com
# 安装依赖(华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -r requirements.txt