o
    h2                     @   s   d dl mZmZ d dlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ e r)d dlZedd	r7d dlm  mZ e	eZeG d
d deZdS )    )	dataclassfield)Tuple   )cached_propertyis_torch_availableis_torch_tpu_availableloggingrequires_backends   )BenchmarkArgumentsNF)check_devicec                       s   e Zd ZU g dZ fddZ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def fddZedd ZedefddZedddZedd Zedd Z  ZS )PyTorchBenchmarkArguments)no_inferenceno_cudano_tpuno_speed	no_memoryno_env_printno_multi_processc                    s   | j D ](}||v r+|dd }t| |||  t| d| d| d||   q|d| j| _|d| j| _|d| j| _t j	d	i | dS )
z
        This __init__ is there for legacy code. When removing deprecated args completely, the class can simply be
        deleted
           Nz! is depreciated. Please use --no_z or =torchscripttorch_xla_tpu_print_metricsfp16_opt_level )
deprecated_argssetattrpoploggerwarningr   r   r   super__init__)selfkwargsdeprecated_argpositive_arg	__class__r   [/var/www/html/ai/venv/lib/python3.10/site-packages/transformers/benchmark/benchmark_args.pyr"   .   s    
z"PyTorchBenchmarkArguments.__init__Fhelpz"Trace the models using torchscript)defaultmetadatar   zPrint Xla/PyTorch tpu metricsr   O1zFor fp16: Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. See details at https://nvidia.github.io/apex/amp.htmlr   returntorch.devicec                 C   sv   t | dg td | jstd}d}||fS t r&t }d}||fS ttj	 r/dnd}tj
 }||fS )NtorchzPyTorch: setting up devicescpur   cuda)r
   r   infor2   r0   devicer   xm
xla_deviceis_availabledevice_count)r#   r4   n_gpur   r   r)   _setup_devicesM   s   


z(PyTorchBenchmarkArguments._setup_devicesc                 C   s   t  o| jS )N)r   tpur#   r   r   r)   is_tpu\   s   z PyTorchBenchmarkArguments.is_tpuc                 C   s   t | dg tj S )Nr0   )r
   r0   r2   current_devicer<   r   r   r)   
device_idx`   s   
z$PyTorchBenchmarkArguments.device_idxc                 C      t | dg | jd S )Nr0   r   r
   r:   r<   r   r   r)   r4   f      
z PyTorchBenchmarkArguments.devicec                 C   r@   )Nr0   r   rA   r<   r   r   r)   r9   k   rB   zPyTorchBenchmarkArguments.n_gpuc                 C   s
   | j dkS )Nr   )r9   r<   r   r   r)   is_gpup   s   
z PyTorchBenchmarkArguments.is_gpu)r.   r/   )__name__
__module____qualname__r   r"   r   r   bool__annotations__r   r   strr   r   intr:   propertyr=   r?   r4   r9   rC   __classcell__r   r   r'   r)   r   "   s.   
 



r   )dataclassesr   r   typingr   utilsr   r   r   r	   r
   benchmark_args_utilsr   r0   torch_xla.core.xla_modelcore	xla_modelr5   
get_loggerrD   r   r   r   r   r   r)   <module>   s   

