


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__   	=							logging.get_logger(__name__)

UpperCAmelCase__   	=							{
    '''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__   (       lowerCAmelCase):
     SCREAMING_SNAKE_CASE__      			=			'''perceiver'''





     def __init__(self		,     UpperCAmelCase=2_5_6		,     UpperCAmelCase=1_2_8_0		,     UpperCAmelCase=7_6_8		,     UpperCAmelCase=1		,     UpperCAmelCase=2_6		,     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=2_6_2		,     UpperCAmelCase=2_0_4_8		,     UpperCAmelCase=5_6		,     UpperCAmelCase=[3_6_8, 4_9_6]		,     UpperCAmelCase=1_6		,     UpperCAmelCase=1_9_2_0		,     UpperCAmelCase=1_6		,     UpperCAmelCase=[1, 1_6, 2_2_4, 2_2_4]		,     **UpperCAmelCase		,     )     ->   str:
      super().__init__(**UpperCAmelCase       )

      _lowercase							      =num_latents
      _lowercase							      =d_latents
      _lowercase							      =d_model
      _lowercase							      =num_blocks
      _lowercase							      =num_self_attends_per_block
      _lowercase							      =num_self_attention_heads
      _lowercase							      =num_cross_attention_heads
      _lowercase							      =qk_channels
      _lowercase							      =v_channels
      _lowercase							      =cross_attention_shape_for_attention
      _lowercase							      =self_attention_widening_factor
      _lowercase							      =cross_attention_widening_factor
      _lowercase							      =hidden_act
      _lowercase							      =attention_probs_dropout_prob
      _lowercase							      =initializer_range
      _lowercase							      =layer_norm_eps
      _lowercase							      =use_query_residual
      # masked language modeling attributes
      _lowercase							      =vocab_size
      _lowercase							      =max_position_embeddings
      # image classification attributes
      _lowercase							      =image_size
      # flow attributes
      _lowercase							      =train_size
      # multimodal autoencoding attributes
      _lowercase							      =num_frames
      _lowercase							      =audio_samples_per_frame
      _lowercase							      =samples_per_patch
      _lowercase							      =output_shape







class       lowerCamelCase__   (       lowerCAmelCase):





     @property
     def      __A					(self       )     ->   Mapping[str, Mapping[int, str]]:
      if self.task == "multiple-choice":
       _lowercase							      ={0: '''batch''', 1: '''choice''', 2: '''sequence'''}
      else:
       _lowercase							      ={0: '''batch''', 1: '''sequence'''}
      return OrderedDict(
          [
              ('''inputs''', dynamic_axis),
              ('''attention_mask''', dynamic_axis),
          ]       )





     @property
     def      __A					(self       )     ->   float:
      return 1e-4





     def      __A					(self		,     UpperCAmelCase		,     UpperCAmelCase = -1		,     UpperCAmelCase = -1		,     UpperCAmelCase = -1		,     UpperCAmelCase = False		,     UpperCAmelCase = None		,     UpperCAmelCase = 3		,     UpperCAmelCase = 4_0		,     UpperCAmelCase = 4_0		,     )     ->   Mapping[str, Any]:
      # copied from `transformers.onnx.config.OnnxConfig` and slightly altered/simplified

      if isinstance(UpperCAmelCase		,     UpperCAmelCase       ):
       # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
       _lowercase							      =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
       _lowercase							      =preprocessor.num_special_tokens_to_add(UpperCAmelCase       )
       _lowercase							      =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
       _lowercase							      =[''' '''.join(['''a''']       ) * seq_length] * batch_size
       _lowercase							      =dict(preprocessor(UpperCAmelCase		,     return_tensors=UpperCAmelCase       )       )
       _lowercase							      =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
       _lowercase							      =compute_effective_axis_dimension(UpperCAmelCase		,     fixed_dimension=OnnxConfig.default_fixed_batch       )
       _lowercase							      =self._generate_dummy_images(UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase		,     UpperCAmelCase       )
       _lowercase							      =dict(preprocessor(images=UpperCAmelCase		,     return_tensors=UpperCAmelCase       )       )
       _lowercase							      =inputs.pop('''pixel_values'''       )
       return inputs
      else:
       raise ValueError(
           '''Unable to generate dummy inputs for the model. Please provide a tokenizer or a preprocessor.'''       )





# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


UpperCAmelCase__   	=							{
    '''configuration_efficientnet''': [
        '''EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''EfficientNetConfig''',
        '''EfficientNetOnnxConfig''',
    ]
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__   	=							['''EfficientNetImageProcessor''']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__   	=							[
      '''EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''EfficientNetForImageClassification''',
      '''EfficientNetModel''',
      '''EfficientNetPreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_efficientnet import (
      EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP,
      EfficientNetConfig,
      EfficientNetOnnxConfig,
  )

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_efficientnet import EfficientNetImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_efficientnet import (
        EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST,
        EfficientNetForImageClassification,
        EfficientNetModel,
        EfficientNetPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__   	=							_LazyModule(__name__, globals()['''__file__'''], _import_structure)

