+
    LjӲ                     T   ^ RI t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	t	^ RI
t
^ RIHu Ht ^ RIHt ^RIHtHtHtHtHtHt ^RIHt ^R	IHtHt ^R
IHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't' ^RI(H)t) ^RI*H+t+ ^RI,H-t-H.t.H/t/H0t0 ^RIH1t1 ]'Pd                  ! ]34      t4Rt5Rt6 ! R R4      t7R# )    N)defaultdict)nullcontext)Path)Callable)validate_hf_hub_args)ImageProjectionIPAdapterFaceIDImageProjection"IPAdapterFaceIDPlusImageProjectionIPAdapterFullImageProjectionIPAdapterPlusImageProjectionMultiIPAdapterImageProjection)load_model_dict_into_meta)_LOW_CPU_MEM_USAGE_DEFAULTload_state_dict)
USE_PEFT_BACKEND_get_model_fileconvert_unet_state_dict_to_peft	deprecateget_adapter_nameget_peft_kwargsis_accelerate_availableis_peft_versionis_torch_versionlogging)empty_device_cache#_func_optionally_disable_offloading)LORA_WEIGHT_NAMELORA_WEIGHT_NAME_SAFETEXT_ENCODER_NAME	UNET_NAME)AttnProcsLayersz$pytorch_custom_diffusion_weights.binz,pytorch_custom_diffusion_weights.safetensorsc                      a  ] tR t^<t o Rt]t]t]	V 3R lR l4       t
R tR t]R 4       tRV 3R lR	 lltR
 t]3R lt]3R lt]3R ltR tRtV tR# )UNet2DConditionLoadersMixinz2
