"""simple docstring"""
import argparse
import json
from collections import OrderedDict

import torch
from huggingface_hub import cached_download, hf_hub_url

from transformers import AutoImageProcessor, CvtConfig, CvtForImageClassification



def 					UpperCamelCase					(       SCREAMING_SNAKE_CASE_ )      ->Optional[Any]:
    _lowerCamelCase	: List[str]       =       []
    embed.append(
        (
            F'''cvt.encoder.stages.{idx}.embedding.convolution_embeddings.projection.weight''',
            F'''stage{idx}.patch_embed.proj.weight''',
        ) )
    embed.append(
        (
            F'''cvt.encoder.stages.{idx}.embedding.convolution_embeddings.projection.bias''',
            F'''stage{idx}.patch_embed.proj.bias''',
        ) )
    embed.append(
        (
            F'''cvt.encoder.stages.{idx}.embedding.convolution_embeddings.normalization.weight''',
            F'''stage{idx}.patch_embed.norm.weight''',
        ) )
    embed.append(
        (
            F'''cvt.encoder.stages.{idx}.embedding.convolution_embeddings.normalization.bias''',
            F'''stage{idx}.patch_embed.norm.bias''',
        ) )
    return embed



def 					UpperCamelCase					(       SCREAMING_SNAKE_CASE_						,	SCREAMING_SNAKE_CASE_ )      ->Union[str, Any]:
    _lowerCamelCase	: Tuple       =       []
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_query.convolution_projection.convolution.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_q.conv.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_query.convolution_projection.normalization.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_q.bn.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_query.convolution_projection.normalization.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_q.bn.bias''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_query.convolution_projection.normalization.running_mean''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_q.bn.running_mean''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_query.convolution_projection.normalization.running_var''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_q.bn.running_var''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_query.convolution_projection.normalization.num_batches_tracked''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_q.bn.num_batches_tracked''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_key.convolution_projection.convolution.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_k.conv.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_key.convolution_projection.normalization.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_k.bn.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_key.convolution_projection.normalization.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_k.bn.bias''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_key.convolution_projection.normalization.running_mean''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_k.bn.running_mean''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_key.convolution_projection.normalization.running_var''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_k.bn.running_var''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_key.convolution_projection.normalization.num_batches_tracked''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_k.bn.num_batches_tracked''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_value.convolution_projection.convolution.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_v.conv.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_value.convolution_projection.normalization.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_v.bn.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_value.convolution_projection.normalization.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_v.bn.bias''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_value.convolution_projection.normalization.running_mean''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_v.bn.running_mean''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_value.convolution_projection.normalization.running_var''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_v.bn.running_var''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.convolution_projection_value.convolution_projection.normalization.num_batches_tracked''',
            F'''stage{idx}.blocks.{cnt}.attn.conv_proj_v.bn.num_batches_tracked''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.projection_query.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.proj_q.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.projection_query.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.proj_q.bias''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.projection_key.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.proj_k.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.projection_key.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.proj_k.bias''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.projection_value.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.proj_v.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.attention.projection_value.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.proj_v.bias''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.output.dense.weight''',
            F'''stage{idx}.blocks.{cnt}.attn.proj.weight''',
        ) )
    attention_weights.append(
        (
            F'''cvt.encoder.stages.{idx}.layers.{cnt}.attention.output.dense.bias''',
            F'''stage{idx}.blocks.{cnt}.attn.proj.bias''',
        ) )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.intermediate.dense.weight''', F'''stage{idx}.blocks.{cnt}.mlp.fc1.weight''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.intermediate.dense.bias''', F'''stage{idx}.blocks.{cnt}.mlp.fc1.bias''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.output.dense.weight''', F'''stage{idx}.blocks.{cnt}.mlp.fc2.weight''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.output.dense.bias''', F'''stage{idx}.blocks.{cnt}.mlp.fc2.bias''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.layernorm_before.weight''', F'''stage{idx}.blocks.{cnt}.norm1.weight''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.layernorm_before.bias''', F'''stage{idx}.blocks.{cnt}.norm1.bias''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.layernorm_after.weight''', F'''stage{idx}.blocks.{cnt}.norm2.weight''') )
    attention_weights.append(
        (F'''cvt.encoder.stages.{idx}.layers.{cnt}.layernorm_after.bias''', F'''stage{idx}.blocks.{cnt}.norm2.bias''') )
    return attention_weights



