Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEA] Add GPUTreeSHAP to cuML explainer module (experimental) #4351

Merged
merged 24 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ if(LINK_FAISS)
endif()

include(cmake/thirdparty/get_treelite.cmake)
include(cmake/thirdparty/get_gputreeshap.cmake)
include(cmake/thirdparty/get_raft.cmake)

if(NOT SINGLEGPU)
Expand Down Expand Up @@ -264,6 +265,7 @@ if(BUILD_CUML_CPP_LIBRARY)
src/decisiontree/decisiontree.cu
src/explainer/kernel_shap.cu
src/explainer/permutation_shap.cu
src/explainer/tree_shap.cu
src/fil/fil.cu
src/fil/infer.cu
src/glm/glm.cu
Expand Down Expand Up @@ -388,6 +390,7 @@ if(BUILD_CUML_CPP_LIBRARY)
CUDA::cusolver
CUDA::cudart
CUDA::cusparse
GPUTreeShap::GPUTreeShap
$<$<BOOL:${NVTX}>:CUDA::nvToolsExt>
$<$<BOOL:${LINK_FAISS}>:FAISS::FAISS>
$<IF:$<BOOL:${Treelite_ADDED}>,treelite::treelite_static,treelite::treelite>
Expand Down
34 changes: 34 additions & 0 deletions cpp/cmake/thirdparty/get_gputreeshap.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#=============================================================================
# Copyright (c) 2021, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

function(find_and_configure_gputreeshap)

set(oneValueArgs VERSION PINNED_TAG)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )

rapids_cpm_find(GPUTreeShap 0.0.1
GLOBAL_TARGETS GPUTreeShap::GPUTreeShap GPUTreeShap
CPM_ARGS
GIT_REPOSITORY https://github.com/rapidsai/gputreeshap.git
GIT_TAG ${PKG_PINNED_TAG}
)

set(GPUTreeShap_ADDED ${GPUTreeShap_ADDED} PARENT_SCOPE)

endfunction()

find_and_configure_gputreeshap(PINNED_TAG c78fe621e429117cbca45e7b23eb5c3b6280fa3a)
44 changes: 44 additions & 0 deletions cpp/include/cuml/explainer/tree_shap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cstddef>
#include <cstdint>
#include <cuml/ensemble/treelite_defs.hpp>
#include <memory>

namespace ML {
namespace Explainer {

// An abstract class representing an opaque handle to path information
// extracted from a tree model. The implementation in tree_shap.cu will
// define an internal class that inherits from this abtract class.
class TreePathInfo {
public:
enum class ThresholdTypeEnum : std::uint8_t { kFloat, kDouble };
virtual ThresholdTypeEnum GetThresholdType() const = 0;
};

std::unique_ptr<TreePathInfo> extract_path_info(ModelHandle model);
void gpu_treeshap(const TreePathInfo* path_info,
const float* data,
std::size_t n_rows,
std::size_t n_cols,
float* out_preds);

} // namespace Explainer
} // namespace ML
1 change: 1 addition & 0 deletions cpp/src/decisiontree/decisiontree.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ tl::Tree<T, T> build_treelite_tree(const DT::TreeMetaDataNode<T, L>& rf_tree,
tl_tree.SetLeafVector(tl_node_id, leaf_vector);
}
}
tl_tree.SetDataCount(tl_node_id, q_node.InstanceCount());
}

cur_level_queue.swap(next_level_queue);
Expand Down
Loading