
import functools
import operator

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


lowerCamelCase__    :		Tuple          =   logging.get_logger(__name__)

lowerCamelCase__    :		Optional[Any]          =   {
    """asapp/sew-d-tiny-100k""": """https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json""",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}



class       _snake_case   (	UpperCAmelCase_							):
 __lowerCAmelCase  :     Dict        =			'sew-d'


 def __init__(					self					,  SCREAMING_SNAKE_CASE_=32					,  SCREAMING_SNAKE_CASE_=7_68					,  SCREAMING_SNAKE_CASE_=12					,  SCREAMING_SNAKE_CASE_=12					,  SCREAMING_SNAKE_CASE_=30_72					,  SCREAMING_SNAKE_CASE_=2					,  SCREAMING_SNAKE_CASE_=5_12					,  SCREAMING_SNAKE_CASE_=2_56					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=("p2c", "c2p")					,  SCREAMING_SNAKE_CASE_="layer_norm"					,  SCREAMING_SNAKE_CASE_="gelu_python"					,  SCREAMING_SNAKE_CASE_=0.1					,  SCREAMING_SNAKE_CASE_=0.1					,  SCREAMING_SNAKE_CASE_=0.1					,  SCREAMING_SNAKE_CASE_=0.0					,  SCREAMING_SNAKE_CASE_=0.1					,  SCREAMING_SNAKE_CASE_=0.0_2					,  SCREAMING_SNAKE_CASE_=1E-7					,  SCREAMING_SNAKE_CASE_=1E-5					,  SCREAMING_SNAKE_CASE_="group"					,  SCREAMING_SNAKE_CASE_="gelu"					,  SCREAMING_SNAKE_CASE_=(64, 1_28, 1_28, 1_28, 1_28, 2_56, 2_56, 2_56, 2_56, 5_12, 5_12, 5_12, 5_12)					,  SCREAMING_SNAKE_CASE_=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)					,  SCREAMING_SNAKE_CASE_=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)					,  SCREAMING_SNAKE_CASE_=False					,  SCREAMING_SNAKE_CASE_=1_28					,  SCREAMING_SNAKE_CASE_=16					,  SCREAMING_SNAKE_CASE_=True					,  SCREAMING_SNAKE_CASE_=0.0_5					,  SCREAMING_SNAKE_CASE_=10					,  SCREAMING_SNAKE_CASE_=2					,  SCREAMING_SNAKE_CASE_=0.0					,  SCREAMING_SNAKE_CASE_=10					,  SCREAMING_SNAKE_CASE_=0					,  SCREAMING_SNAKE_CASE_="mean"					,  SCREAMING_SNAKE_CASE_=False					,  SCREAMING_SNAKE_CASE_=False					,  SCREAMING_SNAKE_CASE_=2_56					,  SCREAMING_SNAKE_CASE_=0					,  SCREAMING_SNAKE_CASE_=1					,  SCREAMING_SNAKE_CASE_=2					,  **SCREAMING_SNAKE_CASE_					,  ):


   '''simple docstring'''




   super().__init__(**SCREAMING_SNAKE_CASE_					,  pad_token_id=SCREAMING_SNAKE_CASE_					,  bos_token_id=SCREAMING_SNAKE_CASE_					,  eos_token_id=SCREAMING_SNAKE_CASE_)
   lowercase__  :   Dict    		=      hidden_size
   lowercase__  :   Union[str, Any]    		=      feat_extract_norm
   lowercase__  :   Optional[Any]    		=      feat_extract_activation
   lowercase__  :   int    		=      list(SCREAMING_SNAKE_CASE_)
   lowercase__  :   List[str]    		=      list(SCREAMING_SNAKE_CASE_)
   lowercase__  :   Optional[Any]    		=      list(SCREAMING_SNAKE_CASE_)
   lowercase__  :   Tuple    		=      conv_bias
   lowercase__  :   List[Any]    		=      num_conv_pos_embeddings
   lowercase__  :   Tuple    		=      num_conv_pos_embedding_groups
   lowercase__  :   Optional[int]    		=      len(self.conv_dim)
   lowercase__  :   Dict    		=      num_hidden_layers
   lowercase__  :   Union[str, Any]    		=      intermediate_size
   lowercase__  :   Tuple    		=      squeeze_factor
   lowercase__  :   Dict    		=      max_position_embeddings
   lowercase__  :   Optional[Any]    		=      position_buckets
   lowercase__  :   Optional[Any]    		=      share_att_key
   lowercase__  :   Tuple    		=      relative_attention
   lowercase__  :   List[str]    		=      norm_rel_ebd
   lowercase__  :   Optional[Any]    		=      list(SCREAMING_SNAKE_CASE_)
   lowercase__  :   List[Any]    		=      hidden_act
   lowercase__  :   Union[str, Any]    		=      num_attention_heads
   lowercase__  :   List[Any]    		=      hidden_dropout
   lowercase__  :   List[str]    		=      attention_dropout
   lowercase__  :   Dict    		=      activation_dropout
   lowercase__  :   int    		=      feat_proj_dropout
   lowercase__  :   List[str]    		=      final_dropout
   lowercase__  :   int    		=      layer_norm_eps
   lowercase__  :   Optional[int]    		=      feature_layer_norm_eps
   lowercase__  :   Any    		=      initializer_range
   lowercase__  :   Optional[Any]    		=      vocab_size

   if (
       (len(self.conv_stride) != self.num_feat_extract_layers)
       or (len(self.conv_kernel) != self.num_feat_extract_layers)
       or (len(self.conv_dim) != self.num_feat_extract_layers)
   ):
     raise ValueError(
         """Configuration for convolutional layers is incorrect."""
         """It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"""
         f'but is `len(config.conv_dim) = {len(self.conv_dim)}`, `len(config.conv_stride)'
         f'= {len(self.conv_stride)}`, `len(config.conv_kernel) = {len(self.conv_kernel)}`.')

   # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
   lowercase__  :   Any    		=      apply_spec_augment
   lowercase__  :   int    		=      mask_time_prob
   lowercase__  :   Optional[Any]    		=      mask_time_length
   lowercase__  :   Any    		=      mask_time_min_masks
   lowercase__  :   Any    		=      mask_feature_prob
   lowercase__  :   List[Any]    		=      mask_feature_length
   lowercase__  :   Optional[Any]    		=      mask_feature_min_masks

   # ctc loss
   lowercase__  :   Optional[int]    		=      ctc_loss_reduction
   lowercase__  :   List[str]    		=      ctc_zero_infinity

   # sequence classification
   lowercase__  :   str    		=      use_weighted_layer_sum
   lowercase__  :   List[str]    		=      classifier_proj_size



 @property
 def      lowercase__     (					self):


   '''simple docstring'''




   return functools.reduce(operator.mul					,  self.conv_stride					,  1)



