


import inspect
import unittest
import warnings
from math import ceil, floor

from transformers import LevitConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

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


if is_torch_available():
						import torch

						from transformers import (
						    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
						    MODEL_MAPPING,
						    LevitForImageClassification,
						    LevitForImageClassificationWithTeacher,
						    LevitModel,
						)
						from transformers.models.levit.modeling_levit import LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import LevitImageProcessor







class  snake_case_     (UpperCamelCase_   ):
					def 				lowerCamelCase__(   self     :Any   )      ->					Optional[int]:
												a__    =  self.config_class(**self.inputs_dict   )
												self.parent.assertTrue(hasattr(__A    ,'hidden_sizes'   )   )
												self.parent.assertTrue(hasattr(__A    ,'num_attention_heads'   )   )







class  snake_case_     :
					def __init__(   self     :Any    ,__snake_case     :Optional[int]    ,__snake_case     :Dict=13    ,__snake_case     :Union[str, Any]=64    ,__snake_case     :int=3    ,__snake_case     :List[str]=3    ,__snake_case     :Optional[Any]=2    ,__snake_case     :Dict=1    ,__snake_case     :Optional[int]=16    ,__snake_case     :Any=[1_28, 2_56, 3_84]    ,__snake_case     :List[str]=[4, 6, 8]    ,__snake_case     :Optional[Any]=[2, 3, 4]    ,__snake_case     :str=[16, 16, 16]    ,__snake_case     :Dict=0    ,__snake_case     :Dict=[2, 2, 2]    ,__snake_case     :Dict=[2, 2, 2]    ,__snake_case     :Dict=0.02    ,__snake_case     :Dict=True    ,__snake_case     :Dict=True    ,__snake_case     :str=2    ,)      ->					Optional[Any]:
												a__    =  parent
												a__    =  batch_size
												a__    =  image_size
												a__    =  num_channels
												a__    =  kernel_size
												a__    =  stride
												a__    =  padding
												a__    =  hidden_sizes
												a__    =  num_attention_heads
												a__    =  depths
												a__    =  key_dim
												a__    =  drop_path_rate
												a__    =  patch_size
												a__    =  attention_ratio
												a__    =  mlp_ratio
												a__    =  initializer_range
												a__    =  [
												    ["Subsample", key_dim[0], hidden_sizes[0] // key_dim[0], 4, 2, 2],
												    ["Subsample", key_dim[0], hidden_sizes[1] // key_dim[0], 4, 2, 2],
												]
												a__    =  is_training
												a__    =  use_labels
												a__    =  num_labels
												a__    =  initializer_range
					def 				lowerCamelCase__(   self     :Tuple   )      ->					Any:
												a__    =  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

												a__    =  None
												if self.use_labels:
																			a__    =  ids_tensor([self.batch_size]    ,self.num_labels   )

												a__    =  self.get_config()
												return config, pixel_values, labels
					def 				lowerCamelCase__(   self     :Dict   )      ->					Optional[Any]:
												return LevitConfig(
												    image_size=self.image_size    ,num_channels=self.num_channels    ,kernel_size=self.kernel_size    ,stride=self.stride    ,padding=self.padding    ,patch_size=self.patch_size    ,hidden_sizes=self.hidden_sizes    ,num_attention_heads=self.num_attention_heads    ,depths=self.depths    ,key_dim=self.key_dim    ,drop_path_rate=self.drop_path_rate    ,mlp_ratio=self.mlp_ratio    ,attention_ratio=self.attention_ratio    ,initializer_range=self.initializer_range    ,down_ops=self.down_ops    ,)
					def 				lowerCamelCase__(   self     :Dict    ,__snake_case     :int    ,__snake_case     :List[str]    ,__snake_case     :List[str]   )      ->					Tuple:
												a__    =  LevitModel(config=__A   )
												model.to(__A   )
												model.eval()
												a__    =  model(__A   )
												a__    =  (self.image_size, self.image_size)
												a__    =  image_size[0], image_size[1]
												for _ in range(4   ):
																			a__    =  floor(((height + 2 * self.padding - self.kernel_size) / self.stride) + 1   )
																			a__    =  floor(((width + 2 * self.padding - self.kernel_size) / self.stride) + 1   )
												self.parent.assertEqual(
												    result.last_hidden_state.shape    ,(self.batch_size, ceil(height / 4   ) * ceil(width / 4   ), self.hidden_sizes[-1])    ,)
					def 				lowerCamelCase__(   self     :Dict    ,__snake_case     :Tuple    ,__snake_case     :Optional[int]    ,__snake_case     :Optional[Any]   )      ->					Optional[int]:
												a__    =  self.num_labels
												a__    =  LevitForImageClassification(__A   )
												model.to(__A   )
												model.eval()
												a__    =  model(__A    ,labels=__A   )
												self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.num_labels)   )



					def 				lowerCamelCase__(   self     :Optional[Any]   )      ->					Tuple:
												a__    =  self.prepare_config_and_inputs()
												a__    =  config_and_inputs
												a__    =  {"pixel_values": pixel_values}
												return config, inputs_dict







