siboehm/lleaves
소개
LLVM 기반의 LightGBM 그래디언트 부스팅 트리 컴파일러입니다. 예측 속도를 10배 이상 향상합니다.
프로그래밍 언어 및 런타임측정된 스타 증가
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- +2
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originallleaves 🍃
A LLVM-based compiler for LightGBM decision trees.
lleaves converts trained LightGBM models to optimized machine code, speeding-up prediction by ≥10x.
Example
lgbm_model = lightgbm.Booster(model_file="NYC_taxi/model.txt")
%timeit lgbm_model.predict(df)
# 12.77s
llvm_model = lleaves.Model(model_file="NYC_taxi/model.txt")
llvm_model.compile()
%timeit llvm_model.predict(df)
# 0.90s
Why lleaves?
- Speed: Both low-latency single-row prediction and high-throughput batch-prediction.
- Drop-in replacement: The interface of
lleaves.Modelis a subset ofLightGBM.Booster. - Dependencies:
llvmliteandnumpy. LLVM comes statically linked.
Installation
pip install lleaves or uv add lleaves (Linux and MacOS only).
Benchmarks
Ran on a dedicated Intel i7-4770 Haswell, 4 cores. Stated runtime is the minimum over 20.000 runs.
Dataset: NYC-taxi
mostly numerical features.
| batchsize | 1 | 10 | 100 |
|---|---|---|---|
| LightGBM | 52.31μs | 84.46μs | 441.15μs |
| ONNX Runtime | 11.00μs | 36.74μs | 190.87μs |
| Treelite | 28.03μs | 40.81μs | 94.14μs |
lleaves |
9.61μs | 14.06μs | 31.88μs |
Dataset: MTPL2
mix of categorical and numerical features.
| batchsize | 10,000 | 100,000 | 678,000 |
|---|---|---|---|
| LightGBM | 95.14ms | 992.47ms | 7034.65ms |
| ONNX Runtime | 38.83ms | 381.40ms | 2849.42ms |
| Treelite | 38.15ms | 414.15ms | 2854.10ms |
lleaves |
5.90ms | 56.96ms | 388.88ms |
Advanced Usage
To avoid expensive recompilation, you can call lleaves.Model.compile() and pass a cache=<filepath> argument.
This will store an ELF (Linux) / Mach-O (macOS) file at the given path when the method is first called.
Subsequent calls of compile(cache=<same filepath>) will skip compilation and load the stored binary file instead.
For more info, see docs.
To eliminate any Python overhead during inference you can link against this generated binary.
For an example of how to do this see benchmarks/c_bench/.
The function signature might change between major versions.
Development
High-level explanation of the inner workings of the lleaves compiler: link
# Using uv (recommended)
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev,test]"
pre-commit install
./benchmarks/data/setup_data.sh
pytest -k "not benchmark"
Alternative with pip:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e ".[dev,test]"
pre-commit install
./benchmarks/data/setup_data.sh
pytest -k "not benchmark"
Cite
If you're using lleaves for your research, I'd appreciate if you could cite it. Use:
@software{Boehm_lleaves,
author = {Boehm, Simon},
title = {lleaves},
url = {https://github.com/siboehm/lleaves},
license = {MIT},
}
관련 프로젝트 살펴보기
불러오는 중…