



'''simple docstring'''




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

from ...configuration_utils import PretrainedConfig
from ...feature_extraction_utils import FeatureExtractionMixin
from ...onnx import OnnxConfig
from ...onnx.utils import compute_effective_axis_dimension
from ...tokenization_utils_base import PreTrainedTokenizerBase
from ...utils import TensorType, logging


UpperCamelCase__ :			int												=				logging.get_logger(__name__)

UpperCamelCase__ :			Optional[int]												=				{
    '''deepmind/language-perceiver''': '''https://huggingface.co/deepmind/language-perceiver/resolve/main/config.json''',
    # See all Perceiver models at https://huggingface.co/models?filter=perceiver
}






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	Optional[Any]    					=	'''perceiver'''

			def __init__(							self  :				Dict							,  lowerCAmelCase__  :				str=2_5_6							,  lowerCAmelCase__  :				List[Any]=1_2_8_0							,  lowerCAmelCase__  :				Union[str, Any]=7_6_8							,  lowerCAmelCase__  :				str=1							,  lowerCAmelCase__  :				Tuple=2_6							,  lowerCAmelCase__  :				str=8							,  lowerCAmelCase__  :				Dict=8							,  lowerCAmelCase__  :				Any=None							,  lowerCAmelCase__  :				Union[str, Any]=None							,  lowerCAmelCase__  :				Any="kv"							,  lowerCAmelCase__  :				Any=1							,  lowerCAmelCase__  :				List[Any]=1							,  lowerCAmelCase__  :				List[Any]="gelu"							,  lowerCAmelCase__  :				Any=0.1							,  lowerCAmelCase__  :				int=0.02							,  lowerCAmelCase__  :				List[Any]=1E-12							,  lowerCAmelCase__  :				Tuple=True							,  lowerCAmelCase__  :				Dict=2_6_2							,  lowerCAmelCase__  :				Any=2_0_4_8							,  lowerCAmelCase__  :				Dict=5_6							,  lowerCAmelCase__  :				Tuple=[3_6_8, 4_9_6]							,  lowerCAmelCase__  :				Optional[Any]=1_6							,  lowerCAmelCase__  :				List[str]=1_9_2_0							,  lowerCAmelCase__  :				Tuple=1_6							,  lowerCAmelCase__  :				str=[1, 1_6, 2_2_4, 2_2_4]							,  **lowerCAmelCase__  :				List[Any]							,  ):





					"""simple docstring"""






					super().__init__(**lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	num_latents
					__SCREAMING_SNAKE_CASE :	Any					 =	d_latents
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	d_model
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	num_blocks
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	num_self_attends_per_block
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	num_self_attention_heads
					__SCREAMING_SNAKE_CASE :	Dict					 =	num_cross_attention_heads
					__SCREAMING_SNAKE_CASE :	str					 =	qk_channels
					__SCREAMING_SNAKE_CASE :	int					 =	v_channels
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	cross_attention_shape_for_attention
					__SCREAMING_SNAKE_CASE :	str					 =	self_attention_widening_factor
					__SCREAMING_SNAKE_CASE :	List[str]					 =	cross_attention_widening_factor
					__SCREAMING_SNAKE_CASE :	List[str]					 =	hidden_act
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	attention_probs_dropout_prob
					__SCREAMING_SNAKE_CASE :	Any					 =	initializer_range
					__SCREAMING_SNAKE_CASE :	int					 =	layer_norm_eps
					__SCREAMING_SNAKE_CASE :	List[str]					 =	use_query_residual
					# masked language modeling attributes
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	vocab_size
					__SCREAMING_SNAKE_CASE :	int					 =	max_position_embeddings
					# image classification attributes
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	image_size
					# flow attributes
					__SCREAMING_SNAKE_CASE :	int					 =	train_size
					# multimodal autoencoding attributes
					__SCREAMING_SNAKE_CASE :	Tuple					 =	num_frames
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	audio_samples_per_frame
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	samples_per_patch
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	output_shape






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			@property
			def UpperCamelCase__      (							self  :				Dict		):





					"""simple docstring"""






					if self.task == "multiple-choice":
							__SCREAMING_SNAKE_CASE :	Tuple					 =	{0: """batch""", 1: """choice""", 2: """sequence"""}
					else:
							__SCREAMING_SNAKE_CASE :	List[str]					 =	{0: """batch""", 1: """sequence"""}
					return OrderedDict(
					    [
					        ("""inputs""", dynamic_axis),
					        ("""attention_mask""", dynamic_axis),
					    ]		)

			@property
			def UpperCamelCase__      (							self  :				Optional[Any]		):





					"""simple docstring"""






					return 1E-4



			def UpperCamelCase__      (							self  :				Optional[int]							,  lowerCAmelCase__  :				Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]							,  lowerCAmelCase__  :				int = -1							,  lowerCAmelCase__  :				int = -1							,  lowerCAmelCase__  :				int = -1							,  lowerCAmelCase__  :				bool = False							,  lowerCAmelCase__  :				Optional[TensorType] = None							,  lowerCAmelCase__  :				int = 3							,  lowerCAmelCase__  :				int = 4_0							,  lowerCAmelCase__  :				int = 4_0							,  ):





					"""simple docstring"""






					if isinstance(lowerCAmelCase__							,  lowerCAmelCase__		):
							# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
							__SCREAMING_SNAKE_CASE :	Dict					 =	compute_effective_axis_dimension(
							    lowerCAmelCase__							,  fixed_dimension=OnnxConfig.default_fixed_batch							,  num_token_to_add=0		)
							# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
							__SCREAMING_SNAKE_CASE :	int					 =	preprocessor.num_special_tokens_to_add(lowerCAmelCase__		)
							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	compute_effective_axis_dimension(
							    lowerCAmelCase__							,  fixed_dimension=OnnxConfig.default_fixed_sequence							,  num_token_to_add=lowerCAmelCase__		)
							# Generate dummy inputs according to compute batch and sequence
							__SCREAMING_SNAKE_CASE :	List[str]					 =	[""" """.join(["""a"""]		) * seq_length] * batch_size
							__SCREAMING_SNAKE_CASE :	int					 =	dict(preprocessor(lowerCAmelCase__							,  return_tensors=lowerCAmelCase__		)		)
							__SCREAMING_SNAKE_CASE :	str					 =	inputs.pop("""input_ids"""		)
							return inputs
					elif isinstance(lowerCAmelCase__							,  lowerCAmelCase__		) and preprocessor.model_input_names[0] == "pixel_values":
							# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
							__SCREAMING_SNAKE_CASE :	List[str]					 =	compute_effective_axis_dimension(lowerCAmelCase__							,  fixed_dimension=OnnxConfig.default_fixed_batch		)
							__SCREAMING_SNAKE_CASE :	Tuple					 =	self._generate_dummy_images(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__		)
							__SCREAMING_SNAKE_CASE :	Dict					 =	dict(preprocessor(images=lowerCAmelCase__							,  return_tensors=lowerCAmelCase__		)		)
							__SCREAMING_SNAKE_CASE :	str					 =	inputs.pop("""pixel_values"""		)
							return inputs
					else:
							raise ValueError(
							    """Unable to generate dummy inputs for the model. Please provide a tokenizer or a preprocessor."""		)




'''simple docstring'''




from unittest.mock import Mock, patch

from file_transfer.send_file import send_file


@patch("""socket.socket"""      )
@patch("""builtins.open"""      )
def        lowerCAmelCase_     (			_lowerCamelCase:     Dict ,   _lowerCamelCase:     List[Any]      ):
		# ===== initialization =====
		__SCREAMING_SNAKE_CASE :	Optional[int]					 =	Mock()
		__SCREAMING_SNAKE_CASE :	Optional[int]					 =	conn, Mock()
		__SCREAMING_SNAKE_CASE :	str					 =	iter([1, None]      )
		__SCREAMING_SNAKE_CASE :	Any					 =	lambda _lowerCamelCase      : next(_lowerCamelCase      )

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

		# ===== 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()