@require_torch
class  snake_case_     (UpperCamelCase_			,		UpperCamelCase_			,		unittest.TestCase   ):
					UpperCAmelCase__      :					Optional[int]					   =    (
					    (LevitModel, LevitForImageClassification, LevitForImageClassificationWithTeacher)
					    if is_torch_available()
					    else ()
					)
					UpperCAmelCase__      :					Tuple					   =    (
					    {
					        '''feature-extraction''': LevitModel,
					        '''image-classification''': (LevitForImageClassification, LevitForImageClassificationWithTeacher),
					    }
					    if is_torch_available()
					    else {}
					)

					UpperCAmelCase__      :					Optional[Any]					   =    False
					UpperCAmelCase__      :					str					   =    False
					UpperCAmelCase__      :					List[str]					   =    False
					UpperCAmelCase__      :					Any					   =    False
					UpperCAmelCase__      :					int					   =    False
					def 				lowerCamelCase__(   self     :Any   )      ->					Tuple:
												a__    =  LevitModelTester(self   )
												a__    =  ConfigTester(self    ,config_class=__A    ,has_text_modality=__A    ,hidden_size=37   )
					def 				lowerCamelCase__(   self     :List[str]   )      ->					Tuple:
												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 				lowerCamelCase__(   self     :Optional[int]   )      ->					Dict:
												return
					@unittest.skip(reason='Levit does not use inputs_embeds'   )
					def 				lowerCamelCase__(   self     :Dict   )      ->					Optional[Any]:
												pass
					@unittest.skip(reason='Levit does not support input and output embeddings'   )
					def 				lowerCamelCase__(   self     :str   )      ->					int:
												pass
					@unittest.skip(reason='Levit does not output attentions'   )
					def 				lowerCamelCase__(   self     :Optional[int]   )      ->					Dict:
												pass
					def 				lowerCamelCase__(   self     :int   )      ->					Optional[Any]:
												a__    =  self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			a__    =  model_class(__A   )
																			a__    =  inspect.signature(model.forward   )
																			# signature.parameters is an OrderedDict => so arg_names order is deterministic
																			a__    =  [*signature.parameters.keys()]

																			a__    =  ["pixel_values"]
																			self.assertListEqual(arg_names[:1]    ,__A   )
					def 				lowerCamelCase__(   self     :Tuple   )      ->					Any:
												def check_hidden_states_output(__snake_case     :Any    ,__snake_case     :Dict    ,__snake_case     :Any   ):
																			a__    =  model_class(__A   )
																			model.to(__A   )
																			model.eval()

																			with torch.no_grad():
																										a__    =  model(**self._prepare_for_class(__A    ,__A   )   )

																			a__    =  outputs.hidden_states

																			a__    =  len(self.model_tester.depths   ) + 1
																			self.assertEqual(len(__A   )    ,__A   )

																			a__    =  (self.model_tester.image_size, self.model_tester.image_size)
																			a__    =  image_size[0], image_size[1]
																			for _ in range(4   ):
																										a__    =  floor(
																										    (
																										        (height + 2 * self.model_tester.padding - self.model_tester.kernel_size)
																										        / self.model_tester.stride
																										    )
																										    + 1   )
																										a__    =  floor(
																										    (
																										        (width + 2 * self.model_tester.padding - self.model_tester.kernel_size)
																										        / self.model_tester.stride
																										    )
																										    + 1   )
																			# verify the first hidden states (first block)
																			self.assertListEqual(
																			    list(hidden_states[0].shape[-2:]   )    ,[
																			        height * width,
																			        self.model_tester.hidden_sizes[0],
																			    ]    ,)

												a__    =  self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																			a__    =  True
																			check_hidden_states_output(__A    ,__A    ,__A   )

																			# check that output_hidden_states also work using config
																			del inputs_dict["output_hidden_states"]
																			a__    =  True

																			check_hidden_states_output(__A    ,__A    ,__A   )
					@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'   )
					def 				lowerCamelCase__(   self     :Tuple   )      ->					Optional[Any]:
												pass
					def 				lowerCamelCase__(   self     :List[str]    ,__snake_case     :str    ,__snake_case     :Optional[int]    ,__snake_case     :Optional[int]=False   )      ->					str:
												a__    =  super()._prepare_for_class(__A    ,__A    ,return_labels=__A   )

												if return_labels:
																			if model_class.__name__ == "LevitForImageClassificationWithTeacher":
																										del inputs_dict["labels"]

												return inputs_dict
					def 				lowerCamelCase__(   self     :List[str]   )      ->					List[Any]:
												a__    =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*__A   )
					def 				lowerCamelCase__(   self     :Tuple   )      ->					Union[str, Any]:
												a__    =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_for_image_classification(*__A   )
					def 				lowerCamelCase__(   self     :List[Any]   )      ->					List[str]:
												if not self.model_tester.is_training:
																			return

												a__    =  self.model_tester.prepare_config_and_inputs_for_common()
												a__    =  True

												for model_class in self.all_model_classes:
																			# LevitForImageClassificationWithTeacher supports inference-only
																			if (
																			    model_class in get_values(__A   )
																			    or model_class.__name__ == "LevitForImageClassificationWithTeacher"
																			):
																										continue
																			a__    =  model_class(__A   )
																			model.to(__A   )
																			model.train()
																			a__    =  self._prepare_for_class(__A    ,__A    ,return_labels=__A   )
																			a__    =  model(**__A   ).loss
																			loss.backward()
					def 				lowerCamelCase__(   self     :Tuple   )      ->					str:
												a__    =  self.model_tester.prepare_config_and_inputs_for_common()
												if not self.model_tester.is_training:
																			return

												a__    =  False
												a__    =  True

												for model_class in self.all_model_classes:
																			if model_class in get_values(__A   ) or not model_class.supports_gradient_checkpointing:
																										continue
																			# LevitForImageClassificationWithTeacher supports inference-only
																			if model_class.__name__ == "LevitForImageClassificationWithTeacher":
																										continue
																			a__    =  model_class(__A   )
																			model.gradient_checkpointing_enable()
																			model.to(__A   )
																			model.train()
																			a__    =  self._prepare_for_class(__A    ,__A    ,return_labels=__A   )
																			a__    =  model(**__A   ).loss
																			loss.backward()
					def 				lowerCamelCase__(   self     :Dict   )      ->					Dict:
												a__    =  self.model_tester.prepare_config_and_inputs_for_common()

												a__    =  [
												    {"title": "multi_label_classification", "num_labels": 2, "dtype": torch.float},
												    {"title": "single_label_classification", "num_labels": 1, "dtype": torch.long},
												    {"title": "regression", "num_labels": 1, "dtype": torch.float},
												]

												for model_class in self.all_model_classes:
																			if (
																			    model_class
																			    not in [
																			        *get_values(__A   ),
																			    ]
																			    or model_class.__name__ == "LevitForImageClassificationWithTeacher"
																			):
																										continue

																			for problem_type in problem_types:
																										with self.subTest(msg=F'Testing {model_class} with {problem_type["title"]}'   ):
																																	a__    =  problem_type["title"]
																																	a__    =  problem_type["num_labels"]

																																	a__    =  model_class(__A   )
																																	model.to(__A   )
																																	model.train()

																																	a__    =  self._prepare_for_class(__A    ,__A    ,return_labels=__A   )

																																	if problem_type["num_labels"] > 1:
																																								a__    =  inputs["labels"].unsqueeze(1   ).repeat(1    ,problem_type['num_labels']   )

																																	a__    =  inputs["labels"].to(problem_type['dtype']   )

																																	# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
																																	# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
																																	# they have the same size." which is a symptom something in wrong for the regression problem.
																																	# See https://github.com/huggingface/transformers/issues/11780
																																	with warnings.catch_warnings(record=__A   ) as warning_list:
																																								a__    =  model(**__A   ).loss
																																	for w in warning_list:
																																								if "Using a target size that is different to the input size" in str(w.message   ):
																																															raise ValueError(
																																															    F'Something is going wrong in the regression problem: intercepted {w.message}'   )

																																	loss.backward()



					@slow
					def 				lowerCamelCase__(   self     :List[str]   )      ->					Any:
												for model_name in LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			a__    =  LevitModel.from_pretrained(__A   )
																			self.assertIsNotNone(__A   )