Load LoRA layers into a [`UNet2DCondtionModel`].
c                Z   < V ^8  d   QhRS[ S[S[ S[P                  3,          ,          /# )   %pretrained_model_name_or_path_or_dict)strdicttorchTensor)format__classdict__s   "B/app/.local/lib/python3.14/site-packages/diffusers/loaders/unet.py__annotate__(UNet2DConditionLoadersMixin.__annotate__E   s1     yJ yJS4PSUZUaUaPaKbEb yJ    c                   ^RI Hp VP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  R	R4      p	VP                  R
R4      p
VP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  R\        4      pRpV'       d   \	        RR4      '       d   \        R4      hVf   RpRpRRRR/pRp\        V\        4      '       g   V'       d   Ve   Ve]   VP                  R4      '       dF    \        TT;'       g    \        VVVVVV	V
VR7
      p\        P                  P                  VRR7      pVf/   \        TT;'       g    \        VVVVVV	V
VR7
      p\!        V4      pMTp\"        ;QJ d*    R XP%                  4        4       F  '       g   K   RM	  RM! R XP%                  4        4       4      p\&        ;QJ d*    R VP%                  4        4       F  '       d   K   RM	  RM! R VP%                  4        4       4      pRpRpRpV'       d   Rp\)        R R!V4       V'       d   V P+                  VR"7      pM<V'       d'   V P-                  VV P.                  VVVVR#7      w  pppM\        V R$24      hV'       dS   VeO   V P1                  VR%7      w  pppV P3                  X4       V P5                  V P6                  V P8                  R&7       V'       d   VP;                  4        R# V'       d   VP=                  4        R# V'       dX   VP>                  PA                  4        F7  p\        V\        PB                  PD                  4      '       g   K/  V! V4       K9  	  R# R#   \         d   pT'       g   Th Rp?ELSRp?ii ; i)'a  
Load pretrained attention processor layers into [`UNet2DConditionModel`]. Attention processor layers have to be
defined in
[`attention_processor.py`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py)
and be a `torch.nn.Module` class. Currently supported: LoRA, Custom Diffusion. For LoRA, one must install
`peft`: `pip install -U peft`.

Parameters:
    pretrained_model_name_or_path_or_dict (`str` or `os.PathLike` or `dict`):
        Can be either:

            - A string, the model id (for example `google/ddpm-celebahq-256`) of a pretrained model hosted on
              the Hub.
            - A path to a directory (for example `./my_model_directory`) containing the model weights saved
              with [`ModelMixin.save_pretrained`].
            - A [torch state
              dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict).

    cache_dir (`str | os.PathLike`, *optional*):
        Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
        is not used.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether or not to force the (re-)download of the model weights and configuration files, overriding the
        cached versions if they exist.

    proxies (`dict[str, str]`, *optional*):
        A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
        'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
    local_files_only (`bool`, *optional*, defaults to `False`):
        Whether to only load local model weights and configuration files or not. If set to `True`, the model
        won't be downloaded from the Hub.
    token (`str` or *bool*, *optional*):
        The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
        `diffusers-cli login` (stored in `~/.huggingface`) is used.
    revision (`str`, *optional*, defaults to `"main"`):
        The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
        allowed by Git.
    subfolder (`str`, *optional*, defaults to `""`):
        The subfolder location of a model file within a larger model repository on the Hub or locally.
    network_alphas (`dict[str, float]`):
        The value of the network alpha used for stable learning and preventing underflow. This value has the
        same meaning as the `--network_alpha` option in the kohya-ss trainer script. Refer to [this
        link](https://github.com/darkstorm2150/sd-scripts/blob/main/docs/train_network_README-en.md#execute-learning).
    adapter_name (`str`, *optional*, defaults to None):
        Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
        `default_{i}` where i is the total number of adapters being loaded.
    weight_name (`str`, *optional*, defaults to None):
        Name of the serialized state dict file.
    low_cpu_mem_usage (`bool`, *optional*):
        Speed up model loading by only loading the pretrained LoRA weights and not initializing the random
        weights.

Example:

```py
from diffusers import AutoPipelineForText2Image
import torch

pipeline = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
).to("cuda")
pipeline.unet.load_attn_procs(
    "jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
```
)*_maybe_remove_and_reapply_group_offloading	cache_dirNforce_downloadFproxieslocal_files_onlytokenrevision	subfolderweight_nameuse_safetensorsadapter_name	_pipelinenetwork_alphaslow_cpu_mem_usage<=z0.13.0zq`low_cpu_mem_usage=True` is not compatible with this `peft` version. Please update it with `pip install -U peft`.T	file_typeattn_procs_weights	frameworkpytorchz.safetensors)	weights_namer4   r5   r6   r7   r8   r9   r:   
user_agentcpu)devicec              3   ,   "   T F
  pR V9   x  K  	  R# 5i)custom_diffusionN .0ks   & r.   	<genexpr>>UNet2DConditionLoadersMixin.load_attn_procs.<locals>.<genexpr>   s     !UCTa"4"9CT   c              3   ^   "   T F#  pR V9   ;'       g    VP                  R4      x  K%  	  R# 5i)loraz.alphaN)endswithrM   s   & r.   rP   rQ      s*     WEVv{::ajj&::EVs   --zUsing the `load_attn_procs()` method has been deprecated and will be removed in a future version. Please use `load_lora_adapter()`.load_attn_procs0.40.0)
state_dict)rX   unet_identifier_keyr?   r=   r>   r@   zQ does not seem to be in the correct format expected by Custom Diffusion training.r>   dtyperI   )#hooks.group_offloadingr3   popr   r   
ValueError
isinstancer)   rU   r   r   safetensorsr*   	load_fileIOErrorr   r   anykeysallr   _process_custom_diffusion_process_lora	unet_name_optionally_disable_offloadingset_attn_processortor\   rI   enable_model_cpu_offloadenable_sequential_cpu_offload
componentsvaluesnnModule)selfr'   kwargsr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   allow_picklerG   
model_filerX   eis_custom_diffusionis_lorais_model_cpu_offloadis_sequential_cpu_offloadis_group_offloaddeprecation_messageattn_processors	components   &&,                           r.   rV   +UNet2DConditionLoadersMixin.load_attn_procsD   s   H 	XJJ{D1	$4e<**Y-!::&8$?

7D)::j$/JJ{D1	jj5 **%6=zz.$7JJ{D1	$4d;"JJ':<VWx!@!@ D  ""OL!#7iP

?FFK$7'K,@,@,P,P!0=%0%I%I4I"+'5 ')9#!)"+#-"J "-!2!2!<!<ZPU!<!VJ !,9!,!@!@0@'#1#%5%')
 -Z8
>J!c!U:??CT!Uccc!U:??CT!UU#WZ__EVW###WZ__EVWW$$)!  #h'3FG"<<
<SOPTPbPb%$(NN-)#"3 Qc QM ";=M ,op  9#8PTPsPs# Qt QM ";=M
 ##O4GG$**T[[G9  ..0&335&1188:	i99>yI ; G  '	s   *O& 95O& &P1
PPc                   ^RI Hp / p\        \        4      pVP	                  4        F  w  rV\        V4      ^ 8X  d   / WE&   K  RV9   dG   RP                  VP                  R4      RR
 4      RP                  VP                  R4      R
R 4      rMERP                  VP                  R4      RR 4      RP                  VP                  R4      RR 4      rWdV,          V&   K  	  VP	                  4        F  w  rY\        V	4      ^ 8X  d   V! RRRRR7      W5&   K%  V	R,          P                  ^,          p
V	R,          P                  ^ ,          pRV	9   d   R	MRpV! R	VVV
R7      W5&   W5,          P                  V	4       K  	  V# )r&   )CustomDiffusionAttnProcessorto_out.NF)train_kvtrain_q_outhidden_sizecross_attention_dimzto_k_custom_diffusion.weightzto_q_custom_diffusion.weightT)
models.attention_processorr   r   r)   itemslenjoinsplitshaper   )rs   rX   r   r~   custom_diffusion_grouped_dictkeyvalueattn_processor_keysub_key
value_dictr   r   r   s   &&           r.   rg   5UNet2DConditionLoadersMixin._process_custom_diffusion  s   M(3D(9%$**,JC5zQ57-2s?25((399S>#2;N2OQTQYQYZ]ZcZcdgZhikilZmQn25((399S>#2;N2OQTQYQYZ]ZcZcdgZhikilZmQnMR.@A'J -  =BBDOC:!#'C"4]a($ '11O&P&V&VWX&Y#()GHNNqQ&D
&RdX]'C! + +(;	($  $44Z@  E" r1   c                   \         '       g   \        R 4      h^ RIHpHpHp	 \        VP                  4       4      p
V
 Uu. uF  qP                  V4      '       g   K  VNK  	  ppVP                  4        UUu/ uF#  w  rW9   g   K  VP                  V R2R4      VbK%  	  pppVew   VP                  4        Uu. uF  qP                  V4      '       g   K  VNK  	  ppVP                  4        UUu/ uF#  w  rW9   g   K  VP                  V R2R4      VbK%  	  pppRpRpRp\        V4      ^ 8  d   TMTp\        V4      ^ 8  Ed`   V\        V R/ 4      9   d   \        RV R24      h\        V4      pVe   \        V4      p/ pVP                  4        F%  w  ppR	V9   g   K  VP                  ^,          VV&   K'  	  \        VW1R
R7      pRV9   dQ   VR,          '       d   \!        RR4      '       d   \        R4      hM#\!        RR4      '       d   VP#                  R4       RV9   dQ   VR,          '       d   \!        RR4      '       d   \        R4      hM#\!        RR4      '       d   VP#                  R4       V! R/ VB pVf   \%        V 4      pV P'                  V4      w  ppp/ p\!        RR4      '       d   VVR&   V! VV 3RV/VB  V	! WV3/ VB pRpVe   \        VRR4      pV'       d@   V Uu. uF  pRV9   g   K  WK9   g   K  VNK  	  ppV'       d   RRP)                  V4       R2p\        VRR4      pV'       dG   V Uu. uF  pRV9   g   K  WK9   g   K  VNK  	  ppV'       d   VRRP)                  V4       R2,          pV'       d   \*        P-                  V4       VVV3# u upi u uppi u upi u uppi u upi u upi ) z)PEFT backend is required for this method.)
LoraConfiginject_adapter_in_modelset_peft_model_state_dictr    NFpeft_configzAdapter name z? already in use in the Unet - please select a new adapter name.lora_BT)is_unetuse_dora<z0.9.0zeYou need `peft` 0.9.0 at least to use DoRA-enabled LoRAs. Please upgrade your installation of `peft`.	lora_biasrA   z0.13.2zcYou need `peft` 0.14.0 at least to use `bias` in LoRAs. Please upgrade your installation of `peft`.>=z0.13.1r@   r=   unexpected_keyslora_zSLoading adapter weights from state_dict led to unexpected keys found in the model: z, z. missing_keyszJLoading adapter weights from state_dict led to missing keys in the model: rL   )r   r_   peftr   r   r   listre   
startswithr   replacer   getattrr   r   r   r   r^   r   rj   r   loggerwarning) rs   rX   rY   r?   r=   r>   r@   r   r   r   re   rO   	unet_keysvunet_state_dict
alpha_keysrz   r{   r|   state_dict_to_be_usedrankr   vallora_config_kwargslora_configpeft_kwargsincompatible_keyswarn_msgr   lora_unexpected_keysr   lora_missing_keyss    &&&&&&&                         r.   rh   )UNet2DConditionLoadersMixin._process_lora#  s"     HIIWWJOO%& $J15H(IQQ	JDNDTDTDV
DVDAZ[Zh7AII,-Q/4a7DV 	 
 %%3%8%8%:`%:llK^>_!!%:J`HVH\H\H^H^bcbq;		013R8!;H^    %$)! 363G!3KQ[$%)wt]B?? #L>1pq  99NOJ) "A!PD&,,.Ss? #		!DI / "1~[_!`//%j11&sG44( D  5
 'sG44*..z:00%k22&tX66( B  7
 'tX66*..{;$:'9:K #/5 QUPsPsQM ";=M KtX..3D/0#K`L`T_` 9$L h\g hH ,")*;=NPT"U"7F+m!'UV,A[g[lAA(+m+  $		*> ?@D !  ''8.$O4@(gLqGqLUaUfL%(g(   $		*; <=Q@
 x(#%>@PPPE K

 aN ,n )hsS   N,N,7
