


from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
	import tensorflow as tf

	from transformers import TFBlipTextModel
	from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST




class       lowercase_					:





				def __init__(				self       ,  lowercase_       ,  lowercase_=12       ,  lowercase_=7       ,  lowercase_=True       ,  lowercase_=True       ,  lowercase_=True       ,  lowercase_=99       ,  lowercase_=32       ,  lowercase_=32       ,  lowercase_=2       ,  lowercase_=4       ,  lowercase_=37       ,  lowercase_=0.1       ,  lowercase_=0.1       ,  lowercase_=512       ,  lowercase_=0.02       ,  lowercase_=0       ,  lowercase_=None       ,  )  -> Union[str, Any]:
											a__      =parent
											a__      =batch_size
											a__      =seq_length
											a__      =is_training
											a__      =use_input_mask
											a__      =use_labels
											a__      =vocab_size
											a__      =hidden_size
											a__      =projection_dim
											a__      =num_hidden_layers
											a__      =num_attention_heads
											a__      =intermediate_size
											a__      =dropout
											a__      =attention_dropout
											a__      =max_position_embeddings
											a__      =initializer_range
											a__      =scope
											a__      =bos_token_id





				def 						__UpperCamelCase    (				self)  -> int:
											a__      =ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size)

											a__      =None
											if self.use_input_mask:
																		a__      =random_attention_mask([self.batch_size, self.seq_length])

											if input_mask is not None:
																		a__      =input_mask.numpy()
																		a__    ,     a__      =input_mask.shape
																		a__      =np.random.randint(1       ,  seq_length - 1       ,  size=(batch_size,))
																		for batch_idx, start_index in enumerate(lowercase_):
																									a__      =1
																									a__      =0

											a__      =self.get_config()

											return config, input_ids, tf.convert_to_tensor(lowercase_)





				def 						__UpperCamelCase    (				self)  -> List[Any]:
											return BlipTextConfig(
											    vocab_size=self.vocab_size       ,  hidden_size=self.hidden_size       ,  projection_dim=self.projection_dim       ,  num_hidden_layers=self.num_hidden_layers       ,  num_attention_heads=self.num_attention_heads       ,  intermediate_size=self.intermediate_size       ,  dropout=self.dropout       ,  attention_dropout=self.attention_dropout       ,  max_position_embeddings=self.max_position_embeddings       ,  initializer_range=self.initializer_range       ,  bos_token_id=self.bos_token_id       ,  )





				def 						__UpperCamelCase    (				self       ,  lowercase_       ,  lowercase_       ,  lowercase_)  -> List[Any]:
											a__      =TFBlipTextModel(config=lowercase_)
											a__      =model(lowercase_       ,  attention_mask=lowercase_       ,  training=lowercase_)
											a__      =model(lowercase_       ,  training=lowercase_)
											self.parent.assertEqual(result.last_hidden_state.shape       ,  (self.batch_size, self.seq_length, self.hidden_size))
											self.parent.assertEqual(result.pooler_output.shape       ,  (self.batch_size, self.hidden_size))





				def 						__UpperCamelCase    (				self)  -> List[str]:
											a__      =self.prepare_config_and_inputs()
											a__    ,     a__    ,     a__      =config_and_inputs
											a__      ={'input_ids': input_ids, 'attention_mask': input_mask}
											return config, inputs_dict







@require_tf
class       lowercase_					(lowercase__      ,					unittest.TestCase   ):
				snake_case	    =(TFBlipTextModel,) if is_tf_available() else ()
				snake_case	    =False
				snake_case	    =False
				snake_case	    =False





				def 						__UpperCamelCase    (				self)  -> Optional[Any]:
											a__      =BlipTextModelTester(self)
											a__      =ConfigTester(self       ,  config_class=lowercase_       ,  hidden_size=37)





				def 						__UpperCamelCase    (				self)  -> Dict:
											self.config_tester.run_common_tests()





				def 						__UpperCamelCase    (				self)  -> int:
											a__      =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*lowercase_)





				def 						__UpperCamelCase    (				self)  -> Union[str, Any]:
											pass





				def 						__UpperCamelCase    (				self)  -> Dict:
											pass





				@unittest.skip(reason='Blip does not use inputs_embeds')
				def 						__UpperCamelCase    (				self)  -> Optional[Any]:
											pass





				@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING')
				def 						__UpperCamelCase    (				self)  -> List[Any]:
											pass





				@unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING')
				def 						__UpperCamelCase    (				self)  -> Dict:
											pass





				@slow
				def 						__UpperCamelCase    (				self)  -> Optional[int]:
											for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		a__      =TFBlipTextModel.from_pretrained(lowercase_)
																		self.assertIsNotNone(lowercase_)





				def 						__UpperCamelCase    (				self       ,  lowercase_=True)  -> str:
											super().test_pt_tf_model_equivalence(allow_missing_keys=lowercase_)





