





import argparse
import os

import torch

from transformers.utils import WEIGHTS_NAME


__A							   =							["small", "medium", "large"]

__A							   =							"lm_head.decoder.weight"
__A							   =							"lm_head.weight"





def 	lowerCAmelCase_					(			__a      ,       __a						)	->						Optional[Any]:







  """simple docstring"""





  lowerCamelCase__: List[Any]         =torch.load(__a						)
  lowerCamelCase__: Optional[int]         =d.pop(__a						)
  os.makedirs(__a      ,       exist_ok=__a						)
  torch.save(__a      ,       os.path.join(__a      ,       __a						)						)


if __name__ == "__main__":
     __A							   =							argparse.ArgumentParser()
     parser.add_argument("--dialogpt_path", default=".", type=str)
     __A							   =							parser.parse_args()
     for MODEL in DIALOGPT_MODELS:
          __A							   =							os.path.join(args.dialogpt_path, f'{MODEL}_ft.pkl')
          __A							   =							f'./DialoGPT-{MODEL}'
          convert_dialogpt_checkpoint(
              checkpoint_path,
              pytorch_dump_folder_path,
          )







import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
     import torch

     from transformers import AutoModelForImageClassification

if is_vision_available():
     from transformers import AutoImageProcessor

@require_torch
@require_vision
class     __a(	unittest.TestCase  ):






    """simple docstring"""





    @slow
    def 				a__ ( self    )					->						List[str]:
         UpperCAmelCase_     :				Tuple  =     AutoImageProcessor.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''    )
         UpperCAmelCase_     :				Union[str, Any]  =     AutoModelForImageClassification.from_pretrained('''microsoft/dit-base-finetuned-rvlcdip'''    )
         model.to(_SCREAMING_SNAKE_CASE    )

         from datasets import load_dataset

         UpperCAmelCase_     :				Optional[int]  =     load_dataset('''nielsr/rvlcdip-demo'''    )

         UpperCAmelCase_     :				Optional[Any]  =     dataset['''train'''][0]['''image'''].convert('''RGB'''    )

         UpperCAmelCase_     :				str  =     image_processor(_SCREAMING_SNAKE_CASE  ,return_tensors='''pt'''    ).to(_SCREAMING_SNAKE_CASE    )

         # forward pass
         with torch.no_grad():
              UpperCAmelCase_     :				Optional[int]  =     model(**_SCREAMING_SNAKE_CASE    )
              UpperCAmelCase_     :				List[Any]  =     outputs.logits

         UpperCAmelCase_     :				Tuple  =     torch.Size((1, 16)    )
         self.assertEqual(logits.shape  ,_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				int  =     torch.tensor(
             [-0.41_58, -0.40_92, -0.43_47]  ,device=_SCREAMING_SNAKE_CASE  ,dtype=torch.float  ,)
         self.assertTrue(torch.allclose(logits[0, :3]  ,_SCREAMING_SNAKE_CASE  ,atol=1e-4    )    )