liveBook · Manning

Lleaves

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

lleaves is a tool that compiles LightGBM tree models to LLVM-generated assembly for faster prediction.

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

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Explains installation, model export, compilation, preprocessing, and prediction, but does not detail generated assembly internals.
Examples
Uses a LightGBM classifier pipeline that saves lgb_model.txt, compiles it, transforms data, and predicts.
What it assumes
Assumes a trained LightGBM pipeline and requires separate handling of its preprocessing stage.
What you can do after
Operate/configure lleaves to compile a LightGBM model and obtain predictions from transformed data.
How it connects
Connects LightGBM, gradient-boosted decision trees, LLVM, model serialization, preprocessing pipelines, and Treelite.

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.