(self,
cross_attn_type,
dim,
ffn_dim,
num_heads,
window_size=(-1, -1),
qk_norm=True,
cross_attn_norm=False,
eps=1e-6,
output_dim=768,
norm_input_visual=True,
class_range=24,
class_interval=4)
| 216 | class WanAttentionBlock(nn.Module): |
| 217 | |
| 218 | def __init__(self, |
| 219 | cross_attn_type, |
| 220 | dim, |
| 221 | ffn_dim, |
| 222 | num_heads, |
| 223 | window_size=(-1, -1), |
| 224 | qk_norm=True, |
| 225 | cross_attn_norm=False, |
| 226 | eps=1e-6, |
| 227 | output_dim=768, |
| 228 | norm_input_visual=True, |
| 229 | class_range=24, |
| 230 | class_interval=4): |
| 231 | super().__init__() |
| 232 | self.dim = dim |
| 233 | self.ffn_dim = ffn_dim |
| 234 | self.num_heads = num_heads |
| 235 | self.window_size = window_size |
| 236 | self.qk_norm = qk_norm |
| 237 | self.cross_attn_norm = cross_attn_norm |
| 238 | self.eps = eps |
| 239 | |
| 240 | # layers |
| 241 | self.norm1 = WanLayerNorm(dim, eps) |
| 242 | self.self_attn = WanSelfAttention(dim, num_heads, window_size, qk_norm, eps) |
| 243 | self.norm3 = WanLayerNorm( |
| 244 | dim, eps, |
| 245 | elementwise_affine=True) if cross_attn_norm else nn.Identity() |
| 246 | self.cross_attn = WanI2VCrossAttention(dim, |
| 247 | num_heads, |
| 248 | (-1, -1), |
| 249 | qk_norm, |
| 250 | eps) |
| 251 | self.norm2 = WanLayerNorm(dim, eps) |
| 252 | self.ffn = nn.Sequential( |
| 253 | nn.Linear(dim, ffn_dim), nn.GELU(approximate='tanh'), |
| 254 | nn.Linear(ffn_dim, dim)) |
| 255 | |
| 256 | # modulation |
| 257 | self.modulation = nn.Parameter(torch.randn(1, 6, dim) / dim**0.5) |
| 258 | |
| 259 | # init audio module |
| 260 | self.audio_cross_attn = SingleStreamMutiAttention( |
| 261 | dim=dim, |
| 262 | encoder_hidden_states_dim=output_dim, |
| 263 | num_heads=num_heads, |
| 264 | qk_norm=False, |
| 265 | qkv_bias=True, |
| 266 | eps=eps, |
| 267 | norm_layer=WanRMSNorm, |
| 268 | class_range=class_range, |
| 269 | class_interval=class_interval |
| 270 | ) |
| 271 | self.norm_x = WanLayerNorm(dim, eps, elementwise_affine=True) if norm_input_visual else nn.Identity() |
| 272 | |
| 273 | |
| 274 | def forward( |
nothing calls this directly
no test coverage detected