






from typing import List, Optional, Union

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


a_		:						Any             =    logging.get_logger(__name__)

a_		:						List[str]             =    {
    'huggingface/time-series-transformer-tourism-monthly': (
        'https://huggingface.co/huggingface/time-series-transformer-tourism-monthly/resolve/main/config.json'
    ),
    # See all TimeSeriesTransformer models at https://huggingface.co/models?filter=time_series_transformer
}

class 		_snake_case  (  A__					):
			_lowercase		:    Optional[int]			     =							'''time_series_transformer'''
			_lowercase		:    int			     =							{
			    '''hidden_size''': '''d_model''',
			    '''num_attention_heads''': '''encoder_attention_heads''',
			    '''num_hidden_layers''': '''encoder_layers''',
			}






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

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

						SCREAMING_SNAKE_CASE						= dropout
						SCREAMING_SNAKE_CASE						= attention_dropout
						SCREAMING_SNAKE_CASE						= activation_dropout
						SCREAMING_SNAKE_CASE						= encoder_layerdrop
						SCREAMING_SNAKE_CASE						= decoder_layerdrop

						SCREAMING_SNAKE_CASE						= activation_function
						SCREAMING_SNAKE_CASE						= init_std

						SCREAMING_SNAKE_CASE						= use_cache

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







			@property
			def    SCREAMING_SNAKE_CASE__    (       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
						)












import unittest

from transformers import DebertaVaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    DebertaVaForMaskedLM,
				    DebertaVaForMultipleChoice,
				    DebertaVaForQuestionAnswering,
				    DebertaVaForSequenceClassification,
				    DebertaVaForTokenClassification,
				    DebertaVaModel,
				)
				from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST

