Skip to content

TypeError when calling tabpfn_extensions.interpretability.shap.get_shap_values #161

@jinyueyuan

Description

@jinyueyuan

Describe the bug

Hi team, I encountered an error "TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''" when calling tabpfn_extensions.interpretability.shap.get_shap_values.
The data is manually generated with both categorical feature and numeric features as below code shown. I could successfully run TabPFNClassifier.fit and predict_proba on this dataset. But when I tried to get the shap_values, it returned errors.

Steps/Code to Reproduce

from tabpfn import TabPFNClassifier
import numpy as np
import pandas as pd
import traceback
from tabpfn_extensions.interpretability.shap import get_shap_values, plot_shap

X_train2 = pd.DataFrame({'riskiness':['High','Middle'],'count':[1,2],'ratio':[0.4, 0.5]})
y_train2 = np.array([1,0])
X_test2 = pd.DataFrame({'riskiness':['High','High'],'count':[1,1],'ratio':[0.3, 0.6]})

# Train a TabPFN model
model = TabPFNClassifier()
model.fit(X_train2, y_train2)

prediction_probabilities = model.predict_proba(X_test2)
print(prediction_probabilities)

shap_values = get_shap_values(model, X_test2)

Expected Results

No error

Actual Results

Traceback (most recent call last):
  File "/tmp/ipykernel_429/1935262485.py", line 3, in <cell line: 1>
    shap_values = get_shap_values(model, X_test2)
  File "/projects/yuejin/apps/yuejin/research/.local/pyvenv/dtr-vip.ccg13.slc.paypalinc.com/core-data-platform/notebook-server-gpu-nlp-torch23-py310/1.0.0.240804/WJU_GENESIS/lib/python3.10/site-packages/tabpfn_extensions/interpretability/shap.py", line 249, in get_shap_values
    shap_values = get_shap()
  File "/projects/yuejin/apps/yuejin/research/.local/pyvenv/dtr-vip.ccg13.slc.paypalinc.com/core-data-platform/notebook-server-gpu-nlp-torch23-py310/1.0.0.240804/WJU_GENESIS/lib/python3.10/site-packages/tabpfn_extensions/interpretability/shap.py", line 239, in get_shap
    return explainer(test_x)
  File "/opt/conda/lib/python3.10/site-packages/shap/explainers/_exact.py", line 69, in __call__
    return super(Exact, self).__call__(
  File "/opt/conda/lib/python3.10/site-packages/shap/explainers/_explainer.py", line 266, in __call__
    row_result = self.explain_row(
  File "/opt/conda/lib/python3.10/site-packages/shap/explainers/_exact.py", line 84, in explain_row
    fm = MaskedModel(self.model, self.masker, self.link, self.linearize_link, *row_args)
  File "/opt/conda/lib/python3.10/site-packages/shap/utils/_masked_model.py", line 28, in __init__
    self._variants = ~self.masker.invariants(*args)
  File "/opt/conda/lib/python3.10/site-packages/shap/maskers/_tabular.py", line 150, in invariants
    return np.isclose(x, self.data)
  File "<__array_function__ internals>", line 180, in isclose
  File "/opt/conda/lib/python3.10/site-packages/numpy/core/numeric.py", line 2372, in isclose
    xfin = isfinite(x)
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Versions

tabpfn_extensions.__version__ = '0.1.4'

Collecting system and dependency information...
PyTorch version: 2.3.1+cu121
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.10.14 (main, May  6 2024, 19:42:50) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-52-generic-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA A100-SXM4-80GB
  MIG 3g.40gb     Device  0:

Nvidia driver version: 550.127.08
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.1.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.1.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Byte Order:                           Little Endian
Address sizes:                        46 bits physical, 57 bits virtual
CPU(s):                               96
On-line CPU(s) list:                  0-95
Thread(s) per core:                   2
Core(s) per socket:                   24
Socket(s):                            2
NUMA node(s):                         2
Vendor ID:                            GenuineIntel
CPU family:                           6
Model:                                106
Model name:                           Intel(R) Xeon(R) Gold 6336Y CPU @ 2.40GHz
Stepping:                             6
CPU MHz:                              800.940
CPU max MHz:                          3600.0000
CPU min MHz:                          800.0000
BogoMIPS:                             4800.00
Virtualization:                       VT-x
L1d cache:                            2.3 MiB
L1i cache:                            1.5 MiB
L2 cache:                             60 MiB
L3 cache:                             72 MiB
NUMA node0 CPU(s):                    0-23,48-71
NUMA node1 CPU(s):                    24-47,72-95
Vulnerability Gather data sampling:   Mitigation; Microcode
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Not affected
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm ida arat pln pts vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities

Dependency Versions:
--------------------
tabpfn: 2.1.3
torch: 2.3.1+cu121
numpy: 1.23.5
scipy: 1.14.0
pandas: 2.2.2
scikit-learn: 1.5.0
typing_extensions: 4.12.2
einops: 0.8.0
huggingface-hub: 0.23.4

Metadata

Metadata

Labels

bugSomething isn't workingtriaged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions