+
    TV-j¡~  ã                   ó  € ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHtHtHtHtHtHtHt ^ RIHt ^ RIHt ]P4                  ! RR4      P7                  4       R8X  d	    ^ RIHt M^ RIHt ]P@                  ! ]PB                  RL4       ^ R
I"H#t#H$t$H%t%H&t& ^RI'H(t( ^RI'H)t* RRRRRRRRRRRRRRRRRR/	t+^t,R t-R R lt.R  R! lt/R" R# lt0R$ t1R% t2RMR& R' llt3R( t4R) R* lt5R+R,R]03R- R. llt6R/ R0 lt7RMR1 lt8RNR2 R3 llt)ROR4R/R5 R6 lllt9RPR7 lt:],3R8 R9 llt;R: R; lt<R< R= lt=R>R+/R? R@ llt>RQRA RB llt?RC RD lt@RE RF ltARRRG RH lltBRI tCRJ RK ltDR#   ] d
    ]! R	4      hi ; i)Sé    N)ÚPath)Údedent)ÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚTypeÚUnionÚMLXLM_USE_MODELSCOPEÚFalseÚtrue)Úsnapshot_downloadz/Run `pip install modelscope` to use ModelScope.)Útree_flattenÚtree_mapÚtree_reduceÚtree_unflatten)ÚTokenizerWrapper)ÚloadÚmistralÚllamaÚllavaÚmistral3zphi-msftÚphixtralÚfalcon_mambaÚmambaÚjoyai_llm_flashÚdeepseek_v3Úkimi_k2Ú
qwen2_5_vlÚqwen2_vlÚ
minimax_m2ÚminimaxÚiquestcoderc           
      ó  € R RRRRRRRR^/p^ pV  F+  pVP                  4       '       g
   VR8X  g    MV^,          pK-  	  \        V RV 4      pWR P                  4       P                  4       p\	        WAV,          ,          4      # )	ÚMg    €„.AÚGg    eÍÍAÚMBÚGBÚ Ú.N)ÚisdigitÚfloatÚstripÚupperÚint)ÚxÚsizesÚsplitÚxiÚdigitsÚsizes   &     Ú]/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/mlx_lm/utils.pyÚ_parse_sizer9   <   s‡   € Ø�#�s˜C  s¨D°#°r¸1Ð=€EØ€EÛˆØ—
‘
—’  c¤	ÙØ��
Šñ ô �1�V�e�9Ó€FØˆfˆI×ÑÓ×$Ñ$Ó&€DÜˆv˜d�Õ#Ó$Ð$ó    c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )é   ÚqweightÚreturn©ÚmxÚarray)Úformats   "r8   Ú__annotate__rC   H   s"   € ÷ 7ñ 7¤§¡ð 7¬b¯h©hñ 7r:   c                 óò   € ^p^ V,          pV P                   w  r4WB,          p^V,          ^,
          p\        P                  ! . RO4      V,          pV R,          V,	          V,          pVP                  W54      # )é   )r   rE   é   é   r<   é   é   é   ).N)Úshaper@   rA   Úreshape)	r=   ÚbitsÚpack_factorÚout_featuresÚ	packed_inÚin_featuresÚmaskÚshiftsÚunpackeds	   &        r8   Ú_unpack_awq_weightsrU   H   sj   € Ø€DØ˜•*€KØ%Ÿm™mÑ€LØÕ)€KØ��I˜�?€DÜ�XŠXÒ.Ó/°$Õ6€FØ˜	Õ" fÕ,°Õ4€HØ×Ñ˜LÓ6Ð6r:   c          
      ó  € V ^8„  d   QhR\         \        \        P                  3,          R\         \        \        3,          R\
        \         \        \        P                  3,          \         \        \        3,          3,          /# )r<   ÚweightsÚquantization_configr>   )r   Ústrr@   rA   r   r
   )rB   s   "r8   rC   rC   S   s_   € ÷ Y)ñ Y)Ü”#”r—x‘x�-Õ ðY)äœc¤3˜h�ðY)ô Œ4””R—X‘X�Õ¤¤S¬# X¥Ð.Õ/ñY)r:   c                 óv  a€ VP                  R ^4      pV^8w  d   \        RV: R24      hVP                  R^€4      p/ p\        V P                  4       4       EFo  oSP	                  R4      '       d   \        RS R24      hSP	                  R4      '       Edß   SRR pW R2,          pV R	2pV R
2pW,          p	^ V,          p
VP
                  w  r¼WÊ,          pW³,          p\        V4      pVP                  pWº,          pVP                  VVV
4      p\        P                  ! V
4      V,          pVP                  \        P                  4      V,          P                  RR7      P                  \        P                  4      p\        P                  ! V	P                  4      p	W€9   dH   W,          p\        V4      pVP                  pVP                  \        P                  4      ) V	,          pMI^V^,
          ,          p\        P                   ! V	P
                  V) \        P                  R7      V	,          pVWE R2&   W”V R	2&   VP                  V	P"                  4      WE R2&   V	P"                  pEK   \$        ;QJ d    V3R lR 4       F  '       g   K   RM	  RM! V3R lR 4       4      '       d   EKc  V S,          VS&   EKr  	  VP'                  4        FQ  w  pp\        P(                  ! VP"                  \        P*                  4      '       g   K=  VP                  X4      VV&   KS  	  RVR V/pVV3# )rM   z