class 		_snake_case  (  A__					):






			def __init__(       self		,					a		,					a=13		,					a=7		,					a=True		,					a=True		,					a=True		,					a=True		,					a=99		,					a=32		,					a=5		,					a=4		,					a=37		,					a="gelu"		,					a=0.1		,					a=0.1		,					a=512		,					a=16		,					a=2		,					a=0.02		,					a=False		,					a=True		,					a="None"		,					a=3		,					a=4		,					a=None		,					)      ->       int:
						SCREAMING_SNAKE_CASE						= parent
						SCREAMING_SNAKE_CASE						= batch_size
						SCREAMING_SNAKE_CASE						= seq_length
						SCREAMING_SNAKE_CASE						= is_training
						SCREAMING_SNAKE_CASE						= use_input_mask
						SCREAMING_SNAKE_CASE						= use_token_type_ids
						SCREAMING_SNAKE_CASE						= use_labels
						SCREAMING_SNAKE_CASE						= vocab_size
						SCREAMING_SNAKE_CASE						= hidden_size
						SCREAMING_SNAKE_CASE						= num_hidden_layers
						SCREAMING_SNAKE_CASE						= num_attention_heads
						SCREAMING_SNAKE_CASE						= intermediate_size
						SCREAMING_SNAKE_CASE						= hidden_act
						SCREAMING_SNAKE_CASE						= hidden_dropout_prob
						SCREAMING_SNAKE_CASE						= attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE						= max_position_embeddings
						SCREAMING_SNAKE_CASE						= type_vocab_size
						SCREAMING_SNAKE_CASE						= type_sequence_label_size
						SCREAMING_SNAKE_CASE						= initializer_range
						SCREAMING_SNAKE_CASE						= num_labels
						SCREAMING_SNAKE_CASE						= num_choices
						SCREAMING_SNAKE_CASE						= relative_attention
						SCREAMING_SNAKE_CASE						= position_biased_input
						SCREAMING_SNAKE_CASE						= pos_att_type
						SCREAMING_SNAKE_CASE						= scope






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       List[str]:
						SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size)

						SCREAMING_SNAKE_CASE						= None
						if self.use_input_mask:
									SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size, self.seq_length]		,					vocab_size=2)

						SCREAMING_SNAKE_CASE						= None
						if self.use_token_type_ids:
									SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size, self.seq_length]		,					self.type_vocab_size)

						SCREAMING_SNAKE_CASE						= None
						SCREAMING_SNAKE_CASE						= None
						SCREAMING_SNAKE_CASE						= None
						if self.use_labels:
									SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size]		,					self.type_sequence_label_size)
									SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size, self.seq_length]		,					self.num_labels)
									SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size]		,					self.num_choices)

						SCREAMING_SNAKE_CASE						= self.get_config()

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       int:
						return DebertaVaConfig(
						    vocab_size=self.vocab_size		,					hidden_size=self.hidden_size		,					num_hidden_layers=self.num_hidden_layers		,					num_attention_heads=self.num_attention_heads		,					intermediate_size=self.intermediate_size		,					hidden_act=self.hidden_act		,					hidden_dropout_prob=self.hidden_dropout_prob		,					attention_probs_dropout_prob=self.attention_probs_dropout_prob		,					max_position_embeddings=self.max_position_embeddings		,					type_vocab_size=self.type_vocab_size		,					initializer_range=self.initializer_range		,					relative_attention=self.relative_attention		,					position_biased_input=self.position_biased_input		,					pos_att_type=self.pos_att_type		,					)






			def    SCREAMING_SNAKE_CASE__    (       self		,					a)      ->       int:
						self.parent.assertListEqual(list(result.loss.size())		,					[])






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       int:
						SCREAMING_SNAKE_CASE						= DebertaVaModel(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a)[0]
						SCREAMING_SNAKE_CASE						= model(a		,					token_type_ids=a)[0]
						SCREAMING_SNAKE_CASE						= model(a)[0]

						self.parent.assertListEqual(list(sequence_output.size())		,					[self.batch_size, self.seq_length, self.hidden_size])






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       Dict:
						SCREAMING_SNAKE_CASE						= DebertaVaForMaskedLM(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a		,					labels=a)

						self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.vocab_size))






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       str:
						SCREAMING_SNAKE_CASE						= self.num_labels
						SCREAMING_SNAKE_CASE						= DebertaVaForSequenceClassification(a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a		,					labels=a)
						self.parent.assertListEqual(list(result.logits.size())		,					[self.batch_size, self.num_labels])
						self.check_loss_output(a)






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       int:
						SCREAMING_SNAKE_CASE						= self.num_labels
						SCREAMING_SNAKE_CASE						= DebertaVaForTokenClassification(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a		,					labels=a)
						self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.num_labels))






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       Optional[int]:
						SCREAMING_SNAKE_CASE						= DebertaVaForQuestionAnswering(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(
						    a		,					attention_mask=a		,					token_type_ids=a		,					start_positions=a		,					end_positions=a		,					)
						self.parent.assertEqual(result.start_logits.shape		,					(self.batch_size, self.seq_length))
						self.parent.assertEqual(result.end_logits.shape		,					(self.batch_size, self.seq_length))






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       Any:
						SCREAMING_SNAKE_CASE						= DebertaVaForMultipleChoice(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= input_ids.unsqueeze(1).expand(-1		,					self.num_choices		,					-1).contiguous()
						SCREAMING_SNAKE_CASE						= token_type_ids.unsqueeze(1).expand(-1		,					self.num_choices		,					-1).contiguous()
						SCREAMING_SNAKE_CASE						= input_mask.unsqueeze(1).expand(-1		,					self.num_choices		,					-1).contiguous()
						SCREAMING_SNAKE_CASE						= model(
						    a		,					attention_mask=a		,					token_type_ids=a		,					labels=a		,					)
						self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.num_choices))







			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Optional[int]:
						SCREAMING_SNAKE_CASE						= self.prepare_config_and_inputs()
						(
						    (
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						
						)						= config_and_inputs
						SCREAMING_SNAKE_CASE						= {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict



@require_torch
class 		_snake_case  (  A__   ,    A__   ,    unittest.TestCase					):
			_lowercase		:    Dict			     =							(
			    (
			        DebertaVaModel,
			        DebertaVaForMaskedLM,
			        DebertaVaForSequenceClassification,
			        DebertaVaForTokenClassification,
			        DebertaVaForQuestionAnswering,
			        DebertaVaForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			_lowercase		:    Optional[int]			     =							(
			    {
			        '''feature-extraction''': DebertaVaModel,
			        '''fill-mask''': DebertaVaForMaskedLM,
			        '''question-answering''': DebertaVaForQuestionAnswering,
			        '''text-classification''': DebertaVaForSequenceClassification,
			        '''token-classification''': DebertaVaForTokenClassification,
			        '''zero-shot''': DebertaVaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)

			_lowercase		:    Optional[int]			     =							True
			_lowercase		:    int			     =							False
			_lowercase		:    Dict			     =							False
			_lowercase		:    Optional[int]			     =							False
			_lowercase		:    List[str]			     =							False






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Optional[int]:
						SCREAMING_SNAKE_CASE						= DebertaVaModelTester(self)
						SCREAMING_SNAKE_CASE						= ConfigTester(self		,					config_class=a		,					hidden_size=37)






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






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Tuple:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       List[Any]:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Dict:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       int:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_multiple_choice(*a)







			@slow
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       str:
						for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE						= DebertaVaModel.from_pretrained(a)
									self.assertIsNotNone(a)



@require_torch
@require_sentencepiece
@require_tokenizers
class 		_snake_case  (  unittest.TestCase					):






			@unittest.skip(reason='Model not available yet')
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						pass







			@slow
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						SCREAMING_SNAKE_CASE						= DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge')

						SCREAMING_SNAKE_CASE						= torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]])
						SCREAMING_SNAKE_CASE						= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
						with torch.no_grad():
									SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a)[0]
						# compare the actual values for a slice.
						SCREAMING_SNAKE_CASE						= torch.tensor(
						    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]])
						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,					a		,					atol=1E-4)		,					f'''{output[:, 1:4, 1:4]}''')




