
"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
							import tensorflow as tf

							from transformers.models.openai.modeling_tf_openai import (
							    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
							    TFOpenAIGPTDoubleHeadsModel,
							    TFOpenAIGPTForSequenceClassification,
							    TFOpenAIGPTLMHeadModel,
							    TFOpenAIGPTModel,
							)

class    A_     :



							"""simple docstring"""






							def __init__(  self  :List[Any]					,							lowerCamelCase_  :str					,							):





										"""simple docstring"""

										lowerCamelCase__     :					Dict		=parent
										lowerCamelCase__     :					str		=13
										lowerCamelCase__     :					Any		=7
										lowerCamelCase__     :					Dict		=True
										lowerCamelCase__     :					List[Any]		=True
										lowerCamelCase__     :					Optional[int]		=True
										lowerCamelCase__     :					List[str]		=True
										lowerCamelCase__     :					Optional[Any]		=True
										lowerCamelCase__     :					List[Any]		=99
										lowerCamelCase__     :					Tuple		=32
										lowerCamelCase__     :					List[str]		=2
										lowerCamelCase__     :					Union[str, Any]		=4
										lowerCamelCase__     :					List[Any]		=37
										lowerCamelCase__     :					Union[str, Any]		='gelu'
										lowerCamelCase__     :					List[str]		=0.1
										lowerCamelCase__     :					List[str]		=0.1
										lowerCamelCase__     :					List[str]		=512
										lowerCamelCase__     :					List[Any]		=16
										lowerCamelCase__     :					str		=2
										lowerCamelCase__     :					List[Any]		=0.02
										lowerCamelCase__     :					List[Any]		=3
										lowerCamelCase__     :					Tuple		=4
										lowerCamelCase__     :					List[Any]		=None
										lowerCamelCase__     :					Any		=self.vocab_size - 1





							def 				UpperCAmelCase__							(  self  :Optional[int]	):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size	)

										lowerCamelCase__     :					Optional[int]		=None
										if self.use_input_mask:
													lowerCamelCase__     :					List[Any]		=random_attention_mask([self.batch_size, self.seq_length]	)

										lowerCamelCase__     :					int		=None
										if self.use_token_type_ids:
													lowerCamelCase__     :					Union[str, Any]		=ids_tensor([self.batch_size, self.seq_length]					,							self.type_vocab_size	)

										lowerCamelCase__     :					Optional[int]		=None
										if self.use_mc_token_ids:
													lowerCamelCase__     :					Optional[int]		=ids_tensor([self.batch_size, self.num_choices]					,							self.seq_length	)

										lowerCamelCase__     :					int		=None
										lowerCamelCase__     :					List[str]		=None
										lowerCamelCase__     :					Tuple		=None
										if self.use_labels:
													lowerCamelCase__     :					int		=ids_tensor([self.batch_size]					,							self.type_sequence_label_size	)
													lowerCamelCase__     :					int		=ids_tensor([self.batch_size, self.seq_length]					,							self.num_labels	)
													lowerCamelCase__     :					Any		=ids_tensor([self.batch_size]					,							self.num_choices	)

										lowerCamelCase__     :					Dict		=OpenAIGPTConfig(
										    vocab_size=self.vocab_size					,							n_embd=self.hidden_size					,							n_layer=self.num_hidden_layers					,							n_head=self.num_attention_heads					,							n_positions=self.max_position_embeddings					,							pad_token_id=self.pad_token_id					,							)

										lowerCamelCase__     :					Any		=ids_tensor([self.num_hidden_layers, self.num_attention_heads]					,							2	)

										return (
										    config,
										    input_ids,
										    input_mask,
										    head_mask,
										    token_type_ids,
										    mc_token_ids,
										    sequence_labels,
										    token_labels,
										    choice_labels,
										)





							def 				UpperCAmelCase__							(  self  :int					,							lowerCamelCase_  :List[str]					,							lowerCamelCase_  :Any					,							lowerCamelCase_  :str					,							lowerCamelCase_  :Dict					,							lowerCamelCase_  :Any					,							*lowerCamelCase_  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					Tuple		=TFOpenAIGPTModel(config=lowerCamelCase_	)
										lowerCamelCase__     :					Optional[int]		={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										lowerCamelCase__     :					int		=model(lowerCamelCase_	)

										lowerCamelCase__     :					List[Any]		=[input_ids, input_mask]
										lowerCamelCase__     :					Any		=model(lowerCamelCase_	)

										lowerCamelCase__     :					List[str]		=model(lowerCamelCase_	)

										self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)	)





							def 				UpperCAmelCase__							(  self  :List[Any]					,							lowerCamelCase_  :Tuple					,							lowerCamelCase_  :Dict					,							lowerCamelCase_  :int					,							lowerCamelCase_  :Optional[int]					,							lowerCamelCase_  :Any					,							*lowerCamelCase_  :Union[str, Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					List[str]		=TFOpenAIGPTLMHeadModel(config=lowerCamelCase_	)
										lowerCamelCase__     :					Any		={'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
										lowerCamelCase__     :					Dict		=model(lowerCamelCase_	)
										self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.vocab_size)	)





							def 				UpperCAmelCase__							(  self  :List[str]					,							lowerCamelCase_  :int					,							lowerCamelCase_  :Optional[Any]					,							lowerCamelCase_  :str					,							lowerCamelCase_  :Tuple					,							lowerCamelCase_  :Optional[int]					,							lowerCamelCase_  :List[str]					,							*lowerCamelCase_  :int	):





										"""simple docstring"""

										lowerCamelCase__     :					str		=TFOpenAIGPTDoubleHeadsModel(config=lowerCamelCase_	)

										lowerCamelCase__     :					List[Any]		=tf.tile(tf.expand_dims(lowerCamelCase_					,							1	)					,							(1, self.num_choices, 1)	)
										lowerCamelCase__     :					Any		=tf.tile(tf.expand_dims(lowerCamelCase_					,							1	)					,							(1, self.num_choices, 1)	)
										lowerCamelCase__     :					Tuple		=tf.tile(tf.expand_dims(lowerCamelCase_					,							1	)					,							(1, self.num_choices, 1)	)

										lowerCamelCase__     :					List[Any]		={
										    'input_ids': multiple_choice_inputs_ids,
										    'mc_token_ids': mc_token_ids,
										    'attention_mask': multiple_choice_input_mask,
										    'token_type_ids': multiple_choice_token_type_ids,
										}
										lowerCamelCase__     :					Union[str, Any]		=model(lowerCamelCase_	)
										self.parent.assertEqual(
										    result.logits.shape					,							(self.batch_size, self.num_choices, self.seq_length, self.vocab_size)	)
										self.parent.assertEqual(result.mc_logits.shape					,							(self.batch_size, self.num_choices)	)





							def 				UpperCAmelCase__							(  self  :Union[str, Any]					,							lowerCamelCase_  :Optional[Any]					,							lowerCamelCase_  :int					,							lowerCamelCase_  :str					,							lowerCamelCase_  :Dict					,							lowerCamelCase_  :Tuple					,							*lowerCamelCase_  :Dict	):





										"""simple docstring"""

										lowerCamelCase__     :					Any		=self.num_labels
										lowerCamelCase__     :					Any		=ids_tensor([self.batch_size]					,							self.type_sequence_label_size	)
										lowerCamelCase__     :					Optional[int]		={
										    'input_ids': input_ids,
										    'attention_mask': input_mask,
										    'token_type_ids': token_type_ids,
										    'labels': sequence_labels,
										}
										lowerCamelCase__     :					Dict		=TFOpenAIGPTForSequenceClassification(lowerCamelCase_	)
										lowerCamelCase__     :					Tuple		=model(lowerCamelCase_	)
										self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.num_labels)	)





							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					str		=self.prepare_config_and_inputs()

										(
										    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    (
										    lowerCamelCase__
										)	,    
										)     :					int		=config_and_inputs

										lowerCamelCase__     :					Union[str, Any]		={'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
										return config, inputs_dict






@require_tf
class    A_     (					A__				, A__				, unittest.TestCase       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       (
							    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
							    if is_tf_available()
							    else ()
							)
							SCREAMING_SNAKE_CASE_     				=       (
							    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
							)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
							SCREAMING_SNAKE_CASE_     				=       (
							    {
							        """feature-extraction""": TFOpenAIGPTModel,
							        """text-classification""": TFOpenAIGPTForSequenceClassification,
							        """text-generation""": TFOpenAIGPTLMHeadModel,
							        """zero-shot""": TFOpenAIGPTForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							SCREAMING_SNAKE_CASE_     				=       False
							SCREAMING_SNAKE_CASE_     				=       False





							def 				UpperCAmelCase__							(  self  :Optional[int]					,							lowerCamelCase_  :List[Any]					,							lowerCamelCase_  :List[Any]					,							lowerCamelCase_  :List[Any]					,							lowerCamelCase_  :Optional[Any]					,							lowerCamelCase_  :Optional[Any]	):





										"""simple docstring"""

										if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
													# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
													# `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
													# tiny config could not be created.
													return True

										return False





							def 				UpperCAmelCase__							(  self  :List[str]	):





										"""simple docstring"""

										lowerCamelCase__     :					Tuple		=TFOpenAIGPTModelTester(self	)
										lowerCamelCase__     :					List[str]		=ConfigTester(self					,							config_class=lowerCamelCase_					,							n_embd=37	)





							def 				UpperCAmelCase__							(  self  :Optional[int]	):





										"""simple docstring"""

										self.config_tester.run_common_tests()





							def 				UpperCAmelCase__							(  self  :int	):





										"""simple docstring"""

										lowerCamelCase__     :					List[str]		=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_model(*lowerCamelCase_	)





							def 				UpperCAmelCase__							(  self  :str	):





										"""simple docstring"""

										lowerCamelCase__     :					List[Any]		=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_lm_head(*lowerCamelCase_	)





							def 				UpperCAmelCase__							(  self  :Optional[int]	):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_double_head(*lowerCamelCase_	)





							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCamelCase_	)





							@slow
							def 				UpperCAmelCase__							(  self  :Optional[Any]	):





										"""simple docstring"""

										for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													lowerCamelCase__     :					Tuple		=TFOpenAIGPTModel.from_pretrained(lowerCamelCase_	)
													self.assertIsNotNone(lowerCamelCase_	)






@require_tf
class    A_     (					unittest.TestCase       ):



							"""simple docstring"""






							@slow
							def 				UpperCAmelCase__							(  self  :Optional[Any]	):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=TFOpenAIGPTLMHeadModel.from_pretrained('openai-gpt'	)
										lowerCamelCase__     :					str		=tf.convert_to_tensor([[481, 4_735, 544]]					,							dtype=tf.intaa	)  # the president is
										lowerCamelCase__     :					Any		=[
										    481,
										    4_735,
										    544,
										    246,
										    963,
										    870,
										    762,
										    239,
										    244,
										    40_477,
										    244,
										    249,
										    719,
										    881,
										    487,
										    544,
										    240,
										    244,
										    603,
										    481,
										]  # the president is a very good man. " \n " i\'m sure he is, " said the

										lowerCamelCase__     :					Dict		=model.generate(lowerCamelCase_					,							do_sample=lowerCamelCase_	)
										self.assertListEqual(output_ids[0].numpy().tolist()					,							lowerCamelCase_	)

"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase								=						{
    """configuration_decision_transformer""": [
        """DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """DecisionTransformerConfig""",
    ],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase								=						[
							    """DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
							    """DecisionTransformerGPT2Model""",
							    """DecisionTransformerGPT2PreTrainedModel""",
							    """DecisionTransformerModel""",
							    """DecisionTransformerPreTrainedModel""",
							]


if TYPE_CHECKING:
							from .configuration_decision_transformer import (
							    DECISION_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    DecisionTransformerConfig,
							)

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_decision_transformer import (
														    DECISION_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DecisionTransformerGPTaModel,
														    DecisionTransformerGPTaPreTrainedModel,
														    DecisionTransformerModel,
														    DecisionTransformerPreTrainedModel,
														)


else:
							import sys

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