Only bits=z& is supported for AutoAWQ/GPTQ models.Ú
group_sizez.g_idxzFound zª in weights. Models with non-contiguous group indices (g_idx) are not currently supported. Please use a model without g_idx or re-quantize the model using mlx_lm.convert.ú.qweightNú.scalesú.qzeros)Úaxis)Údtypez.weightz.biasesc              3   óF   <"  € T F  pSP                  V4      x € K  	  R # 5i©N)Úendswith)Ú.0ÚsuffixÚkeys   & €r8   Ú	<genexpr>Ú)_transform_awq_weights.<locals>.<genexpr>ž   s!   øé € ð 
Ù/Q VˆC�L‰L˜× Ð Ó/Qùs   ƒ!TFiøÿÿÿéÿÿÿÿ)r\   r^   r]   )ÚgetÚ
ValueErrorÚlistÚkeysrc   rK   rU   ÚTrL   r@   ÚarangeÚastypeÚuint32ÚsumÚ
contiguousÚfloat32Úfullr`   ÚanyÚitemsÚ
issubdtypeÚfloating)rW   rX   rM   r[   Únew_weightsÚprefixr=   Ú
scales_keyÚ
qzeros_keyÚscalesrN   rQ   Ú
packed_outrO   Ún_groupsÚunpacked_weightrP   ÚrepackedrS   ÚweightÚqzerosÚunpacked_zerosÚbiasesÚ
zero_pointÚmodel_dtypeÚkÚwÚmlx_quantizationrf   s   &&                          @r8   Ú_transform_awq_weightsrŒ   S   só  ø€ ð ×"Ñ" 6¨1Ó-€DØˆq„yÜ˜; ¡Ð'MÐNÓOÐOØ$×(Ñ(¨°sÓ;€Jà€Kä�G—L‘L“N×#ˆØ�<‰<˜×!Ò!ÜØ˜˜ð Að Aóð ð �<‰<˜
×#Ó#Ø˜˜"�XˆFà ¨Ð1Õ2ˆGØ"˜8 7Ð+ˆJØ"˜8 7Ð+ˆJàÕ(ˆFð  �*ˆKØ&-§m¡mÑ#ˆKØ%Õ3ˆLØ"Õ0ˆHô 2°'Ó:ˆOà-×/Ñ/ˆOð $Õ2ˆIØ&×.Ñ.¨|¸YÈÓTˆHÜ—Y’Y˜{Ó+¨dÕ2ˆFà—‘¤§¡Ó+¨vÕ5×:Ñ:ÀÐ:ÓC×JÑJÌ2Ï9É9ÓUð ô —]’] 6§8¡8Ó,ˆFð Ô$Ø Õ,�ô "5°VÓ!<�à!/×!1Ñ!1�ð
 )×/Ñ/´·
±
Ó;Ð;¸fÕD‘ð  4¨!¥8�_�
ÜŸš §¡°
¨{Ä"Ç*Á*ÔMÐPVÕV�à.4ˆK˜( 'Ð*Ñ+Ø.4˜6˜( 'Ð*Ñ+Ø.4¯m©m¸F¿L¹LÓ.IˆK˜( 'Ð*Ñ+Ø Ÿ,™,‹Kç“ô 
Ù/Qó
——’ô 
Ù/Qó
÷ 
õ 
ð  ' s�|ˆK˜ÔñG $ðJ ×!Ñ!Ö#‰ˆˆ1Ü�=Š=˜Ÿ™¤"§+¡+×.Ô.ØŸX™X kÓ2ˆK˜‹Nñ $ð
 	�jØ�ðÐð
 Ð(Ð(Ð(r:   c                ó$   € V ^8„  d   QhR\         /# )r<   Úconfig)Údict)rB   s   "r8   rC   rC   ¯   s   € ÷ &ñ &œñ &r:   c                óâ   € V R,          p\         P                  W4      p \        P                  ! RV 24      pTP                  TP                  3#   \         d    RT R2p\        T4      hi ; i)zÄ
Retrieve the model and model args classes based on the configuration.

Args:
    config (dict): The model configuration.

Returns:
    A tuple containing the Model class and the ModelArgs class.
Ú
model_typezmlx_lm.models.zModel type z not supported.)ÚMODEL_REMAPPINGrj   Ú	importlibÚimport_moduleÚImportErrorrk   ÚModelÚ	ModelArgs)rŽ   r‘   ÚarchÚmsgs   &   r8   Ú_get_classesrš   ¯   sx   € ð ˜Õ%€JÜ ×$Ñ$ ZÓ<€JðÜ×&Ò&¨¸
°|Ð'DÓEˆð
 �:‰:�t—~‘~Ð%Ð%øô	 ô Ø˜J˜< Ð7ˆÜ˜‹oÐðús    A ÁA.c                 ól   a€ \        V P                  4       R  R7      pR o\        V3R lV 4       4      # )c                 ó6   € \        V \        P                  4      # rb   )Ú
isinstanceÚnnÚModule)Úms   &r8   Ú<lambda>Ú&get_total_parameters.<locals>.<lambda>Æ   s   € ´
¸1¼b¿i¹iÔ0Hr:   ©Úis_leafc                 ó4  € \        V R 4      '       d_   \        V R4      '       g   ^ MV P                  P                  pWP                  P                  ^ ,          V P                  ,          ,           # \        R \        V P                  4       4       4       4      # )rM   Úbiasc              3   ó>   "  € T F  w  rVP                   x € K  	  R # 5irb   )r7   )rd   Ú_Úvs   &  r8   rg   Ú8get_total_parameters.<locals>.nparams.<locals>.<genexpr>Í   s   é € ÐCÑ&B™d˜a�1—6–6Ó&Bùs   ‚)Úhasattrr¦   r7   rƒ   rM   rr   r   Ú
parameters)r    Úns   & r8   ÚnparamsÚ%get_total_parameters.<locals>.nparamsÉ   se   € Ü�1�f×ÒÜ   F×+Ò+‘°·±·±ˆAØ—x‘x—}‘} rÕ)¨Q¯V©VÕ3Õ3Ð3ÜÑC¤l°1·<±<³>Ô&BÓCÓCÐCr:   c              3   ó8   <"  € T F  w  rS! V4      x € K  	  R # 5irb   © )rd   r¨   r    r®   s   &  €r8   rg   Ú'get_total_parameters.<locals>.<genexpr>Ï   s   øé € Ð3¡l™d˜a‰w�q�zˆz£lùs   ƒ)r   Úleaf_modulesrr   )Úmodelr³   r®   s   & @r8   Úget_total_parametersrµ   Ä   s5   ø€ ÜØ×ÑÓÑ&Hô€LòDô Ô3¡lÓ3Ó3Ð3r:   c                 óT   € \        R  V ^ 4      p\        V 4      pV^,          V,          # )c                 ój   € \        V\        P                  4      '       d   WP                  ,           # T # rb   )r�   r@   rA   Únbytes)Úaccr2   s   &&r8   r¡   Ú)compute_bits_per_weight.<locals>.<lambda>Ô   s"   € ¬°A´r·x±x×)@Ò)@�sŸX™X•~ÐIÀcÐIr:   )r   rµ   )r´   Úmodel_bytesÚmodel_paramss   &  r8   Úcompute_bits_per_weightr½   Ò   s/   € ÜÙIÈ5ÐRSó€Kô (¨Ó.€LØ˜�?˜\Õ)Ð)r:   c                ót   € V ^8„  d   QhR\         R\        \         ,          R\        \         ,          R\        /# )r<   Úpath_or_hf_repoÚrevisionÚallow_patternsr>   )rY   r	   r   r   )rB   s   "r8   rC   rC   Ú   s8   € ÷ &ñ &Üð&ä”s�mð&ô œ•Ið&ô 
ñ	&r:   c                ó’   € \        V 4      pVP                  4       '       g&   T;'       g    . ROp\        \        V VVR7      4      pV# )a`  
Ensures the model is available locally. If the path does not exist locally,
it is downloaded from the Hugging Face Hub.

Args:
    path_or_hf_repo (str): The local path or Hugging Face repository ID of the model.
    revision (str, optional): A revision id which can be a branch name, a tag, or a commit hash.

