dsgibbons / shap

A game theoretic approach to explain the output of any machine learning model.
https://shap-community.readthedocs.io/en/latest/
MIT License
25 stars 5 forks source link

Fixed Visual Studio 2022 support for Nvidia GPU support (NVCC Compilation Error Fix) #2890 #100

Closed prabathbr closed 1 year ago

prabathbr commented 1 year ago

As mentioned in https://github.com/dsgibbons/shap/issues/2 ; I am raising this PR

NVCC compilation in Windows with Visual Studio 2022 is not working with current setup.py file and compilation fails with below error. Therefore, GPU bases models like shap.explainers.GPUTree can't be used without CUDA support.

Error during compilation:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\crt/host_config.h(160): fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2019 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.

This pull request has modified NVCC command by adding -allow-unsupported-compiler to override limitation up to Visual Studio 2019.

nvcc_command = "-allow-unsupported-compiler shap/cext/_cext_gpu.cu -lib -o {} -Xcompiler {} -I{} " \

thatlittleboy commented 1 year ago

Hi @prabathbr , thanks for the PR. Two things:

  1. I dont' have a machine with a GPU to test this, can you confirm after the changes in this PR, it doesn't introduce any other issues with the compilation of the gpu cext, and you're able to use gpu cext normally after this change?
  2. Can you rebase your changes on our latest master branch, please?
connortann commented 1 year ago

I approved the workflow and rebased on top of master.

codecov[bot] commented 1 year ago

Codecov Report

Merging #100 (f5a417a) into master (b1252d9) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #100   +/-   ##
=======================================
  Coverage   53.58%   53.58%           
=======================================
  Files          90       90           
  Lines       12893    12893           
=======================================
  Hits         6909     6909           
  Misses       5984     5984           

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

thatlittleboy commented 1 year ago

If anybody can verify this change works on their machine, I'm happy to merge this in. (I'm just worried that this change introduces other bugs, because we're not currently testing the gpu-code in our CI, as far as I can tell).

prabathbr commented 1 year ago

If anybody can verify this change works on their machine, I'm happy to merge this in. (I'm just worried that this change introduces other bugs, because we're not currently testing the gpu-code in our CI, as far as I can tell).

Hi, I was able to compile the library successfully after this modification and it generated "_cext_gpu.lib" under the build folder. I tested it using "explainer = shap.explainers.GPUTree(model, X)" with "shap.datasets.adult()" dataset with a RTX3090.