



from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
 import torch

if is_torch_tpu_available(check_device=False):
 import torch_xla.core.xla_model as xm


a_   :Tuple        =      logging.get_logger(__name__)




@dataclass
class 					snake_case__						(       lowerCAmelCase_     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	[
         """no_inference""",
         """no_cuda""",
         """no_tpu""",
         """no_speed""",
         """no_memory""",
         """no_env_print""",
         """no_multi_process""",
     ]






     def __init__(       self  :  Any, **_snake_case  :  Union[str, Any]					)   ->Optional[Any]:
            for deprecated_arg in self.deprecated_args:
                   if deprecated_arg in kwargs:
                          snake_case__							:	int   	=	deprecated_arg[3:]
                          setattr(self, _snake_case, not kwargs.pop(_snake_case					)					)
                          logger.warning(
                              F'''{deprecated_arg} is depreciated. Please use --no_{positive_arg} or'''
                              F''' {positive_arg}={kwargs[positive_arg]}'''					)

            snake_case__							:	Union[str, Any]   	=	kwargs.pop('torchscript', self.torchscript					)
            snake_case__							:	int   	=	kwargs.pop('torch_xla_tpu_print_metrics', self.torch_xla_tpu_print_metrics					)
            snake_case__							:	Optional[Any]   	=	kwargs.pop('fp16_opt_level', self.fpaa_opt_level					)
            super().__init__(**_snake_case					)

     _SCREAMING_SNAKE_CASE						=	field(default=lowerCAmelCase_				,     metadata={"""help""": """Trace the models using torchscript"""}     )
     _SCREAMING_SNAKE_CASE						=	field(default=lowerCAmelCase_				,     metadata={"""help""": """Print Xla/PyTorch tpu metrics"""}     )
     _SCREAMING_SNAKE_CASE						=	field(
         default="""O1"""				,     metadata={
             """help""": (
                 """For fp16: Apex AMP optimization level selected in ['O0', 'O1', 'O2', and 'O3']. """
                 """See details at https://nvidia.github.io/apex/amp.html"""
             )
         }				,     )






     @cached_property
     def    lowercase_   (       self  :  int					)   ->Tuple["torch.device", int]:
            requires_backends(self, ['torch']					)
            logger.info('PyTorch: setting up devices'					)
            if not self.cuda:
                   snake_case__							:	Union[str, Any]   	=	torch.device('cpu'					)
                   snake_case__							:	Tuple   	=	0
            elif is_torch_tpu_available():
                   snake_case__							:	Union[str, Any]   	=	xm.xla_device()
                   snake_case__							:	Tuple   	=	0
            else:
                   snake_case__							:	str   	=	torch.device('cuda' if torch.cuda.is_available() else 'cpu'					)
                   snake_case__							:	Union[str, Any]   	=	torch.cuda.device_count()
            return device, n_gpu






     @property
     def    lowercase_   (       self  :  Union[str, Any]					)   ->List[str]:
            return is_torch_tpu_available() and self.tpu






     @property
     def    lowercase_   (       self  :  List[Any]					)   ->int:
            requires_backends(self, ['torch']					)
            # TODO(PVP): currently only single GPU is supported
            return torch.cuda.current_device()






     @property
     def    lowercase_   (       self  :  Union[str, Any]					)   ->"torch.device":
            requires_backends(self, ['torch']					)
            return self._setup_devices[0]






     @property
     def    lowercase_   (       self  :  Tuple					)   ->Tuple:
            requires_backends(self, ['torch']					)
            return self._setup_devices[1]






     @property
     def    lowercase_   (       self  :  int					)   ->Union[str, Any]:
            return self.n_gpu > 0











from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_   :Optional[int]        =      logging.get_logger(__name__)

a_   :Dict        =      {"openai-gpt": "https://huggingface.co/openai-gpt/resolve/main/config.json"}




class 					snake_case__						(       lowerCAmelCase_     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	"""openai-gpt"""
     _SCREAMING_SNAKE_CASE						=	{
         """max_position_embeddings""": """n_positions""",
         """hidden_size""": """n_embd""",
         """num_attention_heads""": """n_head""",
         """num_hidden_layers""": """n_layer""",
     }






     def __init__(       self  :  Optional[int], _snake_case  :  Dict=4_0_4_7_8, _snake_case  :  str=5_1_2, _snake_case  :  int=7_6_8, _snake_case  :  Tuple=1_2, _snake_case  :  Any=1_2, _snake_case  :  str="gelu", _snake_case  :  List[str]=0.1, _snake_case  :  Any=0.1, _snake_case  :  Dict=0.1, _snake_case  :  int=1e-5, _snake_case  :  Optional[Any]=0.0_2, _snake_case  :  List[Any]="cls_index", _snake_case  :  Any=True, _snake_case  :  Any=None, _snake_case  :  int=True, _snake_case  :  Optional[Any]=0.1, **_snake_case  :  List[Any], )   ->Optional[int]:
            snake_case__							:	int   	=	vocab_size
            snake_case__							:	Dict   	=	n_positions
            snake_case__							:	str   	=	n_embd
            snake_case__							:	str   	=	n_layer
            snake_case__							:	List[Any]   	=	n_head
            snake_case__							:	List[Any]   	=	afn
            snake_case__							:	Optional[Any]   	=	resid_pdrop
            snake_case__							:	List[str]   	=	embd_pdrop
            snake_case__							:	List[Any]   	=	attn_pdrop
            snake_case__							:	Optional[int]   	=	layer_norm_epsilon
            snake_case__							:	str   	=	initializer_range
            snake_case__							:	List[str]   	=	summary_type
            snake_case__							:	Optional[int]   	=	summary_use_proj
            snake_case__							:	List[str]   	=	summary_activation
            snake_case__							:	Optional[Any]   	=	summary_first_dropout
            snake_case__							:	int   	=	summary_proj_to_labels
            super().__init__(**_snake_case					)






