

"""simple docstring"""




import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
    pass

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


__UpperCAmelCase =				logging.get_logger(__name__)

__UpperCAmelCase =				{
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}







class      __lowercase			(    __lowerCamelCase					):
  snake_case_				       =       """align_text_model"""

  def __init__(  self		:			List[Any]					,A		:			List[str]=30_522					,A		:			List[str]=768					,A		:			Optional[Any]=12					,A		:			int=12					,A		:			str=3_072					,A		:			Any="gelu"					,A		:			Optional[Any]=0.1					,A		:			str=0.1					,A		:			Union[str, Any]=512					,A		:			int=2					,A		:			Any=0.0_2					,A		:			Any=1e-12					,A		:			str=0					,A		:			Union[str, Any]="absolute"					,A		:			List[str]=True					,**A		:			Any					,):






   '''simple docstring'''
   super().__init__(**A    )

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




  @classmethod
  def    __lowercase       (  cls		:			int					,A		:			Union[str, os.PathLike]					,**A		:			Optional[Any]    ):






   '''simple docstring'''
   cls._set_token_in_kwargs(A    )

   UpperCAmelCase__					:  str					   =					cls.get_config_dict(A					,**A    )

   # get the text config dict if we are loading from AlignConfig
   if config_dict.get("""model_type"""    ) == "align":
    UpperCAmelCase__					:  str					   =					config_dict["""text_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(A					,**A    )







class      __lowercase			(    __lowerCamelCase					):
  snake_case_				       =       """align_vision_model"""

  def __init__(  self		:			Tuple					,A		:			int = 3					,A		:			int = 600					,A		:			float = 2.0					,A		:			float = 3.1					,A		:			int = 8					,A		:			List[int] = [3, 3, 5, 3, 5, 5, 3]					,A		:			List[int] = [32, 16, 24, 40, 80, 112, 192]					,A		:			List[int] = [16, 24, 40, 80, 112, 192, 320]					,A		:			List[int] = []					,A		:			List[int] = [1, 2, 2, 2, 1, 2, 1]					,A		:			List[int] = [1, 2, 2, 3, 3, 4, 1]					,A		:			List[int] = [1, 6, 6, 6, 6, 6, 6]					,A		:			float = 0.2_5					,A		:			str = "swish"					,A		:			int = 2_560					,A		:			str = "mean"					,A		:			float = 0.0_2					,A		:			float = 0.0_0_1					,A		:			float = 0.9_9					,A		:			float = 0.2					,**A		:			Optional[Any]					,):






   '''simple docstring'''
   super().__init__(**A    )

   UpperCAmelCase__					:  Tuple					   =					num_channels
   UpperCAmelCase__					:  Optional[Any]					   =					image_size
   UpperCAmelCase__					:  Dict					   =					width_coefficient
   UpperCAmelCase__					:  str					   =					depth_coefficient
   UpperCAmelCase__					:  List[Any]					   =					depth_divisor
   UpperCAmelCase__					:  Tuple					   =					kernel_sizes
   UpperCAmelCase__					:  Dict					   =					in_channels
   UpperCAmelCase__					:  int					   =					out_channels
   UpperCAmelCase__					:  List[str]					   =					depthwise_padding
   UpperCAmelCase__					:  List[str]					   =					strides
   UpperCAmelCase__					:  List[str]					   =					num_block_repeats
   UpperCAmelCase__					:  int					   =					expand_ratios
   UpperCAmelCase__					:  List[str]					   =					squeeze_expansion_ratio
   UpperCAmelCase__					:  Tuple					   =					hidden_act
   UpperCAmelCase__					:  Union[str, Any]					   =					hidden_dim
   UpperCAmelCase__					:  Union[str, Any]					   =					pooling_type
   UpperCAmelCase__					:  Any					   =					initializer_range
   UpperCAmelCase__					:  Any					   =					batch_norm_eps
   UpperCAmelCase__					:  Optional[int]					   =					batch_norm_momentum
   UpperCAmelCase__					:  Tuple					   =					drop_connect_rate
   UpperCAmelCase__					:  Tuple					   =					sum(A    ) * 4




  @classmethod
  def    __lowercase       (  cls		:			Union[str, Any]					,A		:			Union[str, os.PathLike]					,**A		:			str    ):






   '''simple docstring'''
   cls._set_token_in_kwargs(A    )

   UpperCAmelCase__					:  List[Any]					   =					cls.get_config_dict(A					,**A    )

   # get the vision config dict if we are loading from AlignConfig
   if config_dict.get("""model_type"""    ) == "align":
    UpperCAmelCase__					:  Dict					   =					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(A					,**A    )







class      __lowercase			(    __lowerCamelCase					):
  snake_case_				       =       """align"""
  snake_case_				       =       True

  def __init__(  self		:			Optional[Any]					,A		:			List[Any]=None					,A		:			List[Any]=None					,A		:			Any=640					,A		:			Tuple=1.0					,A		:			List[str]=0.0_2					,**A		:			int					,):






   '''simple docstring'''
   super().__init__(**A    )

   if text_config is None:
    UpperCAmelCase__					:  int					   =					{}
    logger.info("""text_config is None. Initializing the AlignTextConfig with default values."""    )

   if vision_config is None:
    UpperCAmelCase__					:  Any					   =					{}
    logger.info("""vision_config is None. Initializing the AlignVisionConfig with default values."""    )

   UpperCAmelCase__					:  int					   =					AlignTextConfig(**A    )
   UpperCAmelCase__					:  Optional[Any]					   =					AlignVisionConfig(**A    )

   UpperCAmelCase__					:  Tuple					   =					projection_dim
   UpperCAmelCase__					:  str					   =					temperature_init_value
   UpperCAmelCase__					:  Dict					   =					initializer_range

  @classmethod
  def    __lowercase       (  cls		:			Tuple					,A		:			AlignTextConfig					,A		:			AlignVisionConfig					,**A		:			Tuple    ):






   '''simple docstring'''
   return cls(text_config=text_config.to_dict()					,vision_config=vision_config.to_dict()					,**A    )




  def    __lowercase       (  self		:			Optional[Any]    ):






   '''simple docstring'''
   UpperCAmelCase__					:  List[Any]					   =					copy.deepcopy(self.__dict__    )
   UpperCAmelCase__					:  List[str]					   =					self.text_config.to_dict()
   UpperCAmelCase__					:  Dict					   =					self.vision_config.to_dict()
   UpperCAmelCase__					:  List[Any]					   =					self.__class__.model_type
   return output








"""simple docstring"""




from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__UpperCAmelCase =				logging.get_logger(__name__)


__UpperCAmelCase =				TypeVar('DatasetType', Dataset, IterableDataset)
def   lowerCAmelCase						(					__UpperCamelCase							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = "first_exhausted"							,    ):
 '''simple docstring'''





 from .arrow_dataset import Dataset
 from .iterable_dataset import IterableDataset

 if not datasets:
  raise ValueError("""Unable to interleave an empty list of datasets."""      )
 for i, dataset in enumerate(__UpperCamelCase      ):
  if not isinstance(__UpperCamelCase							,    (Dataset, IterableDataset)      ):
   if isinstance(__UpperCamelCase							,    (DatasetDict, IterableDatasetDict)      ):
    if not dataset:
     raise ValueError(
         F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
         """is an empty dataset dictionary."""      )
    raise ValueError(
        F"Dataset at position {i} has at least one split: {list(__UpperCamelCase      )}\n"
        F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase      )      )}']"      )
   raise ValueError(
       F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase      ).__name__}."      )
  if i == 0:
   UpperCAmelCase__   ,      UpperCAmelCase__					:  List[str]					   =					(
       (Dataset, IterableDataset) if isinstance(__UpperCamelCase							,    __UpperCamelCase      ) else (IterableDataset, Dataset)
   )
  elif not isinstance(__UpperCamelCase							,    __UpperCamelCase      ):
   raise ValueError(
       F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."      )
 if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
  raise ValueError(F"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."      )
 if dataset_type is Dataset:
  return _interleave_map_style_datasets(
      __UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    stopping_strategy=__UpperCamelCase      )
 else:
  return _interleave_iterable_datasets(
      __UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    stopping_strategy=__UpperCamelCase      )




def   lowerCAmelCase						(					__UpperCamelCase							,    __UpperCamelCase = None							,    __UpperCamelCase = None							,    __UpperCamelCase = 0							,    ):
 '''simple docstring'''





 if not dsets:
  raise ValueError("""Unable to concatenate an empty list of datasets."""      )
 for i, dataset in enumerate(__UpperCamelCase      ):
  if not isinstance(__UpperCamelCase							,    (Dataset, IterableDataset)      ):
   if isinstance(__UpperCamelCase							,    (DatasetDict, IterableDatasetDict)      ):
    if not dataset:
     raise ValueError(
         F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
         """is an empty dataset dictionary."""      )
    raise ValueError(
        F"Dataset at position {i} has at least one split: {list(__UpperCamelCase      )}\n"
        F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase      )      )}']"      )
   raise ValueError(
       F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase      ).__name__}."      )
  if i == 0:
   UpperCAmelCase__   ,      UpperCAmelCase__					:  Optional[int]					   =					(
       (Dataset, IterableDataset) if isinstance(__UpperCamelCase							,    __UpperCamelCase      ) else (IterableDataset, Dataset)
   )
  elif not isinstance(__UpperCamelCase							,    __UpperCamelCase      ):
   raise ValueError(
       F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."      )
 if dataset_type is Dataset:
  return _concatenate_map_style_datasets(__UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    axis=__UpperCamelCase      )
 else:
  return _concatenate_iterable_datasets(__UpperCamelCase							,    info=__UpperCamelCase							,    split=__UpperCamelCase							,    axis=__UpperCamelCase      )





