Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
LightGBM Rust Bindings
Rust bindings for LightGBM, a fast, distributed, high-performance gradient boosting framework. This crate provides a safe and ergonomic Rust interface to LightGBM's C API.
Features
- Cross-platform: Works on Linux, macOS, and Windows
- Self-contained: Downloads LightGBM binaries at build time - no system dependencies required
- Version control: Specify different LightGBM versions via environment variable
- Safe Rust API: Memory-safe wrapper around LightGBM's C API
- Multiple prediction types: Support for normal predictions, raw scores, leaf indices, and SHAP values
- Debugger-friendly: Proper rpath configuration for IDE debugging
- GPU support: Optional GPU acceleration (requires
gpufeature)
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
For GPU support:
[]
= { = "0.1.0", = ["gpu"] }
Quick Start
use ;
Usage Examples
Basic Usage
use ;
// Load model from file
let booster = load?;
// Single prediction
let data = vec!;
let predictions = booster.predict?;
// Batch prediction (3 samples with 4 features each)
let batch_data = vec!;
let batch_predictions = booster.predict?;
Loading from Buffer
use Booster;
use fs;
// Load from string
let model_string = read_to_string?;
let booster = load_from_string?;
// Load from byte buffer
let model_bytes = read?;
let booster = load_from_buffer?;
Using f32 for Memory Efficiency
use ;
let booster = load?;
// Use f32 instead of f64 for large datasets
let data_f32: = vec!;
let predictions = booster.predict_f32?;
Different Prediction Types
use ;
let booster = load?;
let data = vec!;
// Normal prediction (default)
let normal = booster.predict?;
// Raw scores (before sigmoid/softmax)
let raw = booster.predict?;
// Leaf indices (which leaf each tree predicts)
let leaves = booster.predict?;
// SHAP feature contributions
let shap = booster.predict?;
Thread Safety
Important: Booster is NOT thread-safe by default. The underlying LightGBM C API does not guarantee thread-safety for concurrent predictions.
For multi-threaded use cases, choose one of these approaches:
Option 1: One Booster per thread (recommended)
use thread;
let model_bytes = read?;
let handles: = .map.collect;
for handle in handles
Option 2: Shared access with Arc<Mutex>
use ;
use thread;
let booster = new;
let handles: = .map.collect;
for handle in handles
Configuration
LightGBM Version
You can specify which version of LightGBM to use by setting the LIGHTGBM_VERSION environment variable:
The default version is 4.6.0.
Supported versions: Any version from 3.0.0 onwards that has pre-built binaries available on the LightGBM releases page.
The library automatically:
- Downloads the correct binary for your platform and specified version
- Fetches the matching C API headers for that version
- Generates version-specific Rust bindings
- Handles API differences across versions