lightgbm-ars
Native LightGBM inference in pure Rust — no C++ runtime, no FFI,
runs anywhere Rust does. Parses LightGBM's model.txt
text format directly and implements inference and exact
path-dependent TreeSHAP without external dependencies.
Why
The official LightGBM bindings drag in a cmake build
and unsafe FFI to a C++ library. lightgbm-ars eliminates
that entire dependency chain — pure Rust, cross-compiles cleanly,
and works on platforms the C++ runtime doesn't support.
Capabilities
- Pure Rust inference — no C/C++ runtime, no FFI, no
cmake - Exact path-dependent TreeSHAP —
sum(values) + bias == raw_margin - Numerical and categorical splits — full
decision_typesupport including all three missing-value modes - Linear leaves — coefficient attribution preserves SHAP additivity
- Batch inference —
predict_manywalks each tree once across rows, keeping the tree hot in cache - Cross-platform — compiles anywhere Rust does, including FreeBSD
- Minimal dependencies — only
thiserror
Usage
use lightgbm_ars::Model;
let m = Model::load(Path::new("model.txt"))?;
let prob = m.predict(&features)?;
let shap = m.shap(&features)?; // sum(values) + bias == raw
let batch = m.predict_many(&rows)?; // row-major
Verification
Validated against Python lightgbm.Booster on
synthetic, categorical, and linear-tree fixtures:
| Metric | Tolerance |
|---|---|
| Probability | < 1e-6 |
| Raw margin | < 1e-5 |
| SHAP additivity | < 1e-5 |
Supported
Binary classification, numerical and categorical splits,
constant and linear leaves. No training, no multi-class
(num_class != 1 is rejected at load), no round-trip
save, no column-major input.
For training, multi-class, or column-major data, use
lightgbm3 —
it binds the C++ library at the cost of a cmake build
and unsafe FFI.