Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- more in-place optimizations
  • Loading branch information
codename0og authored Dec 29, 2024
1 parent 9eafffe commit b3b3238
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rvc/lib/algorithm/generators/hifigan.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ def __init__(
self.cond = torch.nn.Conv1d(gin_channels, upsample_initial_channel, 1)

def forward(self, x: torch.Tensor, g: Optional[torch.Tensor] = None):
# new tensor
x = self.conv_pre(x)

if g is not None:
x = x + self.cond(g)
# in-place call
x += self.cond(g)

for i in range(self.num_upsamples):
x = torch.nn.functional.leaky_relu(x, LRELU_SLOPE)
# in-place call
x = torch.nn.functional.leaky_relu_(x, LRELU_SLOPE)
x = self.ups[i](x)
xs = None
for j in range(self.num_kernels):
Expand All @@ -85,10 +89,11 @@ def forward(self, x: torch.Tensor, g: Optional[torch.Tensor] = None):
else:
xs += self.resblocks[i * self.num_kernels + j](x)
x = xs / self.num_kernels

x = torch.nn.functional.leaky_relu(x)
# in-place call
x = torch.nn.functional.leaky_relu_(x)
x = self.conv_post(x)
x = torch.tanh(x)
# in-place call
x = torch.tanh_(x)

return x

Expand Down

0 comments on commit b3b3238

Please sign in to comment.