Returns:
    Path: The local file path.
)rÀ   rÁ   )	ú*.jsonúmodel*.safetensorsú*.pyútokenizer.modelú
*.tiktokenútiktoken.modelú*.txtú*.jsonlú*.jinja)r   Úexistsr   )r¿   rÀ   rÁ   Ú
model_paths   &&& r8   Ú	_downloadrÎ   Ú   sV   € ô  �oÓ&€Jà×Ñ×ÒØ'÷ 

ð 

ò 
,
ˆô ÜØØ!Ø-ôó
ˆ
ð Ðr:   c                 ó.   € \        \        V R R7      4      # )T)Úlocal_files_only)r   r   )Úhf_repos   &r8   Úhf_repo_to_pathrÒ     s   € ÜÔ! '¸DÔAÓBÐBr:   c                ó0   € V ^8„  d   QhR\         R\        /# )r<   rÍ   r>   )r   r�   )rB   s   "r8   rC   rC     s   € ÷ ñ œDð ¤Tñ r:   c                 óä  € \        V R ,          R4      ;_uu_ 4       p\        P                  ! V4      pRRR4       V R,          pVP                  4       '       dV   / p \        VR4      ;_uu_ 4       p\        P                  ! V4      pRRR4       TP                  RR4      ;p'       d   TXR&   X#   + '       g   i     L†; i  + '       g   i     LD; i  \        P                   d     L^i ; i)úconfig.jsonÚrNúgeneration_config.jsonÚeos_token_idF)ÚopenÚjsonr   rÌ   ÚJSONDecodeErrorrj   )rÍ   ÚfrŽ   Úgeneration_config_fileÚgeneration_configrØ   s   &     r8   Úload_configrß     sÅ   € Ü	ˆj˜=Õ(¨#×	.Ô	.°!Ü—’˜1“ˆ÷ 
/ð (Ð*BÕBÐØ×$Ñ$×&Ò&ØÐð	ÜÐ,¨c×2Ô2°aÜ$(§I¢I¨a£LÐ!÷ 3ð
 -×0Ñ0°ÀÓGÐGˆ<ÖGØ%1ˆF�>Ñ"à€M÷ 
/×	.ú÷ 3×2ûä×#Ñ#ô 	Ùð	ús;   œB1ÁC Á1CÂC Â1C	ÃC	ÃC ÃC ÃC/Ã.C/FTc                ó>  € V ^8„  d   QhR\         R\        R\        R\        \        \        \
        3,          ,          R\        \        .\        \        \        P                  ,          \        3,          3,          R\        \        P                  \        3,          /# )r<   rÍ   ÚlazyÚstrictÚmodel_configÚget_model_classesr>   )r   Úboolr	   r   rY   r   r   r�   r
   r   rž   rŸ   )rB   s   "r8   rC   rC     s„   € ÷ Jñ JÜðJä
ðJô ðJô œ4¤¤S �>Õ*ð	Jô
  ¤ ¬¬d´2·9±9­o¼tÐ.CÕ(DÐ DÕEðJô Œ2�9‰9”dˆ?ÕñJr:   c                ó^  aaa€ \        V 4      oVe   SP                  V4       \        P                  ! \        V R,          4      4      pV'       g   V'       d   \	        RV  24      h/ oV F(  pSP                  \
        P                  ! V4      4       K*  	  SP                  R4      ;pey   \        P                  P                  RW,          4      p\        P                  P                  V4      p	VP                  P                  V	4       V	P                  V	P                  rºMV! SR7      w  r«RS9  d&   SP                  R/ 4      pRV9   d   VR,          SR&   VP!                  S4      pV
! V4      o\#        SR	4      '       d   SP%                  S4      oVVV3R
 lpSP                  RR4      ;pe
   V! V4       M¦SP                  RR4      ;p'       d�   VR,          pVR8X  d   ^RIHp V! SV4      oMlVR8X  d   R^ R^RR/pVSR&   VSR&   V! V4       MJVR8X  d   R^ R^RR/pVSR&   VSR&   V! V4       M(VR9   d"   \+        SV4      w  opVSR&   VSR&   V! V4       SP                  RR4      '       dI   R p\-        VSP/                  4       \0        P2                  P4                  R7      pSP7                  V4       SP9                  4        SP;                  \=        SP?                  4       4      VR7       V'       g%   \
        P8                  ! SPA                  4       4       SS3# )aö  
Load and initialize the model from a given path.

Args:
    model_path (Path): The path to load the model from.
    lazy (bool): If False eval the model parameters to make sure they are
        loaded in memory before returning, otherwise they will be loaded
        when needed. Default: ``False``
    strict (bool): Whether or not to raise an exception if weights don't
        match. Default: ``True``
    model_config (dict, optional): Optional configuration parameters for the
        model. Defaults to an empty dictionary.
    get_model_classes (Callable[[dict], Tuple[Type[nn.Module], Type]], optional):
        A function that returns the model class and model args class given a config.
        Defaults to the ``_get_classes`` function.

Returns:
    Tuple[nn.Module, dict[str, Any]]: The loaded and initialized model and config.

Raises:
    FileNotFoundError: If the weight files (.safetensors) are not found.
    ValueError: If the model class or args class are not found or cannot be instantiated.
NrÄ   zNo safetensors found in Ú
model_fileÚcustom_model)rŽ   rX   Útext_configÚsanitizec           	      óˆ   <€ VV3R  lp\         P                  ! SV R,          V R,          V P                  RR4      VR7       R# )c                 óx   <€ V SR ,          9   d   SR ,          V ,          # \        VR4      '       g   R# V  R2S9   # )ÚquantizationÚto_quantizedFr]   )r«   )Úpr    rŽ   rW   s   &&€€r8   Úclass_predicateÚ6load_model.<locals>._quantize.<locals>.class_predicate]  sA   ø€ à�F˜>Õ*Ô*Ø˜nÕ-¨aÕ0Ð0Ü˜1˜n×-Ò-ÙØ�S˜�= GÑ+Ð+r:   r[   rM   ÚmodeÚaffine)r[   rM   rò   rð   N)rž   Úquantizerj   )rí   rð   rŽ   r´   rW   s   & €€€r8   Ú	_quantizeÚload_model.<locals>._quantize\  s<   ø€ ö	,ô 	�ŠØØ# LÕ1Ø˜fÕ%Ø×!Ñ! &¨(Ó3Ø+÷	
r:   rí   FÚquant_methodÚbitnet)Úbitnet_quantizeÚmxfp4r[   rM   rò   zcompressed-tensorsró   Úquantize_activationsc                 ó–  € \        V \        P                  4      '       d©   V P                  R9  d   \	        R4      hV P                  RR4      '       d   \	        R4      hV P                  P                  w  rV^ V P                  ,          ,          p\        P                  ! W!V P                  V P                  V P                  4      # V # )Únvfp4z8Mode ({m.mode}) does not support activation quantizationr¦   Fz?Linear layer with bias does not support activation quantization)rý   Úmxfp8)r�   rž   ÚQuantizedLinearrò   rk   rj   rƒ   rK   rM   ÚQQLinearr[   )r    Úout_dimsÚin_dimss   &  r8   Ú	_maybe_qqÚload_model.<locals>._maybe_qqŠ  sŸ   € Ü˜!œR×/Ñ/×0Ò0Ø—6‘6Ð!3Ô3Ü$ØRóð ð —5‘5˜ ×'Ò'Ü$ØYóð ð %&§H¡H§N¡NÑ!�Ø˜2 §¡�<Õ'�Ü—{’{ 7°a·l±lÀAÇFÁFÈAÏFÉFÓSÐSà�r:   r£   )râ   )ÚawqÚgptq)!rß   ÚupdateÚglobrY   ÚFileNotFoundErrorr@   r   rj   r“   ÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚexec_moduler–   r—   Ú	from_dictr«   rê   Úmodels.bitlinear_layersrù   rŒ   r   r³   rž   rŸ   Ú	is_moduleÚupdate_modulesÚevalÚload_weightsrl   rw   r¬   )rÍ   rá   râ   rã   rä   Úweight_filesÚwfrç   Úspecr˜   Úmodel_classÚmodel_args_classré   Ú
model_argsrõ   rí   rX   r÷   rù   r  ÚleavesrŽ   r´   rW   s   &&&&&                @@@r8   Ú
load_modelr    sé  ú€ ô< ˜Ó$€FØÒØ�‰�lÔ#ä—9’9œS Ð.BÕ!BÓCÓD€LçŸFÜÐ":¸:¸,Ð GÓHÐHà€GÛˆØ�‰”r—w’w˜r“{Ö#ñ ð —j‘j Ó.Ð.ˆ
Ò;Ü�~‰~×5Ñ5ØØÕ#ó
ˆô �~‰~×.Ñ.¨tÓ4ˆØ�‰×Ñ Ô%Ø(,¯
©
°D·N±NÑ%á(9ÀÔ(HÑ%ˆà FÔ*Ø—j‘j °Ó3ˆØ  KÔ/Ø,7Ð8MÕ,NˆFÐ(Ñ)à!×+Ñ+¨FÓ3€Já˜
Ó#€Eäˆu�j×!Ò!Ø—.‘. Ó)ˆ÷
ð" Ÿ
™
 >°4Ó8Ð8ˆÒEÙ�,Õà &§
¡
Ð+@À%Ó HÐ	HÐ	Ö	Hà*¨>Õ:ˆØ˜8Ô#Ý@á# EÐ+>Ó?‰EØ˜WÔ$Ø(¨"¨f°a¸ÀÐIˆLØ%1ˆF�>Ñ"Ø,8ˆFÐ(Ñ)Ù�lÕ#ØÐ1Ô1Ø(¨"¨f°a¸ÀÐJˆLØ%1ˆF�>Ñ"Ø,8ˆFÐ(Ñ)Ù�lÕ#Ø˜_Ô,ä$:¸7ÐDWÓ$XÑ!ˆG�\Ø%1ˆF�>Ñ"Ø,8ˆFÐ(Ñ)Ù�lÔ#à‡z�zÐ(¨%×0Ò0ò	ô  ˜) U×%7Ñ%7Ó%9Ä2Ç9Á9×CVÑCVÔWˆà×Ñ˜VÔ$à	‡J�J„LØ	×Ñ”t˜GŸM™M›OÓ,°VÐÔ<çÜ
�Š�× Ñ Ó"Ô#à�&ˆ=Ðr:   c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r<   r´   Úadapter_pathr>   )rž   rŸ   rY   )rB   s   "r8   rC   rC   §  s)   € ÷ /ñ /œŸ™ð /´#ð /¼"¿)¹)ñ /r:   c                 ó   € ^RI Hp V! W4      # )rF   )Úload_adapters)Útuner.utilsr   )r´   r  Ú_load_adapterss   && r8   r   r   §  s   € Ý<á˜%Ó.Ð.r:   c                ó<   € \        V . ROR7      p \        V VVR7      # )zXLoad a huggingface tokenizer and try to infer the type of streaming
detokenizer to use.
©rÁ   ©Úeos_token_ids©rÃ   rÅ   rÆ   rÇ   rÈ   rÉ   rÊ   rË   )rÎ   Ú_load_tokenizer)rÍ   Útokenizer_config_extrar&  s   &&&r8   Úload_tokenizerr*  ­  s.   € ô Øò	
ô€Jô ØØØ#ôð r:   c                óÎ  € V ^8„  d   QhR\         R\        \        \         \        3,          ,          R\        \        \         \        3,          ,          R\        \         ,          R\        R\        R\        \         ,          R\
        \        \        P                  \        3,          \        \        P                  \        \        \         \        3,          3,          3,          /# )	r<   r¿   Útokenizer_configrã   r  rá   Úreturn_configrÀ   r>   )
rY   r	   r   r   rå   r   r
   rž   rŸ   r   )rB   s   "r8   rC   rC   Å  s²   € ÷ 1 ñ 1 Üð1 äœt¤C¬ H�~Õ.ð1 ô œ4¤¤S �>Õ*ð1 ô œ3•-ð	1 ô
 ð1 ô ð1 ô ”s�mð1 ô Ü	Œ"�)‰)Ô%Ð
%Õ&Ü	Œ"�)‰)Ô%¤t¬C´¨H¥~Ð
5Õ6ð8õñ1 r:   c                óÎ   € \        WR7      p\        WtVR7      w  r‰Ve   \        Wƒ4      pVP                  4        \	        WqV	P                  RR4      R7      p
V'       d   WŠV	3# WŠ3# )a   
Load the model and tokenizer from a given path or a huggingface repository.

Args:
    path_or_hf_repo (Path): The path or the huggingface repository to load the model from.
    tokenizer_config (dict, optional): Configuration parameters specifically for the tokenizer.
        Defaults to an empty dictionary.
    model_config(dict, optional): Configuration parameters specifically for the model.
        Defaults to an empty dictionary.
    adapter_path (str, optional): Path to the LoRA adapters. If provided, applies LoRA layers
        to the model. Default: ``None``.
    lazy (bool): If ``False`` eval the model parameters to make sure they are
        loaded in memory before returning, otherwise they will be loaded
        when needed. Default: ``False``
    return_config (bool: If ``True`` return the model config as the last item..
    revision (str, optional): A revision id which can be a branch name, a tag, or a commit hash.
Returns:
    Union[Tuple[nn.Module, TokenizerWrapper], Tuple[nn.Module, TokenizerWrapper, Dict[str, Any]]]:
        A tuple containing the loaded model, tokenizer and, if requested, the model config.

Raises:
    FileNotFoundError: If config file or safetensors are not found.
    ValueError: If model class or args class are not found.
)rÀ   )rã   NrØ   r%  )rÎ   r  r   r  r*  rj   )r¿   r,  rã   r  rá   r-  rÀ   rÍ   r´   rŽ   Ú	tokenizers   &&&&&&&    r8   r   r   Å  si   € ôH ˜?Ô>€Jä˜z¸lÔK�M€EØÒÜ˜eÓ2ˆØ�
‰
ŒÜØ°F·J±J¸~ÈtÓ4Tô€I÷ Ø Ð'Ð'àÐÐr:   r,  c                óü   € V ^8„  d   QhR\         \        P                  P                  ,          R\         \        P                  P                  ,          R\        R\         \
        \        \        3,          ,          /# )r<   Úpipeline_groupÚtensor_groupr-  r,  )r	   r@   ÚdistributedÚGrouprå   r   rY   r   )rB   s   "r8   rC   rC   ù  sc   € ÷ V ñ V äœRŸ^™^×1Ñ1Õ2ðV ô œ2Ÿ>™>×/Ñ/Õ0ðV ô ð	V ô œt¤C¬ H�~Õ.ñV r:   c                óÒ  € \        V . ROR7      p\        VRRR7      w  rg\        VR4      ;'       d    \        VP                  R4      p\        VR4      p	Ve   V'       g   \	        R	4      hVe   V	'       g   \	        R
