[CUDA] Fix division by zero in histogram construction with discrete data#7123
Open
[CUDA] Fix division by zero in histogram construction with discrete data#7123
Conversation
Co-authored-by: shiyu1994 <14541765+shiyu1994@users.noreply.github.com>
Co-authored-by: shiyu1994 <14541765+shiyu1994@users.noreply.github.com>
Co-authored-by: shiyu1994 <14541765+shiyu1994@users.noreply.github.com>
Co-authored-by: shiyu1994 <14541765+shiyu1994@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix SIGFPE crash in LightGBM with CUDA on discrete data
[CUDA] Fix division by zero in histogram construction with discrete data
Jan 9, 2026
jameslamb
requested changes
Jan 9, 2026
Member
jameslamb
left a comment
There was a problem hiding this comment.
Thanks @shiyu1994 for looking into this so soon!
But the tests are segfaulting and the test code has some issues. Pelase see my comments.
| y = np.random.uniform(0, 1, 50000).astype(np.float32) | ||
|
|
||
| # This should not crash with SIGFPE | ||
| model = lgb.LGBMRegressor(device='cuda', n_estimators=10, verbose=-1) |
Member
There was a problem hiding this comment.
We should not be using a scikit-learn estimator (LGBMRegressor) here in test_engine.py. This should be changes to use lgb.train().
| # Test case from the issue: 5 discrete values × 600 features | ||
| # This used to cause SIGFPE due to division by zero in max_num_column_per_partition_ | ||
| np.random.seed(42) | ||
| X = np.random.randint(0, 5, (50000, 600)).astype(np.float32) |
Member
There was a problem hiding this comment.
Do we REALLY need 600 features to observe this failure? That's a huge and costly dataset for testing. It might make it difficult to run the tests on some types of systems.
Can we reproduce this with a smaller dataset?
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.
CUDA builds crash with SIGFPE when training on discrete data where
n_unique_values * n_featuresexceeds histogram bin thresholds (e.g., 5 values × 600 features).Root Cause
Division by zero in
CalcConstructHistogramKernelDim():*block_dim_y = NUM_THREADS_PER_BLOCK / cuda_row_data_->max_num_column_per_partition();The feature partitioning logic in
cuda_row_data.cppcan producemax_num_column_per_partition_ = 0when all partitions end up with zero columns—an edge case in how bins are distributed across partitions.Changes
max_num_column_per_partition_to be at least 1 in bothDivideCUDAFeatureGroups()andGetSparseDataPartitioned()Example
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.