# Copyright 2023 The HuggingFace Inc. 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

import torch

from ..models.auto import AutoModelForVisualQuestionAnswering, AutoProcessor
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
     from PIL import Image



class       _snake_case   (	UpperCAmelCase_							):
 __lowerCAmelCase  :     Any        =			'dandelin/vilt-b32-finetuned-vqa'
 __lowerCAmelCase  :     Union[str, Any]        =			(
     'This is a tool that answers a question about an image. It takes an input named `image` which should be the '
     'image containing the information, as well as a `question` which should be the question in English. It '
     'returns a text that is the answer to the question.'
 )
 __lowerCAmelCase  :     str        =			'image_qa'
 __lowerCAmelCase  :     int        =			AutoProcessor
 __lowerCAmelCase  :     Optional[Any]        =			AutoModelForVisualQuestionAnswering

 __lowerCAmelCase  :     str        =			['image', 'text']
 __lowerCAmelCase  :     Optional[int]        =			['text']


 def __init__(					self					,  *SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   requires_backends(self					,  ["""vision"""])
   super().__init__(*SCREAMING_SNAKE_CASE_					,  **SCREAMING_SNAKE_CASE_)


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   return self.pre_processor(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  return_tensors="""pt""")


 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   with torch.no_grad():
     return self.model(**SCREAMING_SNAKE_CASE_).logits



 def      lowercase__     (					self					,  SCREAMING_SNAKE_CASE_):


   '''simple docstring'''




   lowercase__  :   Dict    		=      outputs.argmax(-1).item()
   return self.model.config.idalabel[idx]






