Repository navigation
Migrate CPU inference to Treelite 4 and TL2cgen - #37
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Py-Boost's CPU inference wrapper uses the Treelite 3 builder and compilation APIs, which prevents upgrading to Treelite 4 and exposes NumPy 2 input-conversion failures. This change migrates both interpreted and compiled CPU inference to Treelite 4 and TL2cgen while preserving Py-Boost's prediction shape and postprocessing.
Fixes #26.
Changes
treelite>=4.1.2,<5andtl2cgen>=1,<2; remove thetreelite_runtimedependency.(n_samples, n_outputs). This preserves regression, binary/multilabel classification, multiclass classification and custom postprocessors.base_scoresby class alone, applying the first target's intercept to all targets. A constant tree avoids that error and matches Py-Boost's accumulation order.tl2cgen.export_lib,tl2cgen.Predictorandtl2cgen.DMatrix. Normalize dense inputs withnp.asarray(..., dtype=np.float32, order="C")for NumPy 1/2 compatibility.copy.copy()copies usable after successful or failed dumps by stripping native handles only from a separate metadata copy insidedump(). Allow overriding the compiled library path and worker count at load time for deployment to another machine.treelite.coreandtl2cgen.libloadera private view ofosthat skips those missing directories. The realos.add_dll_directoryandbuiltins.__import__stay unchanged, including on unrelated threads; unrelated loading errors still propagate. The finder is removed after either success or failure.Validation
Built both the source distribution and wheel. GitHub Actions installs the wheel and runs the full test suite outside the source checkout. All eight jobs passed on commit
3d9c043: successful CI run.Skips cover GPU-only and platform-specific tests. The matrix covers NumPy 1.x on Python 3.8 and NumPy 2.x on modern Python versions. Locally, the full Linux GPU suite passed on NVIDIA A100 with Python 3.12, NumPy 2.5.4, Treelite 4.8.1 and TL2cgen 1.0.0: 130 passed, 1 Windows-only test skipped, using the installed wheel.
Checks cover actual compiled libraries, scalar/vector regression, MSLE, binary/multilabel/multiclass probabilities, distinct target intercepts, NaN routing, threshold equality, constant trees, float64/Fortran/strided/list inputs, empty and one-row batches, save/load, library relocation, failed dumps, shallow copies, sparse buffers and CPU-only built-in postprocessing. GPU prediction comparisons use
rtol=2e-5, atol=2e-6. Windows tests also verify that a fresh import leaves the DLL loader and filesystem unchanged. Loader regression tests execute both dependency modules through the adapter and verify that an unrelated thread still sees the originalos.add_dll_directorybehavior.uv pip checkpassed in the five local Python/NumPy/Treelite environments.actionlint, Ruff's syntax/undefined-name checks andgit diff --checkpassed. Existing CuPyscatter_adddeprecation warnings remain.Compatibility
target_splitter='Single'restriction remains. This PR does not add support for multiple tree groups.treelite_runtimecompiled libraries must be re-exported from the original Py-Boost model.