def 					UpperCamelCase					(       SCREAMING_SNAKE_CASE_ )      ->List[Any]:
    _lowerCamelCase	: List[Any]       =       []
    token.append((F'''cvt.encoder.stages.{idx}.cls_token''', '''stage2.cls_token''') )
    return token



def 					UpperCamelCase					(       )      ->List[str]:
    _lowerCamelCase	: int       =       []
    head.append(('''layernorm.weight''', '''norm.weight''') )
    head.append(('''layernorm.bias''', '''norm.bias''') )
    head.append(('''classifier.weight''', '''head.weight''') )
    head.append(('''classifier.bias''', '''head.bias''') )
    return head



def 					UpperCamelCase					(       SCREAMING_SNAKE_CASE_						,	SCREAMING_SNAKE_CASE_						,	SCREAMING_SNAKE_CASE_						,	SCREAMING_SNAKE_CASE_ )      ->Union[str, Any]:
    _lowerCamelCase	: str       =       '''imagenet-1k-id2label.json'''
    _lowerCamelCase	: Optional[int]       =       1000

    _lowerCamelCase	: Tuple       =       '''huggingface/label-files'''
    _lowerCamelCase	: Optional[int]       =       num_labels
    _lowerCamelCase	: Optional[int]       =       json.load(open(cached_download(hf_hub_url(lowerCAmelCase_						,	lowerCAmelCase_						,	repo_type='''dataset''' ) )						,	'''r''' ) )
    _lowerCamelCase	: Dict       =       {int(lowerCAmelCase_ ): v for k, v in idalabel.items()}

    _lowerCamelCase	: List[Any]       =       idalabel
    _lowerCamelCase	: Optional[int]       =       {v: k for k, v in idalabel.items()}

    _lowerCamelCase	: List[str]       =       CvtConfig(num_labels=lowerCAmelCase_						,	idalabel=lowerCAmelCase_						,	labelaid=lowerCAmelCase_ )

    # For depth size 13 (13 = 1+2+10)
    if cvt_model.rsplit('''/'''						,	1 )[-1][4:6] == "13":
        _lowerCamelCase	: int       =       [1, 2, 10]

    # For depth size 21 (21 = 1+4+16)
    elif cvt_model.rsplit('''/'''						,	1 )[-1][4:6] == "21":
        _lowerCamelCase	: Union[str, Any]       =       [1, 4, 16]

    # For wide cvt (similar to wide-resnet) depth size 24 (w24 = 2 + 2 20)
    else:
        _lowerCamelCase	: List[str]       =       [2, 2, 20]
        _lowerCamelCase	: Union[str, Any]       =       [3, 12, 16]
        _lowerCamelCase	: Optional[Any]       =       [192, 768, 1024]

    _lowerCamelCase	: Any       =       CvtForImageClassification(lowerCAmelCase_ )
    _lowerCamelCase	: str       =       AutoImageProcessor.from_pretrained('''facebook/convnext-base-224-22k-1k''' )
    _lowerCamelCase	: List[Any]       =       image_size
    _lowerCamelCase	: Optional[int]       =       torch.load(lowerCAmelCase_						,	map_location=torch.device('''cpu''' ) )

    _lowerCamelCase	: List[Any]       =       OrderedDict()
    _lowerCamelCase	: str       =       []

    for idx in range(len(config.depth ) ):
        if config.cls_token[idx]:
            _lowerCamelCase	: List[Any]       =       list_of_state_dict + cls_token(lowerCAmelCase_ )
        _lowerCamelCase	: str       =       list_of_state_dict + embeddings(lowerCAmelCase_ )
        for cnt in range(config.depth[idx] ):
            _lowerCamelCase	: Any       =       list_of_state_dict + attention(lowerCAmelCase_						,	lowerCAmelCase_ )

    _lowerCamelCase	: Any       =       list_of_state_dict + final()
    for gg in list_of_state_dict:
        print(lowerCAmelCase_ )
    for i in range(len(lowerCAmelCase_ ) ):
        _lowerCamelCase	: Tuple       =       original_weights[list_of_state_dict[i][1]]

    model.load_state_dict(lowerCAmelCase_ )
    model.save_pretrained(lowerCAmelCase_ )
    image_processor.save_pretrained(lowerCAmelCase_ )


