Treelite
Treelite is a universal model exchange and serialization format for decision tree forests. Treelite aims to be a small library that enables other C++ applications to exchange and store decision trees on the disk as well as the network.
Star WatchWarning
Tree compiler was migrated to TL2cgen
If you are looking for a compiler to translate tree models into C code, use TL2cgen. To migrate existing code using Treelite 3.x, consult the page Migration Guide: How to migrate from Treelite 3.x.
Why Treelite?
Universal, lightweight specification for all tree models
Are you designing a C++ application that needs to read and write tree models, e.g. a prediction server? Do not be overwhelmed by the variety of tree models in the wild. Treelite lets you convert many kinds of tree models into a common specification. By using Treelite as a library, your application now only needs to deal with one model specification instead of many. Treelite currently supports:
flexible builder class for users of other tree libraries
In addition, tree libraries can directly output trained trees using the Treelite specification. For example, the random forest algoritm in RAPIDS cuML stores the random forest object using Treelite.
A small library that’s easy to embed in another C++ application
Treelite has an up-to-date CMake build script. If your C++ application uses CMake, it is easy to embed Treelite. Treelite is currently used by the following applications:
Forest Inference Library (FIL) in RAPIDS cuML
Triton Inference Server FIL Backend, an optimized prediction runtime for CPUs and GPUs.
Quick start
Install Treelite:
# From PyPI
pip install treelite
# From Conda
conda install -c conda-forge treelite
Import your tree ensemble model into Treelite:
import treelite
model = treelite.frontend.load_xgboost_model("my_model.json")
Compute predictions using General Tree Inference Library (GTIL):
X = ... # numpy array
treelite.gtil.predict(model, data=X)