
    n i                     h    d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ  G d de j	                  Z
dS )    N)Optional)ACCEPTED_MODEL_TYPES	ModelSpecc                       e Zd ZdZedej        dej        fd            Zdej        de	fdZ
	 	 	 dd	e	d
ee	         dee	         dede	f
dZej        d             ZdS )	Converterz Base class for model converters.parserreturnc                     |                      ddd           |                      ddd           |                      d	dt          d
           |                      ddd           | S )zAdds 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    `/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/ctranslate2/converters/converter.pydeclare_argumentszConverter.declare_arguments   s     	T0I 	 	
 	
 	
 	t2W 	 	
 	
 	
 	(,	 	 	
 	
 	
 	P 	 	
 	
 	

     argsc                 \    |                      |j        |j        |j        |j                  S )a  Helper 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_argszConverter.convert_from_args(   s5     ||O#**	  
 
 	
r   NFr   r   r   r   c                    t           j                            |          r|st          d|z            |                                 }|t          d          ||                    |           |                                 |                    |           t           j                            |          rt          j
        |           t          j        |           |                    |           |S )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 overrideNz<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   zConverter.convert9   s    4 7>>*%% 	e 	M  
 ZZ\\
%N   224888666 7>>*%% 	&M*%%%
J
###r   c                     t                      )N)r%   )r   s    r   r$   zConverter._loadk   s    !###r   )NNF)__name__
__module____qualname____doc__staticmethodargparseArgumentParserr   	Namespacestrr   r   boolr   abcabstractmethodr$    r   r   r   r      s        **("9 h>U    \2
h&8 
S 
 
 
 
( #&*0 00 sm0 sm	0
 0 
0 0 0 0d 	$ $ $ $ $r   r   )r9   r4   r    r)   typingr   ctranslate2.specs.model_specr   r   ABCr   r;   r   r   <module>r?      s    



  				        H H H H H H H Hb$ b$ b$ b$ b$ b$ b$ b$ b$ b$r   