+
    i\i:                     ,   ^ 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 ^ RIHt ^ RI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!OtR"R R lltR tR R ltR R ltR#R R lltR$R R lltR R lt R%R R  llt!R# )&    N)Path)dedent)ListOptionalTupleUnion)snapshot_download)tree_flattenoutettssparkmarvissesamecsmvoxcpmz	voxcpm1.5vibevoice_streaming	vibevoicechatterbox_turbosopranoc                R    V ^8  d   QhR\         R\        \         ,          R\        /# )   path_or_hf_reporevisionreturn)strr   r   )formats   "k/Users/agent/.cache/uv/archive-v0/6ZL4-8mCcRNgGE9wi6M6J/lib/python3.14/site-packages/mlx_audio/tts/utils.py__annotate__r      s%     # #C #8C= #D #    c                z    \        V 4      pVP                  4       '       g   \        \        V V. ROR7      4      pV# )ab  
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 path to the model.
)r   allow_patterns)*.json*.safetensors*.pyz*.modelz
*.tiktoken*.txtz*.jsonl*.yaml*.wavr$   z*.pth)r   existsr	   )r   r   
model_paths   && r   get_model_pathr)      sB     o&J! 

( r   c                 |   \        \        4      P                  R,          p . pV P                  4       '       d   V P	                  4       '       dn   V P                  4        FY  pVP	                  4       '       g   K  VP                  P                  R4      '       d   K>  VP                  VP                  4       K[  	  V# )z
Get a list of all available TTS model types by scanning the models directory.

Returns:
    List[str]: A list of available model type names
models__)	r   __file__parentr'   is_diriterdirname
startswithappend)
models_diravailable_modelsitems      r   get_available_modelsr7   E   s     h&&1Jz0022&&(D{{}}TYY%9%9$%?%? ''		2 ) r   c                F    V ^8  d   QhR\         R\        \         ,          /# )r   
model_type
model_name)r   r   )r   s   "r   r   r   W   s     , ,3 ,DI ,r   c                R   \         P                  V R4      p\        4       pVe2   W 8w  d,   V F%  pWC9   d   Tp V\         9   g   K  \         V,          p  M	   \        P                  ! RV  24      pWP3#   \
         d)    RT  R2p\        P                  ! T4       \        T4      hi ; i)a  
Retrieve the model architecture module based on the model type and name.

This function attempts to find the appropriate model architecture by:
1. Checking if the model_type is directly in the MODEL_REMAPPING dictionary
2. Looking for partial matches in segments of the model_name

Args:
    model_type (str): The type of model to load (e.g., "outetts").
    model_name (List[str]): List of model name components that might contain
                           remapping information.

Returns:
    Tuple[module, str]: A tuple containing:
        - The imported architecture module
        - The resolved model_type string after remapping

Raises:
    ValueError: If the model type is not supported (module import fails).
Nzmlx_audio.tts.models.zModel type z not supported.)	MODEL_REMAPPINGgetr7   	importlibimport_moduleImportErrorloggingerror
ValueError)r9   r:   model_type_mappedr+   partarchmsgs   &&     r   get_model_and_argsrH   W   s    , (++J= "#F"3"AD~!
 &,T2
 &&)>zl'KL   J<7cos   A3 33B&c                R    V ^8  d   QhR\         \        \        3,          R\        /# )r   r(   r   )r   r   r   dict)r   s   "r   r   r      s'     R RE#t), R4 Rr   c                   ^ RI Hp \        V \        4      '       d   \	        V 4      p  VP
                  ! V 3/ VB P                  4       #   \         dy     \        T R,          RR7      ;_uu_ 4       p\        P                  ! T4      uuRRR4       u #   + '       g   i      R# ; i  \         d   p\        RT  24      ThRp?ii ; ii ; i)aA  Load model configuration from a path or Hugging Face repo.

Args:
    model_path: Local path or Hugging Face repo ID to load config from
    **kwargs: Additional keyword arguments to pass to the config loader

Returns:
    dict: Model configuration

Raises:
    FileNotFoundError: If config.json is not found at the path
)
AutoConfigconfig.jsonzutf-8)encodingNzConfig not found at )transformersrL   
isinstancer   r)   from_pretrainedto_dictrC   openjsonloadFileNotFoundError)r(   kwargsrL   fexcs   &,   r   load_configrZ      s     (*c""#J/
R))*??GGII R	Rj=07CCqyy| DCCC  	R#&::,$GHcQ	R	RsM    A
 
CB*2B
B*CB' B*'B**C	5CC		Cc                \    V ^8  d   QhR\         R\        R\        R\        P                  /# )r   r(   lazystrictr   )r   boolnnModule)r   s   "r   r   r      s6     G GG G26GYYGr   c                  aa Rp\        V \        4      '       dA   V P                  4       P                  R4      R,          P                  R4      p\	        V 4      p \        V \
        4      '       dk    V P                  P                  R4      pV P                  V^,           ,          P                  4       P                  R4      R,          P                  R4      pM\        R\        V 4       24      h\        V 3/ VB oV SR&   \        V 4      SR&   SP                  R	R4      pVf   SP                  R
