(
self,
hidden_size: int,
cross_attention_dim: Optional[int] = None,
rank: int = 4,
network_alpha: Optional[int] = None,
**kwargs,
)
| 1823 | |
| 1824 | class LoRAAttnProcessor(nn.Module): |
| 1825 | def __init__( |
| 1826 | self, |
| 1827 | hidden_size: int, |
| 1828 | cross_attention_dim: Optional[int] = None, |
| 1829 | rank: int = 4, |
| 1830 | network_alpha: Optional[int] = None, |
| 1831 | **kwargs, |
| 1832 | ): |
| 1833 | deprecation_message = "Using LoRAAttnProcessor is deprecated. Please use the PEFT backend for all things LoRA. You can install PEFT by running `pip install peft`." |
| 1834 | deprecate("LoRAAttnProcessor", "0.30.0", deprecation_message, standard_warn=False) |
| 1835 | |
| 1836 | super().__init__() |
| 1837 | |
| 1838 | self.hidden_size = hidden_size |
| 1839 | self.cross_attention_dim = cross_attention_dim |
| 1840 | self.rank = rank |
| 1841 | |
| 1842 | q_rank = kwargs.pop("q_rank", None) |
| 1843 | q_hidden_size = kwargs.pop("q_hidden_size", None) |
| 1844 | q_rank = q_rank if q_rank is not None else rank |
| 1845 | q_hidden_size = q_hidden_size if q_hidden_size is not None else hidden_size |
| 1846 | |
| 1847 | v_rank = kwargs.pop("v_rank", None) |
| 1848 | v_hidden_size = kwargs.pop("v_hidden_size", None) |
| 1849 | v_rank = v_rank if v_rank is not None else rank |
| 1850 | v_hidden_size = v_hidden_size if v_hidden_size is not None else hidden_size |
| 1851 | |
| 1852 | out_rank = kwargs.pop("out_rank", None) |
| 1853 | out_hidden_size = kwargs.pop("out_hidden_size", None) |
| 1854 | out_rank = out_rank if out_rank is not None else rank |
| 1855 | out_hidden_size = out_hidden_size if out_hidden_size is not None else hidden_size |
| 1856 | |
| 1857 | self.to_q_lora = LoRALinearLayer(q_hidden_size, q_hidden_size, q_rank, network_alpha) |
| 1858 | self.to_k_lora = LoRALinearLayer(cross_attention_dim or hidden_size, hidden_size, rank, network_alpha) |
| 1859 | self.to_v_lora = LoRALinearLayer(cross_attention_dim or v_hidden_size, v_hidden_size, v_rank, network_alpha) |
| 1860 | self.to_out_lora = LoRALinearLayer(out_hidden_size, out_hidden_size, out_rank, network_alpha) |
| 1861 | |
| 1862 | def __call__(self, attn: Attention, hidden_states: torch.FloatTensor, *args, **kwargs) -> torch.FloatTensor: |
| 1863 | self_cls_name = self.__class__.__name__ |
nothing calls this directly
no test coverage detected