The [`ControlNetModel`] forward method. Args: sample (`torch.Tensor`): The noisy input tensor. timestep (`Union[torch.Tensor, float, int]`): The number of timesteps to denoise an input. encoder_hidden_states (`torc
(
self,
sample: torch.Tensor,
timestep: Union[torch.Tensor, float, int],
encoder_hidden_states: torch.Tensor,
controlnet_cond: torch.Tensor,
conditioning_scale: float = 1.0,
class_labels: Optional[torch.Tensor] = None,
timestep_cond: Optional[torch.Tensor] = None,
attention_mask: Optional[torch.Tensor] = None,
added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
guess_mode: bool = False,
return_dict: bool = True,
)
| 664 | module.gradient_checkpointing = value |
| 665 | |
| 666 | def forward( |
| 667 | self, |
| 668 | sample: torch.Tensor, |
| 669 | timestep: Union[torch.Tensor, float, int], |
| 670 | encoder_hidden_states: torch.Tensor, |
| 671 | controlnet_cond: torch.Tensor, |
| 672 | conditioning_scale: float = 1.0, |
| 673 | class_labels: Optional[torch.Tensor] = None, |
| 674 | timestep_cond: Optional[torch.Tensor] = None, |
| 675 | attention_mask: Optional[torch.Tensor] = None, |
| 676 | added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None, |
| 677 | cross_attention_kwargs: Optional[Dict[str, Any]] = None, |
| 678 | guess_mode: bool = False, |
| 679 | return_dict: bool = True, |
| 680 | ) -> Union[ControlNetOutput, Tuple[Tuple[torch.Tensor, ...], torch.Tensor]]: |
| 681 | """ |
| 682 | The [`ControlNetModel`] forward method. |
| 683 | |
| 684 | Args: |
| 685 | sample (`torch.Tensor`): |
| 686 | The noisy input tensor. |
| 687 | timestep (`Union[torch.Tensor, float, int]`): |
| 688 | The number of timesteps to denoise an input. |
| 689 | encoder_hidden_states (`torch.Tensor`): |
| 690 | The encoder hidden states. |
| 691 | controlnet_cond (`torch.Tensor`): |
| 692 | The conditional input tensor of shape `(batch_size, sequence_length, hidden_size)`. |
| 693 | conditioning_scale (`float`, defaults to `1.0`): |
| 694 | The scale factor for ControlNet outputs. |
| 695 | class_labels (`torch.Tensor`, *optional*, defaults to `None`): |
| 696 | Optional class labels for conditioning. Their embeddings will be summed with the timestep embeddings. |
| 697 | timestep_cond (`torch.Tensor`, *optional*, defaults to `None`): |
| 698 | Additional conditional embeddings for timestep. If provided, the embeddings will be summed with the |
| 699 | timestep_embedding passed through the `self.time_embedding` layer to obtain the final timestep |
| 700 | embeddings. |
| 701 | attention_mask (`torch.Tensor`, *optional*, defaults to `None`): |
| 702 | An attention mask of shape `(batch, key_tokens)` is applied to `encoder_hidden_states`. If `1` the mask |
| 703 | is kept, otherwise if `0` it is discarded. Mask will be converted into a bias, which adds large |
| 704 | negative values to the attention scores corresponding to "discard" tokens. |
| 705 | added_cond_kwargs (`dict`): |
| 706 | Additional conditions for the Stable Diffusion XL UNet. |
| 707 | cross_attention_kwargs (`dict[str]`, *optional*, defaults to `None`): |
| 708 | A kwargs dictionary that if specified is passed along to the `AttnProcessor`. |
| 709 | guess_mode (`bool`, defaults to `False`): |
| 710 | In this mode, the ControlNet encoder tries its best to recognize the input content of the input even if |
| 711 | you remove all prompts. A `guidance_scale` between 3.0 and 5.0 is recommended. |
| 712 | return_dict (`bool`, defaults to `True`): |
| 713 | Whether or not to return a [`~models.controlnet.ControlNetOutput`] instead of a plain tuple. |
| 714 | |
| 715 | Returns: |
| 716 | [`~models.controlnet.ControlNetOutput`] **or** `tuple`: |
| 717 | If `return_dict` is `True`, a [`~models.controlnet.ControlNetOutput`] is returned, otherwise a tuple is |
| 718 | returned where the first element is the sample tensor. |
| 719 | """ |
| 720 | # check channel order |
| 721 | channel_order = self.config.controlnet_conditioning_channel_order |
| 722 | |
| 723 | if channel_order == "rgb": |
nothing calls this directly
no test coverage detected