Skip to content

Commit 14c3609

Browse files
authored
Fix some issue about Initialization (#250)
issue 249(2/3/4)
1 parent 300676a commit 14c3609

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

modules/backbones/lynxnet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import torch.nn as nn
77
import torch.nn.functional as F
88

9-
from modules.commons.common_layers import SinusoidalPosEmb, SwiGLU, Conv1d, Transpose
9+
from modules.commons.common_layers import SinusoidalPosEmb, SwiGLU, Transpose
10+
from modules.commons.common_layers import KaimingNormalConv1d as Conv1d
1011
from utils.hparams import hparams
1112

1213

modules/backbones/lynxnet2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import torch.nn as nn
33
import torch.nn.functional as F
44

5-
from modules.commons.common_layers import SinusoidalPosEmb, SwiGLU, Conv1d, Transpose
5+
from modules.commons.common_layers import SinusoidalPosEmb, SwiGLU, Transpose
66
from utils.hparams import hparams
77

88

@@ -42,6 +42,8 @@ def __init__(self, in_dims, n_feats, *, num_layers=6, num_channels=512, expansio
4242
self.n_feats = n_feats
4343
self.input_projection = nn.Linear(in_dims * n_feats, num_channels)
4444
self.conditioner_projection = nn.Linear(hparams['hidden_size'], num_channels)
45+
# It may need to be modified at some point to be compatible with the condition cache
46+
# self.conditioner_projection = nn.Conv1d(hparams['hidden_size'], num_channels, 1)
4547
self.diffusion_embedding = nn.Sequential(
4648
SinusoidalPosEmb(num_channels),
4749
nn.Linear(num_channels, num_channels * 4),
@@ -80,6 +82,8 @@ def forward(self, spec, diffusion_step, cond):
8082

8183
x = self.input_projection(x.transpose(1, 2)) # [B, T, F x M]
8284
x = x + self.conditioner_projection(cond.transpose(1, 2))
85+
# It may need to be modified at some point to be compatible with the condition cache
86+
# x = x + self.conditioner_projection(cond.transpose(1, 2))
8387
x = x + self.diffusion_embedding(diffusion_step).unsqueeze(1)
8488

8589
for layer in self.residual_layers:

modules/backbones/wavenet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import torch.nn as nn
66
import torch.nn.functional as F
77

8-
from modules.commons.common_layers import SinusoidalPosEmb, Conv1d
8+
from modules.commons.common_layers import SinusoidalPosEmb
9+
from modules.commons.common_layers import KaimingNormalConv1d as Conv1d
910
from utils.hparams import hparams
1011

1112

modules/commons/common_layers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ def forward(self, x):
121121
max_abs_out = torch.max(-out_min, out_max).float()
122122
max_abs_gate = torch.max(-gate_min, gate_max).float()
123123
if max_abs_out * max_abs_gate > 1000:
124-
return (out.float() * gate.float()).clamp(-1000, 1000).half()
124+
return (out.float() * gate.float()).clamp(-1000, 1000).half()
125125
return out * gate
126126

127127

128-
class Conv1d(torch.nn.Conv1d):
128+
class KaimingNormalConv1d(torch.nn.Conv1d):
129129
def __init__(self, *args, **kwargs):
130130
super().__init__(*args, **kwargs)
131131
nn.init.kaiming_normal_(self.weight)
@@ -190,10 +190,17 @@ def __init__(self, embed_dim, num_heads, dropout=0.1, bias=False, rotary_embed=N
190190

191191
# Dropout layer
192192
self.dropout = nn.Dropout(dropout)
193-
193+
194194
# Rotary Embeddings
195195
self.rotary_embed = rotary_embed
196196

197+
# Initialization parameters
198+
nn.init.xavier_uniform_(self.in_proj.weight)
199+
nn.init.xavier_uniform_(self.out_proj.weight)
200+
if bias:
201+
nn.init.constant_(self.in_proj.bias, 0.0)
202+
nn.init.constant_(self.out_proj.bias, 0.0)
203+
197204
def forward(self, x, key_padding_mask=None):
198205
# x: (B, L, C)
199206
# key_padding_mask: (B, L)

0 commit comments

Comments
 (0)