lleaves compiles a LightGBM gradient-boosted decision-tree model with LLVM into assembly, targeting faster prediction and simpler deployment. It supports LightGBM models only. section 6.4.3
A practical prediction-speed workflow is:
- Train the LightGBM model inside a preprocessing pipeline. section 6.4.3
- Save the underlying booster as lgb_model.txt, load it with lleaves.Model, and compile it. section 6.4.3
- Transform predictors separately before passing them to the compiled model, because lleaves compiles the model rather than the pipeline. section 6.4.3
Listing 6.19 LightGBM prediction speedup by lleaves
import lleaves
lgbm = LGBMClassifier(boosting_type='gbdt',
n_estimators=10,
max_depth=3)
model_pipeline = Pipeline(
[('processing', column_transform),
('lightgbm', lgbm)])
model_pipeline.fit(X=data, y=target_median)
model = model_pipeline["lightgbm"]
model.booster_.save_model('lgb_model.txt') #1
llvm_model = lleaves.Model(model_file="lgb_model.txt") #2
llvm_model.compile() #3
X = model_pipeline["processing"].transform(data) #4
llvm_model.predict(X)
The listing demonstrates model extraction, compilation, preprocessing, and prediction with lleaves. section 6.4.3
