Download codec/audio_processing/descriptaudiocodec/dac/nn/layers.py from Respair/dune_codec: direct link, hf CLI and curl.
- Browser
- Download file 809 Bytes
-
https://huggingface.co/Respair/dune_codec/resolve/main/codec/audio_processing/descriptaudiocodec/dac/nn/layers.py
- Command line
-
hf download hf://Respair/dune_codec/codec/audio_processing/descriptaudiocodec/dac/nn/layers.py
-
curl -L -o layers.py https://huggingface.co/Respair/dune_codec/resolve/main/codec/audio_processing/descriptaudiocodec/dac/nn/layers.py
809 Bytes
| import numpy as np | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| from einops import rearrange | |
| from torch.nn.utils import weight_norm | |
| def WNConv1d(*args, **kwargs): | |
| return weight_norm(nn.Conv1d(*args, **kwargs)) | |
| def WNConvTranspose1d(*args, **kwargs): | |
| return weight_norm(nn.ConvTranspose1d(*args, **kwargs)) | |
| # Scripting this brings model speed up 1.4x | |
| def snake(x, alpha): | |
| shape = x.shape | |
| x = x.reshape(shape[0], shape[1], -1) | |
| x = x + (alpha + 1e-9).reciprocal() * torch.sin(alpha * x).pow(2) | |
| x = x.reshape(shape) | |
| return x | |
| class Snake1d(nn.Module): | |
| def __init__(self, channels): | |
| super().__init__() | |
| self.alpha = nn.Parameter(torch.ones(1, channels, 1)) | |
| def forward(self, x): | |
| return snake(x, self.alpha) | |