mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-30 04:50:16 +08:00
Adios mattport
This commit is contained in:
1 parent
9d2b34ab60
commit
b26408eb7a
86 files changed
+176
-176
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
Sampler.
|
||||
"""
|
||||
|
||||
import math
|
||||
|
||||
import torch
|
||||
from torch import nn
|
||||
|
||||
import radiance_cuda
|
||||
|
||||
|
||||
class LLTMFunction(torch.autograd.Function):
|
||||
@staticmethod
|
||||
def forward(ctx, input, weights, bias, old_h, old_cell):
|
||||
outputs = radiance_cuda.forward(input, weights, bias, old_h, old_cell)
|
||||
new_h, new_cell = outputs[:2]
|
||||
variables = outputs[1:] + [weights]
|
||||
ctx.save_for_backward(*variables)
|
||||
|
||||
return new_h, new_cell
|
||||
|
||||
@staticmethod
|
||||
def backward(ctx, grad_h, grad_cell):
|
||||
outputs = radiance_cuda.backward(grad_h.contiguous(), grad_cell.contiguous(), *ctx.saved_variables)
|
||||
d_old_h, d_input, d_weights, d_bias, d_old_cell, d_gates = outputs
|
||||
return d_input, d_weights, d_bias, d_old_h, d_old_cell
|
||||
|
||||
|
||||
class Sampler(nn.Module):
|
||||
def __init__(self, input_features, state_size):
|
||||
super().__init__()
|
||||
self.input_features = input_features
|
||||
self.state_size = state_size
|
||||
self.weights = nn.Parameter(torch.Tensor(3 * state_size, input_features + state_size))
|
||||
self.bias = nn.Parameter(torch.Tensor(1, 3 * state_size))
|
||||
self.reset_parameters()
|
||||
|
||||
def reset_parameters(self):
|
||||
stdv = 1.0 / math.sqrt(self.state_size)
|
||||
for weight in self.parameters():
|
||||
weight.data.uniform_(-stdv, +stdv)
|
||||
|
||||
def forward(self, input, state):
|
||||
return LLTMFunction.apply(input, self.weights, self.bias, *state)
|
||||
Reference in new issue
Block a user