ó
    ÷“,jÊ  ã            /       óð  • S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJrJrJrJrJr  S SKrSSKJr  SSKJrJrJrJrJrJrJrJr  SS	KJr  SS
KJ r J!r!J"r"J#r#  SSK$J%r%J&r&J'r'J(r(J)r)  SSK*J+r+J,r,J-r-J.r.J/r/  SSK0J1r1J2r2J3r3J4r4  Sr5\
" \65      Rn                  S-  /r80 q9S r:S r;\;" 5         S r<S r=Sr5Sr>S\?S\\\?   \?4   4S jr@ SDS\?S\\?   4S jjrAS rB  SES\?4S jjrC   SFS\\\4   S\?S\DS \D4S! jjrES"\
S\\?   4S# jrF                   SGS\?S$\\?   S%\DS&\?S'\\?\RŽ                  4   S(\DS)\DS*\DS+\\H   S,\\\I\\I\I4   4      S-\\\?\4      S.\\I   S/\DS0\DS1\\?   S2\\?   S\\?   S3\\D   S4\DS \DS\R”                  R–                  4*S5 jjrL   SHS\?S6\\I   S\\?   4S7 jjrM SIS\R”                  R–                  S'\RŽ                  S&\?S8\D4S9 jjrNS: rO                      SJS\?S$\\?   S%\DS&\?S'\\?\RŽ                  4   S(\DS)\DS*\DS+\\H   S,\\\I\\I\I4   4      S.\\I   S;\\\HS<4      S=\\\HS<4      S>\\?   S?\\?   S@\\\\?\4   \,4      S/\DS0\DS1\\?   S2\\?   S\\?   S3\\D   S \D4.SA jjrP               SKS\?S$\\?   S&\?S'\\?\RŽ                  4   S(\DS)\DS*\DS,\\\I\\I\I4   4      S.\\I   S;\\\HS<4      S=\\\HS<4      S>\\?   S?\\?   SB\DS\\?   S \D4 SC jjrQg)Lé    N)Údeepcopy)Úasdict)ÚPath)ÚAnyÚDictÚOptionalÚTupleÚUnioné   )Úconvert_state_dict)ÚCLIPÚCustomTextCLIPÚconvert_weights_to_lpÚ!convert_to_custom_text_state_dictÚresize_pos_embedÚget_cast_dtypeÚresize_text_pos_embedÚset_model_preprocess_cfg)ÚCoCa)ÚClipLossÚDistillClipLossÚCoCaLossÚ
SigLipLoss)Úis_pretrained_cfgÚget_pretrained_cfgÚdownload_pretrainedÚlist_pretrained_tags_by_modelÚdownload_pretrained_from_hf)Úimage_transform_v2ÚAugmentationCfgÚPreprocessCfgÚmerge_preprocess_dictÚmerge_preprocess_kwargs)ÚHFTokenizerÚSimpleTokenizerÚSigLipTokenizerÚDEFAULT_CONTEXT_LENGTHzhf-hub:zmodel_configs/c                 ó¶   • [         R                  " SU R                  5       5       Vs/ s H$  oR                  5       (       a  [	        U5      OUPM&     sn$ s  snf )Nz(\d+))ÚreÚsplitÚlowerÚisdigitÚint)Ústring_Úss     ÚŸC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\open_clip/factory.pyÚ_natural_keyr1      s>   € Ü24·(²(¸8ÀWÇ]Á]Ã_Ô2UÓVÒ2U¨Q—i‘i—k‘kŒC�ŒF qÒ(Ñ2UÑVÐVùÒVs   ¨+Ac                  ót  ^• Sn / n[          H~  nUR                  5       (       a#  UR                  U ;   a  UR                  U5        M;  UR	                  5       (       d  MR  U  H&  nUR                  UR                  SU 35      5        M(     M€     U H[  n[        US5       n[        R                  " U5      m[        U4S jS 5       5      (       a  T[        UR                  '   S S S 5        M]     [        [        R                  5       S S9 VVs0 s H  u  pgXg_M	     snnqg ! , (       d  f       M¡  = fs  snnf )N)z.jsonÚ*Úrc              3   ó,   >#   • U  H	  oT;   v •  M     g 7f©N© )Ú.0ÚaÚ	model_cfgs     €r0   Ú	<genexpr>Ú(_rescan_model_configs.<locals>.<genexpr>/   s   øé € ÐSÒ+R a˜	–>Ò+Rùs   ƒ)Ú	embed_dimÚ
vision_cfgÚtext_cfgc                 ó   • [        U S   5      $ )Nr   )r1   ©Úxs    r0   Ú<lambda>Ú'_rescan_model_configs.<locals>.<lambda>2   s   € ÔT`ÐabÐcdÑaeÔTfó    ©Úkey)Ú_MODEL_CONFIG_PATHSÚis_fileÚsuffixÚappendÚis_dirÚextendÚglobÚopenÚjsonÚloadÚallÚ_MODEL_CONFIGSÚstemÚsortedÚitems)	Ú
config_extÚconfig_filesÚconfig_pathÚextÚcfÚfÚkÚvr:   s	           @r0   Ú_rescan_model_configsr_       s   ø€ ð €JØ€Lß*ˆØ×Ñ× Ñ  [×%7Ñ%7¸:Ó%EØ×Ñ Ö,Ø×Ñ×!Ó!Û!�Ø×#Ñ# K×$4Ñ$4°q¸¸°YÓ$?Ö@ó "ñ	 +ó ˆÜ�"�cŒ]˜aÜŸ	š	 !›ˆIÜÔSÑ+RÓS×SÑSØ*3”˜rŸw™wÑ'÷ ‰]ñ ô (.¬n×.BÑ.BÓ.DÑJfÒ'gÔhÒ'g™t˜q�a’dÑ'gÒh�N÷ Ž]üó
 is   ÂAD"ÄD4Ä"
D1	c                  ó<   • [        [        R                  5       5      $ )z>enumerate available model architectures based on config files )ÚlistrS   Úkeysr7   rE   r0   Úlist_modelsrc   8   s   € ä”×#Ñ#Ó%Ó&Ð&rE   c                 ó‚   • [        U [        5      (       d  [        U 5      n [        R                  U 5        [	        5         g)z2add model config path or file and update registry N)Ú
isinstancer   rH   rK   r_   )Úpaths    r0   Úadd_model_configrg   =   s,   € ä�dœD×!Ñ!Ü�D‹zˆÜ×Ñ˜tÔ$ÜÕrE   z
local-dir:Ú
model_nameÚreturnc                 ó  • U R                  [        5      (       a(  U [        [        5      S nU(       d  [        S5      eSU4$ U R                  [        5      (       a(  U [        [        5      S nU(       d  [        S5      eSU4$ SU 4$ )a¬  
Parses a model name string to identify a schema and the remaining identifier.

Args:
    model_name: The model name string (e.g., 'ViT-B-32',
                'hf-hub:org/repo', 'local-dir:/path/to/dir',
                'local-dir:./relative/path').

Returns:
    A tuple (schema, identifier):
      - schema (Optional[str]): 'hf-hub', 'local-dir', or None if no schema detected.
      - identifier (str): The part after the schema prefix, or the original
                          string if no schema was present. For 'local-dir',
                          this is the raw path string provided.
Raises:
    ValueError: If a schema prefix is present but the identifier part is empty.
Nz/Empty path specified after 'local-dir:' schema.ú	local-dirz2Empty identifier specified after 'hf-hub:' schema.úhf-hub)Ú
startswithÚLOCAL_DIR_PREFIXÚlenÚ
ValueErrorÚHF_HUB_PREFIX)rh   Ú
identifiers     r0   Úparse_model_namers   I   s‘   € ð& ×ÑÔ-×.Ñ.à¤Ô$4Ó 5Ð 6Ð7ˆ
æÜÐNÓOÐOð ˜JÐ&Ð&ð 
×	Ñ	œ}×	-Ñ	-à¤¤MÓ 2Ð 3Ð4ˆ
æÜÐQÓRÐRà˜Ð#Ð#ð
 �ZÐÐrE   Úmodel_idÚ	cache_dirc                 ó”   • [        U SUS9n[        USSS9 n[        R                  " U5      nSSS5        U$ ! , (       d  f       W$ = f)z-Fetch model config from HuggingFace Hub.
    úopen_clip_config.json)Úfilenameru   r4   úutf-8©ÚencodingN)r   rO   rP   rQ   )rt   ru   rY   r\   Úconfigs        r0   Ú_get_hf_configr}   w   sL   € ô .ØØ(Øñ€Kô
 
ˆk˜3¨Ò	1°QÜ—’˜1“ˆ÷ 
2à€M÷ 
2Ô	1à€Mús	   —8¸
Ac                 ó^  • [        U 5      u  pUS:X  aJ  [        U5      S-  n[        USSS9 n[        R                  " U5      nSSS5        WR                  SU5      $ US:X  a  [        U5      nUR                  SU5      $ U [        ;   a  [        [        U    5      $ g! , (       d  f       N`= f)	zPFetch model config from schema specified location or local library configs.
    rk   rw   r4   ry   rz   Nr:   rl   )	rs   r   rO   rP   rQ   Úgetr}   rS   r   )rh   Úlocrt   Ú
local_pathr\   r|   s         r0   Úget_model_configr‚   ‡   sž   € ô % ZÓ0�M€CØ
ˆkÓÜ˜(“^Ð&=Ñ=ˆ
Ü�*˜c¨GÒ4¸Ü—Y’Y˜q“\ˆF÷ 5à�z‰z˜+ vÓ.Ð.Ø	�‹Ü Ó)ˆØ�z‰z˜+ vÓ.Ð.Ø	”~Ó	%Üœ zÑ2Ó3Ð3à÷ 5Õ4ús   ­BÂ
B,Úcheckpoint_pathc                 ó�  • [        U 5      R                  S5      (       a  SSKJn  U" XS9nO [        R
                  " XUS9n[        U[        5      (       a  SU;   a  US   nOW[        U[        R                  R                  5      (       a,  UR                  5       nS H  nUR                  US 5        M     OUn[        [        UR                  5       5      5      S   R!                  S	5      (       a(  UR                  5        VVs0 s H  u  pxUS
S  U_M     nnnU$ ! [         a    [        R
                  " XS9n Nûf = fs  snnf )Nú.safetensorsr   )Ú	load_file©Údevice)Úmap_locationÚweights_only)r‰   Ú
state_dict)Úinput_resolutionÚcontext_lengthÚ
vocab_sizeÚmoduleé   )ÚstrÚendswithÚsafetensors.torchr†   ÚtorchrQ   Ú	TypeErrorre   ÚdictÚjitÚScriptModuler‹   ÚpopÚnextÚiterrV   rm   )	rƒ   rˆ   rŠ   r†   Ú
checkpointr‹   rG   r]   r^   s	            r0   Úload_state_dictr�   ™   s"  € ô ˆ?Ó×$Ñ$ ^×4Ñ4Ý/Ù˜Ñ>‰
ð	JÜŸš OÐWcÑdˆJô �*œd×#Ñ#¨¸
Ó(BØ Ñ-‰
Ü	�J¤§	¡	× 6Ñ 6×	7Ñ	7Ø×*Ñ*Ó,ˆ
ÛGˆCØ�N‰N˜3 Ö%ò Hð  ˆ
ÜŒD�×!Ñ!Ó#Ó$Ó% aÑ(×3Ñ3°H×=Ñ=Ø+5×+;Ñ+;Ô+=Ô>Ò+=¡4 1�a˜˜�e˜Q’hÑ+=ˆ
Ñ>ØÐøô ó 	JÜŸš OÑIŠJð	Jüó ?s   ®D ÄEÄD?Ä>D?ÚmodelÚstrictrŠ   c                 ó   • [        U5      R                  S;   a  SSKJn  U" X5        0 $ [	        XUS9n[        X5      nSU;   a  [        U S5      (       d  [        U5      nSU;   aR  U R                  R                  US   R                  :w  a+  US   R                  U R                  R                  5      US'   SU;   aR  U R                  R                  US   R                  :w  a+  US   R                  U R                  R                  5      US'   SU;  a)  U R                  b  [        R                  " US   5      US'   SnXv;   a  [        X5      (       d  Xg	 [        X`5        [!        X`5        U R	                  XbS	9nU$ )
N)z.npzz.npyr   )Úload_big_vision_weights©rˆ   rŠ   Úpositional_embeddingÚlogit_scaleÚ
logit_biasz(text.transformer.embeddings.position_ids©rŸ   )r   rJ   Úopen_clip.convertr¡   r�   r   Úhasattrr   r¤   ÚndimÚreshapeÚshaper¥   r”   Ú
zeros_liker   r   )	rž   rƒ   rŸ   rŠ   rˆ   r¡   r‹   Úposition_id_keyÚincompatible_keyss	            r0   Úload_checkpointr¯   µ   sv  € ô ˆOÓ×#Ñ#Ð'7Ó7å=Ù Ô7Øˆ	ä  ÈlÑ[€Jô $ EÓ6€Jð  Ó+´G¸EÐCY×4ZÑ4ZÜ6°zÓBˆ
ð ˜
Ó" u×'8Ñ'8×'=Ñ'=ÀÈMÑAZ×A_ÑA_Ó'_Ø$.¨}Ñ$=×$EÑ$EÀe×FWÑFW×F]ÑF]Ó$^ˆ
�=Ñ!ð �zÓ! e×&6Ñ&6×&;Ñ&;¸zÈ,Ñ?W×?\Ñ?\Ó&\Ø#-¨lÑ#;×#CÑ#CÀE×DTÑDT×DZÑDZÓ#[ˆ
�<Ñ ð ˜:Ó%¨%×*:Ñ*:Ñ*FÜ#(×#3Ò#3°J¸}Ñ4MÓ#Nˆ
�<Ñ ð A€OØÓ$¬W°U×-LÑ-LØÐ'ä�ZÔ'Ü˜*Ô,ð ×-Ñ-¨jÐ-ÐHÐØÐrE   Údir_pathc           	      ó   ^• [        U R                  S5      5      [        U R                  S5      5      -   [        U R                  S5      5      -   nU(       d  g UR                  5         UR                  S SS9  / SQmU Vs/ s H  o"R                  T;   d  M  UPM     nnU(       aI  UR                  U4S jS	9  US
   n[        R
                  " SUR                   SU  35        [        U5      $ US
   n[        R                  " SU  SU Vs/ s H  o"R                  PM     sn SUR                   S35        [        U5      $ s  snf s  snf )Nz*.safetensorsz*.binz*.pthc                 ó    • U R                   S:H  $ )Nr…   )rJ   rA   s    r0   rC   Ú)_find_checkpoint_in_dir.<locals>.<lambda>é   s   €  1§8¡8¨~Ò#=rE   T)rG   Úreverse)zopen_clip_model.safetensorsz#open_clip_pytorch_model.safetensorszopen_clip_pytorch_model.binzopen_clip_pytorch_model.pthzmodel.safetensorszpytorch_model.binzpytorch_model.pthz	model.pthc                 ó:   >• TR                  U R                  5      $ r6   )ÚindexÚname)rB   Úpreferred_orders    €r0   rC   r³   ñ   s   ø€ °×1FÑ1FÀqÇvÁvÔ1NrE   rF   r   z!Found preferred checkpoint file: z in zMultiple checkpoints found in ú: z	. Using 'z'.)ra   rN   Úsortr·   ÚloggingÚinfor‘   Úwarning)r°   ÚcheckpointsÚcÚpreferred_checkpointsÚchosenr¸   s        @r0   Ú_find_checkpoint_in_dirrÂ   ä   s5  ø€ Ü�x—}‘} _Ó5Ó6¼¸h¿m¹mÈGÓ>TÓ9UÑUÔX\Ð]e×]jÑ]jÐkrÓ]sÓXtÑt€KÞØØ×ÑÔØ×ÑÑ=ÀtÐÑLò€Oñ
 )4ÓQª 1·v±vÀÑ7PŸQ©ÐÐQÞØ×"Ñ"Ô'NÐ"ÑOØ& qÑ)ˆÜ�ŠÐ8¸¿¹¸ÀTÈ(ÈÐTÔUÜ�6‹{ÐØ˜‰^€FÜ‡O‚OØ
(¨¨
°"ÁkÓ5RÂkÀ·f´fÁkÑ5RÐ4SÐS\Ð]c×]hÑ]hÐ\iÐikÐlônäˆv‹;Ðùò Rùò 6Ss   ÂEÂEÄEÚ
pretrainedÚload_weightsÚ	precisionrˆ   r—   Úforce_quick_geluÚforce_custom_textÚforce_patch_dropoutÚforce_image_sizeÚforce_preprocess_cfgÚforce_context_lengthÚpretrained_imageÚpretrained_textÚpretrained_image_pathÚpretrained_text_pathÚoutput_dictÚrequire_pretrainedc           
      ó"  • [        U 5      u  nnSU;   a  UR                  S5      n[        U[        5      (       a  [        R
                  " U5      nSn[        [        5       5      nSnSn[        R                  " SU SU 35        U(       a&  U(       a  [        R                  " SU SU S35        SnUS:X  Ga1  [        U5      nUR                  5       (       d  [        S	U 35      eUS
-  n[        R                  " SU 35        UR                  5       (       aÂ   [        USSS9 n[         R"                  " U5      nSSS5        SW;   a‚  US   n[%        UUR'                  S0 5      5      n[        R                  " SU 35        [)        U5      nU(       a  [        R                  " SU 35        GOÖ[        R                  " SU 35        GO»[+        SU S35      e[        SU 35      eUS:X  a™  Un [        R                  " SU  35         [/        U US9n!SU!;  a  [1        SU  35      eU!S   n[%        UU!R'                  S0 5      5      n[        R                  " SU  35         [3        U US9n[        R                  " SU 35        OÿUcü  UR5                  S"S#5      n$[7        U$5      nUc  [1        S$U$ S%[9        5        35      e[        R                  " S&U$ S'35        U(       a¢  [;        U$U5      nU(       a   [=        UUS9n[%        UU5      nOw[@        RB                  RE                  U5      (       a  [        R                  " S)U 35        UnO7[        R>                  " S*U S+U$ S,[G        U$5       35        [1        S-U S.35      eUc  [1        S/5      eUS0   n%US1   n&U(       a  S2US3'   Ub  UU&S4'   U	b  U	U&S5'   Ub  UU%S6'   UcV  U(       aO  UR'                  S3S75      n'UR'                  S3S75      n(U(U':w  a%  [H        RJ                  " S8U' S9U S:U( S;3[L        5        Ub$  U(       d  [        R                  " S<U S=35        SnO[        R                  " S>5        U=(       a    USL =(       a    USL n)U=(       a    USL =(       a    USL n*S?UR'                  S10 5      ;   n+S@UR'                  S00 5      ;   n,U+(       a  U)U&SA'   OS7n)U,(       a  U*U%SB'   OS7n*UR                  SCS75      =(       d    U=(       d    U,n-U-(       a  SDU;   a  [N        n.O[P        n.O[R        n.[U        U5      n/U/RW                  U5        [Y        U5      n0[        R                  " SEU.RZ                   35        U." Sk0 U/DSFU00D6n1[]        U1XCU+5        S7n2U(       a(  [        R                  " SGU 35        [_        U1US2USHSI9  S2n2S7n3U(       aÆ  [@        RB                  RE                  U5      (       a‰  [        R                  " SJU 35         [a        USHUSK9n4[c        U1SL5      (       a9  U1Rd                  Ra                  U4S7SM9n5[        R                  " SNU SOU5 35        S2n3O3[        R                  " SPU 35        O[        R                  " SRU 35        S7n6U(       a»  [@        RB                  RE                  U5      (       a~  [        R                  " SSU 35         [a        USHUSK9n7[g        U1STU15      n8U8b/  U8Ra                  U7S7SM9n5[        R                  " SUU SOU5 35        S2n6O3[        R                  " SVU 35        O[        R                  " SXU 35        U*=(       d    U)=(       d    U3=(       d    U6n9U(       a  U2(       d  [1        SYU  SZU S[35      eU2(       d"  U9(       a  [        R                  " S\U  S]35        O(U2(       d!  U9(       d  [        R                  " S^U  S_35        U(       a  [c        U1S`5      (       a  S2U1l4        U	bW  U+(       aP  [c        U1Rd                  Sa5      (       a5  [        R                  " SbU	 Sc35        U1Rd                  Rk                  U	5        U(       aL  [        R                  " Sd5         [        Rl                  Ro                  U15      n1[        R                  " Se5        [U        U5      n:[g        U1SLS5      n;U;b   [c        U;S55      (       a  U;Rp                  U:Sh'   [%        U:U
=(       d    0 5      n:[s        U1U:5        [        R                  " SiU: 35        [        R                  " S\U  Sj35        U1$ ! , (       d  f       GNó= f! [,         a  n[+        SU SU 35      UeSnAff = f! [,         a'  n"[        R                  " SU  S U" 35         Sn"A"GNSn"A"ff = f! [,         a  n#[1        S!U  S U# 35      U#eSn#A#ff = f! [,         a2  n[        R>                  " S(U SU 35        [1        S(U SU 35      eSnAff = f! [,         a'  n[        R>                  " SQU S U 35         SnAGN¨SnAff = f! [,         a'  n[        R>                  " SWU S U 35         SnAGNSnAff = f! [,         a%  n[        R                  " SfU Sg35         SnAGNðSnAff = f)la4	  
Creates and configures a contrastive vision-language model.

`model_name` specifies architecture/config source:
  - 'ViT-B-32': Built-in model name. `pretrained` specifies CLIP weights source (tag or file path).
  - 'hf-hub:org/repo': Loads config/weights from HF Hub. `pretrained` is IGNORED.
  - 'local-dir:/path/to/folder': Loads config/weights from local dir. `pretrained` is IGNORED.

Base tower weights loading controlled by `pretrained_image` and `pretrained_text` flags,
only effective if no full CLIP checkpoint (`pretrained` or schema source) is loaded.

Tower-specific weights can be loaded *after* creation via `pretrained_image_path`
and `pretrained_text_path`.

Args:
    model_name: Model identifier, potentially with schema ('hf-hub:', 'local-dir:').
    pretrained: Source for CLIP weights (tag or file path) ONLY if model_name has no schema.
    load_weights: Load the resolved pretrained weights if True, otherwise random init or tower overrides only.
    precision: Model precision ('fp32', 'fp16', 'bf16', ...).
    device: Device ('cpu', 'cuda', ...).
    jit: If True, JIT compile the model.
    force_quick_gelu: Force use of QuickGELU activation in model config.
    force_custom_text: Force use of custom text encoder architecture.
    force_patch_dropout: Override patch dropout value in model config.
    force_image_size: Override image size in model config.
    force_preprocess_cfg: Dict to override specific FINAL preprocessing parameters.
    force_context_length: Override context length in model config.
    pretrained_image: Load default base weights for image tower at creation if no CLIP weights loaded.
    pretrained_text: Load default base weights for text tower at creation if no CLIP weights loaded (default: True).
    pretrained_image_path: Path to load weights specifically into image tower after creation.
    pretrained_text_path: Path to load weights specifically into text tower after creation.
    cache_dir: Cache directory for downloads.
    output_dict: If True and model supports it, return dict output.
    require_pretrained: Raise error if no `pretrained` CLIP weights loaded when required.
    weights_only: Use weights_only=True for torch.load (safer).
    **model_kwargs: Additional keyword arguments for model constructor (highest override priority).

Returns:
    The created model instance.
Úpretrained_hfNz"Parsing model identifier. Schema: ú, Identifier: zIgnoring `pretrained='z'` because `model_name` has 'z	' schema.rk   z7Directory specified via 'local-dir:' schema not found: rw   z*Attempting to load config from local dir: r4   ry   rz   r:   Úpreprocess_cfgz)Loaded model config and preprocess from: z$Found CLIP weights in local folder: z2Local config loaded, but no CLIP weights found in úLocal config ú missing 'model_cfg'.z6Could not load valid config from specified 'local-dir:z': ú1'local-dir:' specified, but config file missing: rl   z'Attempting to load config from HF Hub: ©ru   z%'model_cfg' not found in config from z!Loaded model config from HF Hub: z&Found default weights file on HF Hub: z6Could not find/download default weights on HF Hub for r¹   z/Failed initial config/weights load from HF Hub Ú/Ú-zModel config for 'z%' not found in built-ins. Available: zLoaded built-in z model config.z$Failed to download weights for tag 'z"`pretrained` specifies file path: zPretrained tag or path (z) for 'z' not found. Available tags: zPretrained value 'z'' is not a known tag or valid file pathz:Model configuration could not be determined after Stage 1.r?   r>   TÚ
quick_geluÚpatch_dropoutÚ
image_sizer�   Fz:QuickGELU mismatch between final model config (quick_gelu=z) and pretrained tag 'z' (quick_gelu=ú).zPotential checkpoint path 'z;' found, but skipping assignment due to load_weights=False.zHNo potential checkpoint path found from config source or pretrained arg.Útimm_model_nameÚhf_model_nameÚtimm_model_pretrainedÚhf_model_pretrainedÚcustom_textÚmultimodal_cfgz"Instantiating model architecture: Ú
cast_dtypez&Loading full pretrained weights from: Úcpu)rŸ   rŠ   rˆ   z-Attempting to load image tower weights from: r¢   Úvisualr¦   z Loaded image tower weights from z. Incompatible keys: zOModel does not have a 'visual' attribute, cannot load image tower weights from z'Error loading image tower weights from z7Invalid file path specified for pretrained_image_path: z,Attempting to load text tower weights from: ÚtextzLoaded text tower weights from zUModel does not have a standard 'text' attribute, cannot load text tower weights from z&Error loading text tower weights from z6Invalid file path specified for pretrained_text_path: z*Required pretrained weights (`model_name='z', pretrained='z'`) could not be loaded. zModel z initialized partially.z(No pretrained weights loaded for model 'z'. Model initialized randomly.rÐ   Úset_input_sizezCalling set_input_size(z) on timm vision model.zAttempting JIT scripting...zJIT scripting successful.zJIT scripting failed: z. Returning non-JIT model.Úsizez-Final image preprocessing configuration set: z creation process complete.r7   ):rs   r™   re   r‘   r”   rˆ   r   r!   r»   r¼   r½   r   rL   ÚFileNotFoundErrorrI   rO   rP   rQ   r"   r   rÂ   rp   Ú	Exceptionr}   ÚRuntimeErrorr   Úreplacer‚   rc   r   r   ÚerrorÚosrf   Úisfiler   ÚwarningsÚwarnÚUserWarningr   r   r   r   Úupdater   Ú__name__Ú_set_model_device_and_precisionr¯   r�   r¨   rè   ÚgetattrrÐ   rê   r—   ÚscriptrÞ   r   )<rh   rÃ   rÄ   rÅ   rˆ   r—   rÆ   rÇ   rÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   ru   rÐ   rÑ   rŠ   Úmodel_kwargsÚschemarr   r:   rÕ   rƒ   Úpretrained_cfg_for_tagr�   Úlocal_config_pathr\   Úlocal_json_configÚert   Ú	hf_configÚ	e_weightsÚe_configÚmodel_name_cleanedr?   r>   Úmodel_quick_geluÚtag_quick_geluÚenable_default_image_weightsÚenable_default_text_weightsÚis_timm_modelÚis_hf_text_modelrä   Úmodel_classÚfinal_model_cfgræ   rž   Úpretrained_loadedÚpretrained_image_loadedÚimage_state_dictr®   Úpretrained_text_loadedÚtext_state_dictÚtext_moduleÚpartially_loadedÚfinal_preprocess_cfgÚvisual_modules<                                                               r0   Úcreate_modelr  û   s#  € ô~ *¨*Ó5Ñ€FˆJØ˜,Ó&à&×*Ñ*¨?Ó;ˆÜ�&œ#×ÑÜ—’˜fÓ%ˆà€IÜœM›OÓ,€NØ€OØ!Ðä‡L‚LÐ5°f°X¸^ÈJÈ<ÐXÔYÞ–*Ü�ŠÐ0°°Ð<YÐZ`ÐYaÐajÐkÔlØˆ
ð �Ôä˜*Ó%ˆ
Ø× Ñ ×"Ñ"Ü#Ð&]Ð^hÐ]iÐ$jÓkÐkà&Ð)@Ñ@ÐÜ�ŠÐAÐBSÐATÐUÔVØ×$Ñ$×&Ñ&ðuäÐ+¨S¸7ÒCÀqÜ(,¯	ª	°!«Ð%÷ Dð Ð"3Ó3à 1°+Ñ >�IÜ%:¸>ÐK\×K`ÑK`ÐaqÐsuÓKvÓ%w�NÜ—L’LÐ#LÐM^ÐL_Ð!`Ôaä&=¸jÓ&I�OÞ&ÜŸšÐ'KÈOÐK\Ð%]Ö^äŸšÐ*\Ð]gÐ\hÐ(iÖjô % }Ð5FÐ4GÐG\Ð%]Ó^Ð^ô $Ð&WÐXiÐWjÐ$kÓlÐlà	�8Ó	àˆÜ�ŠÐ>¸x¸jÐIÔJð	wä& x¸9ÑEˆIØ )Ó+Ü"Ð%JÈ8È*Ð#UÓVÐVà! +Ñ.ˆIÜ2°>À9Ç=Á=ÐQaÐceÓCfÓgˆNÜ�LŠLÐ<¸X¸JÐGÔHðrÜ"=¸hÐR[Ñ"\�Ü—’ÐEÀoÐEVÐWÕXð 
‰ð (×/Ñ/°°SÓ9Ðô %Ð%7Ó8ˆ	ØÑäØ$Ð%7Ð$8Ð8]Ô^iÓ^kÐ]lÐmóoð oä�ŠÐ'Ð(:Ð';¸>ÐJÔKö ä%7Ð8JÈJÓ%WÐ"Þ%ðbä&9Ð:PÐ\eÑ&f�OÜ%:¸>ÐKaÓ%b‘Nô
 —‘—‘ 
×+Ñ+ä—’ÐAÀ*ÀÐNÔOØ",‘ä—’Ø.¨z¨l¸'ÐBTÐAUð V'Ü'DÐEWÓ'XÐ&Yð[ôô #Ð%7¸
°|ÐCjÐ#kÓlÐlð ÑÜÐWÓXÐXØ˜Ñ$€HØ˜<Ñ(€JÞØ"&ˆ	�,ÑØÑ&Ø&9ˆ
�?Ñ#ØÑ#Ø#3ˆ
�<Ñ ØÑ'Ø%9ˆÐ!Ñ"ð �~Ö0à$Ÿ=™=¨°uÓ=ÐØ/×3Ñ3°LÀ%ÓHˆØÐ-Ó-ä�]Š]ØMÐN^ÐM_ð `(Ø(2 |°>À.ÐAQÐQSðUäôð Ñ"ÞÜ�LŠLØ-¨oÐ->Ð>yÐzô|à"ˆOøä�ŠÐ_Ô`ð $4×#qÐ8MÐQUÐ8U×#qÐZiÐmqÐZqÐ Ø"1×"nÐ6JÈdÐ6R×"nÐWfÐjnÐWnÐØ%¨¯©°|ÀRÓ)HÑH€MØ&¨)¯-©-¸
ÀBÓ*GÑGÐÞØ.Jˆ
Ð*Ò+à',Ð$ÞØ*EˆÐ&Ò'à&+Ð#ð —-‘- ¨uÓ5×^Ð9J×^ÐN^€KÞà˜yÓ(Ü‰Kä(‰Kô ˆô ˜yÓ)€OØ×Ñ˜<Ô(ô   	Ó*€Jô ‡L‚LÐ5°k×6JÑ6JÐ5KÐLÔMÙÑA˜/ÑA°jÒA€EÜ# E¨6¸mÔLð ÐÞÜ�ŠÐ=¸oÐ=NÐOÔPô 	ØØØØ%Øò	
ð !Ðð $ÐÞÜ�7‰7�>‰>Ð/×0Ñ0Ü�LŠLÐHÐI^ÐH_Ð`Ôaðfä#2Ø)Ø Ø!-ñ$Ð ô ˜5 (×+Ñ+à(-¯©×(DÑ(DÐEUÐ^cÐ(DÐ(dÐ%Ü—L’LØ:Ð;PÐ:QÐQfÐgxÐfyÐzô|à.2Ñ+ô —O’OØiÐjð  jAð  BõCô �OŠOÐUÐVkÐUlÐmÔnà"ÐÞÜ�7‰7�>‰>Ð.×/Ñ/Ü�LŠLÐGÐH\ÐG]Ð^Ô_ðdä"1Ø(Ø Ø!-ñ#�ô & e¨V°UÓ;�ØÑ*à(3×(CÑ(CÀOÐ\aÐ(CÐ(bÐ%Ü—L’LÐ#BÐCWÐBXÐXmÐnð  nAð  "Bô  CØ-1Ñ*ô —O’OÐ&{ð  }Qð  |Rð  %Sõ  Tô �OŠOÐTÐUiÐTjÐkÔlà2÷ =Ð6R÷ =Ø"÷=Ø&<ð æÖ"3ô Ø9¸*¸À_ÐU_ÐT`Ð`yÐzóð 
ö Ö#3ä	�Š˜6 * Ð-DÐEÕ	FÞÖ'7ä	�ŠÐCÀJÀ<ÐOmÐnÔ	oæ”w˜u m×4Ñ4à ˆÔð Ñ#®¼'À%Ç,Á,ÐP`×:aÑ:aÜ�ŠÐ.Ð/?Ð.@Ð@WÐXÔYØ�‰×#Ñ#Ð$4Ô5æ
Ü�ŠÐ2Ô3ð	TÜ—I‘I×$Ñ$ UÓ+ˆEÜ�LŠLÐ4Ô5ô
 $ NÓ3Ðä˜E 8¨TÓ2€MØÑ ¤W¨]¸L×%IÑ%Ià(5×(@Ñ(@Ð	˜fÑ	%ä0Ð1EÐG[×GaÐ_aÓbÐô ˜UÐ$8Ô9Ü‡L‚LÐ@ÐAUÐ@VÐWÔXô ‡L‚L�6˜*˜Ð%@ÐAÔBØ€L÷u DÖCûô" ó uä Ð#YÐZdÐYeÐehÐijÐhkÐ!lÓmÐstÐtûðuûô0 ó rä—’Ð"XÐYaÐXbÐbdÐenÐdoÐ p×qÒqûðrûô ó 	wäÐ!PÐQYÐPZÐZ\Ð]eÐ\fÐgÓhÐnvÐvûð	wûô8 !ó bÜ—M’MÐ$HÈÈÐTWÐXYÐWZÐ"[Ô\Ü&Ð)MÈjÈ\ÐY\Ð]^Ð\_Ð'`ÓaÐaûðbûô~ ó fä—’Ð GÐH]ÐG^Ð^`ÐabÐ`cÐd×eÒeûðfûô8 ó dä—’Ð FÐG[ÐF\Ð\^Ð_`Ð^aÐb×cÒcûðdûôH ó 	TÜ�OŠOÐ4°Q°CÐ7QÐR×SÒSûð	Túsè   Äd< Ä'd*Ä>A3d< Æ3d< Çd< ÈAf É&#e  Ë;f8 ×3Ag7 Ùg7 ÛA	h+ Üh+ á$5i ä*
d9ä4d< ä<
eåeåeå 
få*fæf æfæf æ
f5æf0æ0f5æ8
g4ç-g/ç/g4ç7
h(èh#è#h(è+
iè5iéié
jé)j	ê	jr�   c                 óÒ  • [        U 5      u  pE0 nSnSn[        R                  " SU SU 35        US:X  aµ  [        U5      nUR	                  5       (       d  [        SU 35      eUS-  n	[        R                  " SU	 35        U	R                  5       (       aF   [        U	SS	S
9 n
[        R                  " U
5      nSSS5        SW;   a  US   nO¼[        SU	 S35      e[        SU	 35      eUS:X  ak  Un[        R                  " SU 35        Sn [        XÒS9nUR                  SS5      nU(       d  SnU(       d!  Un0 n[        R                  " SU SU S35        O.Uc+  U(       a$  [        R                  " SU 35        [!        U5      nUc0  [        R                  " S5        [#        S.SU=(       d    [$        0UD6$ UR                  S0 5      nUc  UR                  S[$        5      nUR                  S0 5      nUR'                  U5        UR                  SS5      nU(       d	  U(       a  UnU(       aL  US:X  a  UnOUnUR                  S S5      n[        R                  " S!U S"U S#35        [)        U4UUUS$.UD6nU$ Ucg  S%UR+                  5       ;   aS  S&UR+                  5       ;   a  S'OS(UR+                  5       ;   a  S)OS*n[        R                  " S+U 35        [-        UUS,9nU$ [        R                  " S-5        [#        S.SU0UD6nU$ ! , (       d  f       GN\= f! [         a  n[        SU SU S35      UeSnAff = f! [         a  n[        U5      n SnAGN.SnAff = f)/ah  
Gets the appropriate tokenizer based on the model identifier schema or name.

`model_name` can specify source via schema:
  - 'ViT-B-32': Looks up built-in config to determine tokenizer type.
  - 'hf-hub:org/repo': Loads config from HF Hub to determine tokenizer type.
  - 'local-dir:/path/to/folder': Loads config from local dir to determine tokenizer type.
Nz&Parsing tokenizer identifier. Schema: rÔ   rk   z9Directory specified via 'local-dir:' schema not found at rw   z*Attempting to load config from local-dir: r4   ry   rz   r:   rÖ   r×   z+Could not load valid config for 'local-dir:z' (rß   rØ   rl   z&Attempting to load config from hf-hub:Ú rÙ   zmodel_cfg key not foundz"Could not load config from hf-hub:z (z/).Falling back to using model_id for tokenizer.z)Attempting to load config from built-in: zAModel configuration not found, returning default SimpleTokenizer.r�   r?   Útokenizer_kwargsÚhf_tokenizer_nameÚtokenizer_modez Using HFTokenizer with source: 'z
', mode: 'Ú')r�   ru   r  ÚsiglipÚsiglip2ÚgemmaÚi18nÚmc4zc4-enzUsing SigLipTokenizer variant: )r�   zUsing default SimpleTokenizer.r7   )rs   r»   r¼   r   rL   rì   rI   rO   rP   rQ   rp   rí   r}   r   r‘   r½   r‚   r%   r'   rö   r$   r+   r&   )rh   r�   ru   Úkwargsrü   rr   r|   Úlocal_dir_pathÚhf_fallback_idrþ   r\   rÿ   r   rt   Ú
config_errr  Útext_configr  r  Útokenizer_sourcer  Ú	tokenizerÚ
tn_variants                          r0   Úget_tokenizerr*  t  sÇ  € ô *¨*Ó5Ñ€Fà€FØ€NØ€Nô ‡L‚LÐ9¸&¸ÀÐPZÈ|Ð\Ô]à�Óä˜jÓ)ˆØ×$Ñ$×&Ñ&Ü#Ð&_Ð`nÐ_oÐ$pÓqÐqØ*Ð-DÑDÐÜ�ŠÐAÐBSÐATÐUÔVØ×$Ñ$×&Ñ&ð	läÐ+¨S¸7ÒCÀqÜ(,¯	ª	°!«Ð%÷ DàÐ"3Ó3Ø.¨{Ñ;‘Fä$ }Ð5FÐ4GÐG\Ð%]Ó^Ð^ô %Ð'XÐYjÐXkÐ%lÓmÐmà	�8Ó	àˆÜ�ŠÐ=¸h¸ZÐHÔIØˆ
ð	 ä& xÑEˆIØ—]‘] ;°Ó5ˆFÞØ6�
ö Ø%ˆNØˆFÜ�OŠOØ4°X°J¸bÀÀð M@ð AôBøð 
‰žJä�ŠÐ@ÀÀÐMÔNÜ! *Ó-ˆð �~Ü�ŠÐ[Ô]ÜÑa¨n×.VÔ@VÐaÐZ`ÑaÐað —*‘*˜Z¨Ó,€Kð Ñà$Ÿ™Ð)9Ô;QÓRˆð #—‘Ð'9¸2Ó>ÐØ×Ñ˜FÔ#ð $Ÿ™Ð(;¸RÓ@ÐÞ¦Ø*Ðæà�[Ó ð  .Ñà0ÐØ$Ÿ™Ð)9¸4Ó@ˆä�ŠÐ7Ð8HÐ7IÈÐTbÐScÐcdÐeÔfÜØð
à)ØØ)ñ	
ð
 ñ
ˆ	ð2 Ðð# 
‰˜H¨
×(8Ñ(8Ó(:Ó:ð !*¨Z×-=Ñ-=Ó-?Ó ?‘WÈfÐXb×XhÑXhÓXjÓNjÁUÐpwˆ
Ü�ŠÐ6°z°lÐCÔDÜ#ØØ)ñ
ˆ	ð Ðô 	�ŠÐ5Ô6Ü#ñ 
Ø)ð
àñ
ˆ	ð
 Ð÷} DÖCûô ó lÜ Ð#NÈzÈlÐZ]Ð^_Ð]`Ð`bÐ!cÓdÐjkÐkûðlûô  ó 	 Ü˜Q›ŽJûð	 úsN   ÂL! Â#LÂ:L! ÃL! Ä$M Ì
LÌL! Ì!
MÌ+L>Ì>MÍ
M&ÍM!Í!M&r	  c                 óŽ  ^• US;   as  SU;   a  [         R                  O[         R                  nU(       a-  SSKJm  U R                  XS9  U4S jnU R                  U5        g U R                  US9  [        XS9  g US	;   a6  SU;   a  [         R                  O[         R                  nU R                  XS9  g U R                  US9  g )
N)Úfp16Úbf16r,  r   )ÚLayerNormFp32)rˆ   Údtypec                 ó2  >• [        U T5      (       a…  U R                  R                  R                  [        R
                  5      U R                  l        U R                  R                  R                  [        R
                  5      U R                  l        g g r6   )re   ÚweightÚdataÚtor”   Úfloat32Úbias)Úmr.  s    €r0   Ú_convert_lnÚ4_set_model_device_and_precision.<locals>._convert_ln  sW   ø€ Ü˜a ×/Ñ/Ø$%§H¡H§M¡M×$4Ñ$4´U·]±]Ó$C�A—H‘H”MØ"#§&¡&§+¡+§.¡.´·±Ó"?�A—F‘F•Kð 0rE   r‡   )r/  )Ú	pure_fp16Ú	pure_bf16)r”   Úfloat16Úbfloat16Útransformerr.  r3  Úapplyr   )rž   rˆ   rÅ   r	  r/  r7  r.  s         @r0   rø   rø   ö  sŸ   ø€ ð Ð$Ó$Ø!'¨9Ó!4”—’¼%¿.¹.ˆæÝ2ð �H‰H˜FˆHÑ0õ@ð
 �K‰K˜Õ$à�H‰H˜FˆHÑ#Ü! %Ó5Ø	Ð0Ó	0Ø!'¨9Ó!4”—’¼%¿.¹.ˆØ�‰˜ˆÒ,à�‰˜ˆÒrE   c                 ó°  • U R                   (       a@  [        U R                  U R                  SU R                  U R
                  U R                  S9$ SU R                  R                  5       ;   aV  [        U R                  U R                  U R                  U R                  SU R                  U R
                  U R                  S9$ U R                  (       aA  U R                  (       a   S5       e[        U R                  U R
                  U R                  S9$ [        U R                  U R                  SU R                  U R
                  U R                  S9$ )NT)Ú
local_lossÚgather_with_gradÚcache_labelsÚrankÚ
world_sizeÚuse_horovodÚcoca)Úcaption_loss_weightÚclip_loss_weightr@  rA  rB  rC  rD  rE  z*Horovod not currently supported for SigLip)rC  rD  Ú	dist_impl)Údistillr   r@  rA  rC  rD  Úhorovodrž   r+   r   Úcoca_caption_loss_weightÚcoca_contrastive_loss_weightr  r   Úloss_dist_implr   )Úargss    r0   Úcreate_lossrP    s  € Ø‡|‡|ÜØ—‘Ø!×2Ñ2ØØ—‘Ø—‘ØŸ™ñ
ð 	
ð 
�4—:‘:×#Ñ#Ó%Ó	%ÜØ $× =Ñ =Ø!×>Ñ>Ø—‘Ø!×2Ñ2ØØ—‘Ø—‘ØŸ™ñ	
ð 		
ð 
��Ø—<—<ÐMÐ!MÓMÐÜØ—‘Ø—‘Ø×)Ñ)ñ
ð 	
ô Ø—?‘?Ø×.Ñ.ØØ�Y‰YØ—?‘?Ø—L‘Lñð rE   Ú
image_mean.Ú	image_stdÚimage_interpolationÚimage_resize_modeÚaug_cfgc                 ó  • [        0 UUUUS9n[        U U40 SU_SU_SU_SU_SU_SU_SU_S	U	_S
U_SU
_SU_SU_SU_SU_SU_SU_SU_UD6n[        S0 UR                  R                  D6n[        USUS9n[        USS9nUUU4$ )as  
Creates a contrastive vision-language model along with preprocessing transforms for training and validation.

This function combines model creation with the generation of appropriate image preprocessing pipelines,
making it convenient for training workflows where both model and transforms are needed.

`model_name` specifies architecture/config source:
  - 'ViT-B-32': Built-in model name. `pretrained` specifies CLIP weights source (tag or file path).
  - 'hf-hub:org/repo': Loads config/weights from HF Hub. `pretrained` is IGNORED.
  - 'local-dir:/path/to/folder': Loads config/weights from local dir. `pretrained` is IGNORED.

The preprocessing transforms are automatically configured based on the model's requirements,
with separate pipelines for training (with augmentation) and validation (without augmentation).

Args:
    model_name: Model identifier, potentially with schema ('hf-hub:', 'local-dir:').
    pretrained: Source for CLIP weights (tag or file path) ONLY if model_name has no schema.
    load_weights: Load the resolved pretrained weights if True, otherwise random init or tower overrides only.
    precision: Model precision ('fp32', 'fp16', 'bf16', ...).
    device: Device ('cpu', 'cuda', ...).
    jit: If True, JIT compile the model.
    force_quick_gelu: Force use of QuickGELU activation in model config.
    force_custom_text: Force use of custom text encoder architecture.
    force_patch_dropout: Override patch dropout value in model config.
    force_image_size: Override image size in model config.
    force_context_length: Override context length in model config.
    image_mean: Override default image normalization mean values (per channel).
    image_std: Override default image normalization std values (per channel).
    image_interpolation: Override default interpolation method for image resizing.
    image_resize_mode: Override resize mode for inference preprocessing ('squash', 'longest', 'shortest').
    aug_cfg: Augmentation configuration for training transforms. Can be dict or AugmentationCfg object.
             Controls random crop, color jitter, etc. If None, uses model defaults.
    pretrained_image: Load default (timm) base weights for image tower at creation if no CLIP weights loaded.
    pretrained_text: Load default (hf) base weights for text tower at creation if no CLIP weights loaded.
    pretrained_image_path: Path to load weights specifically into image tower after creation.
    pretrained_text_path: Path to load weights specifically into text tower after creation.
    cache_dir: Cache directory for downloads.
    output_dict: If True and model supports it, return dict output.
    weights_only: Use weights_only=True for torch.load (safer).
    **model_kwargs: Additional keyword arguments for model constructor (highest override priority).

Returns:
    Tuple[torch.nn.Module, Callable, Callable]: A tuple containing:
        - model: The created model instance
        - preprocess_train: Image preprocessing transform for training (includes augmentation)
        - preprocess_val: Image preprocessing transform for validation/inference (no augmentation)

Example:
    >>> # Basic usage with built-in model
    >>> model, train_transform, val_transform = create_model_and_transforms('ViT-B-32', pretrained='openai')
    >>>
    >>> # With custom augmentation
    >>> aug_cfg = {'scale': (0.9, 1.0), 'ratio': (1.0, 1.0)}
    >>> model, train_transform, val_transform = create_model_and_transforms(
    ...     'ViT-L-14',
    ...     pretrained='datacomp_xl_s13b_b90k',
    ...     aug_cfg=aug_cfg
    ... )
    >>>
    >>> # From Hugging Face Hub
    >>> model, train_transform, val_transform = create_model_and_transforms('hf-hub:org/model-repo')

Note:
    The training transform includes data augmentation based on `aug_cfg`, while the validation
    transform performs only the necessary preprocessing (resize, center crop, normalize) without
    any random augmentation.
©ÚmeanÚstdÚinterpolationÚresize_moderÄ   rÅ   rˆ   r—   rÆ   rÇ   rÈ   rÉ   rÊ   rË   rÌ   rÍ   rÎ   rÏ   ru   rÐ   rŠ   T)Úis_trainrU  F©r\  r7   )r#   r  r!   rè   rÕ   r   )rh   rÃ   rÄ   rÅ   rˆ   r—   rÆ   rÇ   rÈ   rÉ   rË   rQ  rR  rS  rT  rU  rÌ   rÍ   rÎ   rÏ   ru   rÐ   rŠ   rû   rÊ   rž   Úpp_cfgÚpreprocess_trainÚpreprocess_vals                                r0   Úcreate_model_and_transformsra  =  s-  € ôz 3Ø
ØØØ)Ø%ñÐô ØØòñ "ðñ ð	ñ
 ðñ ðñ *ðñ ,ðñ 0ðñ *ðñ 2ðñ 2ðñ *ðñ (ðñ 4ðñ  2ð!ñ" ð#ñ$  ð%ñ& "Ø
ñ)€Eô. Ñ9˜UŸ\™\×8Ñ8Ñ9€Fä)ØØØñÐô
 (ØØñ€Nð
 Ð" NÐ2Ð2rE   Úreturn_transformc                 ó¶   • [        0 U	U
UUS9n[        U U4UUUUUUUUUSUS.UD6nU(       d  U$ [        [        S0 UR                  R
                  D6SS9nUU4$ )aW  
Creates a contrastive vision-language model from pretrained weights with optional preprocessing transform.

This function is a convenience wrapper around `create_model` that enforces loading of pretrained weights
(require_pretrained=True) and optionally returns the appropriate preprocessing transform for inference.
It's designed for use cases where a pretrained model is required, such as feature extraction,
zero-shot classification, or fine-tuning.

`model_name` specifies architecture/config source:
  - 'ViT-B-32': Built-in model name. `pretrained` specifies CLIP weights source (tag or file path).
  - 'hf-hub:org/repo': Loads config/weights from HF Hub. `pretrained` is IGNORED.
  - 'local-dir:/path/to/folder': Loads config/weights from local dir. `pretrained` is IGNORED.

Unlike `create_model`, this function will raise an error if pretrained weights cannot be loaded.

Args:
    model_name: Model identifier, potentially with schema ('hf-hub:', 'local-dir:').
    pretrained: Source for CLIP weights (tag or file path) ONLY if model_name has no schema.
               If None and schema requires it, will raise an error.
    precision: Model precision ('fp32', 'fp16', 'bf16', ...).
    device: Device ('cpu', 'cuda', ...).
    jit: If True, JIT compile the model.
    force_quick_gelu: Force use of QuickGELU activation in model config.
    force_custom_text: Force use of custom text encoder architecture.
    force_image_size: Override image size in model config. Useful for using models at different resolutions.
    force_context_length: Override context length in model config.
    image_mean: Override default image normalization mean values (per channel).
    image_std: Override default image normalization std values (per channel).
    image_interpolation: Override default interpolation method for image resizing ('bicubic', 'bilinear', 'nearest').
    image_resize_mode: Override resize mode for inference preprocessing ('squash', 'longest', 'shortest').
        Only affects the returned preprocessing transform, not training.
    return_transform: If True, returns (model, preprocess). If False, returns only model.
    cache_dir: Cache directory for downloads.
    weights_only: Use weights_only=True for torch.load (safer).
    **model_kwargs: Additional keyword arguments for model constructor (highest override priority).

Returns:
    Union[torch.nn.Module, Tuple[torch.nn.Module, Callable]]:
        - If return_transform=False: Just the model instance
        - If return_transform=True: Tuple of (model, preprocess) where preprocess is the
          inference preprocessing transform

Raises:
    RuntimeError: If pretrained weights are required but cannot be loaded.

Example:
    >>> # Load model with preprocessing
    >>> model, preprocess = create_model_from_pretrained('ViT-B-32', pretrained='openai')
    >>>
    >>> # Load model without preprocessing (e.g., when using custom preprocessing)
    >>> model = create_model_from_pretrained('ViT-B-32', pretrained='openai', return_transform=False)
    >>>
    >>> # Load from Hugging Face Hub
    >>> model, preprocess = create_model_from_pretrained('hf-hub:laion/CLIP-ViT-L-14-DataComp.XL-s13B-b90K')
    >>>
    >>> # Load with custom image size
    >>> model, preprocess = create_model_from_pretrained(
    ...     'ViT-L-14',
    ...     pretrained='openai',
    ...     force_image_size=336
    ... )

Note:
    This function always requires pretrained weights to be available and loaded successfully.
    For cases where you want to create a model without pretrained weights or with only
    partial weight loading, use `create_model` or `create_model_and_transforms` instead.
rW  T)rÅ   rˆ   r—   rÆ   rÇ   rÉ   rÊ   rË   ru   rÑ   rŠ   Fr]  r7   )r#   r  r   r!   rè   rÕ   )rh   rÃ   rÅ   rˆ   r—   rÆ   rÇ   rÉ   rË   rQ  rR  rS  rT  rb  ru   rŠ   rû   rÊ   rž   Ú
preprocesss                       r0   Úcreate_model_from_pretrainedre  È  sœ   € ôl 3Ø
ØØØ)Ø%ñÐô ØØðð ØØØ)Ø+Ø)Ø1Ø1ØØØ!ñð ñ€Eö" Øˆä#ÜÑ4˜Ÿ™×3Ñ3Ñ4Øñ€Jð
 �*ÐÐrE   r6   )rç   T)TTrç   )NTÚfp32rç   FFFNNNNFTNNNNFT)r  NN)F)NTrf  rç   FFFNNNNNNNNFTNNNNT)Nrf  rç   FFFNNNNNNTNT)RrP   r»   rñ   r)   ró   Úcopyr   Údataclassesr   Úpathlibr   Útypingr   r   r   r	   r
   r”   Úconvertr   rž   r   r   r   r   r   r   r   r   Ú
coca_modelr   Úlossr   r   r   r   rÃ   r   r   r   r   r   Ú	transformr   r    r!   r"   r#   r(  r$   r%   r&   r'   rq   Ú__file__ÚparentrH   rS   r1   r_   rc   rg   rn   r‘   rs   r}   r‚   r�   Úboolr¯   rÂ   rˆ   Úfloatr-   ÚnnÚModuler  r*  rø   rP  ra  re  r7   rE   r0   Ú<module>ru     s@  ðÛ Û Û 	Û 	Û Ý Ý Ý ß 4Õ 4ã å '÷V÷ Vó Vå ß AÓ A÷?õ ?ç yÕ yß \Ó \à€Ù˜H“~×,Ñ,°Ñ@ÐAÐ Ø€òWòiñ* Ô ò'ò
ð €ØÐ ð+  ð + ¨¨x¸©}¸cÐ/AÑ)Bô + ð` $(ñØðà˜C‘=õò ð( ØñØõð> Ø!Øñ,Ø�T˜>Ð)Ñ*ð,àð,ð ð,ð õ	,ð^ dð ¨x¸©}ô ð2 %)Ø!ØØ+0ØØ!&Ø"'Ø/3ØBFØ9=Ø.2Ø!&Ø $Ø/3Ø.2Ø#'Ø&*Ø#(Ø!ñ)vØðvà˜S‘Mðvð ðvð ð	vð
 �c˜5Ÿ<™<Ð'Ñ(ðvð ðvð ðvð  ðvð & e™_ðvð # 5¨¨e°C¸°H©oÐ)=Ñ#>Ñ?ðvð ' t¨C°¨H¡~Ñ6ðvð ' s™mðvð ðvð ðvð  (¨™}ðvð  ' s™mð!vð" ˜C‘=ð#vð$ ˜d‘^ð%vð& !ð'vð( ð)vð, ‡X�X‡_�_õ-vðt Ø(,Ø#'ñØðà  ™ðð ˜C‘=õðL $ñ	 Ø�x‰x�‰ð à—‘ð ð ð ð õ	 ò@$ðR %)Ø!ØØ+0ØØ!&Ø"'Ø/3ØBFØ.2Ø26Ø15Ø-1Ø+/ØDHØ!&Ø $Ø/3Ø.2Ø#'Ø&*Ø!ñ/H3ØðH3à˜S‘MðH3ð ðH3ð ð	H3ð
 �c˜5Ÿ<™<Ð'Ñ(ðH3ð ðH3ð ðH3ð  ðH3ð & e™_ðH3ð # 5¨¨e°C¸°H©oÐ)=Ñ#>Ñ?ðH3ð ' s™mðH3ð ˜U 5¨# :Ñ.Ñ/ðH3ð ˜E %¨ *Ñ-Ñ.ðH3ð & c™]ðH3ð $ C™=ðH3ð  ˜%  S¨# X¡°Ð ?Ñ@ÑAð!H3ð" ð#H3ð$ ð%H3ð&  (¨™}ð'H3ð( ' s™mð)H3ð* ˜C‘=ð+H3ð, ˜d‘^ð-H3ð. õ/H3ðZ %)ØØ+0ØØ!&Ø"'ØBFØ.2Ø26Ø15Ø-1Ø+/Ø!%Ø#'Ø!ñ!wØðwà˜S‘Mðwð ðwð �c˜5Ÿ<™<Ð'Ñ(ð	wð
 ðwð ðwð  ðwð # 5¨¨e°C¸°H©oÐ)=Ñ#>Ñ?ðwð ' s™mðwð ˜U 5¨# :Ñ.Ñ/ðwð ˜E %¨ *Ñ-Ñ.ðwð & c™]ðwð $ C™=ðwð ðwð ˜C‘=ðwð  ö!wrE   