def 							__lowercase     (				):
							a__    =  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
							return image







@require_torch
@require_vision
class  snake_case_     (unittest.TestCase   ):
					@cached_property
					def 				lowerCamelCase__(   self     :Dict   )      ->					str:
												return LevitImageProcessor.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   )



					@slow
					def 				lowerCamelCase__(   self     :Optional[Any]   )      ->					str:
												a__    =  LevitForImageClassificationWithTeacher.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]   ).to(
												    __A   )

												a__    =  self.default_image_processor
												a__    =  prepare_img()
												a__    =  image_processor(images=__A    ,return_tensors='pt'   ).to(__A   )

												# forward pass
												with torch.no_grad():
																			a__    =  model(**__A   )

												# verify the logits
												a__    =  torch.Size((1, 10_00)   )
												self.assertEqual(outputs.logits.shape    ,__A   )

												a__    =  torch.tensor([1.04_48, -0.37_45, -1.83_17]   ).to(__A   )

												self.assertTrue(torch.allclose(outputs.logits[0, :3]    ,__A    ,atol=1E-4   )   )








import gc
import unittest

from transformers import CTRLConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CTRLForSequenceClassification,
						    CTRLLMHeadModel,
						    CTRLModel,
						)







class  snake_case_     :
					def __init__(   self     :Optional[Any]    ,__snake_case     :str    ,__snake_case     :Optional[Any]=14    ,__snake_case     :Dict=7    ,__snake_case     :Optional[int]=True    ,__snake_case     :Optional[int]=True    ,__snake_case     :Dict=True    ,__snake_case     :List[Any]=True    ,__snake_case     :Optional[int]=True    ,__snake_case     :Any=99    ,__snake_case     :List[str]=32    ,__snake_case     :List[str]=5    ,__snake_case     :Tuple=4    ,__snake_case     :Optional[int]=37    ,__snake_case     :Optional[int]="gelu"    ,__snake_case     :Tuple=0.1    ,__snake_case     :Tuple=0.1    ,__snake_case     :Dict=5_12    ,__snake_case     :Union[str, Any]=16    ,__snake_case     :str=2    ,__snake_case     :Optional[Any]=0.02    ,__snake_case     :Dict=3    ,__snake_case     :Optional[Any]=4    ,__snake_case     :Optional[Any]=None    ,)      ->					Tuple:
												a__    =  parent
												a__    =  batch_size
												a__    =  seq_length
												a__    =  is_training
												a__    =  use_token_type_ids
												a__    =  use_input_mask
												a__    =  use_labels
												a__    =  use_mc_token_ids
												a__    =  vocab_size
												a__    =  hidden_size
												a__    =  num_hidden_layers
												a__    =  num_attention_heads
												a__    =  intermediate_size
												a__    =  hidden_act
												a__    =  hidden_dropout_prob
												a__    =  attention_probs_dropout_prob
												a__    =  max_position_embeddings
												a__    =  type_vocab_size
												a__    =  type_sequence_label_size
												a__    =  initializer_range
												a__    =  num_labels
												a__    =  num_choices
												a__    =  scope
												a__    =  self.vocab_size - 1
					def 				lowerCamelCase__(   self     :Optional[int]   )      ->					Union[str, Any]:
												a__    =  ids_tensor([self.batch_size, self.seq_length]    ,self.vocab_size   )

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

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

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

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

												a__    =  self.get_config()

												a__    =  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     :Optional[Any]   )      ->					Tuple:
												return 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    ,)
					def 				lowerCamelCase__(   self     :str    ,__snake_case     :List[str]    ,__snake_case     :Any    ,__snake_case     :Dict    ,__snake_case     :int    ,__snake_case     :Optional[Any]    ,*__snake_case     :List[str]   )      ->					List[Any]:
												a__    =  CTRLModel(config=__snake_case   )
												model.to(__snake_case   )
												model.eval()

												model(__snake_case    ,token_type_ids=__snake_case    ,head_mask=__snake_case   )
												model(__snake_case    ,token_type_ids=__snake_case   )
												a__    =  model(__snake_case   )
												self.parent.assertEqual(result.last_hidden_state.shape    ,(self.batch_size, self.seq_length, self.hidden_size)   )
												self.parent.assertEqual(len(result.past_key_values   )    ,config.n_layer   )
					def 				lowerCamelCase__(   self     :Optional[int]    ,__snake_case     :List[str]    ,__snake_case     :Union[str, Any]    ,__snake_case     :str    ,__snake_case     :str    ,__snake_case     :Dict    ,*__snake_case     :Dict   )      ->					Dict:
												a__    =  CTRLLMHeadModel(__snake_case   )
												model.to(__snake_case   )
												model.eval()

												a__    =  model(__snake_case    ,token_type_ids=__snake_case    ,labels=__snake_case   )
												self.parent.assertEqual(result.loss.shape    ,()   )
												self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.seq_length, self.vocab_size)   )
					def 				lowerCamelCase__(   self     :Optional[Any]   )      ->					Optional[Any]:
												a__    =  self.prepare_config_and_inputs()

												(
												    (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      (
												    a__
												)   ,      
												)    =  config_and_inputs

												a__    =  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'head_mask': head_mask}

												return config, inputs_dict



					def 				lowerCamelCase__(   self     :Optional[int]    ,__snake_case     :Tuple    ,__snake_case     :str    ,__snake_case     :str    ,__snake_case     :List[str]    ,*__snake_case     :Optional[int]   )      ->					List[Any]:
												a__    =  self.num_labels
												a__    =  CTRLForSequenceClassification(__snake_case   )
												model.to(__snake_case   )
												model.eval()
												a__    =  ids_tensor([self.batch_size]    ,self.type_sequence_label_size   )
												a__    =  model(__snake_case    ,token_type_ids=__snake_case    ,labels=__snake_case   )
												self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.num_labels)   )