from typing import List, Optional

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


_lowerCAmelCase:						List[Any]   				=       logging.get_logger(__name__)

_lowerCAmelCase:						Any   				=       {
    'huggingface/autoformer-tourism-monthly': 'https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json',
}




class       lowercase_					(lowercase__   ):
				snake_case	    ='autoformer'
				snake_case	    ={
				    'hidden_size': 'd_model',
				    'num_attention_heads': 'encoder_attention_heads',
				    'num_hidden_layers': 'encoder_layers',
				}





				def __init__(				self       ,  lowercase_ = None       ,  lowercase_ = None       ,  lowercase_ = "student_t"       ,  lowercase_ = "nll"       ,  lowercase_ = 1       ,  lowercase_ = [1, 2, 3, 4, 5, 6, 7]       ,  lowercase_ = True       ,  lowercase_ = 0       ,  lowercase_ = 0       ,  lowercase_ = 0       ,  lowercase_ = 0       ,  lowercase_ = None       ,  lowercase_ = None       ,  lowercase_ = 64       ,  lowercase_ = 2       ,  lowercase_ = 2       ,  lowercase_ = 2       ,  lowercase_ = 2       ,  lowercase_ = 32       ,  lowercase_ = 32       ,  lowercase_ = "gelu"       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 0.1       ,  lowercase_ = 100       ,  lowercase_ = 0.02       ,  lowercase_ = True       ,  lowercase_=True       ,  lowercase_ = 10       ,  lowercase_ = 25       ,  lowercase_ = 3       ,  **lowercase_       ,  )  -> Union[str, Any]:
											# time series specific configuration
											a__      =prediction_length
											a__      =context_length if context_length is not None else prediction_length
											a__      =distribution_output
											a__      =loss
											a__      =input_size
											a__      =num_time_features
											a__      =lags_sequence
											a__      =scaling
											a__      =num_dynamic_real_features
											a__      =num_static_real_features
											a__      =num_static_categorical_features
											if cardinality is not None and num_static_categorical_features > 0:
																		if len(lowercase_) != num_static_categorical_features:
																									raise ValueError(
																									    'The cardinality should be a list of the same length as `num_static_categorical_features`')
																		a__      =cardinality
											else:
																		a__      =[0]
											if embedding_dimension is not None and num_static_categorical_features > 0:
																		if len(lowercase_) != num_static_categorical_features:
																									raise ValueError(
																									    'The embedding dimension should be a list of the same length as `num_static_categorical_features`')
																		a__      =embedding_dimension
											else:
																		a__      =[min(50       ,  (cat + 1) // 2) for cat in self.cardinality]
											a__      =num_parallel_samples

											# Transformer architecture configuration
											a__      =input_size * len(self.lags_sequence) + self._number_of_features
											a__      =d_model
											a__      =encoder_attention_heads
											a__      =decoder_attention_heads
											a__      =encoder_ffn_dim
											a__      =decoder_ffn_dim
											a__      =encoder_layers
											a__      =decoder_layers

											a__      =dropout
											a__      =attention_dropout
											a__      =activation_dropout
											a__      =encoder_layerdrop
											a__      =decoder_layerdrop

											a__      =activation_function
											a__      =init_std

											a__      =use_cache

											# Autoformer
											a__      =label_length
											a__      =moving_average
											a__      =autocorrelation_factor

											super().__init__(is_encoder_decoder=lowercase_       ,  **lowercase_)





				@property
				def 						__UpperCamelCase    (				self)  -> int:
											return (
											    sum(self.embedding_dimension)
											    + self.num_dynamic_real_features
											    + self.num_time_features
											    + self.num_static_real_features
											    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
											)

