"""simple docstring"""


import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


__UpperCamelCase       :    Any         =		1_0_0_0
class   UpperCAmelCase_	:
    def __init__(	self			:       Union[str, Any]   ,						_lowercase			:       Dict   ,						_lowercase			:       Optional[Any]=1.2   ,						_lowercase			:       str="g"   ,						_lowercase			:       Optional[Any]=0.5   ,						_lowercase			:       Optional[Any]="-"   ,						_lowercase			:       Optional[int]="test_out.jpg"   ,						_lowercase			:       Optional[int]=True   ,						_lowercase			:       Dict=False   ,						_lowercase			:       Tuple=None   ,						_lowercase			:       Any=None   ,						_lowercase			:       Optional[int]=0.7   ,						)						->    str:
       if isinstance(_lowercase   ,						torch.Tensor		):
          _lowercase							     =       img.numpy().astype("np.uint8"		)
       if isinstance(_lowercase   ,						_lowercase		):
          _lowercase							     =       img_tensorize(_lowercase		)
       assert isinstance(_lowercase   ,						np.ndarray		)

       _lowercase     ,  _lowercase							     =       img.shape[1], img.shape[0]
       _lowercase							     =       mplfigure.Figure(frameon=_lowercase		)
       _lowercase							     =       fig.get_dpi()
       _lowercase							     =       (width * scale + 1e-2) / dpi
       _lowercase							     =       (height * scale + 1e-2) / dpi
       fig.set_size_inches(_lowercase   ,						_lowercase		)
       _lowercase							     =       fig.add_axes([0.0, 0.0, 1.0, 1.0]		)
       ax.axis("off"		)
       ax.set_xlim(0.0   ,						_lowercase		)
       ax.set_ylim(_lowercase		)

       _lowercase							     =       saveas
       _lowercase							     =       rgb
       _lowercase							     =       pynb
       _lowercase							     =       img
       _lowercase							     =       edgecolor
       _lowercase							     =       0.5
       _lowercase							     =       linestyle
       _lowercase							     =       int(np.sqrt(min(_lowercase   ,						_lowercase		)		) * scale // 3		)
       _lowercase							     =       width
       _lowercase							     =       height
       _lowercase							     =       scale
       _lowercase							     =       fig
       _lowercase							     =       ax
       _lowercase							     =       pad
       _lowercase							     =       idaobj
       _lowercase							     =       idaattr
       _lowercase							     =       FigureCanvasAgg(_lowercase		)
    def 		_lowerCamelCase      (	self			:       List[str]   ,						_lowercase			:       Union[str, Any]   ,						_lowercase			:       Tuple=None		)						->    int:
       if color is None:
          _lowercase							     =       self.edgecolor
       ((_lowercase)     ,  (_lowercase)     ,  (_lowercase)     ,  (_lowercase))							     =       box
       _lowercase							     =       xa - xa
       _lowercase							     =       ya - ya
       self.ax.add_patch(
           mpl.patches.Rectangle(
               (xa, ya)   ,						_lowercase   ,						_lowercase   ,						fill=_lowercase   ,						edgecolor=_lowercase   ,						linewidth=self.font_size // 3   ,						alpha=self.alpha   ,						linestyle=self.linestyle   ,						)		)
    def 		_lowerCamelCase      (	self			:       Any   ,						_lowercase			:       Optional[Any]   ,						_lowercase			:       Optional[Any]=None   ,						_lowercase			:       List[str]=None   ,						_lowercase			:       Tuple=None   ,						_lowercase			:       Union[str, Any]=None		)						->    Union[str, Any]:
       if len(boxes.shape		) > 2:
          _lowercase							     =       boxes[0]
       if len(obj_ids.shape		) > 1:
          _lowercase							     =       obj_ids[0]
       if len(obj_scores.shape		) > 1:
          _lowercase							     =       obj_scores[0]
       if len(attr_ids.shape		) > 1:
          _lowercase							     =       attr_ids[0]
       if len(attr_scores.shape		) > 1:
          _lowercase							     =       attr_scores[0]
       if isinstance(_lowercase   ,						torch.Tensor		):
          _lowercase							     =       boxes.numpy()
       if isinstance(_lowercase   ,						_lowercase		):
          _lowercase							     =       np.array(_lowercase		)
       assert isinstance(_lowercase   ,						np.ndarray		)
       _lowercase							     =       np.prod(boxes[:, 2:] - boxes[:, :2]   ,						axis=1		)
       _lowercase							     =       np.argsort(-areas		).tolist()
       _lowercase							     =       boxes[sorted_idxs] if boxes is not None else None
       _lowercase							     =       obj_ids[sorted_idxs] if obj_ids is not None else None
       _lowercase							     =       obj_scores[sorted_idxs] if obj_scores is not None else None
       _lowercase							     =       attr_ids[sorted_idxs] if attr_ids is not None else None
       _lowercase							     =       attr_scores[sorted_idxs] if attr_scores is not None else None

       _lowercase							     =       [self._random_color(maximum=1		) for _ in range(len(_lowercase		)		)]
       _lowercase							     =       [assigned_colors[idx] for idx in sorted_idxs]
       if obj_ids is not None:
          _lowercase							     =       self._create_text_labels_attr(_lowercase   ,						_lowercase   ,						_lowercase   ,						_lowercase		)
          for i in range(len(_lowercase		)		):
             _lowercase							     =       assigned_colors[i]
             self.add_box(boxes[i]   ,						_lowercase		)
             self.draw_labels(labels[i]   ,						boxes[i]   ,						_lowercase		)
    def 		_lowerCamelCase      (	self			:       Optional[int]   ,						_lowercase			:       Optional[Any]   ,						_lowercase			:       Optional[Any]   ,						_lowercase			:       str		)						->    Optional[Any]:
       _lowercase     ,  _lowercase     ,  _lowercase     ,  _lowercase							     =       box
       _lowercase							     =       (xa, ya)
       _lowercase							     =       (ya - ya) * (xa - xa)
       _lowercase							     =       _SMALL_OBJ * self.scale
       if instance_area < small or ya - ya < 4_0 * self.scale:
          if ya >= self.height - 5:
             _lowercase							     =       (xa, ya)
          else:
             _lowercase							     =       (xa, ya)

       _lowercase							     =       (ya - ya) / np.sqrt(self.height * self.width		)
       _lowercase							     =       self._change_color_brightness(_lowercase   ,						brightness_factor=0.7		)
       _lowercase							     =       np.clip((height_ratio - 0.02) / 0.08 + 1   ,						1.2   ,						2		)
       font_size *= 0.75 * self.font_size

       self.draw_text(
           text=_lowercase   ,						position=_lowercase   ,						color=_lowercase   ,						)
    def 		_lowerCamelCase      (	self			:       Any   ,						_lowercase			:       Optional[Any]   ,						_lowercase			:       Optional[int]   ,						_lowercase			:       Optional[int]="g"   ,						_lowercase			:       Optional[int]="left"   ,						)						->    str:
       _lowercase							     =       0
       _lowercase							     =       self.font_size
       _lowercase							     =       np.maximum(list(mplc.to_rgb(_lowercase		)		)   ,						0.2		)
       _lowercase							     =       max(0.8   ,						np.max(_lowercase		)		)
       _lowercase							     =       {
           "facecolor": "black",
           "alpha": self.alpha,
           "pad": self.pad,
           "edgecolor": "none",
       }
       _lowercase     ,  _lowercase							     =       position
       self.ax.text(
           _lowercase   ,						_lowercase   ,						_lowercase   ,						size=font_size * self.scale   ,						family="sans-serif"   ,						bbox=_lowercase   ,						verticalalignment="top"   ,						horizontalalignment=_lowercase   ,						color=_lowercase   ,						zorder=1_0   ,						rotation=_lowercase   ,						)
    def 		_lowerCamelCase      (	self			:       Union[str, Any]   ,						_lowercase			:       Optional[int]=None		)						->    int:
       if saveas is None:
          _lowercase							     =       self.saveas
       if saveas.lower().endswith(".jpg"		) or saveas.lower().endswith(".png"		):
          cva.imwrite(
              _lowercase   ,						self._get_buffer()[:, :, ::-1]   ,						)
       else:
          self.fig.savefig(_lowercase		)
    def 		_lowerCamelCase      (	self			:       Tuple   ,						_lowercase			:       Any   ,						_lowercase			:       List[Any]   ,						_lowercase			:       Optional[int]   ,						_lowercase			:       List[str]		)						->    Union[str, Any]:
       _lowercase							     =       [self.idaobj[i] for i in classes]
       _lowercase							     =       [self.idaattr[i] for i in attr_classes]
       _lowercase							     =       [
           f"""{label} {score:.2f} {attr} {attr_score:.2f}"""
           for label, score, attr, attr_score in zip(_lowercase   ,						_lowercase   ,						_lowercase   ,						_lowercase		)
       ]
       return labels
    def 		_lowerCamelCase      (	self			:       Optional[Any]   ,						_lowercase			:       Dict   ,						_lowercase			:       str		)						->    int:
       _lowercase							     =       [self.idaobj[i] for i in classes]
       if scores is not None:
          if labels is None:
             _lowercase							     =       ["{:.0f}%".format(s * 1_0_0		) for s in scores]
          else:
             _lowercase							     =       ["{} {:.0f}%".format(_lowercase   ,						s * 1_0_0		) for li, s in zip(_lowercase   ,						_lowercase		)]
       return labels
    def 		_lowerCamelCase      (	self			:       Optional[int]   ,						_lowercase			:       Dict=2_5_5		)						->    Optional[int]:
       _lowercase							     =       np.random.randint(0   ,						len(_COLORS		)		)
       _lowercase							     =       _COLORS[idx] * maximum
       if not self.rgb:
          _lowercase							     =       ret[::-1]
       return ret
    def 		_lowerCamelCase      (	self			:       List[Any]		)						->    Dict:
       if not self.pynb:
          _lowercase     ,  _lowercase							     =       self.canvas.print_to_buffer()
          if (width, height) != (self.width, self.height):
             _lowercase							     =       cva.resize(self.img   ,						(width, height)		)
          else:
             _lowercase							     =       self.img
       else:
          _lowercase							     =       io.BytesIO()  # works for cairo backend
          self.canvas.print_rgba(_lowercase		)
          _lowercase     ,  _lowercase							     =       self.width, self.height
          _lowercase							     =       buf.getvalue()
          _lowercase							     =       self.img

       _lowercase							     =       np.frombuffer(_lowercase   ,						dtype="uint8"		)
       _lowercase							     =       buffer.reshape(_lowercase   ,						_lowercase   ,						4		)
       _lowercase     ,  _lowercase							     =       np.split(_lowercase   ,						[3]   ,						axis=2		)

       try:
          import numexpr as ne  # fuse them with numexpr

          _lowercase							     =       ne.evaluate("img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"		)
       except ImportError:
          _lowercase							     =       alpha.astype("float32"		) / 2_55.0
          _lowercase							     =       img * (1 - alpha) + rgb * alpha

       return visualized_image.astype("uint8"		)




    def 		_lowerCamelCase      (	self			:       List[str]   ,						_lowercase			:       int   ,						_lowercase			:       str		)						->    Any:
       assert brightness_factor >= -1.0 and brightness_factor <= 1.0
       _lowercase							     =       mplc.to_rgb(_lowercase		)
       _lowercase							     =       colorsys.rgb_to_hls(*mplc.to_rgb(_lowercase		)		)
       _lowercase							     =       polygon_color[1] + (brightness_factor * polygon_color[1])
       _lowercase							     =       0.0 if modified_lightness < 0.0 else modified_lightness
       _lowercase							     =       1.0 if modified_lightness > 1.0 else modified_lightness
       _lowercase							     =       colorsys.hls_to_rgb(polygon_color[0]   ,						_lowercase   ,						polygon_color[2]		)
       return modified_color
__UpperCamelCase       :    Tuple         =		(
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)
"""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   UpperCAmelCase_	:
    def __init__(	self			:       Tuple   ,						_lowercase			:       List[str]   ,						)						->    Tuple:
       _lowercase							     =       parent
       _lowercase							     =       1_3
       _lowercase							     =       7
       _lowercase							     =       True
       _lowercase							     =       True
       _lowercase							     =       True
       _lowercase							     =       True
       _lowercase							     =       True
       _lowercase							     =       9_9
       _lowercase							     =       3_2
       _lowercase							     =       2
       _lowercase							     =       4
       _lowercase							     =       3_7
       _lowercase							     =       "gelu"
       _lowercase							     =       0.1
       _lowercase							     =       0.1
       _lowercase							     =       5_1_2
       _lowercase							     =       1_6
       _lowercase							     =       2
       _lowercase							     =       0.02
       _lowercase							     =       3
       _lowercase							     =       4
       _lowercase							     =       None
       _lowercase							     =       self.vocab_size - 1
    def 		_lowerCamelCase      (	self			:       int		)						->    List[Any]:
       _lowercase							     =       ids_tensor([self.batch_size, self.seq_length]   ,						self.vocab_size		)

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

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

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

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

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

       _lowercase							     =       [input_ids, input_mask]
       _lowercase							     =       model(_lowercase		)

       _lowercase							     =       model(_lowercase		)

       self.parent.assertEqual(result.last_hidden_state.shape   ,						(self.batch_size, self.seq_length, self.hidden_size)		)
    def 		_lowerCamelCase      (	self			:       Any   ,						_lowercase			:       Optional[Any]   ,						_lowercase			:       Optional[int]   ,						_lowercase			:       str   ,						_lowercase			:       Dict   ,						_lowercase			:       List[str]   ,						*_lowercase			:       Optional[Any]		)						->    Dict:
       _lowercase							     =       TFOpenAIGPTLMHeadModel(config=_lowercase		)
       _lowercase							     =       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       _lowercase							     =       model(_lowercase		)
       self.parent.assertEqual(result.logits.shape   ,						(self.batch_size, self.seq_length, self.vocab_size)		)
    def 		_lowerCamelCase      (	self			:       Union[str, Any]   ,						_lowercase			:       Optional[int]   ,						_lowercase			:       int   ,						_lowercase			:       str   ,						_lowercase			:       int   ,						_lowercase			:       Optional[int]   ,						_lowercase			:       List[Any]   ,						*_lowercase			:       Tuple		)						->    Optional[int]:
       _lowercase							     =       TFOpenAIGPTDoubleHeadsModel(config=_lowercase		)

       _lowercase							     =       tf.tile(tf.expand_dims(_lowercase   ,						1		)   ,						(1, self.num_choices, 1)		)
       _lowercase							     =       tf.tile(tf.expand_dims(_lowercase   ,						1		)   ,						(1, self.num_choices, 1)		)
       _lowercase							     =       tf.tile(tf.expand_dims(_lowercase   ,						1		)   ,						(1, self.num_choices, 1)		)

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




    def 		_lowerCamelCase      (	self			:       str		)						->    Tuple:
       _lowercase							     =       self.prepare_config_and_inputs()

       (
           (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  (
           _lowercase
       )     ,  
       )							     =       config_and_inputs

       _lowercase							     =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
       return config, inputs_dict
@require_tf
class   UpperCAmelCase_	(				lowercase__,    lowercase__,    unittest.TestCase   ):
    snake_case_											=      (
        (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
        if is_tf_available()
        else ()
    )
    snake_case_											=      (
        (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
    )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
    snake_case_											=      (
        {
            """feature-extraction""": TFOpenAIGPTModel,
            """text-classification""": TFOpenAIGPTForSequenceClassification,
            """text-generation""": TFOpenAIGPTLMHeadModel,
            """zero-shot""": TFOpenAIGPTForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    snake_case_											=      False
    snake_case_											=      False
    def 		_lowerCamelCase      (	self			:       Optional[int]   ,						_lowercase			:       Optional[int]   ,						_lowercase			:       List[str]   ,						_lowercase			:       Tuple   ,						_lowercase			:       Union[str, Any]   ,						_lowercase			:       Any		)						->    List[str]:
       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 		_lowerCamelCase      (	self			:       Union[str, Any]		)						->    str:
       _lowercase							     =       TFOpenAIGPTModelTester(self		)
       _lowercase							     =       ConfigTester(self   ,						config_class=_lowercase   ,						n_embd=3_7		)
    def 		_lowerCamelCase      (	self			:       List[Any]		)						->    Optional[int]:
       self.config_tester.run_common_tests()
    def 		_lowerCamelCase      (	self			:       Any		)						->    List[str]:
       _lowercase							     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_model(*_lowercase		)
    def 		_lowerCamelCase      (	self			:       Optional[int]		)						->    List[Any]:
       _lowercase							     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_lm_head(*_lowercase		)
    def 		_lowerCamelCase      (	self			:       Optional[Any]		)						->    List[Any]:
       _lowercase							     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_double_head(*_lowercase		)
    def 		_lowerCamelCase      (	self			:       int		)						->    Union[str, Any]:
       _lowercase							     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*_lowercase		)




    @slow
    def 		_lowerCamelCase      (	self			:       Tuple		)						->    Dict:
       for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          _lowercase							     =       TFOpenAIGPTModel.from_pretrained(_lowercase		)
          self.assertIsNotNone(_lowercase		)
@require_tf
class   UpperCAmelCase_	(				unittest.TestCase   ):
    @slow
    def 		_lowerCamelCase      (	self			:       Optional[Any]		)						->    Union[str, Any]:
       _lowercase							     =       TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt"		)
       _lowercase							     =       tf.convert_to_tensor([[4_8_1, 4_7_3_5, 5_4_4]]   ,						dtype=tf.intaa		)  # the president is
       _lowercase							     =       [
           4_8_1,
           4_7_3_5,
           5_4_4,
           2_4_6,
           9_6_3,
           8_7_0,
           7_6_2,
           2_3_9,
           2_4_4,
           4_0_4_7_7,
           2_4_4,
           2_4_9,
           7_1_9,
           8_8_1,
           4_8_7,
           5_4_4,
           2_4_0,
           2_4_4,
           6_0_3,
           4_8_1,
       ]  # the president is a very good man. " \n " i\'m sure he is, " said the

       _lowercase							     =       model.generate(_lowercase   ,						do_sample=_lowercase		)
       self.assertListEqual(output_ids[0].numpy().tolist()   ,						_lowercase		)