(self,
dim,
num_heads,
window_size=(-1, -1),
qk_norm=True,
eps=1e-6)
| 259 | class WanSelfAttention(nn.Module): |
| 260 | |
| 261 | def __init__(self, |
| 262 | dim, |
| 263 | num_heads, |
| 264 | window_size=(-1, -1), |
| 265 | qk_norm=True, |
| 266 | eps=1e-6): |
| 267 | assert dim % num_heads == 0 |
| 268 | super().__init__() |
| 269 | self.dim = dim |
| 270 | self.num_heads = num_heads |
| 271 | self.head_dim = dim // num_heads |
| 272 | self.window_size = window_size |
| 273 | self.qk_norm = qk_norm |
| 274 | self.eps = eps |
| 275 | |
| 276 | # layers |
| 277 | self.q = nn.Linear(dim, dim) |
| 278 | self.k = nn.Linear(dim, dim) |
| 279 | self.v = nn.Linear(dim, dim) |
| 280 | self.o = nn.Linear(dim, dim) |
| 281 | self.norm_q = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity() |
| 282 | self.norm_k = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity() |
| 283 | |
| 284 | def forward(self, x, seq_lens, freqs): |
| 285 | b, s, n, d = *x.shape[:2], self.num_heads, self.head_dim |
nothing calls this directly
no test coverage detected