


import copy
import os
from typing import Union

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


lowerCAmelCase           =		logging.get_logger(__name__)

lowerCAmelCase           =		{
    '''BAAI/AltCLIP''': '''https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json''',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}





class       A    (   A_ ):
							UpperCamelCase_   :							int       ='''altclip_text_model'''


							def __init__(self      ,				lowerCAmelCase=2_5_0_0_0_2      ,				lowerCAmelCase=1_0_2_4      ,				lowerCAmelCase=2_4      ,				lowerCAmelCase=1_6      ,				lowerCAmelCase=4_0_9_6      ,				lowerCAmelCase="gelu"      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=5_1_4      ,				lowerCAmelCase=1      ,				lowerCAmelCase=0.02      ,				lowerCAmelCase=0.02      ,				lowerCAmelCase=1E-05      ,				lowerCAmelCase=1      ,				lowerCAmelCase=0      ,				lowerCAmelCase=2      ,				lowerCAmelCase="absolute"      ,				lowerCAmelCase=True      ,				lowerCAmelCase=7_6_8      ,				**lowerCAmelCase      ,				):
									super().__init__(pad_token_id=lowerCAmelCase      ,				bos_token_id=lowerCAmelCase      ,				eos_token_id=lowerCAmelCase      ,				**lowerCAmelCase					)

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





class       A    (   A_ ):
							UpperCamelCase_   :							List[str]       ='''altclip_vision_model'''


							def __init__(self      ,				lowerCAmelCase=7_6_8      ,				lowerCAmelCase=3_0_7_2      ,				lowerCAmelCase=5_1_2      ,				lowerCAmelCase=1_2      ,				lowerCAmelCase=1_2      ,				lowerCAmelCase=3      ,				lowerCAmelCase=2_2_4      ,				lowerCAmelCase=3_2      ,				lowerCAmelCase="quick_gelu"      ,				lowerCAmelCase=1E-5      ,				lowerCAmelCase=0.0      ,				lowerCAmelCase=0.02      ,				lowerCAmelCase=1.0      ,				**lowerCAmelCase      ,				):
									super().__init__(**lowerCAmelCase					)

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







							@classmethod
							def 			_A       (cls      ,				lowerCAmelCase      ,				**lowerCAmelCase					):
									cls._set_token_in_kwargs(lowerCAmelCase					)

									__lowercase,							__lowercase=			cls.get_config_dict(lowerCAmelCase      ,				**lowerCAmelCase					)

									# get the vision config dict if we are loading from AltCLIPConfig
									if config_dict.get('model_type'					) == "altclip":
											__lowercase=			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_ ):
							UpperCamelCase_   :							str       ='''altclip'''
							UpperCamelCase_   :							List[Any]       =True


							def __init__(self      ,				lowerCAmelCase=None      ,				lowerCAmelCase=None      ,				lowerCAmelCase=7_6_8      ,				lowerCAmelCase=2.65_92      ,				**lowerCAmelCase					):
									# 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!).
									__lowercase=			kwargs.pop('text_config_dict'      ,				lowerCAmelCase					)
									__lowercase=			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:
													__lowercase=			{}

											# This is the complete result when using `text_config_dict`.
											__lowercase=			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:
																	__lowercase=			(
																	    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:
																	__lowercase=			(
																	    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:
													__lowercase=			{}

											# This is the complete result when using `vision_config_dict`.
											__lowercase=			AltCLIPVisionConfig(**lowerCAmelCase					).to_dict()
											# convert keys to string instead of integer
											if "id2label" in _vision_config_dict:
													__lowercase=			{
													    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:
																	__lowercase=			(
																	    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:
																	__lowercase=			(
																	    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:
											__lowercase=			{}
											logger.info('`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'					)

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

									__lowercase=			AltCLIPTextConfig(**lowerCAmelCase					)
									__lowercase=			AltCLIPVisionConfig(**lowerCAmelCase					)

									__lowercase=			projection_dim
									__lowercase=			logit_scale_init_value
									__lowercase=			1.0


							@classmethod
							def 			_A       (cls      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				**lowerCAmelCase					):
									return cls(text_config=text_config.to_dict()      ,				vision_config=vision_config.to_dict()      ,				**lowerCAmelCase					)







							def 			_A       (self					):
									__lowercase=			copy.deepcopy(self.__dict__					)
									__lowercase=			self.text_config.to_dict()
									__lowercase=			self.vision_config.to_dict()
									__lowercase=			self.__class__.model_type
									return output










from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available
from ...utils import OptionalDependencyNotAvailable


lowerCAmelCase           =		{'''configuration_gpt_neox''': ['''GPT_NEOX_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''GPTNeoXConfig''']}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase           =		['''GPTNeoXTokenizerFast''']

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	lowerCAmelCase           =		[
	    '''GPT_NEOX_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''GPTNeoXForCausalLM''',
	    '''GPTNeoXForQuestionAnswering''',
	    '''GPTNeoXForSequenceClassification''',
	    '''GPTNeoXForTokenClassification''',
	    '''GPTNeoXLayer''',
	    '''GPTNeoXModel''',
	    '''GPTNeoXPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_gpt_neox import GPT_NEOX_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoXConfig

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_gpt_neox_fast import GPTNeoXTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_gpt_neox import (
		    GPT_NEOX_PRETRAINED_MODEL_ARCHIVE_LIST,
		    GPTNeoXForCausalLM,
		    GPTNeoXForQuestionAnswering,
		    GPTNeoXForSequenceClassification,
		    GPTNeoXForTokenClassification,
		    GPTNeoXLayer,
		    GPTNeoXModel,
		    GPTNeoXPreTrainedModel,
		)


else:
	import sys

	lowerCAmelCase           =		_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






