(self,
dim,
num_heads,
window_size=(-1, -1),
qk_norm=True,
eps=1e-6)
| 105 | class WanSelfAttention(nn.Module): |
| 106 | |
| 107 | def __init__(self, |
| 108 | dim, |
| 109 | num_heads, |
| 110 | window_size=(-1, -1), |
| 111 | qk_norm=True, |
| 112 | eps=1e-6): |
| 113 | assert dim % num_heads == 0 |
| 114 | super().__init__() |
| 115 | self.dim = dim |
| 116 | self.num_heads = num_heads |
| 117 | self.head_dim = dim // num_heads |
| 118 | self.window_size = window_size |
| 119 | self.qk_norm = qk_norm |
| 120 | self.eps = eps |
| 121 | |
| 122 | # layers |
| 123 | self.q = nn.Linear(dim, dim) |
| 124 | self.k = nn.Linear(dim, dim) |
| 125 | self.v = nn.Linear(dim, dim) |
| 126 | self.o = nn.Linear(dim, dim) |
| 127 | self.norm_q = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity() |
| 128 | self.norm_k = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity() |
| 129 | |
| 130 | def forward(self, x, seq_lens, grid_sizes, freqs): |
| 131 | r""" |
nothing calls this directly
no test coverage detected