




from __future__ import annotations

import random
import unittest

from transformers import TransfoXLConfig, 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
      import tensorflow as tf

      from transformers import (
          TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFTransfoXLForSequenceClassification,
          TFTransfoXLLMHeadModel,
          TFTransfoXLModel,
      )





class     SCREAMING_SNAKE_CASE__		:
     def __init__(						self	:		List[str]       ,						__lowerCamelCase	:		Any       ,						):



       """simple docstring"""
       lowerCAmelCase__										=      parent
       lowerCAmelCase__										=      13
       lowerCAmelCase__										=      7
       lowerCAmelCase__										=      30
       lowerCAmelCase__										=      self.seq_length + self.mem_len
       lowerCAmelCase__										=      15
       lowerCAmelCase__										=      True
       lowerCAmelCase__										=      True
       lowerCAmelCase__										=      99
       lowerCAmelCase__										=      [10, 50, 80]
       lowerCAmelCase__										=      32
       lowerCAmelCase__										=      32
       lowerCAmelCase__										=      4
       lowerCAmelCase__										=      8
       lowerCAmelCase__										=      1_28
       lowerCAmelCase__										=      2
       lowerCAmelCase__										=      2
       lowerCAmelCase__										=      None
       lowerCAmelCase__										=      1
       lowerCAmelCase__										=      0
       lowerCAmelCase__										=      3
       lowerCAmelCase__										=      self.vocab_size - 1
       lowerCAmelCase__										=      0.01
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size						)
       lowerCAmelCase__										=      ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size						)

       lowerCAmelCase__										=      None
       if self.use_labels:
         lowerCAmelCase__										=      ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size						)

       lowerCAmelCase__										=      TransfoXLConfig(
           vocab_size=self.vocab_size       ,						mem_len=self.mem_len       ,						clamp_len=self.clamp_len       ,						cutoffs=self.cutoffs       ,						d_model=self.hidden_size       ,						d_embed=self.d_embed       ,						n_head=self.num_attention_heads       ,						d_head=self.d_head       ,						d_inner=self.d_inner       ,						div_val=self.div_val       ,						n_layer=self.num_hidden_layers       ,						eos_token_id=self.eos_token_id       ,						pad_token_id=self.vocab_size - 1       ,						init_range=self.init_range       ,						num_labels=self.num_labels       ,						)

       return (config, input_ids_a, input_ids_a, lm_labels)
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       random.seed(self.seed						)
       tf.random.set_seed(self.seed						)
     def        A__      (						self	:		int       ,						__lowerCamelCase	:		List[str]       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		str       ,						__lowerCamelCase	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      TFTransfoXLModel(_snake_case						)

       lowerCAmelCase__				,      lowerCAmelCase__										=      model(_snake_case						).to_tuple()

       lowerCAmelCase__										=      {'''input_ids''': input_ids_a, '''mems''': mems_a}

       lowerCAmelCase__				,      lowerCAmelCase__										=      model(_snake_case						).to_tuple()

       self.parent.assertEqual(hidden_states_a.shape       ,						(self.batch_size, self.seq_length, self.hidden_size)						)
       self.parent.assertEqual(hidden_states_a.shape       ,						(self.batch_size, self.seq_length, self.hidden_size)						)
       self.parent.assertListEqual(
           [mem.shape for mem in mems_a]       ,						[(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers       ,						)
       self.parent.assertListEqual(
           [mem.shape for mem in mems_a]       ,						[(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers       ,						)
     def        A__      (						self	:		int       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      TFTransfoXLLMHeadModel(_snake_case						)

       lowerCAmelCase__				,      lowerCAmelCase__										=      model(_snake_case						).to_tuple()

       lowerCAmelCase__										=      {'''input_ids''': input_ids_a, '''labels''': lm_labels}
       lowerCAmelCase__				,      lowerCAmelCase__										=      model(_snake_case						).to_tuple()

       lowerCAmelCase__				,      lowerCAmelCase__										=      model([input_ids_a, mems_a]						).to_tuple()

       lowerCAmelCase__										=      {'''input_ids''': input_ids_a, '''mems''': mems_a, '''labels''': lm_labels}

       lowerCAmelCase__				,      lowerCAmelCase__										=      model(_snake_case						).to_tuple()

       self.parent.assertEqual(lm_logits_a.shape       ,						(self.batch_size, self.seq_length, self.vocab_size)						)
       self.parent.assertListEqual(
           [mem.shape for mem in mems_a]       ,						[(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers       ,						)

       self.parent.assertEqual(lm_logits_a.shape       ,						(self.batch_size, self.seq_length, self.vocab_size)						)
       self.parent.assertListEqual(
           [mem.shape for mem in mems_a]       ,						[(self.mem_len, self.batch_size, self.hidden_size)] * self.num_hidden_layers       ,						)
     def        A__      (						self	:		Optional[Any]       ,						__lowerCamelCase	:		Tuple       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		int       ,						__lowerCamelCase	:		Tuple						):



       """simple docstring"""
       lowerCAmelCase__										=      TFTransfoXLForSequenceClassification(_snake_case						)
       lowerCAmelCase__										=      model(_snake_case						)
       self.parent.assertEqual(result.logits.shape       ,						(self.batch_size, self.num_labels)						)



     def        A__      (						self	:		Optional[Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      self.prepare_config_and_inputs()
       ((lowerCAmelCase__)				,      (lowerCAmelCase__)				,      (lowerCAmelCase__)				,      (lowerCAmelCase__))										=      config_and_inputs
       lowerCAmelCase__										=      {'''input_ids''': input_ids_a}
       return config, inputs_dict





@require_tf
class     SCREAMING_SNAKE_CASE__		(UpperCAmelCase_    ,					UpperCAmelCase_    ,					unittest.TestCase			):
     lowercase_ :      Optional[Any]				= (
         (TFTransfoXLModel, TFTransfoXLLMHeadModel, TFTransfoXLForSequenceClassification) if is_tf_available() else ()
     )
     lowercase_ :      str				= () if is_tf_available() else ()
     lowercase_ :      Optional[int]				= (
         {
             "feature-extraction": TFTransfoXLModel,
             "text-classification": TFTransfoXLForSequenceClassification,
             "text-generation": TFTransfoXLLMHeadModel,
             "zero-shot": TFTransfoXLForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     # TODO: add this test when TFTransfoXLLMHead has a linear output layer implemented
     lowercase_ :      List[str]				= False
     lowercase_ :      int				= False
     lowercase_ :      Tuple				= False
     lowercase_ :      Dict				= False
     def        A__      (						self	:		Dict       ,						__lowerCamelCase	:		List[Any]       ,						__lowerCamelCase	:		int       ,						__lowerCamelCase	:		Dict       ,						__lowerCamelCase	:		List[str]       ,						__lowerCamelCase	:		str						):



       """simple docstring"""


       if pipeline_test_casse_name == "TextGenerationPipelineTests":
         # Get `ValueError: AttributeError: 'NoneType' object has no attribute 'new_ones'` or `AssertionError`.
         # `TransfoXLConfig` was never used in pipeline tests: cannot create a simple
         # tokenizer.
         return True

       return False
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__										=      TFTransfoXLModelTester(self						)
       lowerCAmelCase__										=      ConfigTester(self       ,						config_class=_snake_case       ,						d_embed=37						)
     def        A__      (						self	:		Tuple						):



       """simple docstring"""
       self.config_tester.run_common_tests()
     def        A__      (						self	:		Any						):



       """simple docstring"""
       self.model_tester.set_seed()
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_transfo_xl_model(*_snake_case						)
     def        A__      (						self	:		Dict						):



       """simple docstring"""
       self.model_tester.set_seed()
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_transfo_xl_lm_head(*_snake_case						)
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_transfo_xl_for_sequence_classification(*_snake_case						)
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       lowerCAmelCase__				,      lowerCAmelCase__										=      self.model_tester.prepare_config_and_inputs_for_common()
       lowerCAmelCase__										=      [TFTransfoXLForSequenceClassification]

       for model_class in self.all_model_classes:
         lowerCAmelCase__										=      model_class(_snake_case						)
         assert isinstance(model.get_input_embeddings()       ,						tf.keras.layers.Layer						)
         if model_class in list_other_models_with_output_ebd:
           lowerCAmelCase__										=      model.get_output_embeddings()
           assert isinstance(_snake_case       ,						tf.keras.layers.Layer						)
           lowerCAmelCase__										=      model.get_bias()
           assert name is None
         else:
           lowerCAmelCase__										=      model.get_output_embeddings()
           assert x is None
           lowerCAmelCase__										=      model.get_bias()
           assert name is None
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       pass
     @slow
     def        A__      (						self	:		str						):



       """simple docstring"""


       for model_name in TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         lowerCAmelCase__										=      TFTransfoXLModel.from_pretrained(_snake_case						)
         self.assertIsNotNone(_snake_case						)



     @unittest.skip(reason='''This model doesn\'t play well with fit() due to not returning a single loss.'''						)
     def        A__      (						self	:		Union[str, Any]						):



       """simple docstring"""
       pass





@require_tf
class     SCREAMING_SNAKE_CASE__		(unittest.TestCase			):
     @unittest.skip('''Skip test until #12651 is resolved.'''						)
     @slow
     def        A__      (						self	:		int						):



       """simple docstring"""
       lowerCAmelCase__										=      TFTransfoXLLMHeadModel.from_pretrained('''transfo-xl-wt103'''						)
       # fmt: off
       lowerCAmelCase__										=      tf.convert_to_tensor([[33,12_97,2,1,10_09,4,11_09,1_17_39,47_62,3_58,5,25,2_45,22,17_06,17,2_00_98,5,32_15,21,37,11_10,3,13,10_41,4,24,6_03,4_90,2,7_14_77,2_00_98,10_44_47,2,2_09_61,1,26_04,4,1,3_29,3,62_24,8_31,1_60_02,2,8,6_03,7_89_67,2_95_46,23,8_03,20,25,4_16,5,8,2_32,4,2_77,6,18_55,46_01,3,2_95_46,54,8,36_09,5,5_72_11,49,4,1,2_77,18,8,17_55,1_56_91,3,3_41,25,4_16,6_93,4_25_73,71,17,4_01,94,31,1_79_19,2,2_95_46,78_73,18,1,4_35,23,1_10_11,7_55,5,51_67,3,79_83,98,84,2,2_95_46,32_67,8,36_09,4,1,48_65,10_75,2,60_87,71,6,3_46,8,58_54,3,2_95_46,8_24,14_00,18_68,2,19,1_60,2,3_11,8,54_96,2,2_09_20,17,25,1_50_97,3,24,24,0]]       ,						dtype=tf.intaa						)  # noqa: E231
       # fmt: on
       #  In 1991 , the remains of Russian Tsar Nicholas II and his family
       #  ( except for Alexei and Maria ) are discovered .
       #  The voice of Nicholas's young son , Tsarevich Alexei Nikolaevich , narrates the
       #  remainder of the story . 1883 Western Siberia ,
       #  a young Grigori Rasputin is asked by his father and a group of men to perform magic .
       #  Rasputin has a vision and denounces one of the men as a horse thief . Although his
       #  father initially slaps him for making such an accusation , Rasputin watches as the
       #  man is chased outside and beaten . Twenty years later , Rasputin sees a vision of
       #  the Virgin Mary , prompting him to become a priest . Rasputin quickly becomes famous ,
       #  with people , even a bishop , begging for his blessing . <eod> </s> <eos>

       # fmt: off
       lowerCAmelCase__										=      [33,12_97,2,1,10_09,4,11_09,1_17_39,47_62,3_58,5,25,2_45,22,17_06,17,2_00_98,5,32_15,21,37,11_10,3,13,10_41,4,24,6_03,4_90,2,7_14_77,2_00_98,10_44_47,2,2_09_61,1,26_04,4,1,3_29,3,62_24,8_31,1_60_02,2,8,6_03,7_89_67,2_95_46,23,8_03,20,25,4_16,5,8,2_32,4,2_77,6,18_55,46_01,3,2_95_46,54,8,36_09,5,5_72_11,49,4,1,2_77,18,8,17_55,1_56_91,3,3_41,25,4_16,6_93,4_25_73,71,17,4_01,94,31,1_79_19,2,2_95_46,78_73,18,1,4_35,23,1_10_11,7_55,5,51_67,3,79_83,98,84,2,2_95_46,32_67,8,36_09,4,1,48_65,10_75,2,60_87,71,6,3_46,8,58_54,3,2_95_46,8_24,14_00,18_68,2,19,1_60,2,3_11,8,54_96,2,2_09_20,17,25,1_50_97,3,24,24,0,33,1,18_57,2,1,10_09,4,11_09,1_17_39,47_62,3_58,5,25,2_45,28,11_10,3,13,10_41,4,24,6_03,4_90,2,7_14_77,2_00_98,10_44_47,2,2_09_61,1,26_04,4,1,3_29,3,0]  # noqa: E231
       # fmt: on
       #  In 1991, the remains of Russian Tsar Nicholas II and his family (
       #  except for Alexei and Maria ) are discovered. The voice of young son,
       #  Tsarevich Alexei Nikolaevich, narrates the remainder of the story.
       #  1883 Western Siberia, a young Grigori Rasputin is asked by his father
       #  and a group of men to perform magic. Rasputin has a vision and
       #  denounces one of the men as a horse thief. Although his father initially
       #  slaps him for making such an accusation, Rasputin watches as the man
       #  is chased outside and beaten. Twenty years later, Rasputin sees a vision
       #  of the Virgin Mary, prompting him to become a priest.
       #  Rasputin quickly becomes famous, with people, even a bishop, begging for
       #  his blessing. <unk> <unk> <eos> In the 1990s, the remains of Russian Tsar
       # Nicholas II and his family were discovered. The voice of <unk> young son,
       # Tsarevich Alexei Nikolaevich, narrates the remainder of the story.<eos>

       lowerCAmelCase__										=      model.generate(_snake_case       ,						max_length=2_00       ,						do_sample=_snake_case						)
       self.assertListEqual(output_ids[0].numpy().tolist()       ,						_snake_case						)






import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import BeitConfig, BeitForImageClassification, BeitForMaskedImageModeling, BeitImageProcessor
from transformers.image_utils import PILImageResampling
from transformers.utils import logging


logging.set_verbosity_info()
SCREAMING_SNAKE_CASE__   			=   logging.get_logger(__name__)


def A    (							__UpperCamelCase			,						__UpperCamelCase=False			,						__UpperCamelCase=False       )    ->   Dict:
			A__	  =     'backbone.' if is_semantic else ''

			A__	  =     []
			for i in range(config.num_hidden_layers       ):
						# encoder layers: output projection, 2 feedforward neural networks and 2 layernorms
						rename_keys.append((f'''{prefix}blocks.{i}.norm1.weight''', f'''beit.encoder.layer.{i}.layernorm_before.weight''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.norm1.bias''', f'''beit.encoder.layer.{i}.layernorm_before.bias''')       )
						rename_keys.append(
						    (f'''{prefix}blocks.{i}.attn.proj.weight''', f'''beit.encoder.layer.{i}.attention.output.dense.weight''')       )
						rename_keys.append(
						    (f'''{prefix}blocks.{i}.attn.proj.bias''', f'''beit.encoder.layer.{i}.attention.output.dense.bias''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.norm2.weight''', f'''beit.encoder.layer.{i}.layernorm_after.weight''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.norm2.bias''', f'''beit.encoder.layer.{i}.layernorm_after.bias''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.mlp.fc1.weight''', f'''beit.encoder.layer.{i}.intermediate.dense.weight''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.mlp.fc1.bias''', f'''beit.encoder.layer.{i}.intermediate.dense.bias''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.mlp.fc2.weight''', f'''beit.encoder.layer.{i}.output.dense.weight''')       )
						rename_keys.append((f'''{prefix}blocks.{i}.mlp.fc2.bias''', f'''beit.encoder.layer.{i}.output.dense.bias''')       )

			# projection layer + position embeddings
			rename_keys.extend(
			    [
			        (f'''{prefix}cls_token''', 'beit.embeddings.cls_token'),
			        (f'''{prefix}patch_embed.proj.weight''', 'beit.embeddings.patch_embeddings.projection.weight'),
			        (f'''{prefix}patch_embed.proj.bias''', 'beit.embeddings.patch_embeddings.projection.bias'),
			        (f'''{prefix}pos_embed''', 'beit.embeddings.position_embeddings'),
			    ]       )

			if has_lm_head:
						# mask token + layernorm
						rename_keys.extend(
						    [
						        ('mask_token', 'beit.embeddings.mask_token'),
						        ('norm.weight', 'layernorm.weight'),
						        ('norm.bias', 'layernorm.bias'),
						    ]       )
			else:
						# layernorm + classification head
						rename_keys.extend(
						    [
						        ('fc_norm.weight', 'beit.pooler.layernorm.weight'),
						        ('fc_norm.bias', 'beit.pooler.layernorm.bias'),
						        ('head.weight', 'classifier.weight'),
						        ('head.bias', 'classifier.bias'),
						    ]       )

			return rename_keys


def A    (							__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase=False			,						__UpperCamelCase=False       )    ->   Optional[Any]:
			for i in range(config.num_hidden_layers       ):
						A__	  =     'backbone.' if is_semantic else ''
						# queries, keys and values
						A__	  =     state_dict.pop(f'''{prefix}blocks.{i}.attn.qkv.weight'''       )
						A__	  =     state_dict.pop(f'''{prefix}blocks.{i}.attn.q_bias'''       )
						A__	  =     state_dict.pop(f'''{prefix}blocks.{i}.attn.v_bias'''       )

						A__	  =     in_proj_weight[
						    : config.hidden_size, :
						]
						A__	  =     q_bias
						A__	  =     in_proj_weight[
						    config.hidden_size : config.hidden_size * 2, :
						]
						A__	  =     in_proj_weight[
						    -config.hidden_size :, :
						]
						A__	  =     v_bias

						# gamma_1 and gamma_2
						# we call them lambda because otherwise they are renamed when using .from_pretrained
						A__	  =     state_dict.pop(f'''{prefix}blocks.{i}.gamma_1'''       )
						A__	  =     state_dict.pop(f'''{prefix}blocks.{i}.gamma_2'''       )

						A__	  =     gamma_a
						A__	  =     gamma_a


def A    (							__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )    ->   Union[str, Any]:
			A__	  =     dct.pop(__UpperCamelCase       )
			A__	  =     val


def A    (							)    ->   Dict:
			A__	  =     'http://images.cocodataset.org/val2017/000000039769.jpg'
			A__	  =     Image.open(requests.get(__UpperCamelCase			,						stream=__UpperCamelCase       ).raw       )
			return im


@torch.no_grad()
def A    (							__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase=False       )    ->   str:
			A__	  =     False if 'rvlcdip' in checkpoint_url else True
			A__	  =     BeitConfig(use_absolute_position_embeddings=__UpperCamelCase			,						use_mask_token=__UpperCamelCase       )

			# size of the architecture
			if "large" in checkpoint_url or "dit-l" in checkpoint_url:
						A__	  =     1_024
						A__	  =     4_096
						A__	  =     24
						A__	  =     16

			# labels
			if "rvlcdip" in checkpoint_url:
						A__	  =     16
						A__	  =     'huggingface/label-files'
						A__	  =     'rvlcdip-id2label.json'
						A__	  =     json.load(open(hf_hub_download(__UpperCamelCase			,						__UpperCamelCase			,						repo_type='dataset'       )			,						'r'       )       )
						A__	  =     {int(__UpperCamelCase       ): v for k, v in idalabel.items()}
						A__	  =     idalabel
						A__	  =     {v: k for k, v in idalabel.items()}

			# load state_dict of original model, remove and rename some keys
			A__	  =     torch.hub.load_state_dict_from_url(__UpperCamelCase			,						map_location='cpu'       )['model']

			A__	  =     create_rename_keys(__UpperCamelCase			,						has_lm_head=__UpperCamelCase       )
			for src, dest in rename_keys:
						rename_key(__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )
			read_in_q_k_v(__UpperCamelCase			,						__UpperCamelCase			,						has_lm_head=__UpperCamelCase       )

			# load HuggingFace model
			A__	  =     BeitForMaskedImageModeling(__UpperCamelCase       ) if has_lm_head else BeitForImageClassification(__UpperCamelCase       )
			model.eval()
			model.load_state_dict(__UpperCamelCase       )

			# Check outputs on an image
			A__	  =     BeitImageProcessor(
			    size=config.image_size			,						resample=PILImageResampling.BILINEAR			,						do_center_crop=__UpperCamelCase       )
			A__	  =     prepare_img()

			A__	  =     image_processor(images=__UpperCamelCase			,						return_tensors='pt'       )
			A__	  =     encoding['pixel_values']

			A__	  =     model(__UpperCamelCase       )
			A__	  =     outputs.logits

			# verify logits
			A__	  =     [1, 16] if 'rvlcdip' in checkpoint_url else [1, 196, 8_192]
			assert logits.shape == torch.Size(__UpperCamelCase       ), "Shape of logits not as expected"

			Path(__UpperCamelCase       ).mkdir(exist_ok=__UpperCamelCase       )
			print(f'''Saving model to {pytorch_dump_folder_path}'''       )
			model.save_pretrained(__UpperCamelCase       )
			print(f'''Saving image processor to {pytorch_dump_folder_path}'''       )
			image_processor.save_pretrained(__UpperCamelCase       )

			if push_to_hub:
						if has_lm_head:
									A__	  =     'dit-base' if 'base' in checkpoint_url else 'dit-large'
						else:
									A__	  =     'dit-base-finetuned-rvlcdip' if 'dit-b' in checkpoint_url else 'dit-large-finetuned-rvlcdip'
						image_processor.push_to_hub(
						    repo_path_or_name=Path(__UpperCamelCase			,						__UpperCamelCase       )			,						organization='nielsr'			,						commit_message='Add image processor'			,						use_temp_dir=__UpperCamelCase			,						)
						model.push_to_hub(
						    repo_path_or_name=Path(__UpperCamelCase			,						__UpperCamelCase       )			,						organization='nielsr'			,						commit_message='Add model'			,						use_temp_dir=__UpperCamelCase			,						)


if __name__ == "__main__":
							SCREAMING_SNAKE_CASE__   			=   argparse.ArgumentParser()

							parser.add_argument(
							    '''--checkpoint_url''',
							    default='''https://layoutlm.blob.core.windows.net/dit/dit-pts/dit-base-224-p16-500k-62d53a.pth''',
							    type=str,
							    help='''URL to the original PyTorch checkpoint (.pth file).''',
							)
							parser.add_argument(
							    '''--pytorch_dump_folder_path''', default=None, type=str, help='''Path to the folder to output PyTorch model.'''
							)
							parser.add_argument(
							    '''--push_to_hub''',
							    action='''store_true''',
							)
							SCREAMING_SNAKE_CASE__   			=   parser.parse_args()
							convert_dit_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path, args.push_to_hub)




