GPUExplainerHelper<T>
Helpers & Utilities · AiDotNet.Interpretability.Helpers
Provides GPU acceleration for interpretability explainers.
Implements: IDisposable
For Beginners
This helper accelerates interpretability computations using GPU hardware. Many explanation methods (SHAP, Integrated Gradients, etc.) require computing many predictions or gradients - operations that are perfect for GPU parallelization.
The helper provides:
- Batch Prediction: Process many inputs simultaneously on GPU
- Parallel Coalition Processing: For SHAP-style algorithms
- GPU Matrix Operations: Fast linear algebra for solving attribution problems
- Automatic Fallback: Falls back to CPU if no GPU is available
Benefits of GPU acceleration for explainers:
- 10-100x speedup for batch predictions
- Enables real-time explanations for complex models
- Makes ensemble/sample-based methods practical for large models
Usage:
Constructors
| Constructor | Summary |
|---|---|
GPUExplainerHelper(int? maxParallelism) |
Initializes a new GPU explainer helper using CPU parallel processing. |
Properties
| Property | Summary |
|---|---|
bool IsGPUEnabled { get; } |
Gets whether GPU acceleration is available and enabled. |
int MaxParallelism { get; } |
Gets the maximum parallelism level for CPU fallback operations. |
object DeviceInfo { get; } |
Gets information about the GPU device. |
Methods
| Method | Summary |
|---|---|
GPUExplainerHelper<T> CreateCPUOnly(int? maxParallelism) |
Creates a CPU-only helper (no GPU acceleration). |
GPUExplainerHelper<T> CreateWithAutoDetect() |
Creates a GPU explainer helper with automatic GPU detection. |
List<Vector<T>> ComputePermutedPredictions(Func<Matrix<T>, Vector<T>> predictFunction, Matrix<T> data, int featureIndex, int numPermutations, int? seed) |
Processes feature permutations in parallel for permutation importance. |
Matrix<T> BatchComputeGradients(Func<Vector<T>, int, Vector<T>> gradientFunction, Matrix<T> inputs, int outputIndex) |
Computes gradients for multiple inputs in parallel using backpropagation. |
Vector<T> BatchPredict(Func<Matrix<T>, Vector<T>> predictFunction, Matrix<T> inputs) |
Processes predictions for multiple inputs in parallel. |
Vector<T> ComputeCoalitionPredictions(Func<Matrix<T>, Vector<T>> predictFunction, Vector<T> instance, List<bool[]> coalitions, Matrix<T> backgroundData, int nBackgroundSamples) |
Computes predictions for multiple coalitions in parallel (for SHAP-style algorithms). |
Vector<T> ComputeIntegratedGradientsParallel(Func<Vector<T>, int, Vector<T>> gradientFunction, Vector<T> input, Vector<T> baseline, int numSteps, int outputIndex) |
Computes Integrated Gradients using parallel path integration. |
Vector<T> SolveWeightedLeastSquares(Matrix<T> X, Vector<T> y, Vector<T> weights) |
Solves weighted least squares using GPU-accelerated matrix operations. |
void Dispose() |
Disposes GPU resources. |