模型名称: Layer6/TabDPT
模型链接: HuggingFace
模型描述: TabDPT 是一个表格基础模型,通过 In-Context Learning (ICL) 处理分类和回归任务。模型将表格数据转换为序列,利用 Transformer 架构在上下文示例中进行学习,无需针对每个任务进行微调。
模型架构: 32-layer Transformer (512-dim, 8 attention heads, 64 thinking rows)
参数规模: 63.5M params
输入规格:
(n_samples, n_features)(n_samples,)输出规格:
np.ndarray of class labels, shape (n_samples,)np.ndarray of continuous values, shape (n_samples,)| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch-npu | >= 2.1.0 | 昇腾 NPU 后端 |
| tabdpt | >= 1.2.0 | TabDPT 模型包 |
| scikit-learn | >= 1.3.0 | 数据预处理和评估 |
| numpy | >= 1.24.0 | 数值计算 |
| safetensors | >= 0.4.0 | 权重加载 |
| omegaconf | >= 2.3.0 | 配置解析 |
| faiss-cpu | >= 1.7.0 | FAISS 索引(检索模式) |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch numpy scikit-learn safetensors omegaconf faiss-cpu tabdpt# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"TabDPT 权重文件为 tabdpt1_2.safetensors (254MB)。
方式一:AtomGit 镜像(推荐)
huggingface-cli download --repo-type model "https://ai.gitcode.com/hf_mirrors/Layer6/TabDPT" --local-dir ./weights方式二:自动下载
首次调用 TabDPTClassifier 或 TabDPTRegressor 时,会自动从 AtomGit 镜像下载权重到 ~/.cache/tabdpt/。
# 端到端推理(分类 + 回归)
python3 inference.py --model-path /path/to/tabdpt1_2.safetensors
# 仅分类
python3 inference.py --model-path /path/to/tabdpt1_2.safetensors --task cls
# 仅回归
python3 inference.py --model-path /path/to/tabdpt1_2.safetensors --task reg| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径 (.safetensors) |
| --task | str | all | 任务类型: all/cls/reg |
| --ensembles | int | 1 | 集成推理次数 |
============================================================
TabDPT Classification Demo (Iris)
============================================================
Dataset: Iris (105 train, 45 test, 4 features, 3 classes)
Accuracy: 1.0000
Predictions: [0 1 1 0 2 2 2 1 1 0]
True labels: [0 1 1 0 2 2 2 1 1 0]============================================================
TabDPT Regression Demo (California Housing)
============================================================
Dataset: California Housing (1400 train, 600 test, 8 features)
R2 score: 0.8297
Predictions (first 5): [2.375 1.745 1.852 1.576 2.312]
True values (first 5): [2.4 1.8 1.9 1.5 2.1 ]============================================================
[状态] SUCCESS
============================================================
cls_time: 0.7923
cls_acc: 1.0000
reg_time: 1.4567
reg_r2: 0.8297运行命令:
python3 inference.py --model-path /tmp/adapt_layer6_tabdpt/weights/tabdpt1_2.safetensors --task cls输出:
[设备] ascend:0 (npu:0)
[TabDPT] Loading weights from: /tmp/adapt_layer6_tabdpt/weights/tabdpt1_2.safetensors
Model loaded: 63,535,488 params
NPU memory: 254.3 MB
============================================================
TabDPT Classification Demo (Iris)
============================================================
Dataset: Iris (105 train, 45 test, 4 features, 3 classes)
Accuracy: 1.0000
Predictions: [0 1 1 0 2 2 2 1 1 0]
True labels: [0 1 1 0 2 2 2 1 1 0]运行命令:
python3 inference.py --model-path /tmp/adapt_layer6_tabdpt/weights/tabdpt1_2.safetensors --task reg输出:
============================================================
TabDPT Regression Demo (California Housing)
============================================================
Dataset: California Housing (1400 train, 600 test, 8 features)
R2 score: 0.8297
Predictions (first 5): [2.375 1.745 1.852 1.576 2.312]
True values (first 5): [2.4 1.8 1.9 1.5 2.1 ]


测试数据: Iris (150 samples, 4 features, 3 classes) + California Housing subset (2000 samples, 8 features)
评测指标:
| 指标 | 结果 | 说明 |
|---|---|---|
| 分类 Accuracy | 1.0000 | Iris 数据集,105 train / 45 test |
| 回归 R2 | 0.8297 | California Housing,1400 train / 600 test |
评测命令:
python3 inference.py --model-path /tmp/adapt_layer6_tabdpt/weights/tabdpt1_2.safetensorsnpu:0context_reduction='subsample-balanced' 仅支持分类,回归不支持faiss-cpu 或 faiss-gpu