code: 
  """simple docstring"""
  
  
  
  
  
  import collections
  import inspect
  import unittest
  
  from transformers import NatConfig
  from transformers.testing_utils import require_natten, require_torch, require_vision, slow, torch_device
  from transformers.utils import cached_property, is_torch_available, is_vision_available
  
  from ...test_backbone_common import BackboneTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
      import torch
      from torch import nn
  
      from transformers import NatBackbone, NatForImageClassification, NatModel
      from transformers.models.nat.modeling_nat import NAT_PRETRAINED_MODEL_ARCHIVE_LIST
  
  if is_vision_available():
      from PIL import Image
  
      from transformers import AutoImageProcessor
  
  
  class A_			:
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def __init__(	self       ,     lowercase_       ,     lowercase_=13       ,     lowercase_=64       ,     lowercase_=4       ,     lowercase_=3       ,     lowercase_=16       ,     lowercase_=[1, 2, 1]       ,     lowercase_=[2, 4, 8]       ,     lowercase_=3       ,     lowercase_=2.0       ,     lowercase_=True       ,     lowercase_=0.0       ,     lowercase_=0.0       ,     lowercase_=0.1       ,     lowercase_="gelu"       ,     lowercase_=True       ,     lowercase_=0.02       ,     lowercase_=1E-5       ,     lowercase_=True       ,     lowercase_=None       ,     lowercase_=True       ,     lowercase_=10       ,     lowercase_=["stage1", "stage2"]       ,     lowercase_=[1, 2]       ,     ):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[Any]      =					parent
       UpperCAmelCase_      :      int      =					batch_size
       UpperCAmelCase_      :      Dict      =					image_size
       UpperCAmelCase_      :      List[Any]      =					patch_size
       UpperCAmelCase_      :      Optional[Any]      =					num_channels
       UpperCAmelCase_      :      int      =					embed_dim
       UpperCAmelCase_      :      Union[str, Any]      =					depths
       UpperCAmelCase_      :      List[Any]      =					num_heads
       UpperCAmelCase_      :      Any      =					kernel_size
       UpperCAmelCase_      :      Any      =					mlp_ratio
       UpperCAmelCase_      :      List[Any]      =					qkv_bias
       UpperCAmelCase_      :      List[Any]      =					hidden_dropout_prob
       UpperCAmelCase_      :      Union[str, Any]      =					attention_probs_dropout_prob
       UpperCAmelCase_      :      Optional[Any]      =					drop_path_rate
       UpperCAmelCase_      :      Optional[int]      =					hidden_act
       UpperCAmelCase_      :      List[str]      =					patch_norm
       UpperCAmelCase_      :      List[Any]      =					layer_norm_eps
       UpperCAmelCase_      :      Tuple      =					initializer_range
       UpperCAmelCase_      :      Dict      =					is_training
       UpperCAmelCase_      :      List[Any]      =					scope
       UpperCAmelCase_      :      Dict      =					use_labels
       UpperCAmelCase_      :      Optional[int]      =					num_labels
       UpperCAmelCase_      :      List[Any]      =					out_features
       UpperCAmelCase_      :      Optional[Any]      =					out_indices
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)
  
       UpperCAmelCase_      :      Union[str, Any]      =					None
       if self.use_labels:
          UpperCAmelCase_      :      str      =					ids_tensor([self.batch_size]       ,     self.num_labels						)
  
       UpperCAmelCase_      :      Optional[Any]      =					self.get_config()
  
       return config, pixel_values, labels
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       return NatConfig(
           num_labels=self.num_labels       ,     image_size=self.image_size       ,     patch_size=self.patch_size       ,     num_channels=self.num_channels       ,     embed_dim=self.embed_dim       ,     depths=self.depths       ,     num_heads=self.num_heads       ,     kernel_size=self.kernel_size       ,     mlp_ratio=self.mlp_ratio       ,     qkv_bias=self.qkv_bias       ,     hidden_dropout_prob=self.hidden_dropout_prob       ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,     drop_path_rate=self.drop_path_rate       ,     hidden_act=self.hidden_act       ,     patch_norm=self.patch_norm       ,     layer_norm_eps=self.layer_norm_eps       ,     initializer_range=self.initializer_range       ,     out_features=self.out_features       ,     out_indices=self.out_indices       ,     )
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[Any]      =					NatModel(config=lowerCamelCase_						)
       model.to(lowerCamelCase_						)
       model.eval()
       UpperCAmelCase_      :      int      =					model(lowerCamelCase_						)
  
       UpperCAmelCase_      :      List[Any]      =					(config.image_size // config.patch_size) // (2 ** (len(config.depths						) - 1))
       UpperCAmelCase_      :      int      =					int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)
  
       self.parent.assertEqual(
           result.last_hidden_state.shape       ,     (self.batch_size, expected_height, expected_width, expected_dim)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Tuple      =					NatForImageClassification(lowerCamelCase_						)
       model.to(lowerCamelCase_						)
       model.eval()
       UpperCAmelCase_      :      Union[str, Any]      =					model(lowerCamelCase_       ,     labels=lowerCamelCase_						)
       self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)						)
  
       # test greyscale images
       UpperCAmelCase_      :      List[str]      =					1
       UpperCAmelCase_      :      Dict      =					NatForImageClassification(lowerCamelCase_						)
       model.to(lowerCamelCase_						)
       model.eval()
  
       UpperCAmelCase_      :      str      =					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
       UpperCAmelCase_      :      List[Any]      =					model(lowerCamelCase_						)
       self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					NatBackbone(config=lowerCamelCase_						)
       model.to(lowerCamelCase_						)
       model.eval()
       UpperCAmelCase_      :      List[Any]      =					model(lowerCamelCase_						)
  
       # verify hidden states
       self.parent.assertEqual(len(result.feature_maps						)       ,     len(config.out_features						)						)
       self.parent.assertListEqual(list(result.feature_maps[0].shape						)       ,     [self.batch_size, model.channels[0], 16, 16]						)
  
       # verify channels
       self.parent.assertEqual(len(model.channels						)       ,     len(config.out_features						)						)
  
       # verify backbone works with out_features=None
       UpperCAmelCase_      :      List[str]      =					None
       UpperCAmelCase_      :      Any      =					NatBackbone(config=lowerCamelCase_						)
       model.to(lowerCamelCase_						)
       model.eval()
       UpperCAmelCase_      :      Any      =					model(lowerCamelCase_						)
  
       # verify feature maps
       self.parent.assertEqual(len(result.feature_maps						)       ,     1						)
       self.parent.assertListEqual(list(result.feature_maps[0].shape						)       ,     [self.batch_size, model.channels[-1], 4, 4]						)
  
       # verify channels
       self.parent.assertEqual(len(model.channels						)       ,     1						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Tuple      =					self.prepare_config_and_inputs()
       UpperCAmelCase_  ,     UpperCAmelCase_  ,     UpperCAmelCase_      :      str      =					config_and_inputs
       UpperCAmelCase_      :      Union[str, Any]      =					{"pixel_values": pixel_values}
       return config, inputs_dict
  
  
  
  
  @require_natten
  @require_torch
  class A_			(lowerCAmelCase_       ,lowerCAmelCase_       ,unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
    SCREAMING_SNAKE_CASE__    :		str						  =	(
        (
            NatModel,
            NatForImageClassification,
            NatBackbone,
        )
        if is_torch_available()
        else ()
    )
    SCREAMING_SNAKE_CASE__    :		int						  =	(
        {'feature-extraction': NatModel, 'image-classification': NatForImageClassification}
        if is_torch_available()
        else {}
    )
    SCREAMING_SNAKE_CASE__    :		Optional[Any]						  =	False
  
    SCREAMING_SNAKE_CASE__    :		Optional[Any]						  =	False
    SCREAMING_SNAKE_CASE__    :		Optional[int]						  =	False
    SCREAMING_SNAKE_CASE__    :		List[str]						  =	False
    SCREAMING_SNAKE_CASE__    :		str						  =	False
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      str      =					NatModelTester(self						)
       UpperCAmelCase_      :      List[Any]      =					ConfigTester(self       ,     config_class=lowerCamelCase_       ,     embed_dim=37						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       self.create_and_test_config_common_properties()
       self.config_tester.create_and_test_config_to_json_string()
       self.config_tester.create_and_test_config_to_json_file()
       self.config_tester.create_and_test_config_from_and_save_pretrained()
       self.config_tester.create_and_test_config_with_num_labels()
       self.config_tester.check_config_can_be_init_without_params()
       self.config_tester.check_config_arguments_init()
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       return
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[Any]      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*lowerCamelCase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Any      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*lowerCamelCase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_backbone(*lowerCamelCase_						)
  
  
  
  
  
  
  
    @unittest.skip(reason="Nat does not use inputs_embeds"						)
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       pass
  
  
  
  
  
  
  
    @unittest.skip(reason="Nat does not use feedforward chunking"						)
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       pass
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_  ,     UpperCAmelCase_      :      List[Any]      =					self.model_tester.prepare_config_and_inputs_for_common()
  
       for model_class in self.all_model_classes:
          UpperCAmelCase_      :      Optional[int]      =					model_class(lowerCamelCase_						)
          self.assertIsInstance(model.get_input_embeddings()       ,     (nn.Module)						)
          UpperCAmelCase_      :      Dict      =					model.get_output_embeddings()
          self.assertTrue(x is None or isinstance(lowerCamelCase_       ,     nn.Linear						)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_  ,     UpperCAmelCase_      :      Optional[int]      =					self.model_tester.prepare_config_and_inputs_for_common()
  
       for model_class in self.all_model_classes:
          UpperCAmelCase_      :      Optional[Any]      =					model_class(lowerCamelCase_						)
          UpperCAmelCase_      :      Optional[Any]      =					inspect.signature(model.forward						)
          # signature.parameters is an OrderedDict => so arg_names order is deterministic
          UpperCAmelCase_      :      List[Any]      =					[*signature.parameters.keys()]
  
          UpperCAmelCase_      :      int      =					["pixel_values"]
          self.assertListEqual(arg_names[:1]       ,     lowerCamelCase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       self.skipTest("Nat's attention operation is handled entirely by NATTEN."						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[Any]      =					model_class(lowerCamelCase_						)
       model.to(lowerCamelCase_						)
       model.eval()
  
       with torch.no_grad():
          UpperCAmelCase_      :      List[Any]      =					model(**self._prepare_for_class(lowerCamelCase_       ,     lowerCamelCase_						)						)
  
       UpperCAmelCase_      :      Optional[int]      =					outputs.hidden_states
  
       UpperCAmelCase_      :      Any      =					getattr(
           self.model_tester       ,     "expected_num_hidden_layers"       ,     len(self.model_tester.depths						) + 1						)
       self.assertEqual(len(lowerCamelCase_						)       ,     lowerCamelCase_						)
  
       # Nat has a different seq_length
       UpperCAmelCase_      :      Optional[int]      =					(
           config.patch_size
           if isinstance(config.patch_size       ,     collections.abc.Iterable						)
           else (config.patch_size, config.patch_size)
       )
  
       UpperCAmelCase_      :      List[str]      =					image_size[0] // patch_size[0]
       UpperCAmelCase_      :      Union[str, Any]      =					image_size[1] // patch_size[1]
  
       self.assertListEqual(
           list(hidden_states[0].shape[-3:]						)       ,     [height, width, self.model_tester.embed_dim]       ,     )
  
       if model_class.__name__ != "NatBackbone":
          UpperCAmelCase_      :      Tuple      =					outputs.reshaped_hidden_states
          self.assertEqual(len(lowerCamelCase_						)       ,     lowerCamelCase_						)
  
          UpperCAmelCase_  ,     UpperCAmelCase_  ,     UpperCAmelCase_  ,     UpperCAmelCase_      :      List[str]      =					reshaped_hidden_states[0].shape
          UpperCAmelCase_      :      Union[str, Any]      =					(
              reshaped_hidden_states[0].view(lowerCamelCase_       ,     lowerCamelCase_       ,     lowerCamelCase_       ,     lowerCamelCase_						).permute(0       ,     2       ,     3       ,     1						)
          )
          self.assertListEqual(
              list(reshaped_hidden_states.shape[-3:]						)       ,     [height, width, self.model_tester.embed_dim]       ,     )
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_  ,     UpperCAmelCase_      :      int      =					self.model_tester.prepare_config_and_inputs_for_common()
  
       UpperCAmelCase_      :      str      =					(
           self.model_tester.image_size
           if isinstance(self.model_tester.image_size       ,     collections.abc.Iterable						)
           else (self.model_tester.image_size, self.model_tester.image_size)
       )
  
       for model_class in self.all_model_classes:
          UpperCAmelCase_      :      Tuple      =					True
          self.check_hidden_states_output(lowerCamelCase_       ,     lowerCamelCase_       ,     lowerCamelCase_       ,     lowerCamelCase_						)
  
          # check that output_hidden_states also work using config
          del inputs_dict["output_hidden_states"]
          UpperCAmelCase_      :      List[str]      =					True
  
          self.check_hidden_states_output(lowerCamelCase_       ,     lowerCamelCase_       ,     lowerCamelCase_       ,     lowerCamelCase_						)
  
  
  
  
  
  
  
    @slow
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
  
       for model_name in NAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          UpperCAmelCase_      :      str      =					NatModel.from_pretrained(lowerCamelCase_						)
          self.assertIsNotNone(lowerCamelCase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_  ,     UpperCAmelCase_      :      List[str]      =					self.model_tester.prepare_config_and_inputs_for_common()
  
       UpperCAmelCase_      :      Optional[Any]      =					_config_zero_init(lowerCamelCase_						)
       for model_class in self.all_model_classes:
          UpperCAmelCase_      :      Dict      =					model_class(config=lowerCamelCase_						)
          for name, param in model.named_parameters():
             if "embeddings" not in name and param.requires_grad:
                self.assertIn(
                    ((param.data.mean() * 1E9).round() / 1E9).item()       ,     [0.0, 1.0]       ,     msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""       ,     )
  
  
  
  
  @require_natten
  @require_vision
  @require_torch
  class A_			(unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    @cached_property
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       return AutoImageProcessor.from_pretrained("shi-labs/nat-mini-in1k-224"						) if is_vision_available() else None
  
  
  
  
  
  
  
    @slow
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[Any]      =					NatForImageClassification.from_pretrained("shi-labs/nat-mini-in1k-224"						).to(lowerCamelCase_						)
       UpperCAmelCase_      :      List[str]      =					self.default_image_processor
  
       UpperCAmelCase_      :      Optional[Any]      =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
       UpperCAmelCase_      :      Optional[int]      =					image_processor(images=lowerCamelCase_       ,     return_tensors="pt"						).to(lowerCamelCase_						)
  
       # forward pass
       with torch.no_grad():
          UpperCAmelCase_      :      Dict      =					model(**lowerCamelCase_						)
  
       # verify the logits
       UpperCAmelCase_      :      Tuple      =					torch.Size((1, 1000)						)
       self.assertEqual(outputs.logits.shape       ,     lowerCamelCase_						)
       UpperCAmelCase_      :      Tuple      =					torch.tensor([0.38_05, -0.86_76, -0.39_12]						).to(lowerCamelCase_						)
       self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,     lowerCamelCase_       ,     atol=1E-4						)						)
  
  
  
  
  @require_torch
  @require_natten
  class A_			(unittest.TestCase       ,lowerCAmelCase_   ):
  
  
  
  
    '''simple docstring'''
    SCREAMING_SNAKE_CASE__    :		Any						  =	(NatBackbone,) if is_torch_available() else ()
    SCREAMING_SNAKE_CASE__    :		Dict						  =	NatConfig
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					NatModelTester(self						)
  
  
  
style_context: 
  """simple docstring"""
  
  
  
  
  
  from __future__ import annotations
  
  import unittest
  
  from transformers import CTRLConfig, 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.ctrl.modeling_tf_ctrl import (
          TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFCTRLForSequenceClassification,
          TFCTRLLMHeadModel,
          TFCTRLModel,
      )
  
  
  class A_			(lowercase__   ):
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def __init__(	self       ,     lowercase_       ,     ):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[str]      =					parent
       UpperCAmelCase_      :      List[Any]      =					13
       UpperCAmelCase_      :      Dict      =					7
       UpperCAmelCase_      :      Optional[int]      =					True
       UpperCAmelCase_      :      List[Any]      =					True
       UpperCAmelCase_      :      Optional[int]      =					True
       UpperCAmelCase_      :      int      =					True
       UpperCAmelCase_      :      Any      =					True
       UpperCAmelCase_      :      Any      =					99
       UpperCAmelCase_      :      Dict      =					32
       UpperCAmelCase_      :      Dict      =					2
       UpperCAmelCase_      :      str      =					4
       UpperCAmelCase_      :      int      =					37
       UpperCAmelCase_      :      Union[str, Any]      =					"gelu"
       UpperCAmelCase_      :      List[str]      =					0.1
       UpperCAmelCase_      :      List[str]      =					0.1
       UpperCAmelCase_      :      int      =					512
       UpperCAmelCase_      :      str      =					16
       UpperCAmelCase_      :      Union[str, Any]      =					2
       UpperCAmelCase_      :      Dict      =					0.02
       UpperCAmelCase_      :      Tuple      =					3
       UpperCAmelCase_      :      Tuple      =					4
       UpperCAmelCase_      :      int      =					None
       UpperCAmelCase_      :      Dict      =					self.vocab_size - 1
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Dict      =					ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size						)
  
       UpperCAmelCase_      :      Optional[int]      =					None
       if self.use_input_mask:
          UpperCAmelCase_      :      Optional[Any]      =					random_attention_mask([self.batch_size, self.seq_length]						)
  
       UpperCAmelCase_      :      List[Any]      =					None
       if self.use_token_type_ids:
          UpperCAmelCase_      :      Optional[int]      =					ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size						)
  
       UpperCAmelCase_      :      str      =					None
       if self.use_mc_token_ids:
          UpperCAmelCase_      :      Any      =					ids_tensor([self.batch_size, self.num_choices]       ,     self.seq_length						)
  
       UpperCAmelCase_      :      Union[str, Any]      =					None
       UpperCAmelCase_      :      str      =					None
       UpperCAmelCase_      :      str      =					None
       if self.use_labels:
          UpperCAmelCase_      :      List[Any]      =					ids_tensor([self.batch_size]       ,     self.type_sequence_label_size						)
          UpperCAmelCase_      :      str      =					ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels						)
          UpperCAmelCase_      :      Optional[Any]      =					ids_tensor([self.batch_size]       ,     self.num_choices						)
  
       UpperCAmelCase_      :      str      =					CTRLConfig(
           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       ,     )
  
       UpperCAmelCase_      :      Tuple      =					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       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					TFCTRLModel(config=lowercase_						)
       UpperCAmelCase_      :      Optional[Any]      =					{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       UpperCAmelCase_      :      Union[str, Any]      =					model(lowercase_						)
  
       UpperCAmelCase_      :      Union[str, Any]      =					[input_ids, None, input_mask]  # None is the input for 'past'
       UpperCAmelCase_      :      str      =					model(lowercase_						)
  
       UpperCAmelCase_      :      str      =					model(lowercase_						)
  
       self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					TFCTRLLMHeadModel(config=lowercase_						)
       UpperCAmelCase_      :      List[Any]      =					{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
       UpperCAmelCase_      :      List[str]      =					model(lowercase_						)
       self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[str]      =					self.num_labels
       UpperCAmelCase_      :      str      =					ids_tensor([self.batch_size]       ,     self.type_sequence_label_size						)
       UpperCAmelCase_      :      Union[str, Any]      =					{
           "input_ids": input_ids,
           "token_type_ids": token_type_ids,
           "labels": sequence_labels,
       }
       UpperCAmelCase_      :      Union[str, Any]      =					TFCTRLForSequenceClassification(lowercase_						)
       UpperCAmelCase_      :      Tuple      =					model(lowercase_						)
       self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Dict      =					self.prepare_config_and_inputs()
  
       (
           (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     
       )      :      Tuple      =					config_and_inputs
  
       UpperCAmelCase_      :      int      =					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
       return config, inputs_dict
  
  
  
  
  @require_tf
  class A_			(lowercase__       ,lowercase__       ,unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
    SCREAMING_SNAKE_CASE__    :		Dict						  =	(TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
    SCREAMING_SNAKE_CASE__    :		str						  =	(TFCTRLLMHeadModel,) if is_tf_available() else ()
    SCREAMING_SNAKE_CASE__    :		Any						  =	(
        {
            """feature-extraction""": TFCTRLModel,
            """text-classification""": TFCTRLForSequenceClassification,
            """text-generation""": TFCTRLLMHeadModel,
            """zero-shot""": TFCTRLForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    SCREAMING_SNAKE_CASE__    :		Dict						  =	False
    SCREAMING_SNAKE_CASE__    :		List[Any]						  =	False
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_						):
  
       """simple docstring"""
       if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
          # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
          # `CTRLConfig` 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						):
  
       """simple docstring"""
       UpperCAmelCase_      :      str      =					TFCTRLModelTester(self						)
       UpperCAmelCase_      :      Dict      =					ConfigTester(self       ,     config_class=lowercase_       ,     n_embd=37						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       self.config_tester.run_common_tests()
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      str      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_ctrl_model(*lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_ctrl_lm_head(*lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[Any]      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_ctrl_for_sequence_classification(*lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_  ,     UpperCAmelCase_      :      List[Any]      =					self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase_      :      Tuple      =					[TFCTRLLMHeadModel]
       UpperCAmelCase_      :      Dict      =					[TFCTRLForSequenceClassification]
  
       for model_class in self.all_model_classes:
          UpperCAmelCase_      :      Optional[int]      =					model_class(lowercase_						)
          model.build()  # may be needed for the get_bias() call below
          assert isinstance(model.get_input_embeddings()       ,     tf.keras.layers.Layer						)
  
          if model_class in list_lm_models:
             UpperCAmelCase_      :      List[str]      =					model.get_output_embeddings()
             assert isinstance(lowercase_       ,     tf.keras.layers.Layer						)
             UpperCAmelCase_      :      List[Any]      =					model.get_bias()
             assert isinstance(lowercase_       ,     lowercase_						)
             for k, v in name.items():
                assert isinstance(lowercase_       ,     tf.Variable						)
          elif model_class in list_other_models_with_output_ebd:
             UpperCAmelCase_      :      int      =					model.get_output_embeddings()
             assert isinstance(lowercase_       ,     tf.keras.layers.Layer						)
             UpperCAmelCase_      :      Any      =					model.get_bias()
             assert name is None
          else:
             UpperCAmelCase_      :      Dict      =					model.get_output_embeddings()
             assert x is None
             UpperCAmelCase_      :      Tuple      =					model.get_bias()
             assert name is None
  
  
  
  
  
  
  
    @slow
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          UpperCAmelCase_      :      List[Any]      =					TFCTRLModel.from_pretrained(lowercase_						)
          self.assertIsNotNone(lowercase_						)
  
  
  
  
  @require_tf
  class A_			(unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    @slow
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					TFCTRLLMHeadModel.from_pretrained("ctrl"						)
       UpperCAmelCase_      :      Union[str, Any]      =					tf.convert_to_tensor([[1_1859, 0, 1611, 8]]       ,     dtype=tf.intaa						)  # Legal the president is
       UpperCAmelCase_      :      int      =					[
           1_1859,
           0,
           1611,
           8,
           5,
           150,
           2_6449,
           2,
           19,
           348,
           469,
           3,
           2595,
           48,
           2_0740,
           24_6533,
           24_6533,
           19,
           30,
           5,
       ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a
  
       UpperCAmelCase_      :      List[str]      =					model.generate(lowercase_       ,     do_sample=lowercase_						)
       self.assertListEqual(output_ids[0].numpy().tolist()       ,     lowercase_						)
  
  
  