R4      pVf   Ve   V^ ,          P                  4       MRpSP                  RR4      p\        P                  ! \        V R,          4      4      pV'       g.   \        P                  ! \        V R,          R,          4      4      pV'       g+   \        P                  ! RV  24       RV  R2p	\!        V	4      h/ oV F(  p
SP#                  \$        P&                  ! V
4      4       K*  	  \)        WdR7      w  r\+        VR4      '       d   VP,                  P/                  S4      MSpVe   \+        VR4      '       d   Wn        VP3                  V4      pSP                  RR4      pVf   VP5                  S4      oSP                  RR4      ;pe0   VV3R lp\6        P8                  ! VVR,          VR,          VR7       VP;                  \=        SP?                  4       4      VR7       V'       g%   \$        P@                  ! VPC                  4       4       VPA                  4        \+        VP2                  R4      '       d   VP2                  PE                  W4      pV#   \         d.    T P                  P                  4       P                  R4      p ELi ; i)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``

Returns:
    nn.Module: The loaded and initialized model.

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.
N/-hubz--zInvalid model path type: tokenizer_namer(   r9   architecturequantizationr"   LLMzNo safetensors found in z
No safetensors found in a  
Create safetensors using the following code:
```
from transformers import AutoModelForCausalLM, AutoProcessor

model_id= "<huggingface_model_id>"
model = AutoModelForCausalLM.from_pretrained(model_id)
processor = AutoProcessor.from_pretrained(model_id)

model.save_pretrained("<local_dir>")
processor.save_pretrained("<local_dir>")
```
Then use the <local_dir> as the --hf-path in the convert script.
```
python -m mlx_audio.tts.convert --hf-path <local_dir> --mlx-path <mlx_dir>
```
        )r9   r:   ModelConfigc                    < V SR ,          9   d   SR ,          V ,          # \        VR4      '       g   R# \        VR4      '       d%   VP                  P                  ^@,          ^ 8w  d   R# V  R2S9   # )rg   to_quantizedFweightz.scales)hasattrrl   size)pmconfigweightss   &&r   get_class_predicate'load_model.<locals>.get_class_predicate	  se    F>**n-a001n--q(##(:a(?S=G++r   
group_sizebits)ru   rv   class_predicate)r]   post_load_hook)#rP   r   lowersplitr)   r   partsindexrC   r1   typerZ   r=   globrA   rB   rV   updatemxrU   rH   rm   ri   	from_dictr(   Modelsanitizer_   quantizeload_weightslistitemseval
parametersrx   )r(   r\   r]   rW   r:   r}   r9   rg   weight_filesmessagewfmodel_classmodel_configmodelrs   rq   rr   s   &&&,           @@r   
load_modelr      sM   & J*c""%%'--c226<<SA
#J/
*d##	<$$**51E#))%!)4::<BB4HLRRSVWJ
 4T*5E4FGHH.v.F)FF<
 L$/JZZ5
.8.DZ]((*$
::nd3L99So!=>?L yyZ%%7/%I!JK0=># %	$  ((Grwwr{#  1K ;.. 	))&1  GL,$G$G",l+E::nd3L..)

>488E
	, 	#L1f%/		
 
tGMMO,V<
  "#	JJL
 {  "233!!00CLY  	<#..066s;J	<s   2A(N 4OOc                r    V ^8  d   QhR\         R\        R\        \        P                  \
        3,          /# )r   r(   r\   r   )r   r^   r   r_   r`   rJ   )r   s   "r   r   r   ,  s1       
299d?r   c                 8    \        W3/ VB p\        V 3/ VB pW43# N)r   rZ   )r(   r\   rW   r   rq   s   &&,  r   fetch_from_hubr   ,  s*     z262E.v.F=r   c                <    V ^8  d   QhR\         R\         R\         /# )r   pathupload_repohf_path)r   )r   s   "r   r   r   4  s&     ,Y ,Y ,Y# ,Y ,Yr   c                   ^ RI p^ RIHpHpHp ^RIHp VP                  V4      pVP                  P                  f   R.MVP                  P                  R.,           VP                  n	        \        RV RV RV RV R	V R
V R24      Vn        VP                  VP                  P                  V R4      4       VP                  ! 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.
    hf_path (str): Path to the original Hugging Face model.
N)HfApi	ModelCardrA   )__version__mlxz
        # z7
        This model was converted to MLX format from [`z`](https://huggingface.co/z) using mlx-audio version **zF**.
        Refer to the [original model card](https://huggingface.co/z) for more details on the model.
        ## Use with mlx

        ```bash
        pip install -U mlx-audio
        ```

        ```bash
        python -m mlx_audio.tts.generate --model z3 --text "Describe this image."
        ```
        z	README.mdT)repo_idexist_okr   )folder_pathr   	repo_typez0Upload successful, go to https://huggingface.co/z for details.)oshuggingface_hubr   r   rA   versionr   rU   datatagsr   textsaver   joinset_verbosity_infocreate_repoupload_folderprint)
r   r   r   r   r   r   rA   r   cardapis
   &&&       r   upload_to_hubr   4  s    99%>>'"D $		 6eWDIINNeW<TDIIN- 77>i?YZaYbb~  @K  L LCCJ) L2 3> ?		DI  	IIbggll4-. 
'COOK$O7  
 
<[M
WXr   c                    V ^8  d   QhR\         R\         R\        R\        R\        R\         R\         R\        \         ,          R	\        R
\        R\        \         ,          /# )r   r   mlx_pathr   q_group_sizeq_bitsdtyper   r   
dequantizetrust_remote_codequant_predicate)r   r^   intr   )r   s   "r   r   r   c  s     h6 h6h6h6 h6 	h6
 h6 h6 h6 smh6 h6 h6 c]h6r   c                   aaa ^ RI Hp ^ RIHpHpHpHp \        R4       \        WR7      p\        VRV	R7      w  pp\        V
