Repository navigation
Add native Permuto and multilevel LoD encodings - #538
Merged
Merged
Conversation
njroussel
reviewed
Sep 22, 2026
shsolanki-1
force-pushed
the
codex/permuto-lod-native
branch
from
September 29, 2026 08:22
2031b7c to
ef4e2df
Compare
shsolanki-1
marked this pull request as ready for review
September 29, 2026 08:31
Register the native Permuto encoding and a hard MultiLevelEncodingLoD wrapper for training, with parameter-gradient, input-gradient, and double backward paths. Add non-JIT FullyFusedMLP double backward for one hidden ReLU layer without an output activation, and let the torch bindings skip the second-order input gradient when callers do not need it. NetworkWithInputEncoding chains double backward through its encoding and network. Network::backward takes the network output, which double backward does not receive, so it is recomputed from the saved encoding output on that path. Storing a copy in forward instead would cost every pass that prepares first-order input gradients. The torch bindings compute the second-order input gradient whenever the input requires a gradient, including when the parameters are frozen. tcnn.Network wraps its network in an Identity encoding, so Identity now implements double backward: it passes the scaled second-order gradient upstream, and its input Hessian is zero because it is linear. Without it, frozen-parameter tcnn.Network double backward would fail in the encoding.
Dispatch the existing native implementation over the public dimension and feature-width matrix. Canonicalize aliases and validate configuration before template construction while preserving the existing 5D/two-feature artifact contract. Cap AoS transpose geometry so wide outputs stay within CUDA block-size limits.
Wrap any multilevel encoding so Grid and Permuto share one hard or soft LoD path. Preserve base layouts, strides, parameters, streams, and double backward by staging incompatible matrices through the preferred layout and retaining unweighted soft outputs. Expose level counts through the minimal base interface and align Grid derivative cutoffs with the forward predicate at the epsilon boundary.
shsolanki-1
force-pushed
the
codex/permuto-lod-native
branch
from
September 29, 2026 09:31
ef4e2df to
5a69b4a
Compare
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.
Summary
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24and features per level1, 2, 4, 8.MultiLevelEncodingLoDto wrap multilevel encodings with hard or soft level selection.NetworkWithInputEncodingdouble backward through its encoding and network. The network output is recomputed only on that path, so first-order input-gradient passes carry no extra state.Identityencoding. The PyTorchtcnn.Networkwraps its network inIdentity, so double backward through it needs this path.Motivation
The existing Permuto factory exposes one fixed specialization, and the existing level-of-detail wrapper is tied to Permuto and hard level selection. This change exposes the existing native implementation over a defined configuration matrix and provides one native multilevel LoD wrapper for Permuto and Grid encodings.
Compatibility
The existing five-dimensional configuration with two features per level retains its parameter order, lattice tables, outputs, gradients, and serialized hyperparameters.
n_featuresandn_grid_featuresare accepted as total-feature aliases and serialize to canonicaln_levelsandn_features_per_levelfields.The LoD ratio is scheduler state. Its input gradient remains zero. Nested LoD wrappers are rejected because their mutable level state does not compose consistently.
The PyTorch bindings compute the second-order input gradient whenever the input requires a gradient, including when all parameters are frozen. Previously that case skipped the native call and returned zero, which is wrong for encodings with a nonzero input Hessian such as Grid and Permuto. Modules without an input-Hessian implementation now raise instead of returning zero. Setting
backward_backward_input_no_input_grad = Trueopts out and returns no input gradient. A frozentcnn.Networkwith one hidden ReLU layer returns the exact zero input Hessian. OtherFullyFusedMLPshapes raise, because the non-JIT network double backward supports only that shape.Grid backward and double-backward kernels now disable a level with the same
level >= max_level + 1e-3fpredicate as the forward kernel, so a level whose output is zeroed no longer receives parameter gradients.Known Issue
HashGrid double backward fails with a CUDA illegal memory access in
kernel_grid_backward_input_backward_dLdoutput. The unmodified base commit fails the same way with a standalonetcnn.Encodingon CUDA 12.8, PyTorch 2.8, and an RTX PRO 6000 Blackwell. This PR does not change that kernel. BecauseNetworkWithInputEncodingnow supports double backward, a HashGrid-based network reaches this kernel instead of raising an unsupported-operation error.Validation
TCNN_CUDA_ARCHITECTURES=89. Passedtest_permutowith 29 test cases and 425,577 assertions on an RTX 4090. Passed the focused non-JITFullyFusedMLPdouble-backward test with 141,383 assertions.TCNN_CUDA_ARCHITECTURES=120on an RTX PRO 6000 Blackwell:test_encodings(including theIdentitydouble-backward test),test_grid,test_jit_losses, andtest_permutopass. Intest_networks, the non-JITFullyFusedMLPdouble-backward test and theNetworkWithInputEncodingempty-batch activation test pass. The existing JIT tolerance testVarious invariance checks for neural networksfails with the same 200 assertions on the unmodified base commit. This PR does not modify the failing networks.sm_120:bindings/torch/tests/test_permuto.pypasses (9 tests), including frozen-parametertcnn.Networkdouble backward.NetworkWithInputEncoding(hard LoD over Permuto,FullyFusedMLPwith one 64-neuron hidden layer, JIT off) matched the preceding revision within run-to-run nondeterminism.git diff --check.Build Impact
The complete native matrix creates 104 Permuto specializations: 13 input dimensions, four feature widths, and two scalar types. In the measured Release build, clean build time increased by 1.2155x,
encoding.cu.oincreased by 2.6306x, andlibtiny-cuda-nn.aincreased by 1.6015x. The retained five-dimensional, two-feature specialization kept the same generated device-code size.Generated inference is intentionally excluded from this PR and is provided by stacked follow-up #539. Generated backward and generated double backward remain unsupported.