4      hV'       g   V	'       g   \	        R4      hYu;J d   fQ   M MMV	'       d    \
        P                  P                  4       pM&V'       d   \
        P                  P                  4       pVeÔ   VP                  P                  V4       \        VR,          R4      ;_uu_ 4       p
\        P                  ! V
4      R,          pRRR4       \        4       p\        VP                  4       4       FC  w  rÞXP                  VR4      RJ ;p'       d   \	        R4      hVP!                  W½,          4       KE  	  \        WR7       M\        V 4       \#        TT;'       g    RR/VP                  RR4      R7      p\        VRRR7      w  rnVe   VP%                  V4       Ve   VP                  P                  V4       \
        P&                  ! VP                  4       4       \
        P&                  ! \
        P                  P)                  \
        P*                  ! R4      \
        P,                  R7      4       V'       d   VVV3# VV3#   + '       g   i     EL�; i)rÃ   r$  TF)rá   râ   r´   ÚpipelineÚshardNzGThe model does not support pipelining but a pipeline_group was providedzMThe model does not support tensor parallelism but a tensor_group was providedz'The model does not support any shardingúmodel.safetensors.index.jsonrÖ   Ú
weight_mapz<Pipeline loading is only supported for MLX converted models.Útrust_remote_coderØ   r%  g      ð?)Ústreamr'  )rÎ   r  r«   r´   rk   r@   r3  Úinitr6  rÙ   rÚ   r   Úsetr   r¬   rj   Úaddr*  r7  r  Úall_sumrA   Úcpu)Úrepor1  r2  r-  r,  rÍ   r´   rŽ   Úhas_pipeliningÚhas_tensor_parallelÚfidÚweight_indexÚlocal_filesr‰   r¨   Ú	file_namer/  s   &&&&$            r8   Úsharded_loadrH  ù  s^  € ô Øò	
ô€Jô  ˜z°¸UÔC�M€Eä˜U GÓ,×QÐQ´¸¿¹ÀjÓ1Q€NÜ! %¨Ó1ÐàÒ!¯.ÜØUó
ð 	
ð Ò×(;ÜØ[ó
ð 	
÷ ×"5ÜÐBÓCÐCà×-Ó-ßÜŸ>™>×.Ñ.Ó0‰LßÜŸ^™^×0Ñ0Ó2ˆNð Ò!Ø�‰×Ñ˜^Ô,ô �*Ð=Õ=¸s×CÔCÀsÜŸ9š9 S›>¨,Õ7ˆL÷ Dô “eˆÜ  ×!1Ñ!1Ó!3Ö4‰DˆAØ(×,Ñ,¨Q°Ó5¸Ð=Ð=ˆyÖ=Ü ØRóð ð �O‰O˜L�OÖ,ñ 5ô 	�$Ö3ä�$Œô ØØ×7Ð7Ð0°$Ð7Ø—j‘j °Ó6ô€Iô
 ˜*¨4¸Ô>�H€EØÒØ�‰�LÔ!ØÒ!Ø�‰×Ñ˜^Ô,Ü‡G‚GˆE×ÑÓÔô ‡G‚GŒB�N‰N×"Ñ"¤2§8¢8¨C£=¼¿¹Ð"Ó@ÔAßØ�i Ð'Ð'à�iÐÐ÷E D×CÐCús   Ä3KËK&	c                 óV   € \        V \        P                  P                  4       R V4      # rb   )rH  r@   r3  r<  )rA  r-  s   &&r8   Úpipeline_loadrJ  R  s    € Ü˜œbŸn™n×1Ñ1Ó3°T¸=ÓIÐIr:   c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r<   rW   Úmax_file_size_gbr>   )r�   r1   rl   )rB   s   "r8   rC   rC   V  s!   € ÷ ñ œð ´ð ÌDñ r:   c                óø   € V^,          p. p/ ^ rTV P                  4        FF  w  rgWWP                  ,           V8”  d   VP                  V4       / ^ rTWtV&   WWP                  ,          pKH  	  VP                  V4       V# )zÃ
Splits the weights into smaller shards.

Args:
    weights (dict): Model weights.
    max_file_size_gb (int): Maximum size of each shard in gigabytes.

Returns:
    list: List of weight shards.
)rw   r¸   Úappend)rW   rL  Úmax_file_size_bytesÚshardsr7  Ú
shard_sizer‰   r©   s   &&      r8   Úmake_shardsrR  V  sv   € ð +¨bÕ0ÐØ€FØ˜Aˆ:Ø—‘–‰ˆØŸ™Õ Ð#6Ô6Ø�M‰M˜%Ô Ø " A�:Øˆa‰Ø—h‘hÕŠ
ñ  ð ‡M�M�%ÔØ€Mr:   c                óv   € V ^8„  d   QhR\         \        \        3,          R\         \        \        R3,          /# )r<   ÚpathÚhf_pathN)r   rY   r   )rB   s   "r8   rC   rC   n  s.   € ÷ /ñ /œE¤#¤t )Õ,ð /´u¼SÄ$È¸_Õ7Mñ /r:   c                ó2  € ^ RI HpHp Vf   VP                  V! RR7      4      pMVP	                  V4      pRVP
                  n        RVP
                  n        VP
                  P                  f   R.VP
                  n        M?RVP
                  P                  9  d%   VP
                  ;P                  R.,          un        Ve   \        V4      VP
                  n
        RVn        VP                  \        P                  P                  V R4      4       R# )	z´
