Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@aamijar
Copy link
Member

@aamijar aamijar commented Oct 23, 2025

Resolves #7001

cuml.explainer algorithms are used for model interpretability usually with tree models and are based on https://github.com/shap/shap.

This PR removes double function support for
kernel_dataset, permutation_shap_dataset, shap_main_effect_dataset update_perm_shap_values
which in turn removes double instantiations for cuml.explainer related kernels.

Users may still pass in double inputs in the python layer, however they will be cast to float for the actual computation. The result will be cast back to double output.

@copy-pr-bot
Copy link

copy-pr-bot bot commented Oct 23, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@aamijar aamijar added the non-breaking Non-breaking change label Oct 23, 2025
@aamijar aamijar added the improvement Improvement / enhancement to an existing function label Oct 23, 2025
@aamijar aamijar marked this pull request as ready for review October 23, 2025 23:37
@aamijar aamijar requested review from a team as code owners October 23, 2025 23:37
@aamijar aamijar requested a review from divyegala October 23, 2025 23:37
Copy link
Contributor

@viclafargue viclafargue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but do we want to remove the float or double instantiation? Is there any argument for one side or the other? Also instead of branching before the C++ call, would it be possible to use the BaseEstimator features to have the output type automatically match the input type while ensuring that the arrays internally always match the type that we choose for C++ instantiations.

Comment on lines 375 to 376
masked_ptr_f32 = masked_inputs_f32.__cuda_array_interface__['data'][0]
bg_ptr_f32 = background_f32.__cuda_array_interface__['data'][0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_cai_ptr here might be nice for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 8dc222c

<bool> row_major)

# Cast result back to float64
masked_inputs[:] = masked_inputs_f32.astype(cp.float64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly please use get_cai_ptr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 8dc222c

@aamijar
Copy link
Member Author

aamijar commented Oct 28, 2025

Thank you for the review @viclafargue!

LGTM, but do we want to remove the float or double instantiation? Is there any argument for one side or the other?

Typically, it seems that we support float32 more often than double in other areas of the codebase? float32 also has a better memory footprint.

Also instead of branching before the C++ call, would it be possible to use the BaseEstimator features to have the output type automatically match the input type while ensuring that the arrays internally always match the type that we choose for C++ instantiations.

What is the process to enable the BaseEstimator features? So BaseEstimator automatically handles the casting of user input and output?

@viclafargue
Copy link
Contributor

What is the process to enable the BaseEstimator features? So BaseEstimator automatically handles the casting of user input and output?

Like :

@cuml.internals.api_base_return_array(input_arg="shap_values", get_output_type=True)
def _explain_single_observation(self,
                                shap_values,
                                row,
                                idx,
                                l1_reg) -> CumlArray:

See estimator guide.

But, just realized that the dtype doesn't come from data dtype, but from SHAPBase argument. I guess this is fine to route the C++ calls that way if we are doing the rest of calculations in the self.dtype dtype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA/C++ Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce binary size of cuml.explainer kernels

2 participants