timber  by kossisoroyce

Compiles classical ML models into fast, native C inference code

Created 2 weeks ago

New!

632 stars

Top 52.4% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

Timber addresses the need for high-performance, portable inference for classical machine learning models by compiling them into optimized native C99 code. It targets teams in fraud detection, edge computing, and regulated industries requiring fast, predictable, and auditable model deployments. The primary benefit is a significant reduction in inference latency and runtime overhead compared to traditional Python-based serving.

How It Works

Timber employs an Ahead-of-Time (AOT) compilation strategy, transforming trained models from frameworks like XGBoost, LightGBM, scikit-learn, CatBoost, and ONNX (specifically TreeEnsemble operators) into standalone C99 inference code. This compiled code is then served via a local HTTP API, following an Ollama-style workflow for loading and querying models. This approach eliminates the Python runtime from the critical inference path, enabling microsecond-level latency.

Quick Start & Requirements

  • Primary install: pip install timber-compiler
  • Load model: timber load <model_file> --name <model_name>
  • Serve model: timber serve <model_name>
  • Supported formats include XGBoost JSON, LightGBM text/model, scikit-learn pickle, ONNX TreeEnsemble, and CatBoost JSON.
  • Docs: https://kossisoroyce.github.io/timber/

Highlighted Details

  • Achieves up to 336x faster inference compared to Python XGBoost for single-sample predictions.
  • Native inference latency is approximately 2 µs.
  • Generates small artifacts, around 48 KB for an example model.
  • Ideal for edge/embedded deployments and environments demanding deterministic, auditable artifacts.

Maintenance & Community

  • Includes contributing guidelines, a code of conduct, and a security policy.
  • Development setup via pip install -e ".[dev]".
  • The project seeks community support and donations via https://buymeacoffee.com/electricsheepafrica.

Licensing & Compatibility

  • Licensed under Apache-2.0, which is permissive for commercial use and integration into closed-source projects.

Limitations & Caveats

  • ONNX support is currently limited to TreeEnsemble operators.
  • CatBoost support requires JSON exports, not native binary formats.
  • scikit-learn parsing may encounter issues with uncommon or custom estimator wrappers; pickle loading requires trusted artifacts.
  • XGBoost primarily accepts JSON model inputs.
  • Optional benchmark backends require separate installation.
Health Check
Last Commit

1 week ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
1
Star History
635 stars in the last 14 days

Explore Similar Projects

Feedback? Help us improve.