# Download the weights from zoo: https://1drv.ms/u/s!AhIXJn_J-blW9RzF3rMW7SsLHa8h?e=blQ0Al

if __name__ == "__main__":
  SCREAMING_SNAKE_CASE__   :      Union[str, Any]							=argparse.ArgumentParser()
  parser.add_argument(
      '--cvt_model',
      default='cvt-w24',
      type=str,
      help='Name of the cvt model you\'d like to convert.',
  )
  parser.add_argument(
      '--image_size',
      default=384,
      type=int,
      help='Input Image Size',
  )
  parser.add_argument(
      '--cvt_file_name',
      default=R'cvtmodels\CvT-w24-384x384-IN-22k.pth',
      type=str,
      help='Input Image Size',
  )
  parser.add_argument(
      '--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model directory.'
  )

  SCREAMING_SNAKE_CASE__   :      int							=parser.parse_args()
  convert_cvt_checkpoint(args.cvt_model, args.image_size, args.cvt_file_name, args.pytorch_dump_folder_path)









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	:


    '''simple docstring'''







    def __init__(       self   ,				A_   ,				A_=14   ,				A_=7   ,				A_=True   ,				A_=True   ,				A_=True   ,				A_=True   ,				A_=True   ,				A_=99   ,				A_=32   ,				A_=5   ,				A_=4   ,				A_=37   ,				A_="gelu"   ,				A_=0.1   ,				A_=0.1   ,				A_=5_12   ,				A_=16   ,				A_=2   ,				A_=0.02   ,				A_=3   ,				A_=4   ,				A_=None   ,				):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			parent
        SCREAMING_SNAKE_CASE__											=			batch_size
        SCREAMING_SNAKE_CASE__											=			seq_length
        SCREAMING_SNAKE_CASE__											=			is_training
        SCREAMING_SNAKE_CASE__											=			use_token_type_ids
        SCREAMING_SNAKE_CASE__											=			use_input_mask
        SCREAMING_SNAKE_CASE__											=			use_labels
        SCREAMING_SNAKE_CASE__											=			use_mc_token_ids
        SCREAMING_SNAKE_CASE__											=			vocab_size
        SCREAMING_SNAKE_CASE__											=			hidden_size
        SCREAMING_SNAKE_CASE__											=			num_hidden_layers
        SCREAMING_SNAKE_CASE__											=			num_attention_heads
        SCREAMING_SNAKE_CASE__											=			intermediate_size
        SCREAMING_SNAKE_CASE__											=			hidden_act
        SCREAMING_SNAKE_CASE__											=			hidden_dropout_prob
        SCREAMING_SNAKE_CASE__											=			attention_probs_dropout_prob
        SCREAMING_SNAKE_CASE__											=			max_position_embeddings
        SCREAMING_SNAKE_CASE__											=			type_vocab_size
        SCREAMING_SNAKE_CASE__											=			type_sequence_label_size
        SCREAMING_SNAKE_CASE__											=			initializer_range
        SCREAMING_SNAKE_CASE__											=			num_labels
        SCREAMING_SNAKE_CASE__											=			num_choices
        SCREAMING_SNAKE_CASE__											=			scope
        SCREAMING_SNAKE_CASE__											=			self.vocab_size - 1



    def  lowercase_					(       self     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			ids_tensor([self.batch_size, self.seq_length]   ,				self.vocab_size     )

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

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

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

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

        SCREAMING_SNAKE_CASE__											=			self.get_config()

        SCREAMING_SNAKE_CASE__											=			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  lowercase_					(       self     ):





        '''simple docstring'''

        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  lowercase_					(       self   ,				A_   ,				A_   ,				A_   ,				A_   ,				A_   ,				*A_     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			CTRLModel(config=A_     )
        model.to(A_     )
        model.eval()

        model(A_   ,				token_type_ids=A_   ,				head_mask=A_     )
        model(A_   ,				token_type_ids=A_     )
        SCREAMING_SNAKE_CASE__											=			model(A_     )
        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  lowercase_					(       self   ,				A_   ,				A_   ,				A_   ,				A_   ,				A_   ,				*A_     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			CTRLLMHeadModel(A_     )
        model.to(A_     )
        model.eval()

        SCREAMING_SNAKE_CASE__											=			model(A_   ,				token_type_ids=A_   ,				labels=A_     )
        self.parent.assertEqual(result.loss.shape   ,				()     )
        self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.seq_length, self.vocab_size)     )



    def  lowercase_					(       self     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			self.prepare_config_and_inputs()

        (
            (
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		(
            SCREAMING_SNAKE_CASE__
        )				,		
        )											=			config_and_inputs

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

        return config, inputs_dict




    def  lowercase_					(       self   ,				A_   ,				A_   ,				A_   ,				A_   ,				*A_     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			self.num_labels
        SCREAMING_SNAKE_CASE__											=			CTRLForSequenceClassification(A_     )
        model.to(A_     )
        model.eval()
        SCREAMING_SNAKE_CASE__											=			ids_tensor([self.batch_size]   ,				self.type_sequence_label_size     )
        SCREAMING_SNAKE_CASE__											=			model(A_   ,				token_type_ids=A_   ,				labels=A_     )
        self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.num_labels)     )





@require_torch
class 					__snake_case	(  __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE			,     unittest.TestCase    ):


    '''simple docstring'''







    lowerCamelCase__    :		Union[str, Any]				=	(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
    lowerCamelCase__    :		List[Any]				=	(CTRLLMHeadModel,) if is_torch_available() else ()
    lowerCamelCase__    :		Tuple				=	(
        {
            """feature-extraction""": CTRLModel,
            """text-classification""": CTRLForSequenceClassification,
            """text-generation""": CTRLLMHeadModel,
            """zero-shot""": CTRLForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    lowerCamelCase__    :		List[Any]				=	True
    lowerCamelCase__    :		Optional[int]				=	False
    lowerCamelCase__    :		Any				=	False



    def  lowercase_					(       self   ,				A_   ,				A_   ,				A_   ,				A_   ,				A_     ):





        '''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  lowercase_					(       self     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			CTRLModelTester(self     )
        SCREAMING_SNAKE_CASE__											=			ConfigTester(self   ,				config_class=A_   ,				n_embd=37     )



    def  lowercase_					(       self     ):





        '''simple docstring'''

        super().tearDown()
        # clean-up as much as possible GPU memory occupied by PyTorch
        gc.collect()
        torch.cuda.empty_cache()



    def  lowercase_					(       self     ):





        '''simple docstring'''

        self.config_tester.run_common_tests()



    def  lowercase_					(       self     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_ctrl_model(*A_     )



    def  lowercase_					(       self     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_lm_head_model(*A_     )



    @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''     )
    def  lowercase_					(       self     ):





        '''simple docstring'''

        pass



    @slow
    def  lowercase_					(       self     ):





        '''simple docstring'''

        for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
            SCREAMING_SNAKE_CASE__											=			CTRLModel.from_pretrained(A_     )
            self.assertIsNotNone(A_     )




    @unittest.skip('''The model doesn\'t support left padding'''     )  # and it's not used enough to be worth fixing :)
    def  lowercase_					(       self     ):





        '''simple docstring'''

        pass





@require_torch
class 					__snake_case	(  unittest.TestCase    ):


    '''simple docstring'''







    def  lowercase_					(       self     ):





        '''simple docstring'''

        super().tearDown()
        # clean-up as much as possible GPU memory occupied by PyTorch
        gc.collect()
        torch.cuda.empty_cache()




    @slow
    def  lowercase_					(       self     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			CTRLLMHeadModel.from_pretrained('''ctrl'''     )
        model.to(A_     )
        SCREAMING_SNAKE_CASE__											=			torch.tensor(
            [[1_18_59, 0, 16_11, 8]]   ,				dtype=torch.long   ,				device=A_     )  # Legal the president is
        SCREAMING_SNAKE_CASE__											=			[
            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

        SCREAMING_SNAKE_CASE__											=			model.generate(A_   ,				do_sample=A_     )
        self.assertListEqual(output_ids[0].tolist()   ,				A_     )
