


'''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 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Any     						=				"align_text_model"







							def __init__(		self ,   lowerCamelCase_=3_05_22 ,   lowerCamelCase_=7_68 ,   lowerCamelCase_=12 ,   lowerCamelCase_=12 ,   lowerCamelCase_=30_72 ,   lowerCamelCase_="gelu" ,   lowerCamelCase_=0.1 ,   lowerCamelCase_=0.1 ,   lowerCamelCase_=5_12 ,   lowerCamelCase_=2 ,   lowerCamelCase_=0.02 ,   lowerCamelCase_=1e-12 ,   lowerCamelCase_=0 ,   lowerCamelCase_="absolute" ,   lowerCamelCase_=True ,   **lowerCamelCase_ ,   )	->							Optional[Any]:
														super().__init__(**lowerCamelCase_       )

														lowerCAmelCase__	       =     vocab_size
														lowerCAmelCase__	       =     hidden_size
														lowerCAmelCase__	       =     num_hidden_layers
														lowerCAmelCase__	       =     num_attention_heads
														lowerCAmelCase__	       =     hidden_act
														lowerCAmelCase__	       =     intermediate_size
														lowerCAmelCase__	       =     hidden_dropout_prob
														lowerCAmelCase__	       =     attention_probs_dropout_prob
														lowerCAmelCase__	       =     max_position_embeddings
														lowerCAmelCase__	       =     type_vocab_size
														lowerCAmelCase__	       =     initializer_range
														lowerCAmelCase__	       =     layer_norm_eps
														lowerCAmelCase__	       =     position_embedding_type
														lowerCAmelCase__	       =     use_cache
														lowerCAmelCase__	       =     pad_token_id







							@classmethod
							def   __SCREAMING_SNAKE_CASE							(		cls ,   lowerCamelCase_ ,   **lowerCamelCase_       )	->							"PretrainedConfig":
														cls._set_token_in_kwargs(lowerCamelCase_       )

														lowerCAmelCase__       , lowerCAmelCase__	       =     cls.get_config_dict(lowerCamelCase_ ,   **lowerCamelCase_       )

														# get the text config dict if we are loading from AlignConfig
														if config_dict.get('''model_type'''       ) == "align":
																					lowerCAmelCase__	       =     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(lowerCamelCase_ ,   **lowerCamelCase_       )




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       List[Any]     						=				"align_vision_model"







							def __init__(		self ,   lowerCamelCase_ = 3 ,   lowerCamelCase_ = 6_00 ,   lowerCamelCase_ = 2.0 ,   lowerCamelCase_ = 3.1 ,   lowerCamelCase_ = 8 ,   lowerCamelCase_ = [3, 3, 5, 3, 5, 5, 3] ,   lowerCamelCase_ = [32, 16, 24, 40, 80, 1_12, 1_92] ,   lowerCamelCase_ = [16, 24, 40, 80, 1_12, 1_92, 3_20] ,   lowerCamelCase_ = [] ,   lowerCamelCase_ = [1, 2, 2, 2, 1, 2, 1] ,   lowerCamelCase_ = [1, 2, 2, 3, 3, 4, 1] ,   lowerCamelCase_ = [1, 6, 6, 6, 6, 6, 6] ,   lowerCamelCase_ = 0.25 ,   lowerCamelCase_ = "swish" ,   lowerCamelCase_ = 25_60 ,   lowerCamelCase_ = "mean" ,   lowerCamelCase_ = 0.02 ,   lowerCamelCase_ = 0.001 ,   lowerCamelCase_ = 0.99 ,   lowerCamelCase_ = 0.2 ,   **lowerCamelCase_ ,   )	->							List[Any]:
														super().__init__(**lowerCamelCase_       )

														lowerCAmelCase__	       =     num_channels
														lowerCAmelCase__	       =     image_size
														lowerCAmelCase__	       =     width_coefficient
														lowerCAmelCase__	       =     depth_coefficient
														lowerCAmelCase__	       =     depth_divisor
														lowerCAmelCase__	       =     kernel_sizes
														lowerCAmelCase__	       =     in_channels
														lowerCAmelCase__	       =     out_channels
														lowerCAmelCase__	       =     depthwise_padding
														lowerCAmelCase__	       =     strides
														lowerCAmelCase__	       =     num_block_repeats
														lowerCAmelCase__	       =     expand_ratios
														lowerCAmelCase__	       =     squeeze_expansion_ratio
														lowerCAmelCase__	       =     hidden_act
														lowerCAmelCase__	       =     hidden_dim
														lowerCAmelCase__	       =     pooling_type
														lowerCAmelCase__	       =     initializer_range
														lowerCAmelCase__	       =     batch_norm_eps
														lowerCAmelCase__	       =     batch_norm_momentum
														lowerCAmelCase__	       =     drop_connect_rate
														lowerCAmelCase__	       =     sum(lowerCamelCase_       ) * 4







							@classmethod
							def   __SCREAMING_SNAKE_CASE							(		cls ,   lowerCamelCase_ ,   **lowerCamelCase_       )	->							"PretrainedConfig":
														cls._set_token_in_kwargs(lowerCamelCase_       )

														lowerCAmelCase__       , lowerCAmelCase__	       =     cls.get_config_dict(lowerCamelCase_ ,   **lowerCamelCase_       )

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




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Any     						=				"align"
							lowercase__      :       str     						=				True







							def __init__(		self ,   lowerCamelCase_=None ,   lowerCamelCase_=None ,   lowerCamelCase_=6_40 ,   lowerCamelCase_=1.0 ,   lowerCamelCase_=0.02 ,   **lowerCamelCase_ ,   )	->							Optional[Any]:
														super().__init__(**lowerCamelCase_       )

														if text_config is None:
																					lowerCAmelCase__	       =     {}
																					logger.info('''text_config is None. Initializing the AlignTextConfig with default values.'''       )

														if vision_config is None:
																					lowerCAmelCase__	       =     {}
																					logger.info('''vision_config is None. Initializing the AlignVisionConfig with default values.'''       )

														lowerCAmelCase__	       =     AlignTextConfig(**lowerCamelCase_       )
														lowerCAmelCase__	       =     AlignVisionConfig(**lowerCamelCase_       )

														lowerCAmelCase__	       =     projection_dim
														lowerCAmelCase__	       =     temperature_init_value
														lowerCAmelCase__	       =     initializer_range







							@classmethod
							def   __SCREAMING_SNAKE_CASE							(		cls ,   lowerCamelCase_ ,   lowerCamelCase_ ,   **lowerCamelCase_       )	->							Optional[Any]:
														return cls(text_config=text_config.to_dict() ,   vision_config=vision_config.to_dict() ,   **lowerCamelCase_       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Union[str, Any]:
														lowerCAmelCase__	       =     copy.deepcopy(self.__dict__       )
														lowerCAmelCase__	       =     self.text_config.to_dict()
														lowerCAmelCase__	       =     self.vision_config.to_dict()
														lowerCAmelCase__	       =     self.__class__.model_type
														return output



'''simple docstring'''






import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Dict     						=				""
							lowercase__      :       str     						=				(
							    None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
							)
							lowercase__      :       str     						=				None  # compression type in fsspec. ex: "gzip"
							lowercase__      :       str     						=				None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz







							def __init__(		self ,   lowerCamelCase_ = "" ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   **lowerCamelCase_       )	->							Any:
														super().__init__(self ,   **lowerCamelCase_       )
														# always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
														lowerCAmelCase__	       =     fsspec.open(
														    lowerCamelCase_ ,   mode='''rb''' ,   protocol=lowerCamelCase_ ,   compression=self.compression ,   client_kwargs={
														        '''requote_redirect_url''': False,  # see https://github.com/huggingface/datasets/pull/5459
														        '''trust_env''': True,  # Enable reading proxy env variables.
														        **(target_options or {}).pop('''client_kwargs''' ,   {}       ),  # To avoid issues if it was already passed.
														    } ,   **(target_options or {}) ,   )
														lowerCAmelCase__	       =     os.path.basename(self.file.path.split('''::'''       )[0]       )
														lowerCAmelCase__	       =     (
														    self.compressed_name[: self.compressed_name.rindex('''.'''       )]
														    if '''.''' in self.compressed_name
														    else self.compressed_name
														)
														lowerCAmelCase__	       =     None







							@classmethod
							def   __SCREAMING_SNAKE_CASE							(		cls ,   lowerCamelCase_       )	->							Any:
														# compressed file paths are always relative to the archive root
														return super()._strip_protocol(lowerCamelCase_       ).lstrip('''/'''       )







							def   __SCREAMING_SNAKE_CASE							(		self       )	->							Optional[int]:
														if self.dir_cache is None:
																					lowerCAmelCase__	       =     {**self.file.fs.info(self.file.path       ), '''name''': self.uncompressed_name}
																					lowerCAmelCase__	       =     {f['''name''']: f}







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_       )	->							List[Any]:
														return self.file.open().read()







							def   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_ = "rb" ,   lowerCamelCase_=None ,   lowerCamelCase_=True ,   lowerCamelCase_=None ,   **lowerCamelCase_ ,   )	->							List[str]:
														lowerCAmelCase__	       =     self._strip_protocol(lowerCamelCase_       )
														if mode != "rb":
																					raise ValueError(F"""Tried to read with mode {mode} on file {self.file.path} opened with mode 'rb'"""       )
														return self.file.open()




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Optional[Any]     						=				"bz2"
							lowercase__      :       str     						=				"bz2"
							lowercase__      :       Optional[int]     						=				".bz2"




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Any     						=				"gzip"
							lowercase__      :       int     						=				"gzip"
							lowercase__      :       int     						=				".gz"




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Tuple     						=				"lz4"
							lowercase__      :       Optional[Any]     						=				"lz4"
							lowercase__      :       int     						=				".lz4"




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Optional[int]     						=				"xz"
							lowercase__      :       str     						=				"xz"
							lowercase__      :       List[Any]     						=				".xz"




class 		a__    (							a__  ):





							'''simple docstring'''






							lowercase__      :       Union[str, Any]     						=				"zstd"
							lowercase__      :       Union[str, Any]     						=				"zstd"
							lowercase__      :       Dict     						=				".zst"







							def __init__(		self ,   lowerCamelCase_ ,   lowerCamelCase_ = "rb" ,   lowerCamelCase_ = None ,   lowerCamelCase_ = None ,   lowerCamelCase_ = DEFAULT_BLOCK_SIZE ,   **lowerCamelCase_ ,   )	->							List[Any]:
														super().__init__(
														    fo=lowerCamelCase_ ,   mode=lowerCamelCase_ ,   target_protocol=lowerCamelCase_ ,   target_options=lowerCamelCase_ ,   block_size=lowerCamelCase_ ,   **lowerCamelCase_ ,   )
														# We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
														#
														# File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
														#     out.close = close
														# AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
														#
														# see https://github.com/intake/filesystem_spec/issues/725
														lowerCAmelCase__	       =     self.file.__enter__




														class 		a__    :





																					'''simple docstring'''






																					def __init__(		self ,   lowerCamelCase_       )	->							List[str]:
																												lowerCAmelCase__	       =     file_







																					def __enter__(		self       )	->							Tuple:
																												self._file.__enter__()
																												return self







																					def __exit__(		self ,   *lowerCamelCase_ ,   **lowerCamelCase_       )	->							str:
																												self._file.__exit__(*lowerCamelCase_ ,   **lowerCamelCase_       )







																					def __iter__(		self       )	->							Any:
																												return iter(self._file       )







																					def   __SCREAMING_SNAKE_CASE							(		self       )	->							Union[str, Any]:
																												return next(self._file       )







																					def __getattr__(		self ,   lowerCamelCase_       )	->							str:
																												return getattr(self._file ,   lowerCamelCase_       )

														def fixed_enter(*lowerCamelCase_ ,   **lowerCamelCase_       ):
																					return WrappedFile(_enter(*lowerCamelCase_ ,   **lowerCamelCase_       )       )

														lowerCAmelCase__	       =     fixed_enter