



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


lowercase_						=       logging.get_logger(__name__)
@dataclass
class 			_snake_case     (   lowercase__):
				UpperCamelCase__			:   List[Any]       						=[
				    """no_inference""",
				    """no_cuda""",
				    """no_tpu""",
				    """no_speed""",
				    """no_memory""",
				    """no_env_print""",
				    """no_multi_process""",
				]




				def __init__(  self   :  List[str],   **__lowercase   :  str  ):
							for deprecated_arg in self.deprecated_args:
										if deprecated_arg in kwargs:
													lowercase__   					=			deprecated_arg[3:]
													setattr(self,   __lowercase,   not kwargs.pop(__lowercase  )  )
													logger.warning(
													    F'''{deprecated_arg} is depreciated. Please use --no_{positive_arg} or'''
													    F''' {positive_arg}={kwargs[positive_arg]}'''  )

							lowercase__   					=			kwargs.pop("torchscript",   self.torchscript  )
							lowercase__   					=			kwargs.pop("torch_xla_tpu_print_metrics",   self.torch_xla_tpu_print_metrics  )
							lowercase__   					=			kwargs.pop("fp16_opt_level",   self.fpaa_opt_level  )
							super().__init__(**__lowercase  )

				UpperCamelCase__			:   bool       						=field(default=lowercase__      ,		metadata={"""help""": """Trace the models using torchscript"""})
				UpperCamelCase__			:   bool       						=field(default=lowercase__      ,		metadata={"""help""": """Print Xla/PyTorch tpu metrics"""})
				UpperCamelCase__			:   str       						=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 							A__ (  self   :  List[Any]  ):
							requires_backends(self,   ["torch"]  )
							logger.info("PyTorch: setting up devices"  )
							if not self.cuda:
										lowercase__   					=			torch.device("cpu"  )
										lowercase__   					=			0
							elif is_torch_tpu_available():
										lowercase__   					=			xm.xla_device()
										lowercase__   					=			0
							else:
										lowercase__   					=			torch.device("cuda" if torch.cuda.is_available() else "cpu"  )
										lowercase__   					=			torch.cuda.device_count()
							return device, n_gpu




				@property
				def 							A__ (  self   :  Union[str, Any]  ):
							return is_torch_tpu_available() and self.tpu




				@property
				def 							A__ (  self   :  List[str]  ):
							requires_backends(self,   ["torch"]  )
							# TODO(PVP): currently only single GPU is supported
							return torch.cuda.current_device()




				@property
				def 							A__ (  self   :  Union[str, Any]  ):
							requires_backends(self,   ["torch"]  )
							return self._setup_devices[0]




				@property
				def 							A__ (  self   :  int  ):
							requires_backends(self,   ["torch"]  )
							return self._setup_devices[1]




				@property
				def 							A__ (  self   :  int  ):
							return self.n_gpu > 0




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


lowercase_						=       logging.get_logger(__name__)

lowercase_						=       {
    """facebook/dpr-ctx_encoder-single-nq-base""": (
        """https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json"""
    ),
    """facebook/dpr-question_encoder-single-nq-base""": (
        """https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json"""
    ),
    """facebook/dpr-reader-single-nq-base""": (
        """https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json"""
    ),
    """facebook/dpr-ctx_encoder-multiset-base""": (
        """https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json"""
    ),
    """facebook/dpr-question_encoder-multiset-base""": (
        """https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json"""
    ),
    """facebook/dpr-reader-multiset-base""": (
        """https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json"""
    ),
}
class 			_snake_case     (   lowercase__):
				UpperCamelCase__			:   str       						="""dpr"""




				def __init__(  self   :  int,   __lowercase   :  List[str]=3_0522,   __lowercase   :  Any=768,   __lowercase   :  Union[str, Any]=12,   __lowercase   :  Optional[int]=12,   __lowercase   :  List[Any]=3072,   __lowercase   :  List[str]="gelu",   __lowercase   :  Union[str, Any]=0.1,   __lowercase   :  str=0.1,   __lowercase   :  List[str]=512,   __lowercase   :  Optional[int]=2,   __lowercase   :  Dict=0.02,   __lowercase   :  Any=1e-1_2,   __lowercase   :  List[Any]=0,   __lowercase   :  str="absolute",   __lowercase   :  int = 0,   **__lowercase   :  str,   ):
							super().__init__(pad_token_id=__lowercase,   **__lowercase  )

							lowercase__   					=			vocab_size
							lowercase__   					=			hidden_size
							lowercase__   					=			num_hidden_layers
							lowercase__   					=			num_attention_heads
							lowercase__   					=			hidden_act
							lowercase__   					=			intermediate_size
							lowercase__   					=			hidden_dropout_prob
							lowercase__   					=			attention_probs_dropout_prob
							lowercase__   					=			max_position_embeddings
							lowercase__   					=			type_vocab_size
							lowercase__   					=			initializer_range
							lowercase__   					=			layer_norm_eps
							lowercase__   					=			projection_dim
							lowercase__   					=			position_embedding_type




