在 昇腾 Ascend NPU(npu:0)上运行 SAP/sap-rpt-1-oss(原 ConTextTab)表格型上下文学习模型。全程 无 CUDA,权重本地缓存加载。
SAP/sap-rpt-1-oss 是一个表格型(tabular)上下文学习模型,用于分类 / 回归任务(pipeline_tag: tabular-classification),不是语音/音频模型。它接受 pandas DataFrame / CSV 作为输入,列名与单元格值由后台句向量模型 sentence-transformers/all-MiniLM-L6-v2 自动嵌入。
因此本适配的输入标志按真实模态取 --csv(FastAPI 接收上传的 CSV 文件),而非 --audio。
.cuda() / cuda: / CUDA 设备调用,模型与输入 Tensor 全部位于 npu:0。inference.py 入口用 try-except 捕获 torch_npu 导入 / npu:0 不可用异常,失败时打印清晰错误并优雅退出。./model_weights/SAP__sap-rpt-1-oss/2025-11-04_sap-rpt-one-oss.pt 加载(命中即用,不触发 HF 下载);句向量模型从 ./model_weights/sentence-transformers__all-MiniLM-L6-v2/ 加载。缺失时才通过 HF_ENDPOINT=https://hf-mirror.com 镜像下载。sap_rpt_oss/ 为官方 Apache-2.0 包 v1.0.1 的昇腾适配副本(见 LICENSE 与 ORIGINAL_README.md)。torch + torch_npu(昇腾后端),transformers、pandas、scikit-learn、pyarrow、torchevalpip install -r requirements.txt权重较大且不随仓库提交,需先放入本地缓存目录:
model_weights/
├── SAP__sap-rpt-1-oss/
│ ├── configuration.json
│ ├── README.md
│ ├── notebook.ipynb
│ └── 2025-11-04_sap-rpt-one-oss.pt # 主模型权重
└── sentence-transformers__all-MiniLM-L6-v2/ # 后台句向量模型
├── config.json
├── pytorch_model.bin
├── tokenizer.json
└── ...句向量模型可由镜像自动下载:
export HF_ENDPOINT=https://hf-mirror.com
python - <<'PY'
from huggingface_hub import snapshot_download
snapshot_download('sentence-transformers/all-MiniLM-L6-v2',
local_dir='model_weights/sentence-transformers__all-MiniLM-L6-v2')
PYCSV 的最后一列为目标列。整数目标列默认按回归处理;若是分类标签请加 --task classification。
python inference.py --csv sample_data.csv --task classification
python inference.py --csv sample_regression.csv输出一份推理 JSON(含 device: npu:0、分类概率 / 回归预测、准确率等)。
常用参数:
--task auto|classification|regression(默认 auto,按目标列 dtype 自动判定)--max-context-size(默认 2048)--bagging(默认 1)--train-fraction(默认 0.8,前 80% 行作为上下文,其余作为查询)python -m uvicorn inference:app --host 0.0.0.0 --port 8001GET /health:健康检查(含 npu_available)POST /predict:curl -F "file=@sample_data.csv" http://127.0.0.1:8001/predict,返回推理 JSON示例:
curl -X POST http://127.0.0.1:8001/predict -F "file=@sample_data.csv"torch.npu.is_available() == True,torch.npu.device_count() == 2device: npu:0,30 条查询全部正确(accuracy 1.0)POST /predict:HTTP 200,返回真实推理 JSON截图见 assets/:
assets/agent_workflow.png:环境部署与任务启动日志assets/npu_device_call.png:CLI 推理 stdout(含 NPU 设备与结果)assets/model_result.png:FastAPI 上传 CSV 返回的推理 JSONLICENSE