CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-scikit-learn-intelex

Intel Extension for Scikit-learn providing hardware-accelerated implementations of scikit-learn algorithms optimized for Intel CPUs and GPUs.

Pending
Overview
Eval results
Files

patching-config.mddocs/

Patching and Configuration

Control functions for enabling Intel optimizations globally and managing package configuration. These functions determine how scikit-learn algorithms are accelerated and allow runtime configuration of optimization behavior.

Capabilities

Global Patching

Enable or disable Intel optimizations for all scikit-learn imports system-wide.

def patch_sklearn():
    """
    Enable Intel Extension optimizations for all scikit-learn algorithms.
    
    After calling this function, all subsequent scikit-learn imports will
    automatically use Intel-optimized implementations when available.
    
    Example:
        from sklearnex import patch_sklearn
        patch_sklearn()
        
        # Now uses Intel-optimized implementation
        from sklearn.ensemble import RandomForestClassifier
    """

def unpatch_sklearn():
    """
    Disable Intel Extension optimizations and restore original scikit-learn.
    
    Returns scikit-learn to its original state, using standard implementations
    for all subsequent imports and operations.
    """

def sklearn_is_patched() -> bool:
    """
    Check if scikit-learn is currently patched with Intel optimizations.
    
    Returns:
        bool: True if Intel optimizations are active, False otherwise
    """

Patch Information

Query available optimizations and check implementation status.

def get_patch_map() -> dict:
    """
    Get mapping of available Intel-optimized implementations.
    
    Returns:
        dict: Mapping from original sklearn classes to Intel implementations
    """

def get_patch_names() -> list:
    """
    Get list of algorithm names available for Intel optimization.
    
    Returns:
        list: Names of algorithms that have Intel-accelerated versions
    """

def is_patched_instance(estimator) -> bool:
    """
    Check if a specific estimator instance uses Intel optimization.
    
    Parameters:
        estimator: Scikit-learn estimator instance
        
    Returns:
        bool: True if instance uses Intel optimization, False otherwise
    """

Configuration Management

Manage runtime configuration for Intel optimizations and scikit-learn settings.

def set_config(**params):
    """
    Set configuration parameters for Intel Extension and scikit-learn.
    
    Parameters:
        **params: Configuration parameters to set
    """

def get_config() -> dict:
    """
    Retrieve current configuration values.
    
    Returns:
        dict: Current configuration parameters and their values
    """

def config_context(**params):
    """
    Context manager for temporary configuration changes.
    
    Parameters:
        **params: Temporary configuration parameters
        
    Example:
        with config_context(assume_finite=True):
            # Code with temporary configuration
            model.fit(X, y)
    """

Usage Examples

Basic Patching

from sklearnex import patch_sklearn, sklearn_is_patched

# Check initial state
print(f"Initially patched: {sklearn_is_patched()}")  # False

# Enable optimizations
patch_sklearn()
print(f"After patching: {sklearn_is_patched()}")    # True

# All sklearn imports now use Intel optimizations
from sklearn.cluster import KMeans
from sklearn.ensemble import RandomForestClassifier

# Create and use optimized models
kmeans = KMeans(n_clusters=3)
rf = RandomForestClassifier(n_estimators=100)

Checking Optimizations

from sklearnex import patch_sklearn, get_patch_names, is_patched_instance
from sklearn.ensemble import RandomForestClassifier

# Enable optimizations
patch_sklearn()

# See what's available
available_patches = get_patch_names()
print(f"Available optimizations: {available_patches}")

# Create model and check if optimized
rf = RandomForestClassifier()
print(f"Using Intel optimization: {is_patched_instance(rf)}")  # True

Configuration Context

from sklearnex import config_context, get_config
from sklearn.ensemble import RandomForestClassifier

# Check current config
current_config = get_config()
print(f"Current config: {current_config}")

# Temporary configuration change
with config_context(assume_finite=True):
    rf = RandomForestClassifier()
    # Model created with temporary configuration

Environment Variables

  • OFF_ONEDAL_IFACE: Set to "1" to disable oneDAL interface entirely
  • SKLEARNEX_PREVIEW: Enable experimental preview features

Performance Notes

  • Patching is a one-time operation per Python session
  • No performance overhead from patching itself
  • Original sklearn behavior can be restored with unpatch_sklearn()
  • Patching affects globally imported modules but not already-imported ones

Install with Tessl CLI

npx tessl i tessl/pypi-scikit-learn-intelex

docs

advanced.md

clustering.md

daal4py-mb.md

decomposition.md

ensemble.md

index.md

linear-models.md

metrics-model-selection.md

neighbors.md

patching-config.md

stats-manifold.md

svm.md

tile.json