tcnn encoding integration (#608)

* tcnn encoding integration

* Add tests, fix lint

* lin
This commit is contained in:
Matthew Tancik authored and GitHub committed 2022-10-02 10:33:43 -07:00
1 parent 178043e906
commit afda888591
10 files changed
+123 -21

No files matched your search

-42
View File
@@ -1,42 +0,0 @@
# Copyright 2022 The Plenoptix Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Special activation functions.
"""
import torch
from torch.autograd import Function
from torch.cuda.amp import custom_bwd, custom_fwd
class _TruncExp(Function): # pylint: disable=abstract-method
# Implementation from torch-ngp:
# https://github.com/ashawkey/torch-ngp/blob/93b08a0d4ec1cc6e69d85df7f0acdfb99603b628/activation.py
@staticmethod
@custom_fwd(cast_inputs=torch.float32)
def forward(ctx, x): # pylint: disable=arguments-differ
ctx.save_for_backward(x)
return torch.exp(x)
@staticmethod
@custom_bwd
def backward(ctx, g): # pylint: disable=arguments-differ
x = ctx.saved_tensors[0]
return g * torch.exp(x.clamp(-15, 15))
trunc_exp = _TruncExp.apply
"""Same as torch.exp, but with the backward pass clipped to prevent vanishing/exploding
gradients."""
+31
View File
@@ -0,0 +1,31 @@
# Copyright 2022 The Plenoptix Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A collection of common strings and print statements used throughout the codebase."""
from rich.console import Console
console = Console(width=120)
def print_tcnn_speed_warning(method_name: str):
"""Prints a warning about the speed of the TCNN."""
console.line()
console.print(f"[bold yellow]WARNING: Using a slow implementation of {method_name}. ")
console.print(
"[bold yellow]:person_running: :person_running: "
+ "Install tcnn for speedups :person_running: :person_running:"
)
console.print("[yellow]pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch")
console.line()
File renamed without changes.