Fix single-precision routing for models with float64 thresholds #245
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 606 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.383
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #245"
general
weight: 0.35
chyunsu3
Models with float64 thresholds (LightGBM, scikit-learn) loaded with
precision="single"can send a float32 input down a different branch than the source model does.Cause
The importer narrows each threshold with
threshold_type(node.threshold()), which rounds to nearest. For inclusive operators (<=,>),decision_forest_builder::add_nodethen storesnextafter(t32, +inf)and inference evaluatesx < stored.When rounding goes up (
t32 > t), the float32 inputx == t32satisfiesx <= tin nvForest, but the source model seesdouble(x) > tand goes the other way. Exclusive operators (<,>=) have the mirror problem when rounding goes down.Only one float32 value per split is affected,
x == t32, but across a large model that adds up. It is more likely with rounded data such as prices or percentages: there the midpoint thresholds are themselves rounded values, which then show up as inputs.Fix
Round in the direction that preserves each comparison:
<= t>= tFor every float32
x,x <= tgives the same result asx <= floor32(t), andx < tthe same asx < ceil32(t). Single precision then routes each float32 input exactly as a float64 comparison would.precision="double"avoids that.The change is a small helper,
detail::cast_threshold, next tosafe_cast_floating_pointindecision_forest_builder.hpp.treelite_importercalls it at load time. Nothing changes for:Thresholds beyond the float range map to
±FLT_MAXor±infon the side that keeps the comparison; LightGBM stores infinite thresholds as±1e300. NaN thresholds are left unchanged.Why the importer and not
add_node:add_nodeonly receives the already-narrowed value.Suggested labels:
bug,non-breaking. The API doesn't change. Single-precision predictions change only for inputs that were misrouted, and they now match the source model.Tests
TreeliteImporter.CastThreshold(C++) tests the conversion directly: ties, round-down cases, out-of-range values, values below the smallest denormal, NaN, and widening.TreeliteImporter.SinglePrecisionDoubleThresholds(C++) builds a float64-threshold model with one tree per operator (<,<=,>,>=).- It loads the model in single precision with each layout.
- It checks the float32 neighbors of thresholds that round up, round down, and overflow (
±1e300) against float64 comparisons.test_sklearn_single_precision_float64_thresholdandtest_lightgbm_single_precision_float64_threshold(Python, CPU and GPU) train a one-split model on synthetic data with each framework.- Each checks nvForest against its framework's own predictions.
- Each asserts that the trained threshold really rounds up, so it can't silently stop covering the bug.
- LightGBM isn't in the test dependencies, so in CI only the scikit-learn test runs. The LightGBM test is skipped unless LightGBM is installed, as
test_lightgbmis.Validated on an NVIDIA B300 with a CUDA 12.9 conda build of this branch:
ctesttests pass. With the importer change reverted,SinglePrecisionDoubleThresholdsfails for<=/>at the round-up threshold and for</>=at the round-down and-1e300thresholds.python/nvforest/testspasses, apart fromtest_lightgbm_train_with_gpu_device_param. That test fails only because the CPU-only LightGBM wheel I installed reports "No OpenCL device found".Reproducer
The same happens on GPU, and with LightGBM: a one-split model trained on the same data predicts 0.55, and nvForest 26.08 gives 0.45.