





import copy
import os
from typing import Union

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


UpperCAmelCase_      							=     logging.get_logger(__name__)

UpperCAmelCase_      							=     {
    """BAAI/AltCLIP""": """https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json""",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class 			UpperCamelCase_		(  _lowerCamelCase					):
					lowerCAmelCase_							=	'''altclip_text_model'''




					def __init__(		self				,						lowerCAmelCase_=25_0002				,						lowerCAmelCase_=1024				,						lowerCAmelCase_=24				,						lowerCAmelCase_=16				,						lowerCAmelCase_=4096				,						lowerCAmelCase_="gelu"				,						lowerCAmelCase_=0.1				,						lowerCAmelCase_=0.1				,						lowerCAmelCase_=514				,						lowerCAmelCase_=1				,						lowerCAmelCase_=0.02				,						lowerCAmelCase_=0.02				,						lowerCAmelCase_=1E-05				,						lowerCAmelCase_=1				,						lowerCAmelCase_=0				,						lowerCAmelCase_=2				,						lowerCAmelCase_="absolute"				,						lowerCAmelCase_=True				,						lowerCAmelCase_=768				,						**lowerCAmelCase_				,						)		->							Tuple:
										super().__init__(pad_token_id=lowerCAmelCase_				,						bos_token_id=lowerCAmelCase_				,						eos_token_id=lowerCAmelCase_				,						**lowerCAmelCase_  )

										_snake_case									=				vocab_size
										_snake_case									=				hidden_size
										_snake_case									=				num_hidden_layers
										_snake_case									=				num_attention_heads
										_snake_case									=				hidden_act
										_snake_case									=				intermediate_size
										_snake_case									=				hidden_dropout_prob
										_snake_case									=				attention_probs_dropout_prob
										_snake_case									=				max_position_embeddings
										_snake_case									=				type_vocab_size
										_snake_case									=				initializer_range
										_snake_case									=				initializer_factor
										_snake_case									=				layer_norm_eps
										_snake_case									=				position_embedding_type
										_snake_case									=				use_cache
										_snake_case									=				project_dim





class 			UpperCamelCase_		(  _lowerCamelCase					):
					lowerCAmelCase_							=	'''altclip_vision_model'''




					def __init__(		self				,						lowerCAmelCase_=768				,						lowerCAmelCase_=3072				,						lowerCAmelCase_=512				,						lowerCAmelCase_=12				,						lowerCAmelCase_=12				,						lowerCAmelCase_=3				,						lowerCAmelCase_=224				,						lowerCAmelCase_=32				,						lowerCAmelCase_="quick_gelu"				,						lowerCAmelCase_=1E-5				,						lowerCAmelCase_=0.0				,						lowerCAmelCase_=0.02				,						lowerCAmelCase_=1.0				,						**lowerCAmelCase_				,						)		->							Union[str, Any]:
										super().__init__(**lowerCAmelCase_  )

										_snake_case									=				hidden_size
										_snake_case									=				intermediate_size
										_snake_case									=				projection_dim
										_snake_case									=				num_hidden_layers
										_snake_case									=				num_attention_heads
										_snake_case									=				num_channels
										_snake_case									=				patch_size
										_snake_case									=				image_size
										_snake_case									=				initializer_range
										_snake_case									=				initializer_factor
										_snake_case									=				attention_dropout
										_snake_case									=				layer_norm_eps
										_snake_case									=				hidden_act






					@classmethod
					def 	lowerCAmelCase			(		cls				,						lowerCAmelCase_				,						**lowerCAmelCase_  )		->							"PretrainedConfig":
										cls._set_token_in_kwargs(lowerCAmelCase_  )

										_snake_case							,     _snake_case									=				cls.get_config_dict(lowerCAmelCase_				,						**lowerCAmelCase_  )

										# get the vision config dict if we are loading from AltCLIPConfig
										if config_dict.get('model_type'  ) == "altclip":
															_snake_case									=				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 			UpperCamelCase_		(  _lowerCamelCase					):
					lowerCAmelCase_							=	'''altclip'''
					lowerCAmelCase_							=	True




					def __init__(		self				,						lowerCAmelCase_=None				,						lowerCAmelCase_=None				,						lowerCAmelCase_=768				,						lowerCAmelCase_=2.65_92				,						**lowerCAmelCase_  )		->							List[Any]:
										# If `_config_dict` exist, we use them for the backward compatibility.
										# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
										# of confusion!).
										_snake_case									=				kwargs.pop('text_config_dict'				,						lowerCAmelCase_  )
										_snake_case									=				kwargs.pop('vision_config_dict'				,						lowerCAmelCase_  )

										super().__init__(**lowerCAmelCase_  )

										# 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:
																				_snake_case									=				{}

															# This is the complete result when using `text_config_dict`.
															_snake_case									=				AltCLIPTextConfig(**lowerCAmelCase_  ).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:
																														_snake_case									=				(
																														    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:
																														_snake_case									=				(
																														    F'''`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '''
																														    F'''value `text_config["{key}"]` will be overriden.'''
																														)
																									logger.warning(lowerCAmelCase_  )

            # 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:
																				_snake_case									=				{}

															# This is the complete result when using `vision_config_dict`.
															_snake_case									=				AltCLIPVisionConfig(**lowerCAmelCase_  ).to_dict()
															# convert keys to string instead of integer
															if "id2label" in _vision_config_dict:
																				_snake_case									=				{
																				    str(lowerCAmelCase_  ): 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:
																														_snake_case									=				(
																														    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:
																														_snake_case									=				(
																														    F'''`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '''
																														    F'''The value `vision_config["{key}"]` will be overriden.'''
																														)
																									logger.warning(lowerCAmelCase_  )

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

										if text_config is None:
															_snake_case									=				{}
															logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'  )

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

										_snake_case									=				AltCLIPTextConfig(**lowerCAmelCase_  )
										_snake_case									=				AltCLIPVisionConfig(**lowerCAmelCase_  )

										_snake_case									=				projection_dim
										_snake_case									=				logit_scale_init_value
										_snake_case									=				1.0




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






					def 	lowerCAmelCase			(		self  )		->							Any:
										_snake_case									=				copy.deepcopy(self.__dict__  )
										_snake_case									=				self.text_config.to_dict()
										_snake_case									=				self.vision_config.to_dict()
										_snake_case									=				self.__class__.model_type
										return output










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


UpperCAmelCase_      							=     {"""configuration_swin""": ["""SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP""", """SwinConfig""", """SwinOnnxConfig"""]}


try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase_      							=     [
					    """SWIN_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """SwinForImageClassification""",
					    """SwinForMaskedImageModeling""",
					    """SwinModel""",
					    """SwinPreTrainedModel""",
					    """SwinBackbone""",
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase_      							=     [
					    """TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """TFSwinForImageClassification""",
					    """TFSwinForMaskedImageModeling""",
					    """TFSwinModel""",
					    """TFSwinPreTrainedModel""",
					]

if TYPE_CHECKING:
					from .configuration_swin import SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinConfig, SwinOnnxConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_swin import (
										    SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
										    SwinBackbone,
										    SwinForImageClassification,
										    SwinForMaskedImageModeling,
										    SwinModel,
										    SwinPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_swin import (
										    TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFSwinForImageClassification,
										    TFSwinForMaskedImageModeling,
										    TFSwinModel,
										    TFSwinPreTrainedModel,
										)

else:
					import sys

					UpperCAmelCase_      							=     _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