\        4      '       d
   V! V
V4      p
\        VRR 4      oV3R	 loV
f   Sp
M	V
oVV3R lp
\        \        VP                  4       4      4      pVf   VP!                  RR
4      pV\"        9   dQ   \        RV4       \        \$        V4      pVP'                  4        UUu/ uF  w  ppVVP)                  V4      bK  	  pppV'       d   V'       d   \+        R4      hV'       dC   \        R4       VP-                  \/        VP'                  4       4      4       V! VVW4V
R7      w  ppV'       d6   \        R4       V! V4      p\        \        VP                  4       4      4      p\        V\        4      '       d   \1        V4      pVP3                  RRR7       R F  p\4        P4                  ! \        VV,          4      4      pV F  p\6        P8                  ! VV4       K  	  \4        P4                  ! \        VR,          V,          4      RR7      pV FZ  p\1        V4      P;                  V4      pVVP<                  ,          pVP3                  RRR7       \6        P8                  ! VV4       K\  	  K  	  V! VVRR7       V! VVR,          R7       Ve   \?        WV 4       R
# R
# u uppi )r   )mixed_quant_predicate_builder)dequantize_modelquantize_modelsave_config
save_modelz[INFO] Loading)r   T)r\   r   model_quant_predicatec                     R # )T )ro   rp   s   &&r   <lambda>convert.<locals>.<lambda>}  s    QUr   c                    < \        VR 4      ;'       dL    VP                  P                  R,          ^@,          ^ 8H  ;'       d    \        VR4      ;'       d	    S! W4      # )rl   rk   ry   )rm   rl   shape)ro   rp   r   s   &&r   base_quant_requirements(convert.<locals>.base_quant_requirements  s^    Ax  , ,r"R'1,, ,>*, , &a+		
r   Nc                 4   < S! W4      ;'       d	    S! W4      # r   r   )ro   rp   r   original_predicates   &&r   r   r     s    #A)FF.@.FFr   torch_dtypez[INFO] Using dtype:z/Choose either quantize or dequantize, not both.z[INFO] Quantizing)r   z[INFO] Dequantizing)parentsr   z**)	recursive)donate_modelrM   )config_path)r#   r!   r&   z*.ptr"   r%   r$   ) mlx_lm.convertr   mlx_lm.utilsr   r   r   r   r   r)   r   rP   r   getattrrJ   r
   r   r=   MODEL_CONVERSION_DTYPESr   r   astyperC   r   r   r   mkdirr   shutilcopyrelative_tor.   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r   rq   rr   kvpatternfilesfilesubdir_filesrel_pathdest_dirr   r   r   s   &&&&&&&&&&&                 @@@r   convertr   c  s    =VV	
;J"1BME6 /3''7O $E+BDUV
 1,
 < 0 0 234G}

=$/''#U+E"29--/B/$!Q1ahhuo%/BJJKK!"401(6<
 #$ '|E$4$4$678(C  > NN4$N/ 		#j7234DKKh'  yyZ$%6%@!ATR DDz--j9H(//1HNN4$N7KKh' !, xT2H}$<=hW5 e Cs   3K8)float16bfloat16float32r   )FT)F)
	mlx_modelF@      NNNFTN)"r   r>   rT   rA   r   pathlibr   textwrapr   typingr   r   r   r   mlx.corecorer   mlx.nnr_   r   r	   	mlx.utilsr
   r<   MAX_FILE_SIZE_GBr   r)   r7   rH   rZ   r   r   r   r   r   r   r   <module>r      s           / /   - " yWh	8h;*y
  < #N$,^R8GT,Y^h6 h6r   