MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / forward

Method forward

src/diffusers/models/brushnet.py:678–925  ·  view source on GitHub ↗

The [`BrushNetModel`] 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 (`t

(
        self,
        sample: torch.FloatTensor,
        timestep: Union[torch.Tensor, float, int],
        encoder_hidden_states: torch.Tensor,
        brushnet_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,
    )

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

BrushNetOutputClass · 0.85
toMethod · 0.45

Tested by

no test coverage detected