Uploads the model to Hugging Face hub.

Args:
    path (Union[str, Path]): Local path to the model.
    hf_path (Union[str, Path, None]): Path to the original Hugging Face model.
)Ú	ModelCardÚModelCardDataNÚen)ÚlanguageÚmlxztext-generationr+   ú	README.md)Úhuggingface_hubrW  rX  Úfrom_templater   ÚdataÚlibrary_nameÚpipeline_tagÚtagsrY   Ú
base_modelÚtextÚsaveÚosrT  Újoin)rT  rU  rW  rX  Úcards   &&   r8   Úcreate_model_cardri  n  s¾   € ÷ 9à‚Ø×&Ñ&¡}¸dÔ'CÓD‰à�~‰~˜gÓ&ˆØ"€D‡I�IÔØ.€D‡I�IÔØ‡y�y‡~�~ÒØ˜ˆ�	‰	�Ø	�d—i‘i—n‘nÔ	$Ø�	‰	�Š˜5˜'Õ!�ØÒÜ" 7›|ˆ�	‰	ÔØ€D„IØ‡I�IŒb�g‰g�l‰l˜4 Ó-Ö.r:   c                ó0   € V ^8„  d   QhR\         R\         /# )r<   rT  Úupload_repo)rY   )rB   s   "r8   rC   rC   ˆ  s   € ÷ ?Yñ ?Yœð ?Y¬#ñ ?Yr:   c                óº  € ^ RI HpHpHp ^RIHp VP                  4        \        V 4      R,          pVP                  V4      pVP                  P                  pVe   RV RV RV RV RV R	2p	MR
p	\        RV RV	 RV R24      Vn        VP                  V4       V! 4       p
V
P                  VRR7       V
P                  V VRR7       \!        RV R24       R# )z‘
Uploads the model to Hugging Face hub.

