Skip to content

Fix NaN output of single-level dense grids with default per_level_scale - #544

Closed
Arthur031221 wants to merge 1 commit into
NVlabs:masterfrom
Arthur031221:fix-dense-grid-single-level-scale
Closed

Arthur031221 wants to merge 1 commit into
NVlabs:masterfrom
Arthur031221:fix-dense-grid-single-level-scale

Conversation

@Arthur031221

Copy link
Copy Markdown

A dense grid with one level and no explicit per_level_scale returns 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 when n_levels is 1. The scale comes out as inf for base_resolution below 256, NaN at 256 and 0 above it, so log2(scale) is never finite and level 0 evaluates exp2f(0 * log2(scale)) to NaN. The level is sized to 8 entries instead of 16^3 and 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_resolution 256 and 512 behave the same way. With this change level_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.cu fails on master with 8 == 4096 and passes with the change.

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.
@Arthur031221

Copy link
Copy Markdown
Author

Do you need anything else from me before reviewing this?

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.

1 participant