

import copy
import os
from typing import Union

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


lowerCAmelCase     :   str						     =  logging.get_logger(__name__)

lowerCAmelCase     :   Any						     =  {
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      List[Any]       =  '''altclip_text_model'''

  def __init__(				self ,					_SCREAMING_SNAKE_CASE=25_0002 ,					_SCREAMING_SNAKE_CASE=1024 ,					_SCREAMING_SNAKE_CASE=24 ,					_SCREAMING_SNAKE_CASE=16 ,					_SCREAMING_SNAKE_CASE=4096 ,					_SCREAMING_SNAKE_CASE="gelu" ,					_SCREAMING_SNAKE_CASE=0.1 ,					_SCREAMING_SNAKE_CASE=0.1 ,					_SCREAMING_SNAKE_CASE=514 ,					_SCREAMING_SNAKE_CASE=1 ,					_SCREAMING_SNAKE_CASE=0.02 ,					_SCREAMING_SNAKE_CASE=0.02 ,					_SCREAMING_SNAKE_CASE=1e-05 ,					_SCREAMING_SNAKE_CASE=1 ,					_SCREAMING_SNAKE_CASE=0 ,					_SCREAMING_SNAKE_CASE=2 ,					_SCREAMING_SNAKE_CASE="absolute" ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=768 ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE ,					bos_token_id=_SCREAMING_SNAKE_CASE ,					eos_token_id=_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Dict           =     vocab_size
        SCREAMING_SNAKE_CASE_				:  Dict           =     hidden_size
        SCREAMING_SNAKE_CASE_				:  Tuple           =     num_hidden_layers
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     num_attention_heads
        SCREAMING_SNAKE_CASE_				:  Any           =     hidden_act
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     intermediate_size
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     hidden_dropout_prob
        SCREAMING_SNAKE_CASE_				:  int           =     attention_probs_dropout_prob
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     max_position_embeddings
        SCREAMING_SNAKE_CASE_				:  Any           =     type_vocab_size
        SCREAMING_SNAKE_CASE_				:  List[str]           =     initializer_range
        SCREAMING_SNAKE_CASE_				:  List[str]           =     initializer_factor
        SCREAMING_SNAKE_CASE_				:  Dict           =     layer_norm_eps
        SCREAMING_SNAKE_CASE_				:  Any           =     position_embedding_type
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     use_cache
        SCREAMING_SNAKE_CASE_				:  Dict           =     project_dim

class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      int       =  '''altclip_vision_model'''

  def __init__(				self ,					_SCREAMING_SNAKE_CASE=768 ,					_SCREAMING_SNAKE_CASE=3072 ,					_SCREAMING_SNAKE_CASE=512 ,					_SCREAMING_SNAKE_CASE=12 ,					_SCREAMING_SNAKE_CASE=12 ,					_SCREAMING_SNAKE_CASE=3 ,					_SCREAMING_SNAKE_CASE=224 ,					_SCREAMING_SNAKE_CASE=32 ,					_SCREAMING_SNAKE_CASE="quick_gelu" ,					_SCREAMING_SNAKE_CASE=1e-5 ,					_SCREAMING_SNAKE_CASE=0.0 ,					_SCREAMING_SNAKE_CASE=0.02 ,					_SCREAMING_SNAKE_CASE=1.0 ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        super().__init__(**_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     hidden_size
        SCREAMING_SNAKE_CASE_				:  List[str]           =     intermediate_size
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     projection_dim
        SCREAMING_SNAKE_CASE_				:  Dict           =     num_hidden_layers
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     num_attention_heads
        SCREAMING_SNAKE_CASE_				:  int           =     num_channels
        SCREAMING_SNAKE_CASE_				:  Tuple           =     patch_size
        SCREAMING_SNAKE_CASE_				:  Dict           =     image_size
        SCREAMING_SNAKE_CASE_				:  int           =     initializer_range
        SCREAMING_SNAKE_CASE_				:  List[str]           =     initializer_factor
        SCREAMING_SNAKE_CASE_				:  List[str]           =     attention_dropout
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     layer_norm_eps
        SCREAMING_SNAKE_CASE_				:  str           =     hidden_act



  @classmethod
  def  UpperCAmelCase    (				cls ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  Any           =     cls.get_config_dict(_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

        # get the vision config dict if we are loading from AltCLIPConfig
        if config_dict.get('model_type'					) == "altclip":
              SCREAMING_SNAKE_CASE_				:  int           =     config_dict['vision_config']

        if "model_type" in config_dict and hasattr(cls ,					'model_type'					) and config_dict["model_type"] != cls.model_type:
              logger.warning(
                  f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
                  f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."					)

        return cls.from_dict(_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      Any       =  '''altclip'''
  SCREAMING_SNAKE_CASE    :      Optional[int]       =  True

  def __init__(				self ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=768 ,					_SCREAMING_SNAKE_CASE=2.6592 ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     kwargs.pop('text_config_dict' ,					_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Dict           =     kwargs.pop('vision_config_dict' ,					_SCREAMING_SNAKE_CASE					)

        super().__init__(**_SCREAMING_SNAKE_CASE					)

        # Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
        # `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
        # cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
        if text_config_dict is not None:
              if text_config is None:
                    SCREAMING_SNAKE_CASE_				:  Tuple           =     {}

              # This is the complete result when using `text_config_dict`.
              SCREAMING_SNAKE_CASE_				:  Tuple           =     AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE					).to_dict()

              # Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
              for key, value in _text_config_dict.items():
                    if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
                          # If specified in `text_config_dict`
                          if key in text_config_dict:
                                SCREAMING_SNAKE_CASE_				:  List[str]           =     (
                                    f"`{key}` is found in both `text_config_dict` and `text_config` but with different values. "
                                    f"The value `text_config_dict[\"{key}\"]` will be used instead."
                                )
                          # If inferred from default argument values (just to be super careful)
                          else:
                                SCREAMING_SNAKE_CASE_				:  Dict           =     (
                                    f"`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The "
                                    f"value `text_config[\"{key}\"]` will be overriden."
                                )
                          logger.warning(_SCREAMING_SNAKE_CASE					)

            # Update all values in `text_config` with the ones in `_text_config_dict`.
              text_config.update(_text_config_dict					)

        if vision_config_dict is not None:
              if vision_config is None:
                    SCREAMING_SNAKE_CASE_				:  Dict           =     {}

              # This is the complete result when using `vision_config_dict`.
              SCREAMING_SNAKE_CASE_				:  Dict           =     AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE					).to_dict()
              # convert keys to string instead of integer
              if "id2label" in _vision_config_dict:
                    SCREAMING_SNAKE_CASE_				:  Optional[int]           =     {
                        str(_SCREAMING_SNAKE_CASE					): value for key, value in _vision_config_dict['id2label'].items()
                    }

              # Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
              for key, value in _vision_config_dict.items():
                    if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
                          # If specified in `vision_config_dict`
                          if key in vision_config_dict:
                                SCREAMING_SNAKE_CASE_				:  int           =     (
                                    f"`{key}` is found in both `vision_config_dict` and `vision_config` but with different "
                                    f"values. The value `vision_config_dict[\"{key}\"]` will be used instead."
                                )
                          # If inferred from default argument values (just to be super careful)
                          else:
                                SCREAMING_SNAKE_CASE_				:  Dict           =     (
                                    f"`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. "
                                    f"The value `vision_config[\"{key}\"]` will be overriden."
                                )
                          logger.warning(_SCREAMING_SNAKE_CASE					)

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
              vision_config.update(_vision_config_dict					)

        if text_config is None:
              SCREAMING_SNAKE_CASE_				:  Optional[int]           =     {}
              logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'					)

        if vision_config is None:
              SCREAMING_SNAKE_CASE_				:  Any           =     {}
              logger.info('`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'					)

        SCREAMING_SNAKE_CASE_				:  List[Any]           =     AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     projection_dim
        SCREAMING_SNAKE_CASE_				:  Dict           =     logit_scale_init_value
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     1.0

  @classmethod
  def  UpperCAmelCase    (				cls ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        return cls(text_config=text_config.to_dict() ,					vision_config=vision_config.to_dict() ,					**_SCREAMING_SNAKE_CASE					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     copy.deepcopy(self.__dict__					)
        SCREAMING_SNAKE_CASE_				:  Tuple           =     self.text_config.to_dict()
        SCREAMING_SNAKE_CASE_				:  List[str]           =     self.vision_config.to_dict()
        SCREAMING_SNAKE_CASE_				:  Tuple           =     self.__class__.model_type
        return output









import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=__magic_name__)
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      str       =  field(default='''automatic-speech-recognition'''   ,     metadata={'''include_in_asdict_even_if_is_default''': True})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''audio''': Audio()})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''transcription''': Value('''string''')})
  SCREAMING_SNAKE_CASE    :      str       =  "audio"
  SCREAMING_SNAKE_CASE    :      str       =  "transcription"

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        if self.audio_column not in features:
              raise ValueError(f"Column {self.audio_column} is not present in features."					)
        if not isinstance(features[self.audio_column] ,					_SCREAMING_SNAKE_CASE					):
              raise ValueError(f"Column {self.audio_column} is not an Audio type."					)
        SCREAMING_SNAKE_CASE_				:  int           =     copy.deepcopy(self					)
        SCREAMING_SNAKE_CASE_				:  int           =     self.input_schema.copy()
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     features[self.audio_column]
        SCREAMING_SNAKE_CASE_				:  List[str]           =     input_schema
        return task_template



  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return {self.audio_column: "audio", self.transcription_column: "transcription"}






