(
self,
channels,
num_heads=1,
num_head_channels=-1,
use_checkpoint=False,
use_new_attention_order=False,
)
| 354 | """ |
| 355 | |
| 356 | def __init__( |
| 357 | self, |
| 358 | channels, |
| 359 | num_heads=1, |
| 360 | num_head_channels=-1, |
| 361 | use_checkpoint=False, |
| 362 | use_new_attention_order=False, |
| 363 | ): |
| 364 | super().__init__() |
| 365 | self.channels = channels |
| 366 | if num_head_channels == -1: |
| 367 | self.num_heads = num_heads |
| 368 | else: |
| 369 | assert ( |
| 370 | channels % num_head_channels == 0 |
| 371 | ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}" |
| 372 | self.num_heads = channels // num_head_channels |
| 373 | self.use_checkpoint = use_checkpoint |
| 374 | self.norm = normalization(channels) |
| 375 | self.qkv = conv_nd(1, channels, channels * 3, 1) |
| 376 | if use_new_attention_order: |
| 377 | # split qkv before split heads |
| 378 | self.attention = QKVAttention(self.num_heads) |
| 379 | else: |
| 380 | # split heads before split qkv |
| 381 | self.attention = QKVAttentionLegacy(self.num_heads) |
| 382 | |
| 383 | self.proj_out = zero_module(conv_nd(1, channels, channels, 1)) |
| 384 | |
| 385 | def forward(self, x, **kwargs): |
| 386 | # TODO add crossframe attention and use mixed checkpoint |
nothing calls this directly
no test coverage detected