Update animatediff/models/motion_module.py
Browse files
animatediff/models/motion_module.py
CHANGED
|
@@ -223,7 +223,24 @@ class TemporalTransformerBlock(nn.Module):
|
|
| 223 |
output = hidden_states
|
| 224 |
return output
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
class PositionalEncoding(nn.Module):
|
| 228 |
def __init__(
|
| 229 |
self,
|
|
@@ -243,7 +260,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__(
|
|
|
|
| 223 |
output = hidden_states
|
| 224 |
return output
|
| 225 |
|
| 226 |
+
class PositionalEncoding(nn.Module):
|
| 227 |
+
def __init__(self, d_model, dropout=0.1, max_len=5000):
|
| 228 |
+
super(PositionalEncoding, self).__init__()
|
| 229 |
+
self.dropout = nn.Dropout(p=dropout)
|
| 230 |
+
|
| 231 |
+
pe = torch.zeros(max_len, d_model)
|
| 232 |
+
position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
|
| 233 |
+
div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-math.log(10000.0) / d_model))
|
| 234 |
+
pe[:, 0::2] = torch.sin(position * div_term)
|
| 235 |
+
pe[:, 1::2] = torch.cos(position * div_term)
|
| 236 |
+
pe = pe.unsqueeze(0).transpose(0, 1)
|
| 237 |
+
self.register_buffer('pe', pe)
|
| 238 |
|
| 239 |
+
def forward(self, x):
|
| 240 |
+
x = x + self.pe[:x.size(0), :]
|
| 241 |
+
return self.dropout(x)
|
| 242 |
+
|
| 243 |
+
"""
|
| 244 |
class PositionalEncoding(nn.Module):
|
| 245 |
def __init__(
|
| 246 |
self,
|
|
|
|
| 260 |
def forward(self, x):
|
| 261 |
x = x + self.pe[:, :x.size(1)]
|
| 262 |
return self.dropout(x)
|
| 263 |
+
"""
|
| 264 |
|
| 265 |
class VersatileAttention(CrossAttention):
|
| 266 |
def __init__(
|