Update animatediff/models/motion_module.py
#2
by
epicgram
- opened
animatediff/models/motion_module.py
CHANGED
@@ -224,6 +224,25 @@ class TemporalTransformerBlock(nn.Module):
|
|
224 |
return output
|
225 |
|
226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
class PositionalEncoding(nn.Module):
|
228 |
def __init__(
|
229 |
self,
|
@@ -243,7 +262,7 @@ class PositionalEncoding(nn.Module):
|
|
243 |
def forward(self, x):
|
244 |
x = x + self.pe[:, :x.size(1)]
|
245 |
return self.dropout(x)
|
246 |
-
|
247 |
|
248 |
class VersatileAttention(CrossAttention):
|
249 |
def __init__(
|
|
|
224 |
return output
|
225 |
|
226 |
|
227 |
+
class PositionalEncoding(nn.Module):
|
228 |
+
|
229 |
+
def __init__(self, d_model, dropout=0.1, max_len=5000):
|
230 |
+
super(PositionalEncoding, self).__init__()
|
231 |
+
self.dropout = nn.Dropout(p=dropout)
|
232 |
+
|
233 |
+
pe = torch.zeros(max_len, d_model)
|
234 |
+
position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
|
235 |
+
div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))
|
236 |
+
pe[:, 0::2] = torch.sin(position * div_term)
|
237 |
+
pe[:, 1::2] = torch.cos(position * div_term)
|
238 |
+
pe = pe.unsqueeze(0).transpose(0, 1)
|
239 |
+
self.register_buffer('pe', pe)
|
240 |
+
|
241 |
+
def forward(self, x):
|
242 |
+
x = x + self.pe[:x.size(0), :]
|
243 |
+
return self.dropout(x)
|
244 |
+
|
245 |
+
"""
|
246 |
class PositionalEncoding(nn.Module):
|
247 |
def __init__(
|
248 |
self,
|
|
|
262 |
def forward(self, x):
|
263 |
x = x + self.pe[:, :x.size(1)]
|
264 |
return self.dropout(x)
|
265 |
+
"""
|
266 |
|
267 |
class VersatileAttention(CrossAttention):
|
268 |
def __init__(
|