(
up_block_type: str,
num_layers: int,
in_channels: int,
out_channels: int,
prev_output_channel: int,
temb_channels: int,
add_upsample: bool,
resnet_eps: float,
resnet_act_fn: str,
resolution_idx: Optional[int] = None,
transformer_layers_per_block: int = 1,
num_attention_heads: Optional[int] = None,
resnet_groups: Optional[int] = None,
cross_attention_dim: Optional[int] = None,
dual_cross_attention: bool = False,
use_linear_projection: bool = False,
only_cross_attention: bool = False,
upcast_attention: bool = False,
resnet_time_scale_shift: str = "default",
attention_type: str = "default",
resnet_skip_time_act: bool = False,
resnet_out_scale_factor: float = 1.0,
cross_attention_norm: Optional[str] = None,
attention_head_dim: Optional[int] = None,
upsample_type: Optional[str] = None,
dropout: float = 0.0,
)
| 325 | |
| 326 | |
| 327 | def get_up_block( |
| 328 | up_block_type: str, |
| 329 | num_layers: int, |
| 330 | in_channels: int, |
| 331 | out_channels: int, |
| 332 | prev_output_channel: int, |
| 333 | temb_channels: int, |
| 334 | add_upsample: bool, |
| 335 | resnet_eps: float, |
| 336 | resnet_act_fn: str, |
| 337 | resolution_idx: Optional[int] = None, |
| 338 | transformer_layers_per_block: int = 1, |
| 339 | num_attention_heads: Optional[int] = None, |
| 340 | resnet_groups: Optional[int] = None, |
| 341 | cross_attention_dim: Optional[int] = None, |
| 342 | dual_cross_attention: bool = False, |
| 343 | use_linear_projection: bool = False, |
| 344 | only_cross_attention: bool = False, |
| 345 | upcast_attention: bool = False, |
| 346 | resnet_time_scale_shift: str = "default", |
| 347 | attention_type: str = "default", |
| 348 | resnet_skip_time_act: bool = False, |
| 349 | resnet_out_scale_factor: float = 1.0, |
| 350 | cross_attention_norm: Optional[str] = None, |
| 351 | attention_head_dim: Optional[int] = None, |
| 352 | upsample_type: Optional[str] = None, |
| 353 | dropout: float = 0.0, |
| 354 | ) -> nn.Module: |
| 355 | # If attn head dim is not defined, we default it to the number of heads |
| 356 | if attention_head_dim is None: |
| 357 | logger.warning( |
| 358 | f"It is recommended to provide `attention_head_dim` when calling `get_up_block`. Defaulting `attention_head_dim` to {num_attention_heads}." |
| 359 | ) |
| 360 | attention_head_dim = num_attention_heads |
| 361 | |
| 362 | up_block_type = up_block_type[7:] if up_block_type.startswith("UNetRes") else up_block_type |
| 363 | if up_block_type == "UpBlock2D": |
| 364 | return UpBlock2D( |
| 365 | num_layers=num_layers, |
| 366 | in_channels=in_channels, |
| 367 | out_channels=out_channels, |
| 368 | prev_output_channel=prev_output_channel, |
| 369 | temb_channels=temb_channels, |
| 370 | resolution_idx=resolution_idx, |
| 371 | dropout=dropout, |
| 372 | add_upsample=add_upsample, |
| 373 | resnet_eps=resnet_eps, |
| 374 | resnet_act_fn=resnet_act_fn, |
| 375 | resnet_groups=resnet_groups, |
| 376 | resnet_time_scale_shift=resnet_time_scale_shift, |
| 377 | ) |
| 378 | elif up_block_type == "ResnetUpsampleBlock2D": |
| 379 | return ResnetUpsampleBlock2D( |
| 380 | num_layers=num_layers, |
| 381 | in_channels=in_channels, |
| 382 | out_channels=out_channels, |
| 383 | prev_output_channel=prev_output_channel, |
| 384 | temb_channels=temb_channels, |
nothing calls this directly
no test coverage detected