N1N19N7N71
N< N<4	OO
O	OOOc                    \        VR 7      # )rZ   r   )clsr>   s   &&r.   rj   :UNet2DConditionLoadersMixin._optionally_disable_offloading  s     3YGGr1   Nc          
      \   < V ^8  d   QhRS[ S[P                  ,          RS[RS[ RS[RS[/# )r&   save_directoryis_main_processr;   save_functionsafe_serialization)r(   osPathLikeboolr   )r,   r-   s   "r.   r/   r0     sM     d; d;bkk)d; d; 	d;
  d; !d;r1   c                  aaa ^RI HoHoHo \        P
                  P                  V4      '       d   \        P                  RV R24       R# \        ;QJ d9    VVV3R lV P                  P                  4        4       F  '       g   K   RM.	  RM*! VVV3R lV P                  P                  4        4       4      pV'       d   V P                  4       pVf   V'       d   VP                  4        U	U
u/ uF)  w  r\        V
\        P                  4      '       d   K'  WbK+  	  pp	p
\!        V4      ^ 8  d'   \        P#                  RVP%                  4        24       VP                  4        U	U
u/ uF)  w  r\        V
\        P                  4      '       g   K'  WbK+  	  pp	p
M4R	p\'        R
RV4       \(        '       g   \+        R4      h^ RIHp V! V 4      pVf   V'       d   R pM\        P0                  p\        P2                  ! VRR7       Vf2   V'       d   V'       d   \4        M\6        pMV'       d   \8        M\:        p\=        W4      P?                  4       pV! W4       \        PA                  RV 24       R# u up
p	i u up
p	i )a  
Save attention processor layers to a directory so that it can be reloaded with the
[`~loaders.UNet2DConditionLoadersMixin.load_attn_procs`] method.

Arguments:
    save_directory (`str` or `os.PathLike`):
        Directory to save an attention processor to (will be created if it doesn't exist).
    is_main_process (`bool`, *optional*, defaults to `True`):
        Whether the process calling this is the main process or not. Useful during distributed training and you
        need to call this function on all processes. In this case, set `is_main_process=True` only on the main
        process to avoid race conditions.
    save_function (`Callable`):
        The function to use to save the state dictionary. Useful during distributed training when you need to
        replace `torch.save` with another method. Can be configured with the environment variable
        `DIFFUSERS_SAVE_MODE`.
    safe_serialization (`bool`, *optional*, defaults to `True`):
        Whether to save the model using `safetensors` or with `pickle`.

Example:

```py
import torch
from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4",
    torch_dtype=torch.float16,
).to("cuda")
pipeline.unet.load_attn_procs("path-to-save-model", weight_name="pytorch_custom_diffusion_weights.bin")
pipeline.unet.save_attn_procs("path-to-save-model", weight_name="pytorch_custom_diffusion_weights.bin")
```
r   CustomDiffusionAttnProcessor2_0$CustomDiffusionXFormersAttnProcessorzProvided path (z#) should be a directory, not a fileNc              3   F   <"   T F  w  r\        VSSS34      x  K  	  R # 5i)N)r`   )rN   _xr   r   r   s   &  r.   rP   >UNet2DConditionLoadersMixin.save_attn_procs.<locals>.<genexpr>  s7      "

 7	 -/NPtu  7s   !TFzfSafetensors does not support saving dicts with non-tensor values. The following keys will be ignored: zUsing the `save_attn_procs()` method has been deprecated and will be removed in a future version. Please use `save_lora_adapter()`.save_attn_procsrW   zOPEFT backend is required for saving LoRAs using the `save_attn_procs()` method.)get_peft_model_state_dictc                 H    \         P                  P                  WR R/R7      # )r,   pt)metadata)ra   r*   	save_file)weightsfilenames   &&r.   r   BUNet2DConditionLoadersMixin.save_attn_procs.<locals>.save_function  s%    &,,66wT\^bSc6ddr1   )exist_okzModel weights saved in )!r   r   r   r   r   pathisfiler   errorrd   r~   r    _get_custom_diffusion_state_dictr`   r*   r+   r   r   re   r   r   r_   
peft.utilsr   savemakedirs!CUSTOM_DIFFUSION_WEIGHT_NAME_SAFEr   CUSTOM_DIFFUSION_WEIGHT_NAMEr   r   as_posixinfo)rs   r   r   r;   r   r   rt   rx   rX   rO   r   empty_state_dictr}   r   	save_pathr   r   r   s   &&&&&&,        @@@r.   r   +UNet2DConditionLoadersMixin.save_attn_procs  s   R	
 	
 77>>.))LL?>*::]^_!c "

 ..446"
ccc "

 ..446"
 
 >>@J$);5?5E5E5G#k5GTQzZ[]b]i]iOjDAD5G #k'(1,NN??O?T?T?V>WY 0:/?/?/Aa/AtqZPQSXS_S_E`dad/A
a #h'3FG## !rss<248J !e !&


NT2!CV?\q>Q:Wg 5>>@	j,-i[9:M $l bs   3$I=I=.$JJc                p   ^RI HpHpHp \	        V P
                  P                  4        UUu/ uF  w  rE\        VVVV34      '       g   K  WEbK   	  upp4      pVP                  4       pV P
                  P                  4        F)  w  r\        V	P                  4       4      ^ 8X  g   K%  / Wx&   K+  	  V# u uppi )r&   r   )
r   r   r   r   r"   r~   r   r`   rX   r   )
rs   r   r   r   yr   model_to_saverX   nameattns
   &         r.   r   <UNet2DConditionLoadersMixin._get_custom_diffusion_state_dict  s    	
 	
 ( #2288::FQ47< :
 #--/
..446JD4??$%*#%
  7 %s   B2
B2
c           
        V'       d/   \        4       '       d   ^ RIHp MRp\        P	                  R4       VRJ d   \        RR4      '       g   \        R4      h/ pRpV'       d   XM\        pR	V9   d   ^pVR	,          P                  R,          pVR	,          P                  ^ ,          ^,          p	V! 4       ;_uu_ 4        \        V	VVR
7      pRRR4       VP                  4        F  w  rV
P                  RR4      pWV&   K  	  EMRV9   d   VR,          P                  ^ ,          pVR,          P                  ^ ,          p	V! 4       ;_uu_ 4        \        WR7      pRRR4       VP                  4        F?  w  rV
P                  RR4      pVP                  RR4      pVP                  RR4      pWV&   KA  	  EMRV9   EdD   VR,          P                  ^,          pVR,          P                  ^ ,          pVR,          P                  ^,          pVR,          P                  ^ ,          pVR,          P                  ^ ,          ^@,          pV! 4       ;_uu_ 4        \        VVVVVR7      pRRR4       VP                  4        EF{  w  rV
P                  RR4      pVP                  RR4      pVP                  RR4      pVP                  R R!4      pVP                  R"R#4      pVP                  R$R%4      pVP                  R&R'4      pVP                  R(R)4      pVP                  R*R+4      pVP                  R,R-4      pVP                  R.R/4      pVP                  R0R14      pVP                  R2R34      pVP                  R4R54      pVP                  R6R74      pVP                  R8R94      pVP                  R:R;4      pVP                  R<R=4      pVP                  R>R?4      pVP                  R@RA4      pVP                  RBRC4      pVP                  RDRE4      pRFV9   d   WVP                  RGRH4      &   EK  RIV9   d   WVP                  RJRK4      &   EK  RLV9   dM   VP                  ^^ RM7      pV^ ,          WLP                  RLRN4      &   V^,          WLP                  RLRO4      &   EK!  RPV9   d   WVP                  RPRQ4      &   EK?  RV8X  d   WRR&   EKM  RSV8X  d   WRT&   EK[  RUV8X  d   WRV&   EKi  RWV8X  d   WRX&   EKw  WV&   EK~  	  EMRYV9   d   VR,          P                  ^,          pVR,          P                  ^ ,          pVV,          pRYpVV,          P                  ^ ,          p	VRU,          P                  ^ ,          V	,          pV! 4       ;_uu_ 4        \        V	VVVRZ7      pRRR4       VP                  4        F-  w  rV
P                  RR4      pVP                  RR4      pWV&   K/  	  EMVR[,          P                  ^,          pVR\,          P                  ^,          pVR],          P                  ^ ,          pVR[,          P                  ^,          p\         ;QJ d    R^ V 4       F  '       g   K   RM	  RM! R^ V 4       4      pV'       d"   VR_,          P                  ^ ,          ^@,          M VR`,          P                  ^ ,          ^@,          pV! 4       ;_uu_ 4        \#        VVVVVRa7      pRRR4       VP                  4        EFx  w  rV
P                  RRb4      pVP                  RcRd4      pVP                  ReRf4      pVP                  RgRh4      pVP                  RiRj4      pVP                  RkRl4      pVP                  RmRn4      pVP                  RoRp4      pVP                  RqRr4      pRLV9   dt   VP%                  Rs4      pRtV^&   RsP'                  V4      pVP                  ^^ RM7      pV^ ,          WLP                  RLRN4      &   V^,          WLP                  RLRO4      &   EK"  RuV9   d/   VP%                  Rs4      pRtV^&   RsP'                  V4      pWV&   EKW  RPV9   d?   VP%                  Rs4      pRtV^&   RsP'                  V4      pWVP                  RPRQ4      &   EK  VP                  RvRw4      pVP                  RxRy4      pVP                  RzR{4      pVP                  R|R}4      pVP                  R~R4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pWV&   EK{  	  V'       g   VP)                  VRR7       V# RV P*                  /p\-        WTVV P.                  R7       \1        4        V#   + '       g   i     E	L; i  + '       g   i     EL; i  + '       g   i     EL; i  + '       g   i     ELz; i  + '       g   i     EL=; i)r   init_empty_weightsF,  Cannot initialize model with low cpu memory usage because `accelerate` was not found in the environment. Defaulting to `low_cpu_mem_usage=False`. It is strongly recommended to install `accelerate` for faster and less memory-intense model loading. You can do so with: 
```
pip install accelerate
```
.Tr   1.9.0~Low memory initialization requires torch >= 1.9.0. Please either update your PyTorch version or set `low_cpu_mem_usage=False`.Nproj.weight)r   image_embed_dimnum_image_text_embedsprojimage_embedsproj.3.weightzproj.0.weight)r   r   zproj.0zff.net.0.projzproj.2zff.net.2zproj.3norm"perceiver_resampler.proj_in.weightz#perceiver_resampler.proj_out.weightz*perceiver_resampler.layers.0.0.to_q.weight)
embed_dimsoutput_dimshidden_dimsheadsid_embeddings_dimzperceiver_resampler.r   z0.tozattn.toz0.1.0.z0.ff.0.z0.1.1.weightz0.ff.1.net.0.proj.weightz0.1.3.weightz0.ff.1.net.2.weightz1.1.0.z1.ff.0.z1.1.1.weightz1.ff.1.net.0.proj.weightz1.1.3.weightz1.ff.1.net.2.weightz2.1.0.z2.ff.0.z2.1.1.weightz2.ff.1.net.0.proj.weightz2.1.3.weightz2.ff.1.net.2.weightz3.1.0.z3.ff.0.z3.1.1.weightz3.ff.1.net.0.proj.weightz3.1.3.weightz3.ff.1.net.2.weightz
layers.0.0zlayers.0.ln0z
layers.0.1zlayers.0.ln1z
layers.1.0zlayers.1.ln0z
layers.1.1zlayers.1.ln1z
layers.2.0zlayers.2.ln0z
layers.2.1zlayers.2.ln1z
layers.3.0zlayers.3.ln0z
layers.3.1zlayers.3.ln1norm1z0.norm10norm2z0.norm21to_kv)dimto_kto_vr   zto_out.0zproj.net.0.proj.weightzproj.0.biaszproj.net.0.proj.biaszproj.2.weightzproj.net.2.weightzproj.2.biaszproj.net.2.biasnorm.weight)r   r   mult
num_tokenslatentszproj_in.weightzproj_out.weightc              3   ,   "   T F
  pR V9   x  K  	  R# 5i)r   NrL   rM   s   & r.   rP   ZUNet2DConditionLoadersMixin._convert_ip_adapter_image_proj_to_diffusers.<locals>.<genexpr>  s     "C
16Q;
rR   zlayers.0.attn.to_q.weightzlayers.0.0.to_q.weight)r   r   r   r   num_queriesz2.toz	0.0.norm1z0.ln0z	0.0.norm2z0.ln1z	1.0.norm1z1.ln0z	1.0.norm2z1.ln1z	2.0.norm1z2.ln0z	2.0.norm2z2.ln1z	3.0.norm1z3.ln0z	3.0.norm2z3.ln1r   r   to_qz0.1.0z0.ff.0z0.1.1z0.ff.1.net.0.projz0.1.3z0.ff.1.net.2z1.1.0z1.ff.0z1.1.1z1.ff.1.net.0.projz1.1.3z1.ff.1.net.2z2.1.0z2.ff.0z2.1.1z2.ff.1.net.0.projz2.1.3z2.ff.1.net.2z3.1.0z3.ff.0z3.1.1z3.ff.1.net.0.projz3.1.3z3.ff.1.net.2)strict
device_mapr\   )r   
accelerater   r   r   r   NotImplementedErrorr   r   r   r   r   r   r
   chunkr	   rd   r   r   r   r   rI   r   r\   r   )rs   rX   r@   r   updated_state_dictimage_projectioninit_contextr   clip_embeddings_dimr   r   r   diffusers_namer   r   r   r   r   v_chunkid_embeddings_dim_inid_embeddings_dim_out
multiplier
norm_layerr  attn_key_presentpartsr  s   &&&                        r.   +_convert_ip_adapter_image_proj_to_diffusersGUNet2DConditionLoadersMixin._convert_ip_adapter_image_proj_to_diffusers  s	   &((9 %*!2 $-=dG-L-L%. 
  ->)KJ&$%!",]";"A"A""E",]";"A"A!"D"I#2(;$7*?$    )..0
!$V^!D5:>2 1 
*",_"="C"CA"F",_"="C"CA"F#?(;$   
 )..0
!$X!G!/!7!7*!M!/!7!7&!I5:>2	 1 2Z? *? ; A A! D#$HIOOPQRJ$%IJPPQRSK$%JKQQRSTKKLRRSTUY[[E#E) + +&7$    )..0
!$-CR!H!/!7!7	!J!/!7!7)!L!/!7!7Hb!c!/!7!7H]!^!/!7!7)!L!/!7!7Hb!c!/!7!7H]!^!/!7!7)!L!/!7!7Hb!c!/!7!7H]!^!/!7!7)!L!/!7!7Hb!c!/!7!7H]!^!/!7!7n!U!/!7!7n!U!/!7!7n!U!/!7!7n!U!/!7!7n!U!/!7!7n!U!/!7!7n!U!/!7!7n!Un,QV~'='=i'MN.QV~'='=i'MN.#kk!k3GRYZ[R\&'='=gv'NORYZ[R\&'='=gv'NO/W\~'='=h
'ST$6CH'?@"n4AF'=>$6>C':;"n4<A'899>~6W 1Z j(#-o#>#D#DQ#G $.$?$E$Ea$H!.2FFJ&J",Z"8">">q"A#O4::1=ATTJ#A(;$8#)	$    )..0
!$X!G!/!7!7*!M5:>2 1 %/y$9$?$?$B!#$45;;A>J$%67==a@K$Y/55a8K"s"C
"Csss"C
"CC $ 67==a@BF 89??BbH  #?) + + 5$    )..0
!$VV!<!/!7!7W!M!/!7!7W!M!/!7!7W!M!/!7!7W!M!/!7!7W!M!/!7!7W!M!/!7!7W!M!/!7!7W!Mn,*005E%E!H%(XXe_N#kk!k3GRYZ[R\&'='=gv'NORYZ[R\&'='=gv'NO~-*005E%E!H%(XXe_N9>~6/*005E%E!H%(XXe_NW\~'='=h
'ST%3%;%;GX%NN%3%;%;GEX%YN%3%;%;G^%TN%3%;%;GX%NN%3%;%;GEX%YN%3%;%;G^%TN%3%;%;GX%NN%3%;%;GEX%YN%3%;%;G^%TN%3%;%;GX%NN%3%;%;GEX%YN%3%;%;G^%TN9>~6[ 1^ !,,-?,M  	 dkk*J%&6Waimisist w     &  ~  4  s<   gg1hh(h-g.	1h	h	h*	-h>	c           
        ^RI HpHpHp V'       d/   \	        4       '       d   ^ RIHp MRp\        P                  R4       VRJ d   \        RR4      '       g   \        R4      h/ p^pV'       d   XM\        p	V P                  P                  4        EFX  p
V
P                  R	4      '       d   R
MV P                  P                   pV
P#                  R4      '       d   V P                  P$                  R$,          pMV
P#                  R4      '       dL   \'        V
\)        R4      ,          4      p\+        \-        V P                  P$                  4      4      V,          pMOV
P#                  R4      '       d9   \'        V
\)        R4      ,          4      pV P                  P$                  V,          pVe   RV
9   d*   V P                  V
,          P.                  pV! 4       Wz&   EKM  R\1        V P                  V
,          P.                  4      9   d   TpM\3        \4        R4      '       d   TMTp. pV F  pRVR,          9   d   V^.,          pK  RVR,          9   d   VR.,          pK7  RVR,          9   d   V^.,          pKQ  RVR,          9   d   V^.,          pKk  VVR,          R,          P6                  ^,          .,          pK  	  V	! 4       ;_uu_ 4        V! XVRVR7      Wz&   R
R
R
4       / p\9        V4       FV  w  ppVP;                  RV R2VR,          V R2,          /4       VP;                  R V R2VR,          V R!2,          /4       KX  	  V'       g   Wz,          P=                  V4       Mq\?        \A        VPC                  4       4      4      PD                  p\?        \A        VPC                  4       4      4      PF                  pR"V/p\I        Wz,          VVVR#7       V^,          pEK[  	  \K        4        V#   + '       g   i     EL#; i)%r&   )IPAdapterAttnProcessorIPAdapterAttnProcessor2_0IPAdapterXFormersAttnProcessorr   Fr   Tr   r   r   zattn1.processorN	mid_block	up_blocksz
up_blocks.down_blockszdown_blocks.motion_modulesXFormersscaled_dot_product_attentionr   
image_projr   i  r   r	  r  g      ?)r   r   scaler  zto_k_ip.z.weight
ip_adapterz.to_k_ip.weightzto_v_ip.z.to_v_ip.weightr   r  r  )&r   r'  r(  r)  r   r  r   r   r   r   r  r   r~   re   rU   configr   r   block_out_channelsintr   r   reversed	__class__r(   hasattrFr   	enumerateupdater   nextiterrp   rI   r\   r   r   )rs   state_dictsr@   r'  r(  r)  r   
attn_procskey_idr  r   r   r   block_idattn_processor_classr   rX   r   irI   r\   r  s   &&&                   r.   %_convert_ip_adapter_attn_to_diffusersAUNet2DConditionLoadersMixin._convert_ip_adapter_attn_to_diffusers  s   	
 	
 &((9 %*!2 $-=dG-L-L%.  
->)K((--/D*.--8I*J*J$PTP[P[PoPo{++"kk<<R@--tC$567"8DKK,J,J#KLXV//tC$789"kk<<XF"*.>$.F'+';';D'A'K'K$#7#9
 T%9%9$%?%I%I!JJ+I( #1&DEE 23 )
 )+%"-J$
<(@@-!4-(J|,DD-#6-=LAYY-!4-&*\*BB-!4- .*\2J92U2[2[\]2^1__- #." "^^';$/,?!#8	(J$ $  
%.{%;MAz%%!G'<j>VZ`YaapWq>r&st%%!G'<j>VZ`YaapWq>r&st &< )$44Z@!$z'8'8':";<CCF j&7&7&9!:;AAE"$fJ-j.>
Waino!} 0@ 	3 $^^s   O;;Pc                    \        V\        4      '       g   V.pV P                  e?   V P                  P                  R8X  d$   \        V R4      '       g   V P                  V n        R V n        V P                  WR7      pV P                  V4       . pV F.  pV P                  VR,          VR7      pVP                  V4       K0  	  \        V4      V n        RV P                  n        V P                  V P                  V P                  R7       R # )N	text_projtext_encoder_hid_proj)r@   r0  ip_image_projr[   )r`   r   encoder_hid_projr3  encoder_hid_dim_typer8  rH  rD  rk   r$  appendr   rl   r\   rI   )rs   r>  r@   r?  image_projection_layersrX   image_projection_layers   &&&    r.   _load_ip_adapter_weights4UNet2DConditionLoadersMixin._load_ip_adapter_weights\  s    +t,,&-K !!-00K?D"9::)-)>)>D& !%???q

+ #%%J%)%U%U<(<M &V &" $**+AB	 & !>>U V+:(djj5r1   c                   / p\        V P                  P                  4       4       EF  w  r4\        V4       EF  w  rVV R 2VR,          9   g   K  WR9  d   / W%&   W%,          P                  RV R 2VR,          V R 2,          /4       W%,          P                  RV R2VR,          V R2,          /4       W%,          P                  RV R2VR,          V R2,          /4       W%,          P                  RV R2VR,          V R2,          /4       W%,          P                  RV R2VR,          V R2,          /4       W%,          P                  RV R2VR,          V R2,          /4       W%,          P                  RV R2VR,          V R2,          /4       W%,          P                  RV R	2VR,          V R	2,          /4       EK  	  EK  	  V# )
z.to_k_lora.down.weightr2  zunet.z.to_q_lora.down.weightz.to_v_lora.down.weightz.to_out_lora.down.weightz.to_k_lora.up.weightz.to_q_lora.up.weightz.to_v_lora.up.weightz.to_out_lora.up.weight)r:  r~   re   r;  )rs   r>  
lora_dictsr@  r   rC  rX   s   &&     r.   _load_ip_adapter_loras2UNet2DConditionLoadersMixin._load_ip_adapter_loras|  s7   
%d&:&:&?&?&ABLF!*;!7X34
<8PP*(*
M((#D6)?@*\BZ#)(*@ AC M((#D6)?@*\BZ#)(*@ AC M((#D6)?@*\BZ#)(*@ AC M((#D6)ABJ|D\#)(*B CE M(( &:;Z=UY_X``tVu=vw M(( &:;Z=UY_X``tVu=vw M(( &:;Z=UY_X``tVu=vw M((#D6)?@*\BZ#)(*@ ACS "8 Cb r1   )rJ  rH  )TNNT)__name__
__module____qualname____firstlineno____doc__r    text_encoder_namer!   ri   r   rV   rg   rh   classmethodrj   r   r   r   r$  rD  rO  rS  __static_attributes____classdictcell__)r-   s   @r.   r$   r$   <   s      *IyJ yJx DsQj H Hd; d;L8 Ys Y v Tn `D Ga 6@3 3r1   r$   )8r   collectionsr   
contextlibr   pathlibr   typingr   ra   r*   torch.nn.functionalrq   
functionalr9  huggingface_hub.utilsr   models.embeddingsr   r	   r
   r   r   r   models.model_loading_utilsr   models.modeling_utilsr   r   utilsr   r   r   r   r   r   r   r   r   r   utils.torch_utilsr   	lora_baser   lora_pipeliner   r   r    r!   r"   
get_loggerrU  r   r   r   r$   rL   r1   r.   <module>rm     s    
 # "       6  C O   3 : ` ` " 
		H	%  F $R !s sr1   