lgbmjit
lgbmjit compiles trained LightGBM models to machine code and predicts with them. Its predictions are bit-identical to lightgbm.Booster.predict.
I wrote it for my own batch forecasting, where LightGBM prediction took most of the run time. On my production model (500 trees of up to 255 leaves, 82 features), lgbmjit predicts between 18 and 25 times faster than LightGBM on one thread.
lgbmjit builds on the idea of lleaves, which compiles LightGBM models with LLVM. Compared with lleaves:
- It compiles in seconds instead of minutes. My model compiles in 1.6 s, where lleaves took 6 minutes on the same Mac and needed about 14 GB of memory on an x86 machine.
- It depends only on NumPy. The compiler, Cranelift, is built into the wheel, so there is no llvmlite or LLVM to install.
- It predicts faster: 0.69 s per million rows against 0.97 s for lleaves on the same model and machine.
- You can tune the generated code for your machine and your data, and cache the result.
Install
pip install lgbmjit
Wheels are built for Linux (x86-64, aarch64), macOS (arm64) and Windows (x86-64), for Python 3.11 and later. The only runtime dependency is NumPy 1.24 or later.
Example
import lightgbm as lgb
import lgbmjit
booster = lgb.train(params, lgb.Dataset(X_train, y_train))
model = lgbmjit.Model.from_booster(booster) # or lgbmjit.Model("model.txt")
predictions = model.predict(X) # same result as booster.predict(X)
predict takes the arguments of Booster.predict: start_iteration, num_iteration, raw_score, validate_features and num_threads. X can be a NumPy array, a list of rows or a pandas DataFrame, including categorical columns. The model compiles on the first predict for float32 or float64 input, which took 1 to 3 seconds for my model.
To pick the fastest code layout for your machine, compile with a sample of your data:
model = lgbmjit.Model("model.txt").compile(tune=X[:20_000], tune_cache="lgbmjit-tuning.json")
Tuning compiles the model several times and times each version, which took 14 seconds on my Mac and 30 seconds on an older x86 machine. The cache file keeps the chosen settings per model and CPU, so later runs skip the timing. Results never depend on the settings, only speed does.
Speed
One thread, 192,000 rows of float32 data with 11% missing values, on the model above:
| Machine | LightGBM 4.7 | lgbmjit | Speedup | Compile |
|---|---|---|---|---|
| Apple M5 Pro | 12.9 s | 0.69 s | 18.6 times | 1.6 s |
| AMD Zen 1 (virtual machine) | 38.1 s | 1.65 s | 23.1 times | 5.7 s |
Times are seconds per million rows. Every prediction was identical to LightGBM's. benchmarks/bench.py runs the same comparison on your own model and data.
What is supported
lgbmjit handles numerical splits with every missing-value setting, categorical splits, and the output of every built-in objective, including multiclass, ranking and random forests. It does not train models, and it raises an error for linear trees, pred_leaf=True and pred_contrib=True. It never silently returns results that differ from LightGBM's.
Development
uv run --extra test pytest tests # build in place and run the Python tests
uv run tasks.py check # formatting, style, types, lints and Rust tests (also the pre-commit hook)
uv run tasks.py build # a release wheel for this machine into dist/
uv run tasks.py test # test that wheel with the newest dependencies and with the oldest supported ones
uv run release.py v0.2.0 --check # check dist/ for that release; without --check it also publishes
To release, push a tag such as v0.2.0 on a commit of main whose CI run passed, then bump the version in Cargo.toml to the next one. The release workflow builds nothing. It fetches the files that CI built and tested for that commit, checks them with release.py and publishes them to PyPI. If that build has expired, the workflow stops and asks you to re-run the commit's CI run.
CI builds and tests in separate jobs. Linux x86-64 tests both the newest dependencies on Python 3.15 and the dependency floors on Python 3.11; the other platforms test only the newest. The test jobs install the newest dependencies from PyPI, and they can read the uploaded builds but not change them. tasks.py test also hashes each file before running the tests and refuses to record a file that changed during them.
On macOS, the tests need the OpenMP runtime that LightGBM loads: brew install libomp.
The Rust core in crates/lgbmjit-core has no Python dependency. crates/lgbmjit-python holds the bindings and python/lgbmjit the Python API.
Credits
lgbmjit follows the approach of lleaves by Simon Boehm. Its test models come from lleaves under the MIT license (tests/models/LICENSE-lleaves).
License
MIT
Metadata
Release files for lgbmjit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lgbmjit-0.1.0.tar.gz | 35.6 kB | With provenance | Details for lgbmjit-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| lgbmjit-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for lgbmjit-0.1.0-cp311-abi3-win_amd64.whl |
| lgbmjit-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details for lgbmjit-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| lgbmjit-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details for lgbmjit-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| lgbmjit-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for lgbmjit-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 6.1 MB
Release files / lgbmjit-0.1.0.tar.gz
| Download URL | lgbmjit-0.1.0.tar.gz |
|---|---|
| Size | 35.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3257fd5d7e34ec5ececbb29e087bd52ff12f5bd58eadbbacbe5d0a8c697148d7
|
|
BLAKE2b-256 checksum How to use checksums |
7a85b74b68901bc734aac3df54884e71492e889b29b9b0c94b046782d82e2d28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / lgbmjit-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | lgbmjit-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
49089e20a44ca71cbaae24e4c2aef86326b0fbfcaece9757db3e7c97ec92f8fd
|
|
BLAKE2b-256 checksum How to use checksums |
21dc27fb094fa5e796947652d0a0ccb18c8a346825bad6fdd2c8ba98300ad3bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / lgbmjit-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | lgbmjit-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3a22131477ddd6141201f8c559b0cca02dfe93e4cef043892ad3b72837ad5d0c
|
|
BLAKE2b-256 checksum How to use checksums |
cd7837eae7e2ff8b7d914e45b0a7915105bfd587645292caaeb381d51c642cd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / lgbmjit-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | lgbmjit-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
01c42a6383394ebb6a1666793b882a692c58d521d07262df4ba3d0a224bd2b6e
|
|
BLAKE2b-256 checksum How to use checksums |
a96c8228f54f4802a2f24bb7e0172918eb6bb502b3faddc7424e13da2c793617
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / lgbmjit-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | lgbmjit-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
549e26617831ebbceb30fd7b7197d1ea4d772e60c2878ca74e5e5e0cc7da47ae
|
|
BLAKE2b-256 checksum How to use checksums |
37883755589e4d4c8c1480972f9d7e6e7975ddf7f67370ec1307b6a46402e898
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logSecurity for lgbmjit 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 5 files in this release have been uploaded with provenance metadata.
Attestation for lgbmjit-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.