Repository navigation
Fix NaN output of single-level dense grids with default per_level_scale - #544
Closed
Arthur031221 wants to merge 1 commit into
Closed
Arthur031221 wants to merge 1 commit into
Arthur031221 wants to merge 1 commit into
Conversation
A DenseGrid with n_levels=1 and no explicit per_level_scale divides by n_levels-1 = 0 when deriving the default scale. log2 of the resulting scale is not finite, so level 0 computes exp2f(0 * log2(scale)) = NaN and the encoded features come out as NaN. Fall back to the non-dense default of 2.0 when there is only one level. Level 0 is the same for any positive finite per_level_scale.
Author
|
Do you need anything else from me before reviewing this? |
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.
A dense grid with one level and no explicit
per_level_scalereturns NaN for every encoded feature, for example with 3 input dims:{"otype": "DenseGrid", "n_levels": 1, "n_features_per_level": 2, "base_resolution": 16}The dense default is
exp(log(256 / base_resolution) / (n_levels - 1)), which divides by zero whenn_levelsis 1. The scale comes out as inf forbase_resolutionbelow 256, NaN at 256 and 0 above it, solog2(scale)is never finite and level 0 evaluatesexp2f(0 * log2(scale))to NaN. The level is sized to 8 entries instead of16^3and the forward pass produces NaN.With the config above on master (0109538),
level_n_params(0)is 8 and the two feature rows are NaN for all 256 inputs of a batch;base_resolution256 and 512 behave the same way. With this changelevel_n_params(0)is 4096 and every output is finite.The fix falls back to the non-dense default of 2.0 when there is a single level. The value has no effect there, since level 0 is the same for any positive finite
per_level_scale.The new test in
tests/test_grid.cufails on master with8 == 4096and passes with the change.