Args:
    path (str): Local path to the model.
    upload_repo (str): Name of the HF repo to upload to.
)ÚHfApirW  Úlogging)Ú__version__r\  Nz
        This model [z](https://huggingface.co/z,) was
        converted to MLX format from [z!)
        using mlx-lm version **z**.
        r+   z
        # z	
        z°
        ## Use with mlx

        ```bash
        pip install mlx-lm
        ```

        ```python
        from mlx_lm import load, generate

        model, tokenizer = load("av  ")

        prompt = "hello"

        if tokenizer.chat_template is not None:
            messages = [{"role": "user", "content": prompt}]
            prompt = tokenizer.apply_chat_template(
                messages, add_generation_prompt=True, return_dict=False,
            )

        response = generate(model, tokenizer, prompt=prompt, verbose=True)
        ```
        T)Úrepo_idÚexist_okr´   )Úfolder_pathrp  Ú	repo_typez0Upload successful, go to https://huggingface.co/z for details.)r]  rm  rW  rn  r+   ro  Úset_verbosity_infor   r   r_  rc  r   rd  re  Úcreate_repoÚupload_large_folderÚprint)rT  rk  rm  rW  rn  ro  Ú	card_pathrh  rU  Ú
provenanceÚapis   &&         r8   Úupload_to_hubr{  ˆ  s  € ÷ :Ñ9åà×ÑÔ Ü�T“
˜[Õ(€IØ�>‰>˜)Ó$€Dà�i‰i×"Ñ"€GàÒðØ �MÐ!:¸;¸-ð H'Ø'. iÐ/HÈÈ	ð R Ø +˜}ð -	ð‰
ð ˆ
äðØˆ-ð 	Ø	ˆð 
"ð #. ð /	ð	ó€D„Ið6 	‡I�IˆiÔá
‹'€CØ‡O�O˜K°$€OÔ7Ø×ÑØØØð ô ô
 
Ð<¸[¸MÈÐ
WÖXr:   Údonate_modelc                óv   € V ^8„  d   QhR\         \        \        3,          R\        P                  R\
        RR/# )r<   Ú	save_pathr´   r|  r>   N)r   rY   r   rž   rŸ   rå   )rB   s   "r8   rC   rC   Ê  s=   € ÷ 9
ñ 9
Ü”Sœ$�YÕð9
ä�9‰9ð9
ô ð	9
ð
 
ñ9
r:   c               ó  € \        V \        4      '       d   \        V 4      p V P                  RRR7       \	        \        VP                  4       4      4      p\        V4      p\        V4      pV^8”  d   RMRp\        R VP                  4        4       4      pRRVR\        V4      /R	/ /pV'       d+   VP                  \        R
 VP                  4       4      4       VP                  4        ?\        \        V4      4       Fw  p	WI,          p
RWI&   VP!                  V	^,           V4      pW,          p\"        P$                  ! \        V4      V
RR/R7       V
P'                  4        F  pW¸R	,          V&   K  	  ?
Ky  	  \)        VR	,          4       Uu/ uF  qîVR	,          V,          bK  	  upVR	&   \+        V R,          R4      ;_uu_ 4       p\,        P.                  ! VV^R7       RRR4       R# u upi   + '       g   i     R# ; i)z?Save model weights and metadata index into specified directory.T)Úparentsrq  z"model-{:05d}-of-{:05d}.safetensorszmodel.safetensorsc              3   ó8   "  € T F  qP                   x € K  	  R # 5irb   )r¸   )rd   r©   s   & r8   rg   Úsave_model.<locals>.<genexpr>Þ  s   é € Ð8Ñ'7 !—X–XÓ'7ùs   ‚ÚmetadataÚ
total_sizeÚtotal_parametersr9  c                 ó.   € \         P                  ! . 4      # rb   r?   )r¨   s   &r8   r¡   Úsave_model.<locals>.<lambda>ç  s   € ¬¯ª°¬r:   NrB   r[  )rƒ  r8  rŠ   ©Úindent)r�   rY   r   Úmkdirr�   r   r¬   rR  Úlenrr   Úvaluesrµ   r  r   ÚclearÚrangerB   r@   Úsave_safetensorsrm   ÚsortedrÙ   rÚ   Údump)r~  r´   r|  rW   rP  Úshards_countÚshard_file_formatr„  Ú
index_dataÚir7  Ú
shard_nameÚ
shard_pathÚweight_namer‰   rÜ   s   &&$             r8   Ú
save_modelr™  Ê  sÒ  € ô �)œS×!Ò!Ü˜“Oˆ	Ø‡O�O˜D¨4€OÔ0ä”< × 0Ñ 0Ó 2Ó3Ó4€GÜ˜Ó!€FÜ�v“;€Lð ˜!Ôñ 	-à ð ô Ñ8 w§~¡~Ô'7Ó8Ó8€JàØ˜*ØÔ 4°UÓ ;ð
ð 	�bð€J÷ Ø�‰”XÑ4°e×6FÑ6FÓ6HÓIÔJð ‡M�M„OØä”3�v“;ÖˆØ•	ˆØˆ‰	Ø&×-Ñ-¨a°!­e°\ÓBˆ
ØÕ+ˆ
ä
×ÒœC 
›O¨U¸hÈÐ=NÕOà Ÿ:™:ž<ˆKØ4>�|Õ$ [Ó1ñ (âñ  ô 17°zÀ,Õ7OÔ0Pó Ù0P¨1ˆ:�lÕ# AÕ&Ò&Ñ0Pñ €Jˆ|Ñô 
ˆiÐ8Õ8¸#×	>Ô	>À!Ü�	Š	ØØØõ	
÷ 
?Ñ	>ùò	 ÷ 
?×	>Ð	>ús   ÆG/ÇG4Ç4H	c                ó\  € V ^8„  d   QhR\         P                  R\        R\        \        ,          R\        \        ,          R\
        R\        \        \
        \         P                  .\        \        \        3,          3,          ,          R\        \         P                  \        3,          /# )r<   r´   rŽ   r[   rM   rò   Úquant_predicater>   )
rž   rŸ   r�   r	   r1   rY   r   r   rå   r
   )rB   s   "r8   rC   rC     s‘   € ÷ L#ñ L#Ü�9‰9ðL#äðL#ô œ•ðL#ô ”3�-ð	L#ô
 ðL#ô œh¬¬R¯Y©YÐ'7¼¼tÄT¸zÕ9JÐ'JÕKÕLðL#ô Œ2�9‰9”dˆ?ÕñL#r:   c                óX  aaa	a
a€ R p\         P                  ! V4      oS;'       g    \        V RR4      oV! VSV4      w  opRSRVRV/o
RS9   d   Ro	MR	o	S
SR&   V	VV
VV3R
 lp\        P                  ! V SVVVR7       SR,          SR&   \        V 4      p\        RVR R24       V S3# )aˆ  
Applies quantization to the model weights.

Args:
    model (nn.Module): The model to be quantized.
    config (dict): Model configuration.
    group_size (Optional[int]): Group size for quantization.
    bits (Optional[int]): Bits per weight for quantization.
    mode (str): The quantization mode.
    quant_predicate (Callable): A callable that decides how to quantize
      each layer based on the path. Accepts the layer `path` and the
      `module`. Returns either a bool to signify quantize/no quantize or
      a dict of quantization parameters to pass to `to_quantized`.

Returns:
    Tuple: Tuple containing quantized model and config.
c                 óZ   € R RRRRRRR/pW0,          w  rET;'       g    TT;'       g    T3# )ró   rú   rý   rþ   )é@   rE   )é    rE   )é   rE   )rŸ  é   r±   )rò   r[   rM   Úmode_defaultsÚdefault_group_sizeÚdefault_bitss   &&&   r8   Údefaults_for_modeÚ)quantize_model.<locals>.defaults_for_mode   sG   € à�gØ�WØ�WØ�Wð	
ˆð ,9Õ+>Ñ(ÐØ×/Ð/Ð/°×1EÐ1E¸ÐEÐEr:   r›  Nr[   rM   rò   rí   TFc                 ó"  <€ \        VR 4      '       g   R# VP                  P                  R,          S,          ^ 8w  d   R# RpSe	   S! W4      p\        V\        4      '       d   VSR,          V &   V# S'       d   V'       d   SSR,          V &   V# )rî   FTrí   ri   )r«   rƒ   rK   r�   r�   )rT  ÚmoduleÚbool_or_paramsÚfine_grained_configr[   Úquant_paramsr›  Úquantized_configs   && €€€€€r8   Úwrapped_predicateÚ)quantize_model.<locals>.wrapped_predicate7  s‰   ø€ Ü�v˜~×.Ò.ÙØ�=‰=×Ñ˜rÕ" ZÕ/°1Ô4ÙØˆØÒ&Ù,¨TÓ:ˆNÜ�n¤d×+Ò+Ø5CÐ˜^Õ,¨TÑ2ð Ð÷ !§^Ø5AÐ˜^Õ,¨TÑ2ØÐr:   )rò   rð   rX   z[INFO] Quantized model with z.3fz bits per weight.)ÚcopyÚdeepcopyÚgetattrrž   rô   r½   rw  )r´   rŽ   r[   rM   rò   r›  r¥  r­  Úbpwrª  r«  r¬  s   &&f&&f   @@@r8   Úquantize_modelr³    sÝ   ü€ ò4Fô —}’} VÓ,Ðà%×PÐP¬°Ð8IÈ4Ó)P€OÙ(¨¨z¸4Ó@Ñ€J�Ø  *¨f°d¸FÀDÐI€LØÐ)Ô)ð #Ñà#ÐØ+7Ð˜Ñ(÷ñ ô ‡K‚KØØØØØ)õð /?¸~Õ.NÐÐ*Ñ+ä
! %Ó
(€CÜ	Ð(¨¨S¨	Ð1BÐ
CÔDàÐ"Ð"Ð"r:   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# ©r<   r´   r>   )rž   rŸ   )rB   s   "r8   rC   rC   U  s"   € ÷ +ñ +œBŸI™Ið +¬"¯)©)ñ +r:   c           	     óþ  € ^RI HpHp . pV P                  4        EF3  w  rERV9   p\	        V\
        P                  4      '       d   \
        P                  pRV/pMM\	        V\
        P                  4      '       d   / p\
        P                  pM\	        WQ4      '       d   RV/pTpMK�  \        P                  ! VP                  VP                  VP                  VP                  VP                   VP"                  4      p	V	P$                  RRR1,          p
