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

Method forward

src/diffusers/models/attention_processor.py:490–531  ·  view source on GitHub ↗

r""" The forward method of the `Attention` class. Args: hidden_states (`torch.Tensor`): The hidden states of the query. encoder_hidden_states (`torch.Tensor`, *optional*): The hidden states of the encoder. attention

(
        self,
        hidden_states: torch.FloatTensor,
        encoder_hidden_states: Optional[torch.FloatTensor] = None,
        attention_mask: Optional[torch.FloatTensor] = None,
        **cross_attention_kwargs,
    )

Source from the content-addressed store, hash-verified

488 return lora_processor
489
490 def forward(
491 self,
492 hidden_states: torch.FloatTensor,
493 encoder_hidden_states: Optional[torch.FloatTensor] = None,
494 attention_mask: Optional[torch.FloatTensor] = None,
495 **cross_attention_kwargs,
496 ) -> torch.Tensor:
497 r"""
498 The forward method of the `Attention` class.
499
500 Args:
501 hidden_states (`torch.Tensor`):
502 The hidden states of the query.
503 encoder_hidden_states (`torch.Tensor`, *optional*):
504 The hidden states of the encoder.
505 attention_mask (`torch.Tensor`, *optional*):
506 The attention mask to use. If `None`, no mask is applied.
507 **cross_attention_kwargs:
508 Additional keyword arguments to pass along to the cross attention.
509
510 Returns:
511 `torch.Tensor`: The output of the attention layer.
512 """
513 # The `Attention` class can call different attention processors / attention functions
514 # here we simply pass along all tensors to the selected processor class
515 # For standard processors that are defined here, `**cross_attention_kwargs` is empty
516
517 attn_parameters = set(inspect.signature(self.processor.__call__).parameters.keys())
518 unused_kwargs = [k for k, _ in cross_attention_kwargs.items() if k not in attn_parameters]
519 if len(unused_kwargs) > 0:
520 logger.warning(
521 f"cross_attention_kwargs {unused_kwargs} are not expected by {self.processor.__class__.__name__} and will be ignored."
522 )
523 cross_attention_kwargs = {k: w for k, w in cross_attention_kwargs.items() if k in attn_parameters}
524
525 return self.processor(
526 self,
527 hidden_states,
528 encoder_hidden_states=encoder_hidden_states,
529 attention_mask=attention_mask,
530 **cross_attention_kwargs,
531 )
532
533 def batch_to_head_dim(self, tensor: torch.Tensor) -> torch.Tensor:
534 r"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected