
    +h=                         S r SSKJr  SSKrSSKJr  SSKrSSKJ	r	  SSK
Jr  SSKJr  \R                  " \5      rS rS	 rg)
z!PyTorch - Flax general utilities.    )UnpicklingErrorN)
from_bytes)flatten_dict   )loggingc                     [        US5       n[        S UR                  5       5      nS S S 5        [        U W5      $ ! , (       d  f       N= f! [         a  n [        U5       nUR                  5       R	                  S5      (       a  [        S5      e[        Ue! , (       d  f        S nAN|= f! [        [        4 a    [        SU S35      ef = fS nAff = f)NrbversionzYou seem to have cloned a repository without having git-lfs installed. Please install git-lfs and run `git lfs install` followed by `git lfs pull` in the folder you cloned.zUnable to convert z  to Flax deserializable object. )
openr   readr   
startswithOSError
ValueErrorUnicodeDecodeErrorEnvironmentError"load_flax_weights_in_pytorch_model)pt_model
model_fileflax_state_f
flax_stateefs         f/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/models/modeling_pytorch_flax_utils.py%load_flax_checkpoint_in_pytorch_modelr   %   s    f*d#|#D,*;*;*=>J $  .h
CC! $# f	fj!Q668&&y11!.  %!+ "!! #J/ 	f"%7
|Cc#dee	ffsU   A =A 
AA A 
CB0$7B
B-	%B0-B00 CCCc                     SSK n[	        [
        R                  R                  S U5      5      R                  5       n[        U5      (       a6  [        R                  S5        [
        R                  R                  S U5      nSU l        [	        USS	9nU R                  5       n/ n[        UR                  5       5      nUR                  5        GH  u  pUR!                  S5      n
U
S
   S:X  a1  U	R"                  S:X  a!  U
SS
 S/-   n
[$        R&                  " U	S5      n	O1U
S
   S:X  a  U
SS
 S/-   n
U	R(                  n	OU
S
   S:X  a	  U
SS
 S/-   n
SU
;  a  [+        U
5       H  u  pUR-                  SS5      R-                  SS5      R-                  SS5      R-                  SS5      R-                  SS5      R-                  SS5      R-                  SS5      R-                  SS 5      R-                  S!S"5      R-                  S#S$5      X'   M     SR/                  U
5      nX;   a  U	R0                  X]   R0                  :w  a+  [3        S%U S&X]   R0                   S'U	R0                   S35      e[5        U	[6        R8                  5      (       d  [6        R:                  " U	5      OU	n	UR=                  U	5      X]'   UR?                  U5        GM  URA                  U5        GM     U RC                  U5        [E        U5      n[G        U5      S:  a^  [        R                  S(U RH                  RJ                   S)U S*U RH                  RJ                   S+U RH                  RJ                   S,3	5        [G        U5      S:  a0  [        R                  S-U RH                  RJ                   S.U S/35        U $ ! [         a    [        R                  S5        e f = f)0z(Load flax checkpoints in a PyTorch modelr   NzLoading Flax weights in PyTorch requires both PyTorch and Flax to be installed. Please see https://pytorch.org/ and https://flax.readthedocs.io/en/latest/installation.html for installation instructions.c                 <    U R                   [        R                  :H  $ N)dtypejnpbfloat16)xs    r   <lambda>4load_flax_weights_in_pytorch_model.<locals>.<lambda>H   s    CLLAX    zFound ``bfloat16`` weights in Flax model. Casting all ``bfloat16`` weights to ``float32`` before loading those in PyTorch model.c                     U R                   [        R                  :X  a  U R                  [        R
                  5      $ U $ r   )r   r   r    astypenpfloat32)paramss    r   r"   r#   R   s)    8T6==4`Z``r$    .)sepkernel   weight)   r   r      scaletime_embedding_0z.0_1z.1_2z.2_3z.3_4z.4_5z.5_6z.6_7z.7_8z.8_9z.9z.Flax checkpoint seems to be incorrect. Weight z was expected to be of shape z	, but is zQSome weights of the Flax model were not used when initializing the PyTorch model z: z,
- This IS expected if you are initializing z from a Flax model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a FlaxBertForPreTraining model).
- This IS NOT expected if you are initializing z from a Flax model that you expect to be exactly identical (e.g. initializing a BertForSequenceClassification model from a FlaxBertForSequenceClassification model).zSome weights of zE were not initialized from the Flax model and are newly initialized: zo
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.)&torchImportErrorloggererrorr   jax	tree_utiltree_mapvaluesanywarningbase_model_prefix
state_dictsetkeysitemssplitndimr   	transposeT	enumeratereplacejoinshaper   
isinstancer'   ndarrayasarray
from_numpyremoveappendload_state_dictlistlen	__class____name__)r   r   r?   is_type_bf16flax_state_dictpt_model_dictunexpected_keysmissing_keysflax_key_tupleflax_tensorflax_key_tuple_arrayiflax_key_tuple_stringflax_keys                 r   r   r   :   s      6 67XZd efmmoL
< 	5	
 ]]++`bl

 "$H":37O'')M O}))+,L'6'<'<'>#-33C8#x/K4D4D4I#7#<z#I --\BK!"%1#7#<z#I %--K!"%0#7#<z#I #77,56J,K()11$=WT4(WT4(WT4(WT4(WT4(WT4(WT4(WT4(WT4( %' -L 8801$  M$;$A$AA D^DT U&&3&=&C&C%DIkN_N_M``ac  >HUWU_U_=`=`bjj5fq*/*:*:;*G'##H- ""8,W (?Z ]+ %L
?a""++,B.? @""++, -88@8J8J8S8S7T U9	9	
 <1x11::; <)N +55	
 OE  	

 	s   N+ +!O)__doc__pickler   rC   	jax.numpynumpyr   r'   flax.serializationr   flax.traverse_utilr   utilsr   
get_loggerr`   rA   r   r    r$   r   <module>ru      s=    ( " 
   ) +  
		H	%D*gr$   