Skip to content

fix: resolve SparseDistribution crash on zero/NaN probability mass#83

Open
Jonathangadeaharder wants to merge 1 commit into
youssofal:mainfrom
Jonathangadeaharder:fix-sparse-distribution-crash
Open

fix: resolve SparseDistribution crash on zero/NaN probability mass#83
Jonathangadeaharder wants to merge 1 commit into
youssofal:mainfrom
Jonathangadeaharder:fix-sparse-distribution-crash

Conversation

@Jonathangadeaharder
Copy link
Copy Markdown

@Jonathangadeaharder Jonathangadeaharder commented May 24, 2026

Resolves #82

Changes

  1. Fallback in SparseDistribution Constructor: Made SparseDistribution.__post_init__ fall back to a valid one-hot distribution on the first available token (greedy choice) if the sum of the probabilities is not finite or <= 0, rather than raising a crash-inducing ValueError.
  2. Robust residual_distribution: Added not np.isfinite(total) checks to the fallback paths in residual_distribution (sparse, dense, and non-sparse branches) to prevent NaN values from bypassing target fallbacks.
  3. Unit Tests: Added test cases in tests/test_sampling.py verifying fallback recovery on zero/NaN probability mass, as well as a mock test for residual_distribution NaN robustness.

All tests pass successfully.

Copilot AI review requested due to automatic review settings May 24, 2026 11:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@Jonathangadeaharder Jonathangadeaharder force-pushed the fix-sparse-distribution-crash branch from 4c2dc4f to e4cf880 Compare May 24, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError: SparseDistribution probabilities must have positive mass during speculative drafting

2 participants