V! V
/ VB pV'       d   VP&                  Vn        W›n        VP)                  WK34       EK6  	  \+        V4      ^ 8”  d   V P-                  \/        V4      4       V # )zª
Dequantize the quantized layers in the model.

Args:
    model (nn.Module): The model with quantized layers.

Returns:
    nn.Module: The model with dequantized layers.
)ÚQuantizedSwitchLinearÚSwitchLinearr¦   Nri   )Úmodels.switch_layersr·  r¸  Únamed_modulesr�   rž   rÿ   ÚLinearÚQuantizedEmbeddingÚ	Embeddingr@   Ú
dequantizerƒ   r~   r†   r[   rM   rò   rK   r¦   rN  r‹  r  r   )r´   r·  r¸  Údequantize_layersÚnamer¨  r¦   ÚclsÚkwargsrƒ   Úargsr    s   &           r8   Údequantize_modelrÄ  U  s8  € ÷ JàÐØ×+Ñ+×-‰ˆØ˜ÑˆÜ�fœb×0Ñ0×1Ò1Ü—)‘)ˆCØ˜d�^‰FÜ˜¤× 5Ñ 5×6Ò6ØˆFÜ—,‘,‰CÜ˜×6Ò6Ø˜d�^ˆFØ‰CáÜ—’Ø�M‰MØ�M‰MØ�M‰MØ×ÑØ�K‰KØ�K‰Kó
ˆð �|‰|™D˜b˜DÕ!ˆÙ�Ð ˜Ñ ˆßØ—[‘[ˆAŒFØŒØ× Ñ  $ ×+ñ5 .ô8 ÐÓ Ô!Ø×Ñœ^Ð,=Ó>Ô?Ø€Lr:   c                óV   € V ^8„  d   QhR\         R\        \        \        3,          RR/# )r<   rŽ   Úconfig_pathr>   N)r�   r   rY   r   )rB   s   "r8   rC   rC   ƒ  s/   € ÷ )ñ )Üð)ä”sœD�yÕ!ð)ð 
ñ)r:   c                óJ  € V P                  RR4       V P                  RR4       RV 9   d   V R,          V R&   \        \        V P                  4       4      4      p \	        VR4      ;_uu_ 4       p\
        P                  ! W^R7       RRR4       R#   + '       g   i     R# ; i)zùSave the model configuration to the ``config_path``.

The final configuration will be sorted before saving for better readability.

Args:
    config (dict): The model configuration.
    config_path (Union[str, Path]): Model configuration file path.
Ú_name_or_pathNÚvision_configrí   rX   rŠ   rˆ  )Úpopr�   r�  rw   rÙ   rÚ   r‘  )rŽ   rÆ  rD  s   && r8   Úsave_configrË  ƒ  s}   € ð ‡J�Jˆ Ô%Ø
‡J�Jˆ Ô%Ø˜ÔØ(.¨~Õ(>ˆÐ$Ñ%ô ”&˜Ÿ™›Ó(Ó)€Fô 
ˆk˜3×	Ô	 3Ü�	Š	�& aÕ(÷ 
 ×	×	Ò	ús   Á.BÂB"	c                óÚ   € V ^8„  d   QhR\         \        \        3,          R\         \        \        3,          R\        P                  R\
        R\        \        \        3,          R\        /# )r<   Údst_pathÚsrc_path_or_repor´   r/  rŽ   r|  )	r   rY   r   rž   rŸ   r   r   r   rå   )rB   s   "r8   rC   rC   �  sb   € ÷ )ñ )Ü”Cœ�IÕð)äœC¤˜IÕ&ð)ô �9‰9ð)ô  ð	)ô
 ””c��Nð)ô ñ)r:   c                 óŒ  € \        V4      pVP                  4       '       g   Tp\        V4      pMR p\        V 4      p \        WRR7       \	        W@R,          R7       VP                  V 4       R FE  p\        P                  ! \        Wh,          4      4       F  p	\        P                  ! W�4       K  	  KG  	  \        W4       R # )NT)r|  rÕ   )rÆ  )rÅ   r×   )r   rÌ   rÒ   r™  rË  Úsave_pretrainedr  rY   Úshutilr¯  ri  )
