lgbm-boost 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lgbm_boost-0.1.0/.github/workflows/ci.yml +88 -0
- lgbm_boost-0.1.0/.github/workflows/publish.yml +90 -0
- lgbm_boost-0.1.0/.gitignore +13 -0
- lgbm_boost-0.1.0/CMakeLists.txt +100 -0
- lgbm_boost-0.1.0/LICENSE +21 -0
- lgbm_boost-0.1.0/PKG-INFO +169 -0
- lgbm_boost-0.1.0/README.md +134 -0
- lgbm_boost-0.1.0/benchmarks/run_suite.py +98 -0
- lgbm_boost-0.1.0/docker/Dockerfile.x86_64 +22 -0
- lgbm_boost-0.1.0/fork_integration/install_into_lightgbm.py +108 -0
- lgbm_boost-0.1.0/fork_integration/lgbm_c_api_hook.hpp +108 -0
- lgbm_boost-0.1.0/include/fast_scorer/compiler.h +17 -0
- lgbm_boost-0.1.0/include/fast_scorer/kernels.h +97 -0
- lgbm_boost-0.1.0/include/fast_scorer/math_simd.h +113 -0
- lgbm_boost-0.1.0/include/fast_scorer/model.h +275 -0
- lgbm_boost-0.1.0/include/fast_scorer/parser.h +12 -0
- lgbm_boost-0.1.0/include/fast_scorer/scorer.h +111 -0
- lgbm_boost-0.1.0/pyproject.toml +89 -0
- lgbm_boost-0.1.0/python/bindings.cpp +265 -0
- lgbm_boost-0.1.0/python/lgbm_boost/__init__.py +295 -0
- lgbm_boost-0.1.0/src/cli_verify.cpp +137 -0
- lgbm_boost-0.1.0/src/compiler.cpp +705 -0
- lgbm_boost-0.1.0/src/kernels_avx2.cpp +626 -0
- lgbm_boost-0.1.0/src/kernels_avx512.cpp +581 -0
- lgbm_boost-0.1.0/src/kernels_scalar.cpp +795 -0
- lgbm_boost-0.1.0/src/model_parser.cpp +235 -0
- lgbm_boost-0.1.0/src/scorer.cpp +657 -0
- lgbm_boost-0.1.0/tests/test_fuzz_hypothesis.py +76 -0
- lgbm_boost-0.1.0/tests/test_missing_edge_cases.py +146 -0
- lgbm_boost-0.1.0/tests/test_numerical_parity.py +235 -0
- lgbm_boost-0.1.0/tests/test_wheel_smoke.py +85 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test:
|
|
15
|
+
name: Test (${{ matrix.os }}, Python ${{ matrix.python-version }})
|
|
16
|
+
runs-on: ${{ matrix.os }}
|
|
17
|
+
strategy:
|
|
18
|
+
fail-fast: false
|
|
19
|
+
matrix:
|
|
20
|
+
os: [ubuntu-latest, macos-latest]
|
|
21
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- name: Checkout repository
|
|
25
|
+
uses: actions/checkout@v7
|
|
26
|
+
|
|
27
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
28
|
+
uses: actions/setup-python@v7
|
|
29
|
+
with:
|
|
30
|
+
python-version: ${{ matrix.python-version }}
|
|
31
|
+
|
|
32
|
+
- name: Install libomp on macOS (required by upstream lightgbm package for parity tests)
|
|
33
|
+
if: runner.os == 'macOS'
|
|
34
|
+
run: brew install libomp
|
|
35
|
+
|
|
36
|
+
- name: Install package and test dependencies
|
|
37
|
+
run: |
|
|
38
|
+
python -m pip install --upgrade pip
|
|
39
|
+
python -m pip install -e ".[dev]"
|
|
40
|
+
|
|
41
|
+
- name: Report detected CPU SIMD ISA
|
|
42
|
+
run: |
|
|
43
|
+
python -c "import lgbm_boost; print('Detected SIMD ISA:', lgbm_boost.detect_best_isa())"
|
|
44
|
+
|
|
45
|
+
- name: Run pytest & Hypothesis test suite
|
|
46
|
+
run: pytest -v
|
|
47
|
+
|
|
48
|
+
- name: Run x86_64 benchmark smoke check
|
|
49
|
+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
|
|
50
|
+
run: python benchmarks/run_suite.py --rows 1000 10000 100000 --leaves 31 63 --repeats 3
|
|
51
|
+
|
|
52
|
+
auto-tag:
|
|
53
|
+
name: Auto-Tag Release from pyproject.toml
|
|
54
|
+
needs: [test]
|
|
55
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
permissions:
|
|
58
|
+
contents: write
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- name: Checkout repository with full history
|
|
62
|
+
uses: actions/checkout@v7
|
|
63
|
+
with:
|
|
64
|
+
fetch-depth: 0
|
|
65
|
+
|
|
66
|
+
- name: Set up Python
|
|
67
|
+
uses: actions/setup-python@v7
|
|
68
|
+
with:
|
|
69
|
+
python-version: "3.12"
|
|
70
|
+
|
|
71
|
+
- name: Create tag and GitHub Release if version is new
|
|
72
|
+
env:
|
|
73
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
74
|
+
run: |
|
|
75
|
+
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
|
76
|
+
TAG="v${VERSION}"
|
|
77
|
+
echo "Detected project version: ${VERSION} -> tag ${TAG}"
|
|
78
|
+
|
|
79
|
+
if git rev-parse "${TAG}" >/dev/null 2>&1; then
|
|
80
|
+
echo "Tag ${TAG} already exists, skipping tag creation."
|
|
81
|
+
exit 0
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
git config user.name "github-actions[bot]"
|
|
85
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
86
|
+
git tag -a "${TAG}" -m "Release ${TAG}"
|
|
87
|
+
git push origin "${TAG}"
|
|
88
|
+
gh release create "${TAG}" --title "${TAG}" --generate-notes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build_wheels:
|
|
14
|
+
name: Build wheels (${{ matrix.os }})
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
include:
|
|
20
|
+
- os: ubuntu-latest
|
|
21
|
+
archs: x86_64
|
|
22
|
+
- os: ubuntu-24.04-arm
|
|
23
|
+
archs: aarch64
|
|
24
|
+
- os: macos-latest
|
|
25
|
+
archs: "arm64 x86_64"
|
|
26
|
+
- os: windows-latest
|
|
27
|
+
archs: AMD64
|
|
28
|
+
|
|
29
|
+
steps:
|
|
30
|
+
- name: Checkout repository
|
|
31
|
+
uses: actions/checkout@v7
|
|
32
|
+
with:
|
|
33
|
+
persist-credentials: false
|
|
34
|
+
|
|
35
|
+
- name: Build and test wheels with cibuildwheel
|
|
36
|
+
uses: pypa/cibuildwheel@v4.3.5
|
|
37
|
+
env:
|
|
38
|
+
CIBW_ARCHS: ${{ matrix.archs }}
|
|
39
|
+
|
|
40
|
+
- name: Upload built wheels
|
|
41
|
+
uses: actions/upload-artifact@v7
|
|
42
|
+
with:
|
|
43
|
+
name: cibw-wheels-${{ matrix.os }}
|
|
44
|
+
path: ./wheelhouse/*.whl
|
|
45
|
+
|
|
46
|
+
build_sdist:
|
|
47
|
+
name: Build source distribution (sdist)
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
steps:
|
|
50
|
+
- name: Checkout repository
|
|
51
|
+
uses: actions/checkout@v7
|
|
52
|
+
with:
|
|
53
|
+
persist-credentials: false
|
|
54
|
+
|
|
55
|
+
- name: Build sdist
|
|
56
|
+
run: pipx run build --sdist
|
|
57
|
+
|
|
58
|
+
- name: Upload sdist
|
|
59
|
+
uses: actions/upload-artifact@v7
|
|
60
|
+
with:
|
|
61
|
+
name: cibw-sdist
|
|
62
|
+
path: dist/*.tar.gz
|
|
63
|
+
|
|
64
|
+
publish_pypi:
|
|
65
|
+
name: Publish wheels and sdist to PyPI
|
|
66
|
+
needs: [build_wheels, build_sdist]
|
|
67
|
+
if: >-
|
|
68
|
+
startsWith(github.ref, 'refs/tags/v') ||
|
|
69
|
+
(github.event_name == 'release' && github.event.action == 'published') ||
|
|
70
|
+
github.event_name == 'workflow_dispatch'
|
|
71
|
+
runs-on: ubuntu-latest
|
|
72
|
+
environment: pypi
|
|
73
|
+
concurrency:
|
|
74
|
+
group: pypi-publish-${{ github.ref_name }}
|
|
75
|
+
cancel-in-progress: false
|
|
76
|
+
permissions:
|
|
77
|
+
id-token: write
|
|
78
|
+
|
|
79
|
+
steps:
|
|
80
|
+
- name: Download all built distributions
|
|
81
|
+
uses: actions/download-artifact@v8
|
|
82
|
+
with:
|
|
83
|
+
pattern: cibw-*
|
|
84
|
+
path: dist
|
|
85
|
+
merge-multiple: true
|
|
86
|
+
|
|
87
|
+
- name: Publish distribution to PyPI via Trusted Publishing
|
|
88
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
89
|
+
with:
|
|
90
|
+
skip-existing: true
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
project(lgbm_boost LANGUAGES CXX)
|
|
3
|
+
|
|
4
|
+
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
7
|
+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
8
|
+
|
|
9
|
+
option(FAST_SCORER_BUILD_PYTHON "Build nanobind Python extension" ON)
|
|
10
|
+
option(FAST_SCORER_BUILD_CPP_TESTS "Build standalone C++ tests/cli" OFF)
|
|
11
|
+
option(FAST_SCORER_USE_OPENMP "Enable OpenMP instead of built-in C++17 ThreadPool" OFF)
|
|
12
|
+
|
|
13
|
+
# Detect target CPU architecture (respecting CMAKE_OSX_ARCHITECTURES for universal/Rosetta builds)
|
|
14
|
+
set(FAST_SCORER_IS_X86_64 OFF)
|
|
15
|
+
if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
|
|
16
|
+
set(FAST_SCORER_IS_X86_64 ON)
|
|
17
|
+
elseif(NOT CMAKE_OSX_ARCHITECTURES AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$")
|
|
18
|
+
set(FAST_SCORER_IS_X86_64 ON)
|
|
19
|
+
endif()
|
|
20
|
+
|
|
21
|
+
set(CORE_SOURCES
|
|
22
|
+
src/model_parser.cpp
|
|
23
|
+
src/compiler.cpp
|
|
24
|
+
src/kernels_scalar.cpp
|
|
25
|
+
src/scorer.cpp
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
if(FAST_SCORER_IS_X86_64)
|
|
29
|
+
list(APPEND CORE_SOURCES
|
|
30
|
+
src/kernels_avx2.cpp
|
|
31
|
+
src/kernels_avx512.cpp
|
|
32
|
+
)
|
|
33
|
+
if(MSVC)
|
|
34
|
+
set_source_files_properties(src/kernels_avx2.cpp PROPERTIES COMPILE_OPTIONS "/O2;/arch:AVX2")
|
|
35
|
+
set_source_files_properties(src/kernels_avx512.cpp PROPERTIES COMPILE_OPTIONS "/O2;/arch:AVX512")
|
|
36
|
+
else()
|
|
37
|
+
set_source_files_properties(src/kernels_avx2.cpp PROPERTIES
|
|
38
|
+
COMPILE_OPTIONS "-O3;-mavx2;-mfma;-mbmi;-mbmi2;-fno-math-errno;-fno-trapping-math"
|
|
39
|
+
)
|
|
40
|
+
set_source_files_properties(src/kernels_avx512.cpp PROPERTIES
|
|
41
|
+
COMPILE_OPTIONS "-O3;-mavx512f;-mavx512cd;-mavx512bw;-mavx512vl;-mavx512dq;-mfma;-mbmi;-mbmi2;-fno-math-errno;-fno-trapping-math"
|
|
42
|
+
)
|
|
43
|
+
endif()
|
|
44
|
+
endif()
|
|
45
|
+
|
|
46
|
+
add_library(fast_scorer_core STATIC ${CORE_SOURCES})
|
|
47
|
+
target_include_directories(fast_scorer_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
|
48
|
+
|
|
49
|
+
if(MSVC)
|
|
50
|
+
target_compile_options(fast_scorer_core PRIVATE /O2)
|
|
51
|
+
else()
|
|
52
|
+
target_compile_options(fast_scorer_core PRIVATE -O3 -fno-math-errno -fno-trapping-math -Wall -Wextra -Wno-unused-parameter)
|
|
53
|
+
endif()
|
|
54
|
+
|
|
55
|
+
if(FAST_SCORER_IS_X86_64)
|
|
56
|
+
target_compile_definitions(fast_scorer_core PUBLIC FAST_SCORER_ARCH_X86_64=1)
|
|
57
|
+
endif()
|
|
58
|
+
|
|
59
|
+
# Optional OpenMP detection (with Homebrew libomp hint on macOS arm64)
|
|
60
|
+
if(FAST_SCORER_USE_OPENMP)
|
|
61
|
+
if(APPLE AND NOT FAST_SCORER_IS_X86_64 AND EXISTS "/opt/homebrew/opt/libomp")
|
|
62
|
+
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include")
|
|
63
|
+
set(OpenMP_CXX_LIB_NAMES "omp")
|
|
64
|
+
set(OpenMP_omp_LIBRARY "/opt/homebrew/opt/libomp/lib/libomp.dylib")
|
|
65
|
+
endif()
|
|
66
|
+
find_package(OpenMP QUIET)
|
|
67
|
+
if(OpenMP_CXX_FOUND)
|
|
68
|
+
message(STATUS "fast_scorer: OpenMP enabled")
|
|
69
|
+
target_link_libraries(fast_scorer_core PUBLIC OpenMP::OpenMP_CXX)
|
|
70
|
+
target_compile_definitions(fast_scorer_core PUBLIC FAST_SCORER_HAVE_OPENMP=1)
|
|
71
|
+
else()
|
|
72
|
+
message(STATUS "fast_scorer: OpenMP not found, using built-in C++17 atomic ThreadPool")
|
|
73
|
+
endif()
|
|
74
|
+
endif()
|
|
75
|
+
|
|
76
|
+
find_package(Threads REQUIRED)
|
|
77
|
+
target_link_libraries(fast_scorer_core PUBLIC Threads::Threads)
|
|
78
|
+
|
|
79
|
+
if(FAST_SCORER_BUILD_PYTHON)
|
|
80
|
+
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development.Module)
|
|
81
|
+
execute_process(
|
|
82
|
+
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
|
|
83
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT
|
|
84
|
+
)
|
|
85
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
86
|
+
|
|
87
|
+
nanobind_add_module(
|
|
88
|
+
_lgbm_boost_ext
|
|
89
|
+
STABLE_ABI
|
|
90
|
+
NB_STATIC
|
|
91
|
+
python/bindings.cpp
|
|
92
|
+
)
|
|
93
|
+
target_link_libraries(_lgbm_boost_ext PRIVATE fast_scorer_core)
|
|
94
|
+
install(TARGETS _lgbm_boost_ext LIBRARY DESTINATION lgbm_boost)
|
|
95
|
+
endif()
|
|
96
|
+
|
|
97
|
+
if(FAST_SCORER_BUILD_CPP_TESTS)
|
|
98
|
+
add_executable(fast_scorer_cli src/cli_verify.cpp)
|
|
99
|
+
target_link_libraries(fast_scorer_cli PRIVATE fast_scorer_core)
|
|
100
|
+
endif()
|
lgbm_boost-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kirill Sholokhov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: lgbm-boost
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: High-throughput SIMD batch inference engine for LightGBM models (V-QuickScorer & Tiled Branchless AVX2/AVX-512)
|
|
5
|
+
Keywords: lightgbm,gbdt,inference,scoring,simd,avx2,avx512,quickscorer,machine-learning
|
|
6
|
+
Author: Kirill Sholokhov
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: C++
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Project-URL: Homepage, https://github.com/1orgar/lgbm-boost
|
|
23
|
+
Project-URL: Repository, https://github.com/1orgar/lgbm-boost
|
|
24
|
+
Project-URL: Issues, https://github.com/1orgar/lgbm-boost/issues
|
|
25
|
+
Project-URL: Releases, https://github.com/1orgar/lgbm-boost/releases
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: lightgbm>=4.0; extra == "dev"
|
|
30
|
+
Requires-Dist: pandas>=2.0; extra == "dev"
|
|
31
|
+
Requires-Dist: scikit-learn>=1.3; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
33
|
+
Requires-Dist: hypothesis>=6.0; extra == "dev"
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# lgbm-boost
|
|
37
|
+
|
|
38
|
+
[](https://github.com/1orgar/lgbm-boost/actions/workflows/ci.yml)
|
|
39
|
+
[](https://github.com/1orgar/lgbm-boost/actions/workflows/publish.yml)
|
|
40
|
+
[](https://pypi.org/project/lgbm-boost/)
|
|
41
|
+
[](LICENSE)
|
|
42
|
+
|
|
43
|
+
**`lgbm-boost`** is a high-throughput C++17 SIMD batch inference engine for **LightGBM** gradient boosted decision tree ensembles.
|
|
44
|
+
|
|
45
|
+
It provides both:
|
|
46
|
+
1. A lightweight, zero-dependency Python package (`lgbm_boost`) with a drop-in `FastBooster` wrapper for `lightgbm.Booster` and `scikit-learn` estimators (`LGBMClassifier`, `LGBMRegressor`, `LGBMRanker`).
|
|
47
|
+
2. A self-contained C++17 `fast_scorer` module (`fork_integration/`) ready to vendor directly into a custom fork of `LightGBM`.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Key Optimizations
|
|
52
|
+
|
|
53
|
+
Stock `LightGBM` evaluates trees row-by-row via pointer-chasing across multiple heap vectors per tree, incurring ~50% branch mispredictions at every tree level, L1/L2 cache thrashing on large ensembles, and full-matrix `float64` allocations when scoring `pandas.DataFrame` inputs.
|
|
54
|
+
|
|
55
|
+
`lgbm-boost` eliminates these bottlenecks through five architectural layers:
|
|
56
|
+
|
|
57
|
+
- **16-Row Vectorized QuickScorer (`V-QuickScorer`, `QS32` & `QS64` for `num_leaves <= 64`)**: Replaces pointer-chasing tree traversal with L1d-resident bitmask intersections (`64` trees per block = `4 KB` working set), branchless monobound threshold range narrowing, hardware `AVX512CD` `vplzcntd`/`vplzcntq` + `{1to16}` embedded broadcast `vpandd {%k1}` on `AVX-512`, and an IEEE-754 float32-exponent parallel `tzcnt` trick on `AVX2`.
|
|
58
|
+
- **SIMD Branchless Compact Traversal (`CompactTree` for deep trees `> 64` leaves)**: Packs internal nodes into aligned 16-byte BFS-ordered records with unrolled root evaluation, 8/16-row SIMD gathers, and zero-cost `NaN` routing via ordered/unordered `VCMPPS` predicates.
|
|
59
|
+
- **Exact `float64 -> float32` Threshold Lowering**: Rounds `double` split thresholds downward via `std::nextafterf` at model compile time so `x_f32 <= t_f32_floor` is mathematically identical to `double(x_f32) <= t_f64` for every representable `float32` value (`max_abs_diff ~ 1e-7` vs stock LightGBM).
|
|
60
|
+
- **Static `NaN` & `Zero` Missing-Value Resolution**: Precomputes LightGBM's exact `NumericalDecision` bitmask semantics (`MissingType::None`, `MissingType::Zero`, `MissingType::NaN`, and `default_left`) at load time, keeping the inner SIMD loop free of missing-type branches.
|
|
61
|
+
- **2D Cache Tiling (`RowTile=128 × TreeBlock=64`) & Zero-Copy `pandas.DataFrame` Streaming**: Streams input columns directly into 64-byte-aligned thread-local L2 buffers without allocating a temporary `N × F` `float64` matrix, followed by fused vectorized `Sigmoid` / `Softmax` / `Exp` (degree-6 Cody–Waite FMA `expf`, `< 1.5 ULP`).
|
|
62
|
+
- **Runtime CPUID + `XGETBV` Dispatch**: Single binary wheel automatically selects `avx512` → `avx2` → `scalar` at runtime and uses a built-in lock-free atomic C++17 worker pool (no external `libomp` runtime required).
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Benchmarks
|
|
67
|
+
|
|
68
|
+
Measured on a `1,000`-tree, `100`-feature binary classification ensemble (`5% NaN` rate) against `lightgbm 4.7.0`.
|
|
69
|
+
|
|
70
|
+
### Linux `x86_64` (`AVX-512`)
|
|
71
|
+
|
|
72
|
+
| `num_leaves` | Rows (`N`) | Input Type | Threads | LightGBM (ms) | `lgbm-boost` (ms) | Speedup | Max Abs Diff |
|
|
73
|
+
| :---: | ---: | :---: | :---: | ---: | ---: | :---: | :---: |
|
|
74
|
+
| **31** | 1,000 | `ndarray float32` | 8 | 15.57 | **2.02** | **7.69x** | `1.12e-07` |
|
|
75
|
+
| **31** | 10,000 | `ndarray float32` | 1 | 467.09 | **62.60** | **7.46x** | `1.60e-07` |
|
|
76
|
+
| **31** | 100,000 | `ndarray float32` | 1 | 4,652.96 | **625.44** | **7.44x** | `1.61e-07` |
|
|
77
|
+
| **31** | 100,000 | `ndarray float32` | 8 | 1,356.72 | **194.74** | **6.97x** | `1.61e-07` |
|
|
78
|
+
| **31** | 100,000 | `pandas.DataFrame` | 8 | 1,374.67 | **196.36** | **7.00x** | `1.61e-07` |
|
|
79
|
+
| **63** | 1,000 | `ndarray float32` | 1 | 75.02 | **15.19** | **4.94x** | `1.44e-07` |
|
|
80
|
+
| **63** | 100,000 | `ndarray float32` | 1 | 7,489.82 | **1,525.04** | **4.91x** | `2.03e-07` |
|
|
81
|
+
| **63** | 100,000 | `pandas.DataFrame` | 8 | 2,127.35 | **562.37** | **3.78x** | `2.03e-07` |
|
|
82
|
+
|
|
83
|
+
### Apple Silicon `arm64` (`Scalar` target)
|
|
84
|
+
|
|
85
|
+
| `num_leaves` | Rows (`N`) | Input Type | Threads | LightGBM (ms) | `lgbm-boost` (ms) | Speedup | Max Abs Diff |
|
|
86
|
+
| :---: | ---: | :---: | :---: | ---: | ---: | :---: | :---: |
|
|
87
|
+
| **31** | 1,000 | `ndarray float32` | 1 | 35.82 | **6.46** | **5.55x** | `1.12e-07` |
|
|
88
|
+
| **31** | 100,000 | `ndarray float32` | 8 | 539.18 | **106.47** | **5.06x** | `1.59e-07` |
|
|
89
|
+
| **31** | 500,000 | `pandas.DataFrame` | 8 | 2,802.03 | **575.82** | **4.87x** | `1.70e-07` |
|
|
90
|
+
| **63** | 100,000 | `ndarray float32` | 1 | 5,621.73 | **1,428.87** | **3.93x** | `1.92e-07` |
|
|
91
|
+
| **127** | 500,000 | `pandas.DataFrame` | 8 | 7,338.70 | **3,201.17** | **2.29x** | `9.88e-07` |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
### From PyPI
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install lgbm-boost
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### From GitHub / Source
|
|
104
|
+
|
|
105
|
+
Requires a C++17 compiler (`g++`, `clang++`, or MSVC). `CMake`, `Ninja`, and `nanobind` are fetched automatically in an isolated build environment:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install "git+https://github.com/1orgar/lgbm-boost.git"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Quickstart
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import lightgbm as lgb
|
|
117
|
+
import numpy as np
|
|
118
|
+
from lgbm_boost import FastBooster, detect_best_isa
|
|
119
|
+
|
|
120
|
+
print("Active SIMD backend:", detect_best_isa()) # 'avx512', 'avx2', or 'scalar'
|
|
121
|
+
|
|
122
|
+
# Load from an in-memory lightgbm.Booster, LGBMClassifier/LGBMRegressor, file path, or model string
|
|
123
|
+
booster = lgb.Booster(model_file="model.txt")
|
|
124
|
+
fast_model = FastBooster(booster)
|
|
125
|
+
|
|
126
|
+
# Score numpy.ndarray (C-contiguous, F-contiguous, float32/float64) or pandas.DataFrame (zero-copy per column)
|
|
127
|
+
X = np.random.randn(100_000, fast_model.num_features).astype(np.float32)
|
|
128
|
+
scores = fast_model.predict(
|
|
129
|
+
X,
|
|
130
|
+
num_threads=8, # 0 = all hardware threads
|
|
131
|
+
raw_score=False, # True = raw margins before sigmoid/softmax/exp
|
|
132
|
+
start_iteration=0,
|
|
133
|
+
num_iteration=-1,
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Supported Model Features
|
|
138
|
+
- **Objectives**: `regression`, `regression_l1`, `huber`, `fair`, `quantile`, `lambdarank`, `binary` (including custom `sigmoid`), `cross_entropy`, `multiclass`, `multiclassova`, `poisson`, `gamma`, `tweedie`, and Random Forest (`boosting="rf"` / `average_output`).
|
|
139
|
+
- **Missing Values**: Full parity with LightGBM `use_missing=True/False`, `zero_as_missing=True/False`, `NaN`, `±0.0`, and `±Inf`.
|
|
140
|
+
- **Tree Sizes**: Arbitrary leaf counts up to `32,768` leaves per tree (including `1`-leaf constant trees and mixed-depth ensembles).
|
|
141
|
+
|
|
142
|
+
*(Note: Categorical bitset splits and `linear_tree=True` are not supported in the standalone engine; when integrated into a LightGBM fork via `fork_integration/`, unsupported models transparently fall back to LightGBM's stock predictor.)*
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Vendoring into a LightGBM Fork
|
|
147
|
+
|
|
148
|
+
To embed `fast_scorer` directly inside a cloned `lightgbm-org/LightGBM` repository so standard `Booster.predict()` accelerates dense batch calls automatically:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
python fork_integration/install_into_lightgbm.py /path/to/LightGBM
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
See [`fork_integration/lgbm_c_api_hook.hpp`](fork_integration/lgbm_c_api_hook.hpp) for the `LGBM_BoosterPredictForMat` integration cache.
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Local Development & Testing
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
uv venv .venv --python 3.12
|
|
162
|
+
uv pip install --python .venv/bin/python -e ".[dev]"
|
|
163
|
+
.venv/bin/pytest -v
|
|
164
|
+
.venv/bin/python benchmarks/run_suite.py --rows 1000 10000 100000 500000 --leaves 31 63 127
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
MIT License — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# lgbm-boost
|
|
2
|
+
|
|
3
|
+
[](https://github.com/1orgar/lgbm-boost/actions/workflows/ci.yml)
|
|
4
|
+
[](https://github.com/1orgar/lgbm-boost/actions/workflows/publish.yml)
|
|
5
|
+
[](https://pypi.org/project/lgbm-boost/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
**`lgbm-boost`** is a high-throughput C++17 SIMD batch inference engine for **LightGBM** gradient boosted decision tree ensembles.
|
|
9
|
+
|
|
10
|
+
It provides both:
|
|
11
|
+
1. A lightweight, zero-dependency Python package (`lgbm_boost`) with a drop-in `FastBooster` wrapper for `lightgbm.Booster` and `scikit-learn` estimators (`LGBMClassifier`, `LGBMRegressor`, `LGBMRanker`).
|
|
12
|
+
2. A self-contained C++17 `fast_scorer` module (`fork_integration/`) ready to vendor directly into a custom fork of `LightGBM`.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Key Optimizations
|
|
17
|
+
|
|
18
|
+
Stock `LightGBM` evaluates trees row-by-row via pointer-chasing across multiple heap vectors per tree, incurring ~50% branch mispredictions at every tree level, L1/L2 cache thrashing on large ensembles, and full-matrix `float64` allocations when scoring `pandas.DataFrame` inputs.
|
|
19
|
+
|
|
20
|
+
`lgbm-boost` eliminates these bottlenecks through five architectural layers:
|
|
21
|
+
|
|
22
|
+
- **16-Row Vectorized QuickScorer (`V-QuickScorer`, `QS32` & `QS64` for `num_leaves <= 64`)**: Replaces pointer-chasing tree traversal with L1d-resident bitmask intersections (`64` trees per block = `4 KB` working set), branchless monobound threshold range narrowing, hardware `AVX512CD` `vplzcntd`/`vplzcntq` + `{1to16}` embedded broadcast `vpandd {%k1}` on `AVX-512`, and an IEEE-754 float32-exponent parallel `tzcnt` trick on `AVX2`.
|
|
23
|
+
- **SIMD Branchless Compact Traversal (`CompactTree` for deep trees `> 64` leaves)**: Packs internal nodes into aligned 16-byte BFS-ordered records with unrolled root evaluation, 8/16-row SIMD gathers, and zero-cost `NaN` routing via ordered/unordered `VCMPPS` predicates.
|
|
24
|
+
- **Exact `float64 -> float32` Threshold Lowering**: Rounds `double` split thresholds downward via `std::nextafterf` at model compile time so `x_f32 <= t_f32_floor` is mathematically identical to `double(x_f32) <= t_f64` for every representable `float32` value (`max_abs_diff ~ 1e-7` vs stock LightGBM).
|
|
25
|
+
- **Static `NaN` & `Zero` Missing-Value Resolution**: Precomputes LightGBM's exact `NumericalDecision` bitmask semantics (`MissingType::None`, `MissingType::Zero`, `MissingType::NaN`, and `default_left`) at load time, keeping the inner SIMD loop free of missing-type branches.
|
|
26
|
+
- **2D Cache Tiling (`RowTile=128 × TreeBlock=64`) & Zero-Copy `pandas.DataFrame` Streaming**: Streams input columns directly into 64-byte-aligned thread-local L2 buffers without allocating a temporary `N × F` `float64` matrix, followed by fused vectorized `Sigmoid` / `Softmax` / `Exp` (degree-6 Cody–Waite FMA `expf`, `< 1.5 ULP`).
|
|
27
|
+
- **Runtime CPUID + `XGETBV` Dispatch**: Single binary wheel automatically selects `avx512` → `avx2` → `scalar` at runtime and uses a built-in lock-free atomic C++17 worker pool (no external `libomp` runtime required).
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Benchmarks
|
|
32
|
+
|
|
33
|
+
Measured on a `1,000`-tree, `100`-feature binary classification ensemble (`5% NaN` rate) against `lightgbm 4.7.0`.
|
|
34
|
+
|
|
35
|
+
### Linux `x86_64` (`AVX-512`)
|
|
36
|
+
|
|
37
|
+
| `num_leaves` | Rows (`N`) | Input Type | Threads | LightGBM (ms) | `lgbm-boost` (ms) | Speedup | Max Abs Diff |
|
|
38
|
+
| :---: | ---: | :---: | :---: | ---: | ---: | :---: | :---: |
|
|
39
|
+
| **31** | 1,000 | `ndarray float32` | 8 | 15.57 | **2.02** | **7.69x** | `1.12e-07` |
|
|
40
|
+
| **31** | 10,000 | `ndarray float32` | 1 | 467.09 | **62.60** | **7.46x** | `1.60e-07` |
|
|
41
|
+
| **31** | 100,000 | `ndarray float32` | 1 | 4,652.96 | **625.44** | **7.44x** | `1.61e-07` |
|
|
42
|
+
| **31** | 100,000 | `ndarray float32` | 8 | 1,356.72 | **194.74** | **6.97x** | `1.61e-07` |
|
|
43
|
+
| **31** | 100,000 | `pandas.DataFrame` | 8 | 1,374.67 | **196.36** | **7.00x** | `1.61e-07` |
|
|
44
|
+
| **63** | 1,000 | `ndarray float32` | 1 | 75.02 | **15.19** | **4.94x** | `1.44e-07` |
|
|
45
|
+
| **63** | 100,000 | `ndarray float32` | 1 | 7,489.82 | **1,525.04** | **4.91x** | `2.03e-07` |
|
|
46
|
+
| **63** | 100,000 | `pandas.DataFrame` | 8 | 2,127.35 | **562.37** | **3.78x** | `2.03e-07` |
|
|
47
|
+
|
|
48
|
+
### Apple Silicon `arm64` (`Scalar` target)
|
|
49
|
+
|
|
50
|
+
| `num_leaves` | Rows (`N`) | Input Type | Threads | LightGBM (ms) | `lgbm-boost` (ms) | Speedup | Max Abs Diff |
|
|
51
|
+
| :---: | ---: | :---: | :---: | ---: | ---: | :---: | :---: |
|
|
52
|
+
| **31** | 1,000 | `ndarray float32` | 1 | 35.82 | **6.46** | **5.55x** | `1.12e-07` |
|
|
53
|
+
| **31** | 100,000 | `ndarray float32` | 8 | 539.18 | **106.47** | **5.06x** | `1.59e-07` |
|
|
54
|
+
| **31** | 500,000 | `pandas.DataFrame` | 8 | 2,802.03 | **575.82** | **4.87x** | `1.70e-07` |
|
|
55
|
+
| **63** | 100,000 | `ndarray float32` | 1 | 5,621.73 | **1,428.87** | **3.93x** | `1.92e-07` |
|
|
56
|
+
| **127** | 500,000 | `pandas.DataFrame` | 8 | 7,338.70 | **3,201.17** | **2.29x** | `9.88e-07` |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
### From PyPI
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install lgbm-boost
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### From GitHub / Source
|
|
69
|
+
|
|
70
|
+
Requires a C++17 compiler (`g++`, `clang++`, or MSVC). `CMake`, `Ninja`, and `nanobind` are fetched automatically in an isolated build environment:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install "git+https://github.com/1orgar/lgbm-boost.git"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Quickstart
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import lightgbm as lgb
|
|
82
|
+
import numpy as np
|
|
83
|
+
from lgbm_boost import FastBooster, detect_best_isa
|
|
84
|
+
|
|
85
|
+
print("Active SIMD backend:", detect_best_isa()) # 'avx512', 'avx2', or 'scalar'
|
|
86
|
+
|
|
87
|
+
# Load from an in-memory lightgbm.Booster, LGBMClassifier/LGBMRegressor, file path, or model string
|
|
88
|
+
booster = lgb.Booster(model_file="model.txt")
|
|
89
|
+
fast_model = FastBooster(booster)
|
|
90
|
+
|
|
91
|
+
# Score numpy.ndarray (C-contiguous, F-contiguous, float32/float64) or pandas.DataFrame (zero-copy per column)
|
|
92
|
+
X = np.random.randn(100_000, fast_model.num_features).astype(np.float32)
|
|
93
|
+
scores = fast_model.predict(
|
|
94
|
+
X,
|
|
95
|
+
num_threads=8, # 0 = all hardware threads
|
|
96
|
+
raw_score=False, # True = raw margins before sigmoid/softmax/exp
|
|
97
|
+
start_iteration=0,
|
|
98
|
+
num_iteration=-1,
|
|
99
|
+
)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Supported Model Features
|
|
103
|
+
- **Objectives**: `regression`, `regression_l1`, `huber`, `fair`, `quantile`, `lambdarank`, `binary` (including custom `sigmoid`), `cross_entropy`, `multiclass`, `multiclassova`, `poisson`, `gamma`, `tweedie`, and Random Forest (`boosting="rf"` / `average_output`).
|
|
104
|
+
- **Missing Values**: Full parity with LightGBM `use_missing=True/False`, `zero_as_missing=True/False`, `NaN`, `±0.0`, and `±Inf`.
|
|
105
|
+
- **Tree Sizes**: Arbitrary leaf counts up to `32,768` leaves per tree (including `1`-leaf constant trees and mixed-depth ensembles).
|
|
106
|
+
|
|
107
|
+
*(Note: Categorical bitset splits and `linear_tree=True` are not supported in the standalone engine; when integrated into a LightGBM fork via `fork_integration/`, unsupported models transparently fall back to LightGBM's stock predictor.)*
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Vendoring into a LightGBM Fork
|
|
112
|
+
|
|
113
|
+
To embed `fast_scorer` directly inside a cloned `lightgbm-org/LightGBM` repository so standard `Booster.predict()` accelerates dense batch calls automatically:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
python fork_integration/install_into_lightgbm.py /path/to/LightGBM
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
See [`fork_integration/lgbm_c_api_hook.hpp`](fork_integration/lgbm_c_api_hook.hpp) for the `LGBM_BoosterPredictForMat` integration cache.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Local Development & Testing
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
uv venv .venv --python 3.12
|
|
127
|
+
uv pip install --python .venv/bin/python -e ".[dev]"
|
|
128
|
+
.venv/bin/pytest -v
|
|
129
|
+
.venv/bin/python benchmarks/run_suite.py --rows 1000 10000 100000 500000 --leaves 31 63 127
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT License — see [LICENSE](LICENSE).
|