(
self,
channels,
num_heads=1,
num_head_channels=-1,
use_checkpoint=False,
use_new_attention_order=False,
)
| 282 | """ |
| 283 | |
| 284 | def __init__( |
| 285 | self, |
| 286 | channels, |
| 287 | num_heads=1, |
| 288 | num_head_channels=-1, |
| 289 | use_checkpoint=False, |
| 290 | use_new_attention_order=False, |
| 291 | ): |
| 292 | super().__init__() |
| 293 | self.channels = channels |
| 294 | if num_head_channels == -1: |
| 295 | self.num_heads = num_heads |
| 296 | else: |
| 297 | assert ( |
| 298 | channels % num_head_channels == 0 |
| 299 | ), f"q,k,v channels {channels} is not divisible by num_head_channels {num_head_channels}" |
| 300 | self.num_heads = channels // num_head_channels |
| 301 | self.use_checkpoint = use_checkpoint |
| 302 | self.norm = normalization(channels) |
| 303 | self.qkv = conv_nd(1, channels, channels * 3, 1) |
| 304 | if use_new_attention_order: |
| 305 | # split qkv before split heads |
| 306 | self.attention = QKVAttention(self.num_heads) |
| 307 | else: |
| 308 | # split heads before split qkv |
| 309 | self.attention = QKVAttentionLegacy(self.num_heads) |
| 310 | |
| 311 | self.proj_out = zero_module(conv_nd(1, channels, channels, 1)) |
| 312 | |
| 313 | def forward(self, x): |
| 314 | return checkpoint(self._forward, (x,), self.parameters(), True) # TODO: check checkpoint usage, is True # TODO: fix the .half call!!! |
nothing calls this directly
no test coverage detected