← Back to Pull requests

Fix categorical split evaluation for negative float inputs #247

Closed
unknown closed this pull request without merging on Oct 13, 2026 02:26 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 00:48 UTC
Author

Fix categorical split evaluation for negative float inputs

Fixes #246.

Problem

evaluate_tree_impl (shared HOST DEVICE code) evaluates categorical
splits with valid_categories.test(input_val), where input_val is a
floating-point feature value and bitset::test takes an unsigned
integer index. The implicit float-to-unsigned conversion is undefined
behavior for negative values, and the two platforms disagree:

  • x86: values <= -1 wrap to a huge unsigned index and fail the bitset

  • bound check (test false); values in (-1, 0) truncate to 0.
  • CUDA: negative floats clamp to 0, so every negative value tests

  • category 0 and takes the wrong tree branch.

    On LightGBM models with categorical splits, this makes the GPU engine
    return different scores than the CPU engine (and than LightGBM itself)
    for any row carrying negative values in a categorical column. Repro
    and measurements in #246: a synthetic categorical booster shows
    Spearman < 1 between engines, and a large real-world categorical
    booster reaches Spearman 0.909 / max delta 0.58 at double precision.
    All-numeric models are unaffected.

    Fix

    Add categorical_bitset_index, an explicit trunc-toward-zero
    conversion with an out-of-range guard ([-1, num_bits) maps like the
    x86 behavior, everything else tests false), and use it at both
    categorical call sites (in-node bitset and external categorical
    storage). NaN handling is unchanged (already guarded by isnan at the
    call sites). Both engines now share the same well-defined semantics,
    matching LightGBM's int-cast lookup.

    Testing

  • Synthetic categorical booster repro from #246: GPU/CPU/LightGBM

  • agreement before vs after (results to be attached from an H200
    validation run of a source build with this patch).
  • Real-world large categorical booster: parity check vs LightGBM CPU.
  • Diff: 227 lines (+170 / -57) across 2 files Reviewer: chyunsu3 Review duration: 8738m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 227 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.325
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #247"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.9% (MEDIUM) · Higher = larger blast radius
    36.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%