or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced.mdclustering.mddaal4py-mb.mddecomposition.mdensemble.mdindex.mdlinear-models.mdmetrics-model-selection.mdneighbors.mdpatching-config.mdstats-manifold.mdsvm.md

daal4py-mb.mddocs/

0

# Model Builder API (daal4py.mb)

1

2

Utility functions for converting external gradient boosting models (XGBoost, LightGBM, CatBoost) into Intel oneDAL format for accelerated inference. This API enables users to leverage Intel hardware optimizations on models trained with other frameworks.

3

4

## Core Imports

5

6

```python

7

from daal4py.mb import GBTDAALBaseModel, convert_model

8

```

9

10

## Capabilities

11

12

### Model Conversion

13

14

Convert external gradient boosting models to Intel oneDAL format for accelerated inference.

15

16

```python { .api }

17

def convert_model(model):

18

"""

19

Convert external gradient boosting model to Intel oneDAL format.

20

21

Automatically detects model type and converts to appropriate oneDAL model

22

for accelerated inference with Intel optimizations.

23

24

Parameters:

25

model: External model instance (XGBoost, LightGBM, or CatBoost)

26

Supported types:

27

- xgboost.sklearn.XGBClassifier/XGBRegressor

28

- xgboost.core.Booster

29

- lightgbm.sklearn.LGBMClassifier/LGBMRegressor

30

- lightgbm.basic.Booster

31

- catboost.core.CatBoostClassifier/CatBoostRegressor

32

- catboost.core.CatBoost

33

34

Returns:

35

Converted oneDAL model with Intel acceleration for inference

36

37

Raises:

38

TypeError: If model type is not supported

39

40

Example:

41

import xgboost as xgb

42

from daal4py.mb import convert_model

43

44

# Train XGBoost model

45

xgb_model = xgb.XGBClassifier(n_estimators=100)

46

xgb_model.fit(X_train, y_train)

47

48

# Convert to Intel oneDAL format

49

daal_model = convert_model(xgb_model)

50

51

# Use accelerated inference

52

predictions = daal_model.predict(X_test)

53

"""

54

55

class GBTDAALBaseModel:

56

"""

57

Base class for gradient boosting tree models converted to Intel oneDAL format.

58

59

Provides common functionality for converted GBT models including parameter

60

extraction, model conversion, and accelerated inference methods.

61

62

Attributes:

63

model_type: Type of original model ('xgboost', 'lightgbm', 'catboost', or None)

64

n_classes_: Number of classes for classification models

65

n_features_in_: Number of input features

66

daal_model_: Internal oneDAL model object

67

"""

68

69

def __init__(self):

70

"""Initialize base model converter."""

71

```

72

73

## Usage Examples

74

75

### Converting XGBoost Models

76

77

```python

78

import xgboost as xgb

79

from daal4py.mb import convert_model

80

from sklearn.datasets import make_classification

81

from sklearn.model_selection import train_test_split

82

83

# Generate sample data

84

X, y = make_classification(n_samples=1000, n_features=20, n_classes=2, random_state=42)

85

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

86

87

# Train XGBoost classifier

88

xgb_model = xgb.XGBClassifier(

89

n_estimators=100,

90

max_depth=6,

91

learning_rate=0.1,

92

random_state=42

93

)

94

xgb_model.fit(X_train, y_train)

95

96

# Convert to Intel oneDAL format for accelerated inference

97

daal_model = convert_model(xgb_model)

98

99

# Use accelerated inference

100

predictions = daal_model.predict(X_test)

101

probabilities = daal_model.predict_proba(X_test) if hasattr(daal_model, 'predict_proba') else None

102

103

print(f"Converted model type: {daal_model.model_type}")

104

print(f"Number of features: {daal_model.n_features_in_}")

105

print(f"Number of classes: {daal_model.n_classes_}")

106

```

107

108

### Converting LightGBM Models

109

110

```python

111

import lightgbm as lgb

112

from daal4py.mb import convert_model

113

114

# Train LightGBM regressor

115

lgb_model = lgb.LGBMRegressor(

116

n_estimators=100,

117

learning_rate=0.1,

118

num_leaves=31,

119

random_state=42

120

)

121

lgb_model.fit(X_train, y_train)

122

123

# Convert to Intel oneDAL format

124

daal_model = convert_model(lgb_model)

125

126

# Accelerated inference

127

predictions = daal_model.predict(X_test)

128

```

129

130

### Converting CatBoost Models

131

132

```python

133

from catboost import CatBoostClassifier

134

from daal4py.mb import convert_model

135

136

# Train CatBoost classifier

137

cb_model = CatBoostClassifier(

138

iterations=100,

139

learning_rate=0.1,

140

depth=6,

141

verbose=False,

142

random_state=42

143

)

144

cb_model.fit(X_train, y_train)

145

146

# Convert to Intel oneDAL format

147

daal_model = convert_model(cb_model)

148

149

# Accelerated inference

150

predictions = daal_model.predict(X_test)

151

```

152

153

## Supported Model Types

154

155

### XGBoost

156

- `xgboost.sklearn.XGBClassifier``GBTDAALClassifier`

157

- `xgboost.sklearn.XGBRegressor``GBTDAALRegressor`

158

- `xgboost.core.Booster``GBTDAALModel`

159

160

### LightGBM

161

- `lightgbm.sklearn.LGBMClassifier``GBTDAALClassifier`

162

- `lightgbm.sklearn.LGBMRegressor``GBTDAALRegressor`

163

- `lightgbm.basic.Booster``GBTDAALModel`

164

165

### CatBoost

166

- `catboost.core.CatBoostClassifier``GBTDAALClassifier`

167

- `catboost.core.CatBoostRegressor``GBTDAALRegressor`

168

- `catboost.core.CatBoost``GBTDAALModel`

169

170

## Performance Benefits

171

172

- **Accelerated Inference**: Up to 10-100x faster prediction on Intel hardware

173

- **Memory Efficiency**: Optimized memory layout for Intel architectures

174

- **Threading**: Automatic parallelization for multi-core systems

175

- **Vectorization**: Intel SIMD optimizations for numerical computations

176

177

## Limitations

178

179

- Model conversion is one-way (cannot convert back to original format)

180

- Training must be performed with original frameworks

181

- Only gradient boosting tree models are supported

182

- Converted models maintain prediction accuracy but may have slight numerical differences