Skip to content

[cuda] Fix dense histogram offset issue for global-memory - #7261

Merged
jameslamb merged 2 commits into
lightgbm-org:masterfrom
maxwbuckley:cuda-hist-offset-test
May 16, 2026
Merged

jameslamb merged 2 commits into
lightgbm-org:masterfrom
maxwbuckley:cuda-hist-offset-test

Conversation

@maxwbuckley

@maxwbuckley maxwbuckley commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

There is a one liner error fix (probably a copy paste error) in CUDAConstructDiscretizedHistogramDenseKernel_GlobalMemory
src/treelearner/cuda/cuda_histogram_constructor.cu.

The correct version of the pattern appears in CUDAConstructDiscretizedHistogramSparseKernel_GlobalMemory (Sparse).
"blockIdx.y * num_total_bin + partition_hist_start" appears 3 times in the file and one time it appears as "blockIdx.y * num_total_bin + partition_column_start"

partition_column_start and partition_hist_start are the same when every column has exactly one bin.

The bug is dispatched only when

  • use_quantized_grad == true,
  • the data is dense, and
  • the global-memory buffer path is taken USE_GLOBAL_MEM_BUFFER == true, i.e. when the per-partition histogram doesn't fit in shared memory).

Verified locally on CUDA 13.2 / sm_120 (RTX 5090).

Added a test that fails on master and passed with the one line fix

CUDAConstructDiscretizedHistogramDenseKernel_GlobalMemory mis-based its
shared_hist_packed pointer on partition_column_start (column-index space)
where partition_hist_start (bin space) is required. The two coincide only
when every column has exactly one bin, which never holds in real
histogram-based training. The three analogous kernels in the same file
(non-discretized dense at line 156, non-discretized sparse at line 215,
discretized sparse at line 472) all use partition_hist_start.

Affects only the dense + use_quantized_grad + USE_GLOBAL_MEM_BUFFER
dispatch path (line 615).

Flips the regression test added in the previous commit from FAIL to PASS.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A two-partition layout with multi-bin features exposes the bug

Is it possible to introduce a Python or C++ test that could catch this?

a bunch of testing jank

πŸ€– Generated with Claude Code

Please, update the PR title to something that'd be appropriate to include in the project's release notes ("I removed a bunch of testing jank" is not), and write the PR description yourself.

As I said in #7256 (review), I am happy to talk to you but not to an LLM through you.

We're happy to have you contributing, but write the PR title and descriptions here yourself from this point forward. I don't trust Claude or any other LLM's auto-generated PR descriptions, and I don't want to have to ask you "did you really do this?" for the things they say.

Sorry if this sounds harsh but maintaining this library is volunteer work and it's been awful recently, I am trying to set boundaries to make it manageable enough to keep going.

Quoting from @adrinjalali 's post at https://blog.probabl.ai/maintaining-open-source-age-of-gen-ai

"Maintainers like our colleagues, who maintain core data science libraries like scikit-learn and skore, are increasingly submerged in LLM-generated comments, auto-generated issues, and many low-quality PRs that do not advance the project, such as redundant contributions to README files and ones that claim significant performance gains while failing basic linting tests."

"While the cost of writing and contributing code has shrunk thanks to AI, the cost of reviewing and maintaining code hasn’t."

@jameslamb jameslamb added the gpu (CUDA) Issue is related to the CUDA GPU variant. label May 7, 2026

@shiyu1994 shiyu1994 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this. Yes, partition_column_start is for data, not for histogram.

@jameslamb jameslamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing @shiyu1994 and for the fix @maxwbuckley . I'll get this merged when CI passes.

@jameslamb
jameslamb merged commit 3140ef4 into lightgbm-org:master May 16, 2026
80 of 82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix gpu (CUDA) Issue is related to the CUDA GPU variant.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants