MCPcopy Create free account
hub / github.com/Francis-Rings/MotionFollower / LoRAAttnProcessor

Class LoRAAttnProcessor

src/models/attn_process_diffuser.py:1701–1770  ·  view source on GitHub ↗

r""" Processor for implementing the LoRA attention mechanism. Args: hidden_size (`int`, *optional*): The hidden size of the attention layer. cross_attention_dim (`int`, *optional*): The number of channels in the `encoder_hidden_states`.

Source from the content-addressed store, hash-verified

1699
1700## Deprecated
1701class LoRAAttnProcessor(nn.Module):
1702 r"""
1703 Processor for implementing the LoRA attention mechanism.
1704
1705 Args:
1706 hidden_size (`int`, *optional*):
1707 The hidden size of the attention layer.
1708 cross_attention_dim (`int`, *optional*):
1709 The number of channels in the `encoder_hidden_states`.
1710 rank (`int`, defaults to 4):
1711 The dimension of the LoRA update matrices.
1712 network_alpha (`int`, *optional*):
1713 Equivalent to `alpha` but it's usage is specific to Kohya (A1111) style LoRAs.
1714 kwargs (`dict`):
1715 Additional keyword arguments to pass to the `LoRALinearLayer` layers.
1716 """
1717
1718 def __init__(
1719 self,
1720 hidden_size: int,
1721 cross_attention_dim: Optional[int] = None,
1722 rank: int = 4,
1723 network_alpha: Optional[int] = None,
1724 **kwargs,
1725 ):
1726 super().__init__()
1727
1728 self.hidden_size = hidden_size
1729 self.cross_attention_dim = cross_attention_dim
1730 self.rank = rank
1731
1732 q_rank = kwargs.pop("q_rank", None)
1733 q_hidden_size = kwargs.pop("q_hidden_size", None)
1734 q_rank = q_rank if q_rank is not None else rank
1735 q_hidden_size = q_hidden_size if q_hidden_size is not None else hidden_size
1736
1737 v_rank = kwargs.pop("v_rank", None)
1738 v_hidden_size = kwargs.pop("v_hidden_size", None)
1739 v_rank = v_rank if v_rank is not None else rank
1740 v_hidden_size = v_hidden_size if v_hidden_size is not None else hidden_size
1741
1742 out_rank = kwargs.pop("out_rank", None)
1743 out_hidden_size = kwargs.pop("out_hidden_size", None)
1744 out_rank = out_rank if out_rank is not None else rank
1745 out_hidden_size = out_hidden_size if out_hidden_size is not None else hidden_size
1746
1747 self.to_q_lora = LoRALinearLayer(q_hidden_size, q_hidden_size, q_rank, network_alpha)
1748 self.to_k_lora = LoRALinearLayer(cross_attention_dim or hidden_size, hidden_size, rank, network_alpha)
1749 self.to_v_lora = LoRALinearLayer(cross_attention_dim or v_hidden_size, v_hidden_size, v_rank, network_alpha)
1750 self.to_out_lora = LoRALinearLayer(out_hidden_size, out_hidden_size, out_rank, network_alpha)
1751
1752 def __call__(self, attn: Attention, hidden_states: torch.FloatTensor, *args, **kwargs) -> torch.FloatTensor:
1753 self_cls_name = self.__class__.__name__
1754 deprecate(
1755 self_cls_name,
1756 "0.26.0",
1757 (
1758 f"Make sure use {self_cls_name[4:]} instead by setting"

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected