model.safetensors (302,717,904 bytes, 75,670,026 参数 F32, 392 tensors)config.json {"dim":512,"dim_output":10,"n_layers":12,"n_heads":4,"task":"CLASSIFICATION"}[batch, rows, features] float32, 支持连续特征与类别特征; 模型内部通过 quantile embedding + 线性投影到 dim 512[batch, n_query, dim_output] logits (前 n_classes 列为有效类别), 经 softmax 得 probabilities, argmax 为预测标签sklearn.datasets.load_wine['alcohol','malic_acid','ash','alcalinity_of_ash','magnesium','total_phenols','flavanoids','nonflavanoid_phenols','proanthocyanins','color_intensity','hue','od280/od315_of_diluted_wines','proline'] (13 列, 顺序固定, dtype float32)target (int64, 0/1/2, 对应 class_0/1/2, n_classes=3, 但模型输出 dim_output=10, 取前 3 列)train_test_split( stratify, test_size=0.2, random_state=42 ) -> train 142, test 36, 固定种子保证 CPU-NPU 同一输入pre_nan_mean 填充, 已在 inference.py:35 说明10eead...x_support (1,142,13), y_support (1,142), x_query (1,36,13), padding 全 0 (无填充), batch=1torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362/tmp/mitra_local (通过 hf-mirror 下载, 3 文件, 已校验 safetensors 392 tensors)pip install -r requirements.txt
# torch==2.9.0
# torch_npu==2.9.0.post1
# numpy==1.26.4 pandas==3.0.2 scikit-learn==1.6.1
# safetensors==0.6.2 einops==0.8.1 einx==0.4.3 huggingface_hub==0.34.4 scipy==1.14.1# 默认执行 (CPU 基准 + NPU 推理 + 一致性 + 10次性能测试)
python inference.py
# 仅推理 (full 模式已含全部)
python inference.py --mode full核心逻辑 (inference.py:1):
Tab2D.from_pretrained(MODEL_DIR) -> model.to("npu:0"), 验证 next(model.parameters()).device == npu:0padding_features/padding_obs_* 全 Falsemodel(x_support_npu, y_support_npu, x_query_npu, padding_features, padding_obs_support, padding_obs_query) 输出 [1,36,10] logits, 同步计时 torch.npu.synchronize() 前后softmax, argmax, 统计分布与精度执行命令: python inference.py (在 npu:0 真实执行, 权重来自本地 /tmp/mitra_local/model.safetensors)
[INFO] Model: autogluon/mitra-classifier-1.1
[INFO] Task: tabular-classification (Mitra foundation model, 72M, 12 layers)
[INFO] NPU available: True, device_name: Ascend910_9362
[CPU] latency 7866.36 ms, logits shape (1, 36, 10), dtype torch.float32
[CPU] logits sample [0,0,:3]: [10.442380905151367, 4.527387619018555, 1.115939974784851]
[CPU] probs sample [0,0]: [0.9972200393676758, 0.0026911755558103323, 8.879105735104531e-05]
[CPU] preds (first 10): [0, 2, 0, 1, 1, 0, 0, 1, 1, 2]
[CPU] preds distribution: [12, 14, 10]
[NPU] latency 273.00 ms, logits shape (1, 36, 10), dtype torch.float32
[NPU] logits sample [0,0,:3]: [10.442069053649902, 4.5313825607299805, 1.1198745965957642]
[NPU] probs sample [0,0]: [0.9972080588340759, 0.0027027586475014687, 8.916785736801103e-05]
[NPU] preds (first 10): [0, 2, 0, 1, 1, 0, 0, 1, 1, 2]
[NPU] preds distribution: [12, 14, 10]
[CONSISTENCY] task=classification, atol=0.01, rtol=0.01, max_abs=0.008332, mean_abs=0.002875, argmax_agreement=1.0000, passed=True
[CONSISTENCY] CPU accuracy: 1.0000, NPU accuracy: 1.0000
[BENCHMARK] NPU avg 28.54 ms, min 28.18, max 29.23, p50 28.45, p90 28.88, p95 29.06
Throughput: 35.04 infer/s, batch=1, rows_query=36, features=13, dtype=float32
[RESULT] PASS/tmp/mitra_cpu_logits.npy 与 /tmp/mitra_npu_logits.npy, 可复现比较/tmp/mitra_local/model.safetensors), 同一 Wine 拆分数据, 同 dtype float32, 同 shape, eval mode, 固定种子 42, 分别在 cpu 与 npu:0 执行, 保存原始 logits .npy 后比较python scripts/compare_outputs.py --cpu /tmp/mitra_cpu_logits.npy --npu /tmp/mitra_npu_logits.npy --task classification --atol 0.01 --rtol 0.01atol=1e-2, rtol=1e-2 因 Transformer 中多层 LayerNorm/Attention/GELU 在 NPU 与 CPU 累积差异导致 logits 绝对差 ~0.008, 但分类决策完全稳定; 若用严格 1e-4 会误报失败, 而任务指标 (accuracy, argmax) 已证明一致。单样本 (36 rows) smoketest, 非完整 TabArena 评测。npu:0 (见 logs/device.log), 输入/输出 Tensor device 均为 npu:0条件: npu:0, float32, batch=1, x_support (1,142,13), x_query (1,36,13), torch.npu.synchronize() 前后计时, 预热 3 次, 正式 10 次
[BENCHMARK] NPU avg 28.54 ms, min 28.18, max 29.23, p50 28.45, p90 28.88, p95 29.06
Throughput: 35.04 infer/s (以 batch 为单位); rows/s ≈ 1261 rows/s (36 rows / 0.02854 s)| 设备 | avg | min | max | p50 | p90 | p95 | throughput |
|---|---|---|---|---|---|---|---|
| NPU (Ascend910) | 28.54 ms | 28.18 | 29.23 | 28.45 | 28.88 | 29.06 | 35.0 infer/s |
| CPU | 7866 ms | - | - | - | - | - | 0.13 infer/s |
npu-smi HBM 3920 MB (权重 ~289 MB + 激活), torch.npu.mem_get_info 可查询三图由 xterm.js 根据本次真实日志生成 (非 Pillow 模拟), 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$:
assets/agent_workflow.png - 阶段日志 (环境检查、获取模型、分析模型、NPU适配、NPU验证、整理仓库)assets/npu_device_call.png - npu-smi info、torch.npu.is_available()、device_name 与模型参数 npu:0 及输入输出 Tensor device 证据assets/model_result.png - python inference.py 真实完整输出、logits、一致性与 PASSfine_tune=False 时 in-context 推理), 若需 fine_tune=True 需额外训练流程, 本仓仅验证推理迁移Hardware: NPU, NPU, Ascend, Ascend910, Ascend910B, tabular-classification, Mitra, Tab2D, tabular-foundation-model