


"""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


__snake_case       =       logging.get_logger(__name__)

__snake_case       =       {
    """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 _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			str				    =    '''perceiver'''







   def __init__(      self		,      UpperCamelCase__=256		,      UpperCamelCase__=1280		,      UpperCamelCase__=768		,      UpperCamelCase__=1		,      UpperCamelCase__=26		,      UpperCamelCase__=8		,      UpperCamelCase__=8		,      UpperCamelCase__=None		,      UpperCamelCase__=None		,      UpperCamelCase__="kv"		,      UpperCamelCase__=1		,      UpperCamelCase__=1		,      UpperCamelCase__="gelu"		,      UpperCamelCase__=0.1		,      UpperCamelCase__=0.02		,      UpperCamelCase__=1e-12		,      UpperCamelCase__=True		,      UpperCamelCase__=262		,      UpperCamelCase__=2048		,      UpperCamelCase__=56		,      UpperCamelCase__=[368, 496]		,      UpperCamelCase__=16		,      UpperCamelCase__=1920		,      UpperCamelCase__=16		,      UpperCamelCase__=[1, 16, 224, 224]		,      **UpperCamelCase__		,      )      ->						Union[str, Any]:

       '''simple docstring'''




       super().__init__(**UpperCamelCase__		)

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







class _lowerCAmelCase							( snake_case_      ):







   @property
   def 					lowerCamelCase						(      self		)      ->						Mapping[str, Mapping[int, str]]:

       '''simple docstring'''




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







   @property
   def 					lowerCamelCase						(      self		)      ->						float:

       '''simple docstring'''




       return 1e-4







   def 					lowerCamelCase						(      self		,      UpperCamelCase__		,      UpperCamelCase__ = -1		,      UpperCamelCase__ = -1		,      UpperCamelCase__ = -1		,      UpperCamelCase__ = False		,      UpperCamelCase__ = None		,      UpperCamelCase__ = 3		,      UpperCamelCase__ = 40		,      UpperCamelCase__ = 40		,      )      ->						Mapping[str, Any]:

       '''simple docstring'''




       if isinstance(UpperCamelCase__		,      UpperCamelCase__		):
           # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
           snake_case       : str    =       compute_effective_axis_dimension(
               UpperCamelCase__		,      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
           snake_case       : Union[str, Any]    =       preprocessor.num_special_tokens_to_add(UpperCamelCase__		)
           snake_case       : Tuple    =       compute_effective_axis_dimension(
               UpperCamelCase__		,      fixed_dimension=OnnxConfig.default_fixed_sequence		,      num_token_to_add=UpperCamelCase__		)
           # Generate dummy inputs according to compute batch and sequence
           snake_case       : Any    =       [" ".join(["a"]		) * seq_length] * batch_size
           snake_case       : Tuple    =       dict(preprocessor(UpperCamelCase__		,      return_tensors=UpperCamelCase__		)		)
           snake_case       : Any    =       inputs.pop("input_ids"		)
           return inputs
       elif isinstance(UpperCamelCase__		,      UpperCamelCase__		) 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
           snake_case       : Dict    =       compute_effective_axis_dimension(UpperCamelCase__		,      fixed_dimension=OnnxConfig.default_fixed_batch		)
           snake_case       : Optional[int]    =       self._generate_dummy_images(UpperCamelCase__		,      UpperCamelCase__		,      UpperCamelCase__		,      UpperCamelCase__		)
           snake_case       : int    =       dict(preprocessor(images=UpperCamelCase__		,      return_tensors=UpperCamelCase__		)		)
           snake_case       : List[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 .imports import is_tqdm_available


if is_tqdm_available():
  from tqdm.auto import tqdm as _tqdm

from ..state import PartialState







def     __lowerCAmelCase		(		lowercase    :    bool = True		,				*lowercase    :    str		,				**lowercase    :    List[Any]					)      ->		List[Any]:


    """simple docstring"""





    if not is_tqdm_available():
        raise ImportError("Accelerate's `tqdm` module requires `tqdm` to be installed. Please run `pip install tqdm`."					)
    snake_case       : Dict    =       False
    if main_process_only:
        snake_case       : int    =       PartialState().local_process_index == 0
    return _tqdm(*lowercase		,				**lowercase		,				disable=lowercase					)





