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