
"""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__						:
			def __init__(      self     ,   _a     ,   ):
										lowercase   :    Union[str, Any]			=							parent
										lowercase   :    Optional[Any]			=							13
										lowercase   :    List[str]			=							7
										lowercase   :    List[Any]			=							True
										lowercase   :    List[str]			=							True
										lowercase   :    Tuple			=							True
										lowercase   :    int			=							True
										lowercase   :    Dict			=							True
										lowercase   :    Optional[Any]			=							99
										lowercase   :    Dict			=							32
										lowercase   :    Optional[int]			=							2
										lowercase   :    Tuple			=							4
										lowercase   :    Optional[Any]			=							37
										lowercase   :    Optional[Any]			=							"gelu"
										lowercase   :    List[Any]			=							0.1
										lowercase   :    str			=							0.1
										lowercase   :    Tuple			=							512
										lowercase   :    List[Any]			=							16
										lowercase   :    Tuple			=							2
										lowercase   :    List[Any]			=							0.0_2
										lowercase   :    List[Any]			=							3
										lowercase   :    Union[str, Any]			=							4
										lowercase   :    Tuple			=							None
										lowercase   :    Any			=							self.vocab_size - 1
			def       __magic_name__      (      self    ):
										lowercase   :    Union[str, Any]			=							ids_tensor([self.batch_size, self.seq_length]     ,   self.vocab_size    )

										lowercase   :    int			=							None
										if self.use_input_mask:
																	lowercase   :    Union[str, Any]			=							random_attention_mask([self.batch_size, self.seq_length]    )

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

										lowercase   :    Tuple			=							None
										if self.use_mc_token_ids:
																	lowercase   :    Tuple			=							ids_tensor([self.batch_size, self.num_choices]     ,   self.seq_length    )

										lowercase   :    Any			=							None
										lowercase   :    int			=							None
										lowercase   :    List[Any]			=							None
										if self.use_labels:
																	lowercase   :    Dict			=							ids_tensor([self.batch_size]     ,   self.type_sequence_label_size    )
																	lowercase   :    Optional[Any]			=							ids_tensor([self.batch_size, self.seq_length]     ,   self.num_labels    )
																	lowercase   :    Optional[Any]			=							ids_tensor([self.batch_size]     ,   self.num_choices    )

										lowercase   :    List[Any]			=							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     ,   )

										lowercase   :    List[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       __magic_name__      (      self     ,   _a     ,   _a     ,   _a     ,   _a     ,   _a     ,   *_a    ):
										lowercase   :    List[str]			=							TFOpenAIGPTModel(config=_a    )
										lowercase   :    Dict			=							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										lowercase   :    Optional[int]			=							model(_a    )

										lowercase   :    Optional[Any]			=							[input_ids, input_mask]
										lowercase   :    int			=							model(_a    )

										lowercase   :    Optional[int]			=							model(_a    )

										self.parent.assertEqual(result.last_hidden_state.shape     ,   (self.batch_size, self.seq_length, self.hidden_size)    )
			def       __magic_name__      (      self     ,   _a     ,   _a     ,   _a     ,   _a     ,   _a     ,   *_a    ):
										lowercase   :    Union[str, Any]			=							TFOpenAIGPTLMHeadModel(config=_a    )
										lowercase   :    Tuple			=							{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
										lowercase   :    Optional[Any]			=							model(_a    )
										self.parent.assertEqual(result.logits.shape     ,   (self.batch_size, self.seq_length, self.vocab_size)    )
			def       __magic_name__      (      self     ,   _a     ,   _a     ,   _a     ,   _a     ,   _a     ,   _a     ,   *_a    ):
										lowercase   :    Optional[Any]			=							TFOpenAIGPTDoubleHeadsModel(config=_a    )

										lowercase   :    Tuple			=							tf.tile(tf.expand_dims(_a     ,   1    )     ,   (1, self.num_choices, 1)    )
										lowercase   :    Optional[Any]			=							tf.tile(tf.expand_dims(_a     ,   1    )     ,   (1, self.num_choices, 1)    )
										lowercase   :    Union[str, Any]			=							tf.tile(tf.expand_dims(_a     ,   1    )     ,   (1, self.num_choices, 1)    )

										lowercase   :    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,
										}
										lowercase   :    Optional[Any]			=							model(_a    )
										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       __magic_name__      (      self     ,   _a     ,   _a     ,   _a     ,   _a     ,   _a     ,   *_a    ):
										lowercase   :    List[Any]			=							self.num_labels
										lowercase   :    Tuple			=							ids_tensor([self.batch_size]     ,   self.type_sequence_label_size    )
										lowercase   :    Optional[int]			=							{
										    "input_ids": input_ids,
										    "attention_mask": input_mask,
										    "token_type_ids": token_type_ids,
										    "labels": sequence_labels,
										}
										lowercase   :    Tuple			=							TFOpenAIGPTForSequenceClassification(_a    )
										lowercase   :    Union[str, Any]			=							model(_a    )
										self.parent.assertEqual(result.logits.shape     ,   (self.batch_size, self.num_labels)    )

			def       __magic_name__      (      self    ):
										lowercase   :    str			=							self.prepare_config_and_inputs()

										(
										    lowercase   
										)   :    Dict			=							config_and_inputs

										lowercase   :    Optional[int]			=							{"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						):
			__lowerCAmelCase						=    (
			    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
			    if is_tf_available()
			    else ()
			)
			__lowerCAmelCase						=    (
			    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
			)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
			__lowerCAmelCase						=    (
			    {
			        """feature-extraction""": TFOpenAIGPTModel,
			        """text-classification""": TFOpenAIGPTForSequenceClassification,
			        """text-generation""": TFOpenAIGPTLMHeadModel,
			        """zero-shot""": TFOpenAIGPTForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)
			__lowerCAmelCase						=    False
			__lowerCAmelCase						=    False
			def       __magic_name__      (      self     ,   _a     ,   _a     ,   _a     ,   _a     ,   _a    ):
										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       __magic_name__      (      self    ):
										lowercase   :    int			=							TFOpenAIGPTModelTester(self    )
										lowercase   :    List[str]			=							ConfigTester(self     ,   config_class=_a     ,   n_embd=37    )
			def       __magic_name__      (      self    ):
										self.config_tester.run_common_tests()
			def       __magic_name__      (      self    ):
										lowercase   :    int			=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_model(*_a    )
			def       __magic_name__      (      self    ):
										lowercase   :    str			=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_lm_head(*_a    )
			def       __magic_name__      (      self    ):
										lowercase   :    Optional[int]			=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_double_head(*_a    )
			def       __magic_name__      (      self    ):
										lowercase   :    List[Any]			=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*_a    )

			@slow
			def       __magic_name__      (      self    ):
										for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowercase   :    Union[str, Any]			=							TFOpenAIGPTModel.from_pretrained(_a    )
																	self.assertIsNotNone(_a    )


@require_tf
class 		a__						(				unittest.TestCase						):
			@slow
			def       __magic_name__      (      self    ):
										lowercase   :    Dict			=							TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt"    )
										lowercase   :    Union[str, Any]			=							tf.convert_to_tensor([[481, 4_735, 544]]     ,   dtype=tf.intaa    )  # the president is
										lowercase   :    Optional[int]			=							[
										    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

										lowercase   :    List[Any]			=							model.generate(_a     ,   do_sample=_a    )
										self.assertListEqual(output_ids[0].numpy().tolist()     ,   _a    )




"""simple docstring"""




import warnings

from ...utils import logging
from .image_processing_convnext import ConvNextImageProcessor


_A      :	List[str]       		=	logging.get_logger(__name__)

class 		a__						(				a_						):
   def __init__(      self     ,   *_a     ,   **_a    ):
          warnings.warn(
              "The class ConvNextFeatureExtractor is deprecated and will be removed in version 5 of Transformers."
              " Please use ConvNextImageProcessor instead."     ,   _a     ,   )
          super().__init__(*_a     ,   **_a    )


