U
    9%eK                     @   sv   d dl Z d dlZd dlZd dl mZmZ d dlmZ d dlmZ ddlm	Z	 e	
eZdddZeG d	d
 d
ZdS )    N)	dataclassfield)time)List   )loggingc                    s   t  fdd|dS )Nc                      s    S )N r   defaultr   j/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/benchmark/benchmark_args_utils.py<lambda>       zlist_field.<locals>.<lambda>)default_factorymetadata)r   r
   r   r   r	   r   
list_field   s    r   c                   @   s  e Zd ZU dZeg ddidZee ed< edgddidZ	ee
 ed< edd	d
dgddidZee
 ed< edddidZeed< edddidZeed< edddidZeed< edddidZeed< edddidZeed< edddidZeed< edddidZeed< edddidZeed< eddd idZeed!< eddd"idZeed#< eddd$idZeed%< eddd&idZeed'< eddd(idZeed)< ed*ee  d+dd,idZeed-< ed.ee  d+dd/idZeed0< ed1ee  d+dd2idZeed3< ed4ee  d+dd5idZ eed6< ed7ee  d+dd8idZ!eed9< ed:ee  d+dd;idZ"eed<< ed=dd>idZ#e
ed?< eddd@idZ$eedA< dBdC Z%dDdE Z&e'ee dFdGdHZ(e'dIdJ Z)dKS )LBenchmarkArgumentsz
    BenchMarkArguments are arguments we use in our benchmark scripts **which relate to the training loop itself**.

    Using `HfArgumentParser` we can turn this class into argparse arguments to be able to specify them on the command
    line.
    helpz|Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version of all available modelsr   models   zKList of batch sizes for which memory and time performance will be evaluatedbatch_sizes       i   zPList of sequence lengths for which memory and time performance will be evaluatedsequence_lengthsTzVWhether to benchmark inference of model. Inference can be disabled via --no-inference.	inferencezMWhether to run on available cuda devices. Cuda can be disabled via --no-cuda.cudazJWhether to run on available tpu devices. TPU can be disabled via --no-tpu.tpuFz!Use FP16 to accelerate inference.fp16zBenchmark training of modeltrainingzVerbose memory tracingverbosezYWhether to perform speed measurements. Speed measurements can be disabled via --no-speed.speedz[Whether to perform memory measurements. Memory measurements can be disabled via --no-memorymemoryzTrace memory line by linetrace_memory_line_by_linezSave result to a CSV filesave_to_csvz'Save all print statements in a log file	log_printz(Whether to print environment information	env_printzWhether to use multiprocessing for memory and speed measurement. It is highly recommended to use multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled for debugging / testing and on TPU.multi_processZinference_time_z.csvz0CSV filename used if saving time results to csv.inference_time_csv_fileZinference_memory_z2CSV filename used if saving memory results to csv.inference_memory_csv_fileZtrain_time_z=CSV filename used if saving time results to csv for training.train_time_csv_fileZtrain_memory_z?CSV filename used if saving memory results to csv for training.train_memory_csv_fileZ	env_info_z4CSV filename used if saving environment information.env_info_csv_fileZlog_z7Log filename used if print statements are saved in log.log_filename   z Times an experiment will be run.repeatzrInstead of loading the model as defined in `config.architectures` if exists, just load the pretrain model weights.only_pretrain_modelc                 C   s   t d| j dt d S )Nz
The class z is deprecated. Hugging Face Benchmarking utils are deprecated in general and it is advised to use external Benchmarking libraries  to benchmark Transformer models.)warningswarn	__class__FutureWarningselfr   r   r   __post_init__   s    z BenchmarkArguments.__post_init__c                 C   s   t jt| ddS )z<
        Serializes this instance to a JSON string.
        r   )indent)jsondumpsdataclassesasdictr4   r   r   r   to_json_string   s    z!BenchmarkArguments.to_json_string)returnc                 C   s   t | jdkrtd| jS )Nr   zPlease make sure you provide at least one model name / model identifier, *e.g.* `--models bert-base-cased` or `args.models = ['bert-base-cased'].)lenr   
ValueErrorr4   r   r   r   model_names   s
    zBenchmarkArguments.model_namesc                 C   s&   | j s
dS | jrtd dS dS d S )NFz1Multiprocessing is currently not possible on TPU.T)r&   Zis_tpuloggerinfor4   r   r   r   do_multi_processing   s    
z&BenchmarkArguments.do_multi_processingN)*__name__
__module____qualname____doc__r   r   r   str__annotations__r   intr   r   r   boolr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   roundr   r'   r(   r)   r*   r+   r,   r.   r/   r6   r<   propertyr@   rC   r   r   r   r   r   "   s   

 
  

r   )NN)r:   r8   r0   r   r   r   typingr   utilsr   Z
get_loggerrD   rA   r   r   r   r   r   r   <module>   s   