@require_torch
class  snake_case_     (lowerCamelCase_			,		lowerCamelCase_			,		lowerCamelCase_			,		unittest.TestCase   ):
					UpperCAmelCase__      :					Union[str, Any]					   =    (CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
					UpperCAmelCase__      :					Any					   =    (CTRLLMHeadModel,) if is_torch_available() else ()
					UpperCAmelCase__      :					Any					   =    (
					    {
					        '''feature-extraction''': CTRLModel,
					        '''text-classification''': CTRLForSequenceClassification,
					        '''text-generation''': CTRLLMHeadModel,
					        '''zero-shot''': CTRLForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					UpperCAmelCase__      :					Tuple					   =    True
					UpperCAmelCase__      :					List[Any]					   =    False
					UpperCAmelCase__      :					List[str]					   =    False
					def 				lowerCamelCase__(   self     :Union[str, Any]    ,__snake_case     :Optional[int]    ,__snake_case     :int    ,__snake_case     :Any    ,__snake_case     :List[str]    ,__snake_case     :Dict   )      ->					Union[str, Any]:
												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 				lowerCamelCase__(   self     :int   )      ->					List[str]:
												a__    =  CTRLModelTester(self   )
												a__    =  ConfigTester(self    ,config_class=__snake_case    ,n_embd=37   )
					def 				lowerCamelCase__(   self     :str   )      ->					str:
												super().tearDown()
												# clean-up as much as possible GPU memory occupied by PyTorch
												gc.collect()
												torch.cuda.empty_cache()
					def 				lowerCamelCase__(   self     :Tuple   )      ->					List[Any]:
												self.config_tester.run_common_tests()
					def 				lowerCamelCase__(   self     :str   )      ->					str:
												a__    =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_ctrl_model(*__snake_case   )
					def 				lowerCamelCase__(   self     :List[Any]   )      ->					Any:
												a__    =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_lm_head_model(*__snake_case   )
					@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'   )
					def 				lowerCamelCase__(   self     :Union[str, Any]   )      ->					Tuple:
												pass
					@slow
					def 				lowerCamelCase__(   self     :int   )      ->					List[Any]:
												for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			a__    =  CTRLModel.from_pretrained(__snake_case   )
																			self.assertIsNotNone(__snake_case   )



					@unittest.skip('The model doesn\'t support left padding'   )  # and it's not used enough to be worth fixing :)
					def 				lowerCamelCase__(   self     :Dict   )      ->					List[str]:
												pass







@require_torch
class  snake_case_     (unittest.TestCase   ):
					def 				lowerCamelCase__(   self     :Union[str, Any]   )      ->					str:
												super().tearDown()
												# clean-up as much as possible GPU memory occupied by PyTorch
												gc.collect()
												torch.cuda.empty_cache()



					@slow
					def 				lowerCamelCase__(   self     :Any   )      ->					Dict:
												a__    =  CTRLLMHeadModel.from_pretrained('ctrl'   )
												model.to(__snake_case   )
												a__    =  torch.tensor(
												    [[1_18_59, 0, 16_11, 8]]    ,dtype=torch.long    ,device=__snake_case   )  # Legal the president is
												a__    =  [
												    1_18_59,
												    0,
												    16_11,
												    8,
												    5,
												    1_50,
												    2_64_49,
												    2,
												    19,
												    3_48,
												    4_69,
												    3,
												    25_95,
												    48,
												    2_07_40,
												    24_65_33,
												    24_65_33,
												    19,
												    30,
												    5,
												]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

												a__    =  model.generate(__snake_case    ,do_sample=__snake_case   )
												self.assertListEqual(output_ids[0].tolist()    ,__snake_case   )




