






import json
import os
import shutil
import tempfile
import unittest

from transformers import BatchEncoding, CanineTokenizer
from transformers.testing_utils import require_tokenizers, require_torch
from transformers.tokenization_utils import AddedToken
from transformers.utils import cached_property

from ...test_tokenization_common import TokenizerTesterMixin




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					,  unittest.TestCase					):


						'''simple docstring'''




						A     :   Union[str, Any]						=					CanineTokenizer
						A     :   List[Any]						=					False






						def       _lowerCAmelCase       (	self				) ->				Union[str, Any]:
								super().setUp()
								snake_case_				:							List[str]						 =       CanineTokenizer()
								tokenizer.save_pretrained(self.tmpdirname				)






						@cached_property
						def       _lowerCAmelCase       (	self				) ->				List[str]:
								return CanineTokenizer.from_pretrained("google/canine-s"				)






						def       _lowerCAmelCase       (	self		,				**_SCREAMING_SNAKE_CASE				) ->				CanineTokenizer:
								snake_case_				:							List[Any]						 =       self.tokenizer_class.from_pretrained(self.tmpdirname		,				**_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Tuple						 =       1024
								return tokenizer






						@require_torch
						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							Optional[int]						 =       self.canine_tokenizer
								snake_case_				:							List[str]						 =       ["Life is like a box of chocolates.", "You never know what you're gonna get."]
								# fmt: off
								snake_case_				:							Any						 =       [5_7344, 76, 105, 102, 101, 32, 105, 115, 32, 108, 105, 107, 101, 32, 97, 32, 98, 111, 120, 32, 111, 102, 32, 99, 104, 111, 99, 111, 108, 97, 116, 101, 115, 46, 5_7345, 0, 0, 0, 0]
								# fmt: on
								snake_case_				:							Any						 =       tokenizer(_SCREAMING_SNAKE_CASE		,				padding=_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				)
								self.assertIsInstance(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Dict						 =       list(batch.input_ids.numpy()[0]				)

								self.assertListEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

								self.assertEqual((2, 39)		,				batch.input_ids.shape				)
								self.assertEqual((2, 39)		,				batch.attention_mask.shape				)






						@require_torch
						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							List[str]						 =       self.canine_tokenizer
								snake_case_				:							Tuple						 =       ["Once there was a man.", "He wrote a test in HuggingFace Tranformers."]
								snake_case_				:							Union[str, Any]						 =       tokenizer(_SCREAMING_SNAKE_CASE		,				padding=_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				)
								# check if input_ids, attention_mask and token_type_ids are returned
								self.assertIn("input_ids"		,				_SCREAMING_SNAKE_CASE				)
								self.assertIn("attention_mask"		,				_SCREAMING_SNAKE_CASE				)
								self.assertIn("token_type_ids"		,				_SCREAMING_SNAKE_CASE				)






						@require_torch
						def       _lowerCAmelCase       (	self				) ->				List[Any]:
								snake_case_				:							Optional[int]						 =       self.canine_tokenizer
								snake_case_				:							str						 =       [
								    "What's the weater?",
								    "It's about 25 degrees.",
								]
								snake_case_				:							Tuple						 =       tokenizer(
								    text_target=_SCREAMING_SNAKE_CASE		,				max_length=32		,				padding="max_length"		,				truncation=_SCREAMING_SNAKE_CASE		,				return_tensors="pt"				)
								self.assertEqual(32		,				targets["input_ids"].shape[1]				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								# safety check on max_len default value so we are sure the test works
								snake_case_				:							Optional[int]						 =       self.get_tokenizers()
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												self.assertNotEqual(tokenizer.model_max_length		,				42				)

        # Now let's start the test
								snake_case_				:							List[Any]						 =       self.get_tokenizers()
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												# Isolate this from the other tests because we save additional tokens/etc
												snake_case_				:							Optional[int]						 =       tempfile.mkdtemp()

												snake_case_				:							List[str]						 =       " He is very happy, UNwant\u00E9d,running"
												snake_case_				:							Any						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												tokenizer.save_pretrained(_SCREAMING_SNAKE_CASE				)

												snake_case_				:							List[Any]						 =       tokenizer.__class__.from_pretrained(_SCREAMING_SNAKE_CASE				)
												snake_case_				:							Optional[int]						 =       after_tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												self.assertListEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

												shutil.rmtree(_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Dict						 =       self.get_tokenizers(model_max_length=42				)
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												# Isolate this from the other tests because we save additional tokens/etc
												snake_case_				:							Tuple						 =       tempfile.mkdtemp()

												snake_case_				:							Optional[Any]						 =       " He is very happy, UNwant\u00E9d,running"

												snake_case_				:							Tuple						 =       tokenizer.additional_special_tokens

												# We can add a new special token for Canine as follows:
												snake_case_				:							Optional[int]						 =       chr(0Xe007				)
												additional_special_tokens.append(_SCREAMING_SNAKE_CASE				)
												tokenizer.add_special_tokens({"additional_special_tokens": additional_special_tokens}				)
												snake_case_				:							str						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												tokenizer.save_pretrained(_SCREAMING_SNAKE_CASE				)

												snake_case_				:							Optional[Any]						 =       tokenizer.__class__.from_pretrained(_SCREAMING_SNAKE_CASE				)
												snake_case_				:							List[str]						 =       after_tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												self.assertListEqual(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
												self.assertIn(_SCREAMING_SNAKE_CASE		,				after_tokenizer.additional_special_tokens				)
												self.assertEqual(after_tokenizer.model_max_length		,				42				)

												snake_case_				:							Any						 =       tokenizer.__class__.from_pretrained(_SCREAMING_SNAKE_CASE		,				model_max_length=43				)
												self.assertEqual(tokenizer.model_max_length		,				43				)

												shutil.rmtree(_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				List[Any]:
								snake_case_				:							Optional[int]						 =       self.get_tokenizers(do_lower_case=_SCREAMING_SNAKE_CASE				)
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												snake_case_ ,       snake_case_				:							Union[str, Any]						 =       self.get_clean_sequence(_SCREAMING_SNAKE_CASE				)

												# a special token for Canine can be defined as follows:
												snake_case_				:							List[Any]						 =       0Xe005
												snake_case_				:							Any						 =       chr(_SCREAMING_SNAKE_CASE				)

												tokenizer.add_special_tokens({"cls_token": special_token}				)
												snake_case_				:							Optional[int]						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												self.assertEqual(len(_SCREAMING_SNAKE_CASE				)		,				1				)

												snake_case_				:							int						 =       tokenizer.decode(ids + encoded_special_token		,				clean_up_tokenization_spaces=_SCREAMING_SNAKE_CASE				)
												snake_case_				:							Optional[Any]						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)

												snake_case_				:							Union[str, Any]						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												snake_case_				:							List[Any]						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												self.assertEqual(_SCREAMING_SNAKE_CASE		,				input_encoded + special_token_id				)

												snake_case_				:							Optional[Any]						 =       tokenizer.decode(_SCREAMING_SNAKE_CASE		,				skip_special_tokens=_SCREAMING_SNAKE_CASE				)
												self.assertTrue(special_token not in decoded				)






						def       _lowerCAmelCase       (	self				) ->				Dict:
								snake_case_				:							Tuple						 =       self.get_tokenizers(do_lower_case=_SCREAMING_SNAKE_CASE				)
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												snake_case_				:							str						 =       chr(0Xe005				)
												snake_case_				:							str						 =       chr(0Xe006				)

												# `add_tokens` method stores special tokens only in `tokenizer.unique_no_split_tokens`. (in tokenization_utils.py)
												tokenizer.add_tokens([SPECIAL_TOKEN_1]		,				special_tokens=_SCREAMING_SNAKE_CASE				)
												# `add_special_tokens` method stores special tokens in `tokenizer.additional_special_tokens`,
												# which also occur in `tokenizer.all_special_tokens`. (in tokenization_utils_base.py)
												tokenizer.add_special_tokens({"additional_special_tokens": [SPECIAL_TOKEN_2]}				)

												snake_case_				:							Tuple						 =       tokenizer.tokenize(_SCREAMING_SNAKE_CASE				)
												snake_case_				:							List[Any]						 =       tokenizer.tokenize(_SCREAMING_SNAKE_CASE				)

												self.assertEqual(len(_SCREAMING_SNAKE_CASE				)		,				1				)
												self.assertEqual(len(_SCREAMING_SNAKE_CASE				)		,				1				)
												self.assertEqual(token_a[0]		,				_SCREAMING_SNAKE_CASE				)
												self.assertEqual(token_a[0]		,				_SCREAMING_SNAKE_CASE				)






						@require_tokenizers
						def       _lowerCAmelCase       (	self				) ->				Tuple:
								snake_case_				:							List[str]						 =       self.get_tokenizers(do_lower_case=_SCREAMING_SNAKE_CASE				)
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												# a special token for Canine can be defined as follows:
												snake_case_				:							List[str]						 =       0Xe006
												snake_case_				:							Optional[int]						 =       chr(_SCREAMING_SNAKE_CASE				)

												snake_case_				:							int						 =       AddedToken(_SCREAMING_SNAKE_CASE		,				lstrip=_SCREAMING_SNAKE_CASE				)
												tokenizer.add_special_tokens({"additional_special_tokens": [new_token]}				)

												with tempfile.TemporaryDirectory() as tmp_dir_name:
														tokenizer.save_pretrained(_SCREAMING_SNAKE_CASE				)
														tokenizer.from_pretrained(_SCREAMING_SNAKE_CASE				)






						def       _lowerCAmelCase       (	self				) ->				int:
								snake_case_				:							Dict						 =       []
								if self.test_slow_tokenizer:
										tokenizer_list.append((self.tokenizer_class, self.get_tokenizer())				)

								if self.test_rust_tokenizer:
										tokenizer_list.append((self.rust_tokenizer_class, self.get_rust_tokenizer())				)

								for tokenizer_class, tokenizer_utils in tokenizer_list:
										with tempfile.TemporaryDirectory() as tmp_dir:
												tokenizer_utils.save_pretrained(_SCREAMING_SNAKE_CASE				)

												with open(os.path.join(_SCREAMING_SNAKE_CASE		,				"special_tokens_map.json"				)		,				encoding="utf-8"				) as json_file:
														snake_case_				:							Dict						 =       json.load(_SCREAMING_SNAKE_CASE				)

												with open(os.path.join(_SCREAMING_SNAKE_CASE		,				"tokenizer_config.json"				)		,				encoding="utf-8"				) as json_file:
														snake_case_				:							List[Any]						 =       json.load(_SCREAMING_SNAKE_CASE				)

												# a special token for Canine can be defined as follows:
												snake_case_				:							Any						 =       0Xe006
												snake_case_				:							List[Any]						 =       chr(_SCREAMING_SNAKE_CASE				)

												snake_case_				:							Union[str, Any]						 =       [new_token_a]
												snake_case_				:							str						 =       [new_token_a]

												with open(os.path.join(_SCREAMING_SNAKE_CASE		,				"special_tokens_map.json"				)		,				"w"		,				encoding="utf-8"				) as outfile:
														json.dump(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)
												with open(os.path.join(_SCREAMING_SNAKE_CASE		,				"tokenizer_config.json"				)		,				"w"		,				encoding="utf-8"				) as outfile:
														json.dump(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)

												# the following checks allow us to verify that our test works as expected, i.e. that the tokenizer takes
												# into account the new value of additional_special_tokens given in the "tokenizer_config.json" and
												# "special_tokens_map.json" files
												snake_case_				:							str						 =       tokenizer_class.from_pretrained(_SCREAMING_SNAKE_CASE		,				extra_ids=0				)
												self.assertIn(_SCREAMING_SNAKE_CASE		,				tokenizer_without_change_in_init.additional_special_tokens				)
												# self.assertIn("an_additional_special_token",tokenizer_without_change_in_init.get_vocab()) # ByT5Tokenization no vocab
												self.assertEqual(
												    [new_token_a]		,				tokenizer_without_change_in_init.convert_ids_to_tokens(
												        tokenizer_without_change_in_init.convert_tokens_to_ids([new_token_a]				)				)		,				)

												snake_case_				:							Union[str, Any]						 =       0Xe007
												snake_case_				:							str						 =       chr(_SCREAMING_SNAKE_CASE				)
												# Now we test that we can change the value of additional_special_tokens in the from_pretrained
												snake_case_				:							List[Any]						 =       [AddedToken(_SCREAMING_SNAKE_CASE		,				lstrip=_SCREAMING_SNAKE_CASE				)]
												snake_case_				:							Optional[int]						 =       tokenizer_class.from_pretrained(
												    _SCREAMING_SNAKE_CASE		,				additional_special_tokens=_SCREAMING_SNAKE_CASE		,				extra_ids=0				)

												self.assertIn(_SCREAMING_SNAKE_CASE		,				tokenizer.additional_special_tokens				)
												# self.assertIn(new_token_2,tokenizer.get_vocab()) # ByT5Tokenization no vocab
												self.assertEqual(
												    [new_token_a]		,				tokenizer.convert_ids_to_tokens(tokenizer.convert_tokens_to_ids([new_token_a]				)				)				)






						@require_tokenizers
						def       _lowerCAmelCase       (	self				) ->				Any:
								snake_case_				:							Any						 =       self.get_tokenizers(do_lower_case=_SCREAMING_SNAKE_CASE				)
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												snake_case_				:							Dict						 =       "hello world"
												if self.space_between_special_tokens:
														snake_case_				:							Optional[Any]						 =       "[CLS] hello world [SEP]"
												else:
														snake_case_				:							Optional[int]						 =       input
												snake_case_				:							int						 =       tokenizer.encode(_SCREAMING_SNAKE_CASE		,				add_special_tokens=_SCREAMING_SNAKE_CASE				)
												snake_case_				:							Optional[int]						 =       tokenizer.decode(_SCREAMING_SNAKE_CASE		,				spaces_between_special_tokens=self.space_between_special_tokens				)
												self.assertIn(_SCREAMING_SNAKE_CASE		,				[output, output.lower()]				)






						def       _lowerCAmelCase       (	self				) ->				Optional[Any]:
								snake_case_				:							Tuple						 =       self.get_tokenizers()
								for tokenizer in tokenizers:
										with self.subTest(f'''{tokenizer.__class__.__name__}'''				):
												snake_case_				:							int						 =       [
												    "bos_token",
												    "eos_token",
												    "unk_token",
												    "sep_token",
												    "pad_token",
												    "cls_token",
												    "mask_token",
												]

								snake_case_				:							Optional[int]						 =       "a"
								snake_case_				:							str						 =       ord(_SCREAMING_SNAKE_CASE				)

								for attr in attributes_list:
										setattr(_SCREAMING_SNAKE_CASE		,				attr + "_id"		,				_SCREAMING_SNAKE_CASE				)
										self.assertEqual(getattr(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)		,				_SCREAMING_SNAKE_CASE				)
										self.assertEqual(getattr(_SCREAMING_SNAKE_CASE		,				attr + "_id"				)		,				_SCREAMING_SNAKE_CASE				)

										setattr(_SCREAMING_SNAKE_CASE		,				attr + "_id"		,				_SCREAMING_SNAKE_CASE				)
										self.assertEqual(getattr(_SCREAMING_SNAKE_CASE		,				_SCREAMING_SNAKE_CASE				)		,				_SCREAMING_SNAKE_CASE				)
										self.assertEqual(getattr(_SCREAMING_SNAKE_CASE		,				attr + "_id"				)		,				_SCREAMING_SNAKE_CASE				)

								setattr(_SCREAMING_SNAKE_CASE		,				"additional_special_tokens_ids"		,				[]				)
								self.assertListEqual(getattr(_SCREAMING_SNAKE_CASE		,				"additional_special_tokens"				)		,				[]				)
								self.assertListEqual(getattr(_SCREAMING_SNAKE_CASE		,				"additional_special_tokens_ids"				)		,				[]				)

								snake_case_				:							List[Any]						 =       0Xe006
								snake_case_				:							Optional[Any]						 =       chr(_SCREAMING_SNAKE_CASE				)
								setattr(_SCREAMING_SNAKE_CASE		,				"additional_special_tokens_ids"		,				[additional_special_token_id]				)
								self.assertListEqual(getattr(_SCREAMING_SNAKE_CASE		,				"additional_special_tokens"				)		,				[additional_special_token]				)
								self.assertListEqual(getattr(_SCREAMING_SNAKE_CASE		,				"additional_special_tokens_ids"				)		,				[additional_special_token_id]				)






						def       _lowerCAmelCase       (	self				) ->				int:
								pass






						def       _lowerCAmelCase       (	self				) ->				Any:
								pass






						def       _lowerCAmelCase       (	self				) ->				Dict:
								pass






						def       _lowerCAmelCase       (	self				) ->				List[Any]:
								pass






						def       _lowerCAmelCase       (	self				) ->				List[str]:
								pass






						def       _lowerCAmelCase       (	self				) ->				str:
								pass






						def       _lowerCAmelCase       (	self				) ->				int:
								pass






						def       _lowerCAmelCase       (	self				) ->				Tuple:
								pass








import copy
import os
from typing import Union

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


lowercase  :							int			  =    logging.get_logger(__name__)

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




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						A     :   int						=					'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		,				) ->				List[str]:
								super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE		,				bos_token_id=_SCREAMING_SNAKE_CASE		,				eos_token_id=_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				)

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




class 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						A     :   List[Any]						=					'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		,				) ->				Optional[Any]:
								super().__init__(**_SCREAMING_SNAKE_CASE				)

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






						@classmethod
						def       _lowerCAmelCase       (	cls		,				_SCREAMING_SNAKE_CASE		,				**_SCREAMING_SNAKE_CASE				) ->				"PretrainedConfig":
								cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE				)

								snake_case_ ,       snake_case_				:							str						 =       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":
										snake_case_				:							List[Any]						 =       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 		UpperCAmelCase_						(	SCREAMING_SNAKE_CASE__					):


						'''simple docstring'''




						A     :   str						=					'altclip'
						A     :   Dict						=					True






						def __init__(	self		,				_SCREAMING_SNAKE_CASE=None		,				_SCREAMING_SNAKE_CASE=None		,				_SCREAMING_SNAKE_CASE=768		,				_SCREAMING_SNAKE_CASE=2.6592		,				**_SCREAMING_SNAKE_CASE				) ->				Optional[int]:
								# 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_				:							Optional[Any]						 =       kwargs.pop("text_config_dict"		,				_SCREAMING_SNAKE_CASE				)
								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:
												snake_case_				:							Any						 =       {}

										# This is the complete result when using `text_config_dict`.
										snake_case_				:							str						 =       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:
																snake_case_				:							Optional[Any]						 =       (
																    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_				:							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:
												snake_case_				:							str						 =       {}

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

								if vision_config is None:
										snake_case_				:							Optional[Any]						 =       {}
										logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."				)

								snake_case_				:							List[Any]						 =       AltCLIPTextConfig(**_SCREAMING_SNAKE_CASE				)
								snake_case_				:							Union[str, Any]						 =       AltCLIPVisionConfig(**_SCREAMING_SNAKE_CASE				)

								snake_case_				:							Optional[int]						 =       projection_dim
								snake_case_				:							Tuple						 =       logit_scale_init_value
								snake_case_				:							List[Any]						 =       1.0






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






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