
    C1i                     j    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Jr   " S S\ R                  5      r
g)    N)Optional)ACCEPTED_MODEL_TYPES	ModelSpecc                       \ rS rSrSr\S\R                  S\R                  4S j5       rS\R                  S\
4S jr   SS	\
S
\\
   S\\
   S\S\
4
S jjr\R                   S 5       rSrg)	Converter   z Base class for model converters.parserreturnc                     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 $ )zoAdds common conversion options to the command line parser.

Arguments:
  parser: Command line argument parser.
z--output_dirTzOutput model directory.)requiredhelpz--vocab_mappingNz#Vocabulary mapping file (optional).)defaultr   z--quantizationzWeight quantization type.)r   choicesr   z--force
store_truez=Force conversion even if the output directory already exists.)actionr   )add_argumentr   )r	   s    Z/home/james-whalen/.local/lib/python3.13/site-packages/ctranslate2/converters/converter.pydeclare_argumentsConverter.declare_arguments   s     	T0I 	 	
 	t2W 	 	
 	(,	 	 	
 	P 	 	

     argsc                 v    U R                  UR                  UR                  UR                  UR                  S9$ )zHelper function to call :meth:`ctranslate2.converters.Converter.convert`
with the parsed command line options.

Arguments:
  args: Namespace containing parsed arguments.

Returns:
  Path to the output directory.
)vmapquantizationforce)convert
output_dirvocab_mappingr   r   )selfr   s     r   convert_from_argsConverter.convert_from_args(   s:     ||OO##****	  
 	
r   Nr   r   r   r   c                    [         R                  R                  U5      (       a  U(       d  [        SU-  5      eU R	                  5       nUc  [        S5      eUb  UR                  U5        UR                  5         UR                  US9  [         R                  R                  U5      (       a  [        R                  " U5        [         R                  " U5        UR                  U5        U$ )a  Converts the model to the CTranslate2 format.

Arguments:
  output_dir: Output directory where the CTranslate2 model is saved.
  vmap: Optional path to a vocabulary mapping file that will be included
    in the converted model directory.
  quantization: Weight quantization scheme (possible values are: int8, int8_float32,
    int8_float16, int8_bfloat16, int16, float16, bfloat16, float32).
  force: Override the output directory if it already exists.

Returns:
  Path to the output directory.

Raises:
  RuntimeError: If the output directory already exists and :obj:`force`
    is not set.
  NotImplementedError: If the converter cannot convert this model to the
    CTranslate2 format.
z;output directory %s already exists, use --force to overridez<This model is not supported by CTranslate2 or this converter)r   )ospathexistsRuntimeError_loadNotImplementedErrorregister_vocabulary_mappingvalidateoptimizeshutilrmtreemakedirssave)r   r   r   r   r   
model_specs         r   r   Converter.convert9   s    4 77>>*%%eM 
 ZZ\
%N  22486 77>>*%%MM*%
J
#r   c                     [        5       e)N)r(   )r   s    r   r'   Converter._loadk   s    !##r    )NNF)__name__
__module____qualname____firstlineno____doc__staticmethodargparseArgumentParserr   	Namespacestrr    r   boolr   abcabstractmethodr'   __static_attributes__r4   r   r   r   r      s    *("9"9 h>U>U  2
h&8&8 
S 
( #&*00 sm0 sm	0
 0 
0d 	$ $r   r   )r@   r;   r#   r,   typingr   ctranslate2.specs.model_specr   r   ABCr   r4   r   r   <module>rF      s)    
  	   Hb$ b$r   