r""" The [`UNet2DConditionModel`] forward method. Args: sample (`torch.FloatTensor`): The noisy input tensor with the following shape `(batch, channel, height, width)`. timestep (`torch.FloatTensor` or `float` or `int`): The number of timestep
(
sample: torch.FloatTensor,
timestep: Union[torch.Tensor, float, int],
encoder_hidden_states: torch.Tensor,
class_labels: Optional[torch.Tensor] = None,
timestep_cond: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,
down_block_additional_residuals: Optional[Tuple[torch.Tensor]] = None,
mid_block_additional_residual: Optional[torch.Tensor] = None,
encoder_attention_mask: Optional[torch.Tensor] = None,
return_dict: bool = True,
)
| 319 | """ |
| 320 | |
| 321 | def forward( |
| 322 | sample: torch.FloatTensor, |
| 323 | timestep: Union[torch.Tensor, float, int], |
| 324 | encoder_hidden_states: torch.Tensor, |
| 325 | class_labels: Optional[torch.Tensor] = None, |
| 326 | timestep_cond: Optional[torch.Tensor] = None, |
| 327 | attention_mask: Optional[torch.Tensor] = None, |
| 328 | cross_attention_kwargs: Optional[Dict[str, Any]] = None, |
| 329 | added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None, |
| 330 | down_block_additional_residuals: Optional[Tuple[torch.Tensor]] = None, |
| 331 | mid_block_additional_residual: Optional[torch.Tensor] = None, |
| 332 | encoder_attention_mask: Optional[torch.Tensor] = None, |
| 333 | return_dict: bool = True, |
| 334 | ) -> Union[UNet2DConditionOutput, Tuple]: |
| 335 | r""" |
| 336 | The [`UNet2DConditionModel`] forward method. |
| 337 | |
| 338 | Args: |
| 339 | sample (`torch.FloatTensor`): |
| 340 | The noisy input tensor with the following shape `(batch, channel, height, width)`. |
| 341 | timestep (`torch.FloatTensor` or `float` or `int`): The number of timesteps to denoise an input. |
| 342 | encoder_hidden_states (`torch.FloatTensor`): |
| 343 | The encoder hidden states with shape `(batch, sequence_length, feature_dim)`. |
| 344 | encoder_attention_mask (`torch.Tensor`): |
| 345 | A cross-attention mask of shape `(batch, sequence_length)` is applied to `encoder_hidden_states`. If |
| 346 | `True` the mask is kept, otherwise if `False` it is discarded. Mask will be converted into a bias, |
| 347 | which adds large negative values to the attention scores corresponding to "discard" tokens. |
| 348 | return_dict (`bool`, *optional*, defaults to `True`): |
| 349 | Whether or not to return a [`~models.unet_2d_condition.UNet2DConditionOutput`] instead of a plain |
| 350 | tuple. |
| 351 | cross_attention_kwargs (`dict`, *optional*): |
| 352 | A kwargs dictionary that if specified is passed along to the [`AttnProcessor`]. |
| 353 | added_cond_kwargs: (`dict`, *optional*): |
| 354 | A kwargs dictionary containin additional embeddings that if specified are added to the embeddings that |
| 355 | are passed along to the UNet blocks. |
| 356 | |
| 357 | Returns: |
| 358 | [`~models.unet_2d_condition.UNet2DConditionOutput`] or `tuple`: |
| 359 | If `return_dict` is True, an [`~models.unet_2d_condition.UNet2DConditionOutput`] is returned, otherwise |
| 360 | a `tuple` is returned where the first element is the sample tensor. |
| 361 | """ |
| 362 | # By default samples have to be AT least a multiple of the overall upsampling factor. |
| 363 | # The overall upsampling factor is equal to 2 ** (# num of upsampling layers). |
| 364 | # However, the upsampling interpolation output size can be forced to fit any upsampling size |
| 365 | # on the fly if necessary. |
| 366 | default_overall_up_factor = 2**self.num_upsamplers |
| 367 | |
| 368 | # upsample size should be forwarded when sample is not a multiple of `default_overall_up_factor` |
| 369 | forward_upsample_size = False |
| 370 | upsample_size = None |
| 371 | |
| 372 | if any(s % default_overall_up_factor != 0 for s in sample.shape[-2:]): |
| 373 | logger.info("Forward upsample size to force interpolation output size.") |
| 374 | forward_upsample_size = True |
| 375 | |
| 376 | # ensure attention_mask is a bias, and give it a singleton query_tokens dimension |
| 377 | # expects mask of shape: |
| 378 | # [batch, key_tokens] |
nothing calls this directly
no test coverage detected