
    gj.                    8   S SK J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rS\R                  ;  a5  \R                  R                  S\" \" \5      R                  S-  5      5        S SKrS SKJrJrJrJrJrJrJrJr  SS jrSS	 jrSS
 jr\S:X  a  \" 5         gg)    )annotationsN)PathNO_LOCAL_GGUF   zgguf-py)	ModelBase	ModelTypeget_model_architectureget_model_classloggerprint_registered_models_mistral_common_installed_mistral_import_error_msgc                   U R                  S5      (       a  [        U S S 5      S-  nOU R                  S5      (       a  [        U S S 5      S-  S-  nO^U R                  S5      (       a  [        U S S 5      S-  S-  S-  nO0U R                  5       (       a  [        U 5      nO[        SU  S35      eUS:  a  [        SU  S	35      eU$ )
NKi  MGzInvalid split size: z5, must be a number, optionally followed by K, M, or Gr   z, must be positive)endswithint	isnumeric
ValueError)	split_strns     convert_hf_to_gguf.pysplit_str_to_n_bytesr      s    #	#2$&			C	 	 	#2$&-			C	 	 	#2$&-4						N/	{:opqq1u/	{:LMNNH    c                 $   [         R                  " SS9n U R                  SSSS9  U R                  S[        SS	9  U R                  S
[        / SQSSS9  U R                  SSSS9  U R                  S[        SSS9  U R                  SSSS9  U R                  SSSS9  U R                  S[        S SS9  U R                  SSSS9  U R                  S[
        SS S9  U R                  S![        S"S#S9  U R                  S$SS%S9  U R                  S&SS'S9  U R                  S([        S)S	9  U R                  S*SS+S9  U R                  S,SS-S9  U R                  S.SS/S9  U R                  S0SS1S9  U R                  S2SS3S9  U R                  S4SS5S9  U R                  S6SS7S9  U R                  S8SS9S9  U R                  S:SS;S9  U R                  S<SS=S9  U R                  5       nUR                  (       d  UR                  c  U R                  S>5        U$ )?Nz5Convert a huggingface model to a GGML compatible file)descriptionz--vocab-only
store_truezextract only the vocab)actionhelpz	--outfilezSpath to write to; default: based on input. {ftype} will be replaced by the outtype.)typer!   z	--outtypef32f16bf16q8_0tq1_0tq2_0autor*   zoutput format - use f32 for float32, f16 for float16, bf16 for bfloat16, q8_0 for Q8_0, tq1_0 or tq2_0 for ternary, and auto for the highest-fidelity 16-bit float type)r"   choicesdefaultr!   z--bigendianz'model is executed on big endian machinemodelzJdirectory containing model file or huggingface repository ID (if --remote)?)r"   r!   nargsz--use-temp-filez^use the tempfile library while processing (helpful when running out of memory, process killed)z	--no-lazyz\use more RAM by computing all outputs before writing (use in case lazy evaluation is broken)z--model-namezname of the model)r"   r,   r!   z	--verbosezincrease output verbosityz--split-max-tensorsr   zmax tensors in each splitz--split-max-size0zmax size per split N(M|G)z	--dry-runzConly print out a split plan and exit, without writing any new filesz--no-tensor-first-splitz;do not add tensors to the first split (disabled by default)z
--metadataz9Specify the path for an authorship metadata override filez--print-supported-modelszPrint the supported modelsz--remoteaq  (Experimental) Read safetensors file remotely without downloading to disk. Config and tokenizer files will still be downloaded. To use this feature, you need to specify Hugging Face model repo name instead of a local directory. For example: 'HuggingFaceTB/SmolLM2-1.7B-Instruct'. Note: To access gated repo, set HF_TOKEN environment variable to your Hugging Face token.z--mmprojzExport multimodal projector (mmproj) for vision models. This will only work on some vision models. An 'mmproj-' prefix will be added to the output file name.z
--code2wavzBExport the code2wav vocoder of a Qwen3-Omni model as its own GGUF.z--mtpzExport only the multi-token prediction (MTP) head as a separate GGUF, suitable for use as a speculative draft. An 'mtp-' prefix will be added to the output file name.z--no-mtpa?  Exclude the multi-token prediction (MTP) head from the converted GGUF. Pair with --mtp on a second run to publish trunk and MTP as two files. Note: the split form duplicates embeddings, but even though the bundled default is more space-efficient overall, this allows differing quantization which may be more performant.z--mistral-formatz9Whether the model is stored following the Mistral format.z)--disable-mistral-community-chat-templateab  Whether to disable usage of Mistral community chat templates. If set, use the Mistral official `mistral-common` library for tokenization and detokenization of Mistral models. Using `mistral-common` ensure correctness and zero-day support of tokenization for models converted from the Mistral format but requires to manually setup the tokenization server.z%--sentence-transformers-dense-moduleszWhether to include sentence-transformers dense modules. It can be used for sentence-transformers models, like google/embeddinggemma-300m. Default these modules are not included.z--fuse-gate-up-expszTFuse gate_exps and up_exps tensors into a single gate_up_exps tensor for MoE models.z+the following arguments are required: model)
argparseArgumentParseradd_argumentr   strr   
parse_argsprint_supported_modelsr-   error)parserargss     r   r5   r5   0   s#   $$KMF
|%   $b   #'_io w   l6   cY  
 ,m   Lk   S$    L(   C(   c(   LR   !,J   4H   "<)   < A   < m   \Q    v   < O   <H   3LB   /8   lc  
 D&&4::+=BCKr   c                    [        5       n U R                  (       a6  [        R                  " S5        [	        5         [
        R                  " S5        U R                  (       a#  [        R                  " [        R                  S9  O"[        R                  " [        R                  S9  U R                  (       ad  U R                  nSSKJn  / SQnU R                   (       a  UR#                  S5        U" UUS9n[%        U5      n[        R&                  " SU 35        OS n[%        U R                  5      nUR)                  5       (       d0  [        R                  " S	U S
35        [
        R                  " S5        [*        R,                  R.                  [*        R,                  R0                  [*        R,                  R2                  [*        R,                  R4                  [*        R,                  R6                  [*        R,                  R8                  [*        R,                  R:                  S.nU R<                  S:  =(       d    U R>                  S:g  nU R@                  (       a3  U(       a,  [        R                  " S5        [
        R                  " S5        U RB                  b  U RB                  nO+U(       a"  [%        SURE                  SS5      -   S-   5      nOUn[        R&                  " SURF                   35        U RH                  n	U	(       a  [J        (       d  [M        [N        5      eU RP                  n
[R        RT                  " 5          X`RV                     nU RX                  (       a  [Z        R\                  O0U R^                  (       a  [Z        R`                  O[Z        Rb                  n[d        Rf                  " XY5      nU	(       dR  [i        X5      n[        R&                  " SU 35         [k        X[Z        R\                  :H  U[Z        R`                  :H  S9nOJU RX                  (       a"  URo                  S5      c   S5       eSSK8J9n  UnOSU;   a	  SSK:J;n  UnOSSK:J<n  UnU Rz                  (       a=  U R|                  (       a,  [        R                  " S5        [
        R                  " S5        U Rz                  (       d  U R|                  (       as  SSK?J@n  [        WU5      (       d,  [        R                  " S 5        [
        R                  " S5        U R|                  (       a  S!Ul>        U Rz                  (       a  S!UlB        W" X[UU R                  U R@                  U R                  U R                  U R                  U R<                  [        U R>                  5      U R                  U R                  XU R                   U R                  S"9nU R                  (       aJ  [        R&                  " S#5        UR                  5         [        R&                  " S$UR                   35        Oz[        R&                  " S%5        UR                  5         U(       a(  UR                  R                   [        R                   3OUR                  n[        R&                  " S&U 35        S S S 5        g ! [l         a4    [        R                  " SU S35        [
        R                  " S5         GNf = f! , (       d  f       g = f)'NzSupported models:r   )level)snapshot_download)LICENSEz*.jsonz*.mdz*.txtztokenizer.modelz*.safetensors)repo_idallow_patternsz#Downloaded config and tokenizer to zError: z is not a directoryr   r#   r0   z*Error: Cannot use temp file when splittingz.//-z-{ftype}.ggufzLoading model: zModel architecture: )mmprojcode2wavzModel z is not supportedvision_encoderz&This model does not support multimodal)PixtralModelmoe)MistralMoeModel)MistralModelz)--mtp and --no-mtp are mutually exclusive)_Qwen35MtpMixinzG--mtp / --no-mtp are only supported for Qwen3.5/3.6 text variants todayT)is_big_endianuse_temp_fileeagermetadata_override
model_namesplit_max_tensorssplit_max_sizedry_runsmall_first_shardremote_hf_model_id'disable_mistral_community_chat_template#sentence_transformers_dense_modulesfuse_gate_up_expszExporting model vocab...z%Model vocab successfully exported to zExporting model...zModel successfully exported to )Rr5   r6   r   r7   r   sysexitverboseloggingbasicConfigDEBUGINFOremoter-   huggingface_hubr<   rU   appendr   infois_dirggufLlamaFileTypeALL_F32
MOSTLY_F16MOSTLY_BF16MOSTLY_Q8_0MOSTLY_TQ1_0MOSTLY_TQ2_0GUESSEDrO   rP   rK   outfilereplacenamemistral_formatr   ImportErrorr   rT   torchinference_modeouttyperB   r   MMPROJrC   CODE2WAVTEXTr   load_hparamsr	   r
   NotImplementedErrorgetconversion.pixtralrE   conversion.mistralrG   rH   mtpno_mtpconversion.qwenrI   
issubclassmtp_only	bigendianno_lazymetadatarN   r   rQ   no_tensor_first_splitrV   
vocab_onlywrite_vocab	fname_outwriteparentossep)r9   
hf_repo_idr<   allowed_patterns	local_dir	dir_model	ftype_mapis_splitr   is_mistral_formatrT   output_type
model_typehparamsmodel_architecturemodel_classrE   rG   rH   rI   model_instanceout_paths                         r   mainr      s   <D""()!||'--0',,/{{ZZ
5T33##O4%+-	 O	9)EF
$	wyk)<=> !!))!!,,""..""..##00##00""**0I %%)GT-@-@C-GHhAB||LL		
 2 23 <<NO		
KK/)..!123++!:!:344.2.Z.Z+				-)-Y%%PTP]P]):L:Lclcqcq
((F !7!LKK./A.BCD-.@XaXhXhJhu  DM  DV  DV  vV  X [[;;/0<f>ff<7&Kg:)K7&K88LLDEHHQK88t{{7k?;;fg{{%)"xx'+$$YY37>>QUQcQc+/<<7;}}QUQ`Q`7;7M7M4HI\I\4]gkgsgs7;7Q7Q8BIMIqIq7;7M7M
' ??KK23&&(KK?@X@X?YZ[KK,-  "GO.2299:266(CUcUmUmHKK9(DEs 
 	 ' v&8%99JKL 
 	s2   
B"[0-,Z/J[0/:[-)[0,[--[00
[>__main__)r   r4   returnr   )r   zargparse.Namespace)r   None)
__future__r   r1   rZ   r   rW   pathlibr   rq   environpathinsertr4   __file__r   rc   
conversionr   r   r	   r
   r   r   r   r   r   r5   r   __name__ r   r   <module>r      s    #   	 
  "**$HHOOAs4>009<=> 	 	 	$odxFv zF r   