rÍ  rÎ  r´   r/  rŽ   r|  Úsrc_pathrÑ   rï   Úfiles
   &&&&&&    r8   re  re  �  s˜   € ô Ð$Ó%€HØ�?‰?×ÒØ"ˆÜ" 7Ó+‰àˆä�H‹~€HÜˆx¨TÕ2Ü�¨}Õ$<Õ=Ø×Ñ˜hÔ'ã/ˆÜ—I’Iœc (¥,Ó/Ö0ˆDÜ�KŠK˜Ö'ó 1ñ 0ô �hÖ(r:   c                ó”   € \        \        V 4      \        V4      4      p\        V4       F  pW,          W,          8w  g   K  Vu # 	  V# )a  
Calculates the length of the common prefix of two lists.

Args:
    list1: The first list of strings.
    list2: The second list of strings.

Returns:
    The length of the common prefix. Returns 0 if lists are empty
    or do not match at the first element.
)Úminr‹  rŽ  )Úlist1Úlist2Úmin_lenr•  s   &&  r8   Úcommon_prefix_lenrÙ  ¹  s@   € ô ”#�e“*œc %›jÓ)€Gô �7Ž^ˆØ�8�u•xÖàŠHñ ð €Nr:   c                óD   € V ^8„  d   QhR\         P                  R\        /# rµ  )rž   rŸ   rå   )rB   s   "r8   rC   rC   Ó  s   € ÷ ñ ¬r¯y©yð ¼Tñ r:   c                ó’   €  \         P                  ! V P                  4      pRVP                  9   #   \        \
        3 d     R# i ; i)zÇ
Check if the model supports input_embeddings in its call signature.
Args:
    model (nn.Module): The model to check.
Returns:
    bool: True if the model supports input_embeddings, False otherwise.
Úinput_embeddingsF)ÚinspectÚ	signatureÚ__call__r¬   rk   Ú	TypeError)r´   rÞ  s   & r8   Ú#does_model_support_input_embeddingsrá  Ó  sC   € ðÜ×%Ò% e§n¡nÓ5ˆ	Ø! Y×%9Ñ%9Ñ9Ð9øÜœ	Ð"ô Úðús   ‚.1 ±AÁA)i   i   )NN)NNNFFN)NNF)F)ró   N)T)Er¯  r  r“   rÝ  rÚ   rf  ÚresourcerÑ  Úpathlibr   Útextwrapr   Útypingr   r   r   r   r	   r
   r   r   Úmlx.coreÚcorer@   Úmlx.nnrž   ÚgetenvÚlowerÚ
modelscoper   r•   r]  Ú	setrlimitÚRLIMIT_NOFILEÚ	mlx.utilsr   r   r   r   Útokenizer_utilsr   r   r(  r’   ÚMAX_FILE_SIZE_GBr9   rU   rŒ   rš   rµ   r½   rÎ   rÒ   rß   r  r   r*  rH  rJ  rR  ri  r{  r™  r³  rÄ  rË  re  rÙ  rá  r±   r:   r8   Ú<module>rñ     s§  ðó Û Û Û Û Û 	Û Û Ý Ý ÷	÷ 	ó 	õ Ý à‡9‚9Ð# WÓ-×3Ñ3Ó5¸Ô?ðMÞ0õ 2ð 	× Ò �8×)Ñ)¨<Ô 8ç IÓ Iõ .Ý 4ð ˆwØˆZØ�
Ø�GØ�}Øˆ}Ø�*Ø�)Ø�7ð
€ð Ð ò	%õ7õY)õx&ò*4ò*÷&òRCõð* ØØ-1ØHT÷JõZ/ô÷01 ñhV ð 26÷V ð V ôrJð 8H÷ õ0/õ4?YðD9
ð ÷	9
÷xL#õ^+õ\)÷4)ò8÷4øðk ô MÙÐKÓLÐLðMús   Á4E. Å.E>