Add np.random.choice fallback for many Gaussians exceeding torch.multinomial limits #338
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.
The current MCMCStrategy (relocate or sample_add) raises an error due to
torch.multinomial
when the number of Gaussians exceeds 2^24 = 16,777,216 (e.g., torch version is 2.0.1+cu117).This Pull Request introduces a fallback mechanism in the _multinomial_sample function to handle cases where the number of elements exceeds the limit. This is achieved by switching to np.random.choice when necessary, ensuring that the function can handle large element sets without encountering runtime errors.
Although np.random.choice may be slightly slower than torch.multinomial, it is not expected to become a bottleneck as long as refine_every is sufficiently large (e.g., 100; default).