





'''simple docstring'''






from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


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

A__				:   int      ={
    '''EleutherAI/gpt-j-6B''': '''https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json''',
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}




class  UpperCAmelCase     (			a__   ):
      _lowercase:			Optional[int]						     =   """gptj"""
      _lowercase:			str						     =   {
          """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			: Optional[int]=5_04_00			,			__snake_case			: int=20_48			,			__snake_case			: Union[str, Any]=40_96			,			__snake_case			: Dict=28			,			__snake_case			: str=16			,			__snake_case			: Union[str, Any]=64			,			__snake_case			: str=None			,			__snake_case			: int="gelu_new"			,			__snake_case			: Optional[int]=0.0			,			__snake_case			: int=0.0			,			__snake_case			: Tuple=0.0			,			__snake_case			: Union[str, Any]=1E-5			,			__snake_case			: Optional[Any]=0.02			,			__snake_case			: int=True			,			__snake_case			: List[str]=5_02_56			,			__snake_case			: int=5_02_56			,			__snake_case			: List[str]=False			,			**__snake_case			: List[Any]			,			)				->      Tuple:
            _lowerCAmelCase							     =							vocab_size
            _lowerCAmelCase							     =							n_positions
            _lowerCAmelCase							     =							n_embd
            _lowerCAmelCase							     =							n_layer
            _lowerCAmelCase							     =							n_head
            _lowerCAmelCase							     =							n_inner
            _lowerCAmelCase							     =							rotary_dim
            _lowerCAmelCase							     =							activation_function
            _lowerCAmelCase							     =							resid_pdrop
            _lowerCAmelCase							     =							embd_pdrop
            _lowerCAmelCase							     =							attn_pdrop
            _lowerCAmelCase							     =							layer_norm_epsilon
            _lowerCAmelCase							     =							initializer_range
            _lowerCAmelCase							     =							use_cache

            _lowerCAmelCase							     =							bos_token_id
            _lowerCAmelCase							     =							eos_token_id

            super().__init__(
                bos_token_id=lowerCAmelCase__			,			eos_token_id=lowerCAmelCase__			,			tie_word_embeddings=lowerCAmelCase__			,			**lowerCAmelCase__  )




class  UpperCAmelCase     (			a__   ):




      def __init__(			self			: Tuple			,			__snake_case			: Optional[Any]			,			__snake_case			: int = "default"			,			__snake_case			: Union[str, Any] = None			,			__snake_case			: Any = False			,			)				->      Union[str, Any]:
            super().__init__(lowerCAmelCase__			,			task=lowerCAmelCase__			,			patching_specs=lowerCAmelCase__			,			use_past=lowerCAmelCase__  )
            if not getattr(self._config			,			"""pad_token_id"""			,			lowerCAmelCase__  ):
                  # TODO: how to do that better?
                  _lowerCAmelCase							     =							0




      @property
      def 				lowercase__    (			self			: Any  )				->      Mapping[str, Mapping[int, str]]:
            _lowerCAmelCase							     =							OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}  )
            if self.use_past:
                  self.fill_with_past_key_values_(lowerCAmelCase__			,			direction="""inputs"""  )
                  _lowerCAmelCase							     =							{0: "batch", 1: "past_sequence + sequence"}
            else:
                  _lowerCAmelCase							     =							{0: "batch", 1: "sequence"}

            return common_inputs




      @property
      def 				lowercase__    (			self			: Optional[int]  )				->      int:
            return self._config.n_layer




      @property
      def 				lowercase__    (			self			: Tuple  )				->      int:
            return self._config.n_head




      def 				lowercase__    (			self			: int			,			__snake_case			: Any			,			__snake_case			: Dict = -1			,			__snake_case			: Tuple = -1			,			__snake_case			: Union[str, Any] = False			,			__snake_case			: Optional[int] = None			,			)				->      Mapping[str, Any]:
            _lowerCAmelCase							     =							super(lowerCAmelCase__			,			self  ).generate_dummy_inputs(
                lowerCAmelCase__			,			batch_size=lowerCAmelCase__			,			seq_length=lowerCAmelCase__			,			is_pair=lowerCAmelCase__			,			framework=lowerCAmelCase__  )

            # We need to order the input in the way they appears in the forward()
            _lowerCAmelCase							     =							OrderedDict({"""input_ids""": common_inputs["""input_ids"""]}  )

            # Need to add the past_keys
            if self.use_past:
                  if not is_torch_available():
                        raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""  )
                  else:
                        import torch

                        _lowerCAmelCase							     =							common_inputs["input_ids"].shape
                        # Not using the same length for past_key_values
                        _lowerCAmelCase							     =							seqlen + 2
                        _lowerCAmelCase							     =							(
                            batch,
                            self.num_attention_heads,
                            past_key_values_length,
                            self._config.hidden_size // self.num_attention_heads,
                        )
                        _lowerCAmelCase							     =							[
                            (torch.zeros(lowerCAmelCase__  ), torch.zeros(lowerCAmelCase__  )) for _ in range(self.num_layers  )
                        ]

            _lowerCAmelCase							     =							common_inputs["attention_mask"]
            if self.use_past:
                  _lowerCAmelCase							     =							ordered_inputs["attention_mask"].dtype
                  _lowerCAmelCase							     =							torch.cat(
                      [ordered_inputs["""attention_mask"""], torch.ones(lowerCAmelCase__			,			lowerCAmelCase__			,			dtype=lowerCAmelCase__  )]			,			dim=1  )

            return ordered_inputs




      @property
      def 				lowercase__    (			self			: Tuple  )				->      int:
            return 13













"""simple docstring"""




from unittest.mock import Mock, patch

from file_transfer.send_file import send_file






@patch("socket.socket"					)
@patch("builtins.open"					)
def       _SCREAMING_SNAKE_CASE		(	_lowercase						:    List[Any]    ,       _lowercase						:    int					) ->str:






	'''simple docstring'''






	a      :		Optional[Any]	=				Mock()
	a      :		Dict	=				conn, Mock()
	a      :		Union[str, Any]	=				iter([1, None]					)
	a      :		Optional[int]	=				lambda _lowercase					: next(_lowercase					)

	# ===== invoke =====
	send_file(filename="mytext.txt"    ,       testing=_lowercase					)

	# ===== ensurance =====
	sock.assert_called_once()
	sock.return_value.bind.assert_called_once()
	sock.return_value.listen.assert_called_once()
	sock.return_value.accept.assert_called_once()
	conn.recv.assert_called_once()

	file.return_value.__enter__.assert_called_once()
	file.return_value.__enter__.return_value.read.assert_called()

	conn.send.assert_called_once()
	conn.close.assert_called_once()
	sock.return_value.shutdown.assert_called_once()
	sock.return_value.close.assert_called_once()


