Bound CUDA PUC chunk size to available GPU memory - #9
Merged
Merged
Conversation
bayesian_blocks (the default discretizer) has no upper bound on the number of bins it selects, and on datasets with many samples (e.g. single-cell data with hundreds of thousands of cells) it can pick thousands of bins per gene. compute_puc_full_cuda's intermediate counts_chunk_gpu/si_chunk_gpu buffers scale with k_bins^2 and k_bins respectively, so the previous fixed chunk_size=256 could request far more GPU memory than is available even for small gene panels (confirmed empirically: a 43-gene x 265,188-sample dataset triggered a 117 GiB allocation request). Size the chunk to fit within the GPU memory actually free at call time instead, clamped to the previous default of at most 256, and raise an actionable error (suggesting uniform_width with a fixed bin count, or the CPU backend) if even a single-gene chunk would not fit, rather than surfacing a raw CUDA out-of-memory error. Verified against test/cuda_numeric_tests.jl's CPU/GPU equivalence, symmetry, and determinism checks (unchanged), and against the previously-failing 43-gene/265,188-sample bayesian_blocks case (now completes, auto-selecting chunk_size=11 for k_bins=1690). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0151Ww8ZmYpes58vMJNbXHpA
jjschirle
approved these changes
Sep 2, 2026
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.
Problem
bayesian_blocks(the default discretizer) has no upper bound on the number of bins it selects. On datasets with many samples — e.g. single-cell data with hundreds of thousands of cells, exactly the use caseNetworkInference/PIDC targets and that GPU acceleration is meant to make tractable — it can pick thousands of bins per gene.compute_puc_full_cuda's intermediate buffers scale as:counts_chunk_gpu:k_bins^2 * num_nodes * chunk_size(Int32)si_chunk_gpu:k_bins * num_nodes * chunk_size(Float64)so the previous fixed
chunk_size = 256could request far more GPU memory than exists, even for small gene panels. Confirmed empirically:infer_networkwith the CUDA backend on a 43-gene x 265,188-sample matrix (continuous, mostly-unique log-normalized single-cell values) triggered:(
bayesian_blockshad pickedk_bins ≈ 1690for this data.) Repository issues are disabled, so opening this directly as a PR rather than filing a report first.Fix
Size the chunk to fit the GPU memory actually free at call time (
CUDA.memory_info()), clamped to the previous default of at most 256, with an 0.8 safety factor for the fixed-size buffers (data_gpu,marginals_gpu,puc_scores_gpu,mi_matrix_gpu) and allocator overhead. If even a single-gene chunk (chunk_size = 1) wouldn't fit, raise a clearErrorExceptionnaming the cause (largek_binsfrom an adaptive discretizer) and suggesting remedies (uniform_widthwith a fixed bin count, orconfig.backend = :cpu), instead of surfacing a raw CUDA OOM stacktrace.No public API changes —
compute_puc_full_cuda's signature and behavior for well-behaved (smallk_bins) inputs are unchanged; verified below.Testing
test/cuda_numeric_tests.jl's CPU/GPU equivalence, symmetry, and determinism checks pass unchanged ontoy_small_200.txt(smallk_bins, sochunk_sizestill resolves to the old default of 200/256 there — confirmed the sizing logic is a no-op in the well-behaved case).k_bins=1690→ auto-selectedchunk_size=11(4 chunk iterations) instead of the 117 GiB allocation attempt.Suggested follow-ups (not included here, happy to open separately if useful)
bayesian_blocks' bin count (or amax_binskeyword) so CPU-backend runs and overall runtime aren't also blown out by very largek_bins.k_bins^2 * num_nodes * chunk_sizeGPU memory scaling and recommendinguniform_widthexplicitly for large-sample-count single-cell inputs in the README/CLI help.🤖 Generated with Claude Code
https://claude.ai/code/session_0151Ww8ZmYpes58vMJNbXHpA