






import unittest

from transformers import DebertaVaTokenizer, DebertaVaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


_A     :      Optional[int]   					=get_tests_dir('''fixtures/spiece.model''')

@require_sentencepiece
@require_tokenizers
class _lowercase     (    a__    ,				unittest.TestCase		):
							a    				=	DebertaVaTokenizer
							a    				=	DebertaVaTokenizerFast
							a    				=	True
							a    				=	True




							def 		lowerCamelCase_    (							self:    str					):
														super().setUp()

														# We have a SentencePiece fixture for testing
														lowerCamelCase__ :     Optional[Any]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							unk_token="""<unk>"""					)
														tokenizer.save_pretrained(self.tmpdirname					)




							def 		lowerCamelCase_    (							self:    str      ,							UpperCamelCase__:    Optional[Any]					):
														lowerCamelCase__ :     List[str]	  =	"this is a test"
														lowerCamelCase__ :     Tuple	  =	"this is a test"
														return input_text, output_text




							def 		lowerCamelCase_    (							self:    List[Any]					):
														lowerCamelCase__ :     Optional[Any]	  =	"<pad>"
														lowerCamelCase__ :     Optional[int]	  =	0

														self.assertEqual(self.get_tokenizer()._convert_token_to_id(lowerCAmelCase__					)      ,							lowerCAmelCase__					)
														self.assertEqual(self.get_tokenizer()._convert_id_to_token(lowerCAmelCase__					)      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    Optional[Any]					):
														lowerCamelCase__ :     int	  =	list(self.get_tokenizer().get_vocab().keys()					)
														self.assertEqual(vocab_keys[0]      ,							"""<pad>"""					)
														self.assertEqual(vocab_keys[1]      ,							"""<unk>"""					)
														self.assertEqual(vocab_keys[-1]      ,							"""[PAD]"""					)
														self.assertEqual(len(lowerCAmelCase__					)      ,							30_001					)




							def 		lowerCamelCase_    (							self:    int					):
														self.assertEqual(self.get_tokenizer().vocab_size      ,							30_000					)




							def 		lowerCamelCase_    (							self:    str					):
														# fmt: off
														lowerCamelCase__ :     List[Any]	  =	" \tHeLLo!how  \n Are yoU?  "
														lowerCamelCase__ :     str	  =	["▁hello", "!", "how", "▁are", "▁you", "?"]
														# fmt: on

														lowerCamelCase__ :     Union[str, Any]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__					)
														lowerCamelCase__ :     List[str]	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Optional[int]	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__					)
														lowerCamelCase__ :     Tuple	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							@unittest.skip("""There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."""					)
							def 		lowerCamelCase_    (							self:    List[Any]					):
														pass




							@unittest.skip("""There is an inconsistency between slow and fast tokenizer due to a bug in the fast one."""					)
							def 		lowerCamelCase_    (							self:    int					):
														pass




							def 		lowerCamelCase_    (							self:    int					):
														# fmt: off
														lowerCamelCase__ :     List[Any]	  =	"I was born in 92000, and this is falsé."
														lowerCamelCase__ :     Tuple	  =	["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
														# fmt: on

														lowerCamelCase__ :     Optional[int]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     int	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Union[str, Any]	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Tuple	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    Optional[int]					):
														# fmt: off
														lowerCamelCase__ :     List[str]	  =	"I was born in 92000, and this is falsé."
														lowerCamelCase__ :     str	  =	["▁i", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
														# fmt: on

														lowerCamelCase__ :     Union[str, Any]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Any	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Optional[int]	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Tuple	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    Tuple					):
														# fmt: off
														lowerCamelCase__ :     Dict	  =	"I was born in 92000, and this is falsé."
														lowerCamelCase__ :     Optional[int]	  =	["▁i", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", ".", ]
														# fmt: on

														lowerCamelCase__ :     List[Any]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     List[Any]	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Optional[Any]	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Union[str, Any]	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    List[str]					):
														# fmt: off
														lowerCamelCase__ :     str	  =	"I was born in 92000, and this is falsé."
														lowerCamelCase__ :     List[str]	  =	["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", "▁", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", "▁", ".", ]
														# fmt: on

														lowerCamelCase__ :     List[Any]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     List[str]	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Any	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Optional[int]	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    Union[str, Any]					):
														# fmt: off
														lowerCamelCase__ :     str	  =	" \tHeLLo!how  \n Are yoU?  "
														lowerCamelCase__ :     str	  =	["▁", "<unk>", "e", "<unk>", "o", "!", "how", "▁", "<unk>", "re", "▁yo", "<unk>", "?"]
														# fmt: on

														lowerCamelCase__ :     Optional[Any]	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Optional[Any]	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     List[Any]	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							do_lower_case=lowerCAmelCase__      ,							split_by_punct=lowerCAmelCase__					)
														lowerCamelCase__ :     Tuple	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)

														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    str					):
														lowerCamelCase__ :     Any	  =	self.get_tokenizer()
														lowerCamelCase__ :     str	  =	self.get_rust_tokenizer()

														lowerCamelCase__ :     List[Any]	  =	"I was born in 92000, and this is falsé."

														lowerCamelCase__ :     Optional[int]	  =	tokenizer.convert_ids_to_tokens(tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)
														lowerCamelCase__ :     Dict	  =	rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     str	  =	tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)
														lowerCamelCase__ :     Dict	  =	rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Union[str, Any]	  =	self.get_rust_tokenizer()
														lowerCamelCase__ :     Any	  =	tokenizer.encode(lowerCAmelCase__					)
														lowerCamelCase__ :     Union[str, Any]	  =	rust_tokenizer.encode(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    List[Any]					):
														lowerCamelCase__ :     str	  =	"This is a test"
														lowerCamelCase__ :     List[Any]	  =	[13, 1, 4_398, 25, 21, 1_289]
														lowerCamelCase__ :     Optional[int]	  =	["▁", "T", "his", "▁is", "▁a", "▁test"]
														lowerCamelCase__ :     Dict	  =	["▁", "<unk>", "his", "▁is", "▁a", "▁test"]

														lowerCamelCase__ :     Any	  =	DebertaVaTokenizer(lowerCAmelCase__      ,							keep_accents=lowerCAmelCase__					)
														lowerCamelCase__ :     List[Any]	  =	DebertaVaTokenizerFast(lowerCAmelCase__      ,							keep_accents=lowerCAmelCase__					)

														lowerCamelCase__ :     Optional[int]	  =	tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     List[Any]	  =	tokenizer.tokenize(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     List[Any]	  =	tokenizer.convert_ids_to_tokens(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     List[Any]	  =	rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     Dict	  =	rust_tokenizer.tokenize(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     Tuple	  =	rust_tokenizer.convert_ids_to_tokens(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														# fmt: off
														lowerCamelCase__ :     Optional[int]	  =	"I was born in 92000, and this is falsé."
														lowerCamelCase__ :     int	  =	[13, 1, 23, 386, 19, 561, 3_050, 15, 17, 48, 25, 8_256, 18, 1, 9]
														lowerCamelCase__ :     Optional[int]	  =	["▁", "I", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "é", ".", ]
														lowerCamelCase__ :     Optional[int]	  =	["▁", "<unk>", "▁was", "▁born", "▁in", "▁9", "2000", ",", "▁and", "▁this", "▁is", "▁fal", "s", "<unk>", ".", ]
														# fmt: on

														lowerCamelCase__ :     str	  =	tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     Any	  =	tokenizer.tokenize(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     str	  =	tokenizer.convert_ids_to_tokens(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)

														lowerCamelCase__ :     Any	  =	rust_tokenizer.encode(lowerCAmelCase__      ,							add_special_tokens=lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     Any	  =	rust_tokenizer.tokenize(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)
														lowerCamelCase__ :     Any	  =	rust_tokenizer.convert_ids_to_tokens(lowerCAmelCase__					)
														self.assertListEqual(lowerCAmelCase__      ,							lowerCAmelCase__					)




							def 		lowerCamelCase_    (							self:    Any					):
														lowerCamelCase__ :     str	  =	DebertaVaTokenizer(lowerCAmelCase__					)

														lowerCamelCase__ :     str	  =	tokenizer.encode("""sequence builders"""					)
														lowerCamelCase__ :     Optional[Any]	  =	tokenizer.encode("""multi-sequence build"""					)

														lowerCamelCase__ :     str	  =	tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__					)
														lowerCamelCase__ :     Dict	  =	tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__      ,							lowerCAmelCase__					)

														self.assertEqual([tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]      ,							lowerCAmelCase__					)
														self.assertEqual(
														    [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [tokenizer.sep_token_id]      ,							lowerCAmelCase__      ,							)




							@slow
							def 		lowerCamelCase_    (							self:    Dict					):
														# fmt: off
														lowerCamelCase__ :     str	  =	{"input_ids": [[1, 39_867, 36, 19_390, 486, 27, 35_052, 81_436, 18, 60_685, 1_225, 7, 35_052, 81_436, 18, 9_367, 16_899, 18, 15_937, 53, 594, 773, 18, 16_287, 30_465, 36, 15_937, 6, 41_139, 38, 36_979, 60_763, 191, 6, 34_132, 99, 6, 50_538, 390, 43_230, 6, 34_132, 2_779, 20_850, 14, 699, 1_072, 1_194, 36, 382, 10_901, 53, 7, 699, 1_072, 2_084, 36, 20_422, 630, 53, 19, 105, 3_049, 1_896, 1_053, 16_899, 1_506, 11, 37_978, 4_243, 7, 1_237, 31_869, 200, 16_566, 654, 6, 35_052, 81_436, 7, 55_630, 13_593, 4, 2], [1, 26, 15_011, 13, 667, 8, 1_053, 18, 23_611, 1_237, 72_356, 12_820, 34, 104_134, 1_209, 35, 13_313, 6_627, 21, 202, 347, 7, 164, 2_399, 11, 46, 4_485, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 5, 1_232, 2_864, 15_785, 14_951, 105, 5, 8_581, 1_250, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "token_type_ids": [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], "attention_mask": [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
														# fmt: on

														self.tokenizer_integration_test_util(
														    expected_encoding=lowerCAmelCase__      ,							model_name="""microsoft/deberta-v2-xlarge"""      ,							revision="""ad6e42c1532ddf3a15c39246b63f5559d558b670"""      ,							)









'''simple docstring'''







import argparse

import requests
import torch
from PIL import Image

from transformers import ViTMAEConfig, ViTMAEForPreTraining, ViTMAEImageProcessor





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase				)				->	List[Any]:
							if "cls_token" in name:
														lowerCamelCase__ :     Any	  =	name.replace("""cls_token"""    ,      """vit.embeddings.cls_token"""				)
							if "mask_token" in name:
														lowerCamelCase__ :     Union[str, Any]	  =	name.replace("""mask_token"""    ,      """decoder.mask_token"""				)
							if "decoder_pos_embed" in name:
														lowerCamelCase__ :     Tuple	  =	name.replace("""decoder_pos_embed"""    ,      """decoder.decoder_pos_embed"""				)
							if "pos_embed" in name and "decoder" not in name:
														lowerCamelCase__ :     str	  =	name.replace("""pos_embed"""    ,      """vit.embeddings.position_embeddings"""				)
							if "patch_embed.proj" in name:
														lowerCamelCase__ :     Optional[int]	  =	name.replace("""patch_embed.proj"""    ,      """vit.embeddings.patch_embeddings.projection"""				)
							if "patch_embed.norm" in name:
														lowerCamelCase__ :     Any	  =	name.replace("""patch_embed.norm"""    ,      """vit.embeddings.norm"""				)
							if "decoder_blocks" in name:
														lowerCamelCase__ :     Dict	  =	name.replace("""decoder_blocks"""    ,      """decoder.decoder_layers"""				)
							if "blocks" in name:
														lowerCamelCase__ :     Union[str, Any]	  =	name.replace("""blocks"""    ,      """vit.encoder.layer"""				)
							if "attn.proj" in name:
														lowerCamelCase__ :     List[Any]	  =	name.replace("""attn.proj"""    ,      """attention.output.dense"""				)
							if "attn" in name:
														lowerCamelCase__ :     List[str]	  =	name.replace("""attn"""    ,      """attention.self"""				)
							if "norm1" in name:
														lowerCamelCase__ :     Any	  =	name.replace("""norm1"""    ,      """layernorm_before"""				)
							if "norm2" in name:
														lowerCamelCase__ :     Dict	  =	name.replace("""norm2"""    ,      """layernorm_after"""				)
							if "mlp.fc1" in name:
														lowerCamelCase__ :     str	  =	name.replace("""mlp.fc1"""    ,      """intermediate.dense"""				)
							if "mlp.fc2" in name:
														lowerCamelCase__ :     Union[str, Any]	  =	name.replace("""mlp.fc2"""    ,      """output.dense"""				)
							if "decoder_embed" in name:
														lowerCamelCase__ :     Tuple	  =	name.replace("""decoder_embed"""    ,      """decoder.decoder_embed"""				)
							if "decoder_norm" in name:
														lowerCamelCase__ :     Optional[int]	  =	name.replace("""decoder_norm"""    ,      """decoder.decoder_norm"""				)
							if "decoder_pred" in name:
														lowerCamelCase__ :     int	  =	name.replace("""decoder_pred"""    ,      """decoder.decoder_pred"""				)
							if "norm.weight" in name and "decoder" not in name:
														lowerCamelCase__ :     Union[str, Any]	  =	name.replace("""norm.weight"""    ,      """vit.layernorm.weight"""				)
							if "norm.bias" in name and "decoder" not in name:
														lowerCamelCase__ :     Dict	  =	name.replace("""norm.bias"""    ,      """vit.layernorm.bias"""				)

							return name





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	Tuple:
							for key in orig_state_dict.copy().keys():
														lowerCamelCase__ :     List[str]	  =	orig_state_dict.pop(UpperCamelCase				)

														if "qkv" in key:
																					lowerCamelCase__ :     List[Any]	  =	key.split("""."""				)
																					lowerCamelCase__ :     Optional[int]	  =	int(key_split[1]				)
																					if "decoder_blocks" in key:
																												lowerCamelCase__ :     str	  =	config.decoder_hidden_size
																												lowerCamelCase__ :     List[Any]	  =	"""decoder.decoder_layers."""
																												if "weight" in key:
																																			lowerCamelCase__ :     int	  =	val[:dim, :]
																																			lowerCamelCase__ :     int	  =	val[dim : dim * 2, :]
																																			lowerCamelCase__ :     Tuple	  =	val[-dim:, :]
																												elif "bias" in key:
																																			lowerCamelCase__ :     Tuple	  =	val[:dim]
																																			lowerCamelCase__ :     Optional[int]	  =	val[dim : dim * 2]
																																			lowerCamelCase__ :     List[Any]	  =	val[-dim:]
																					else:
																												lowerCamelCase__ :     List[Any]	  =	config.hidden_size
																												lowerCamelCase__ :     Optional[int]	  =	"""vit.encoder.layer."""
																												if "weight" in key:
																																			lowerCamelCase__ :     str	  =	val[:dim, :]
																																			lowerCamelCase__ :     List[Any]	  =	val[dim : dim * 2, :]
																																			lowerCamelCase__ :     Optional[int]	  =	val[-dim:, :]
																												elif "bias" in key:
																																			lowerCamelCase__ :     int	  =	val[:dim]
																																			lowerCamelCase__ :     List[Any]	  =	val[dim : dim * 2]
																																			lowerCamelCase__ :     Optional[int]	  =	val[-dim:]

														else:
																					lowerCamelCase__ :     int	  =	val

							return orig_state_dict





def 			SCREAMING_SNAKE_CASE_	(UpperCamelCase    ,      UpperCamelCase				)				->	int:
							lowerCamelCase__ :     Any	  =	ViTMAEConfig()
							if "large" in checkpoint_url:
														lowerCamelCase__ :     Any	  =	1024
														lowerCamelCase__ :     Optional[Any]	  =	4096
														lowerCamelCase__ :     List[str]	  =	24
														lowerCamelCase__ :     Union[str, Any]	  =	16
							elif "huge" in checkpoint_url:
														lowerCamelCase__ :     List[str]	  =	14
														lowerCamelCase__ :     Dict	  =	1280
														lowerCamelCase__ :     Tuple	  =	5120
														lowerCamelCase__ :     List[str]	  =	32
														lowerCamelCase__ :     Union[str, Any]	  =	16

							lowerCamelCase__ :     List[Any]	  =	ViTMAEForPreTraining(UpperCamelCase				)

							lowerCamelCase__ :     str	  =	torch.hub.load_state_dict_from_url(UpperCamelCase    ,      map_location="""cpu"""				)["""model"""]

							lowerCamelCase__ :     Union[str, Any]	  =	ViTMAEImageProcessor(size=config.image_size				)

							lowerCamelCase__ :     List[str]	  =	convert_state_dict(UpperCamelCase    ,      UpperCamelCase				)

							model.load_state_dict(UpperCamelCase				)
							model.eval()

							lowerCamelCase__ :     Union[str, Any]	  =	"""https://user-images.githubusercontent.com/11435359/147738734-196fd92f-9260-48d5-ba7e-bf103d29364d.jpg"""

							lowerCamelCase__ :     List[Any]	  =	Image.open(requests.get(UpperCamelCase    ,      stream=UpperCamelCase				).raw				)
							lowerCamelCase__ :     str	  =	ViTMAEImageProcessor(size=config.image_size				)
							lowerCamelCase__ :     Any	  =	image_processor(images=UpperCamelCase    ,      return_tensors="""pt"""				)

							# forward pass
							torch.manual_seed(2				)
							lowerCamelCase__ :     Optional[Any]	  =	model(**UpperCamelCase				)
							lowerCamelCase__ :     Optional[Any]	  =	outputs.logits

							if "large" in checkpoint_url:
														lowerCamelCase__ :     List[Any]	  =	torch.tensor(
														    [[-0.7309, -0.7128, -1.0169], [-1.0161, -0.9058, -1.1878], [-1.0478, -0.9411, -1.1911]]				)
							elif "huge" in checkpoint_url:
														lowerCamelCase__ :     Optional[Any]	  =	torch.tensor(
														    [[-1.1599, -0.9199, -1.2221], [-1.1952, -0.9269, -1.2307], [-1.2143, -0.9337, -1.2262]]				)
							else:
														lowerCamelCase__ :     int	  =	torch.tensor(
														    [[-0.9192, -0.8481, -1.1259], [-1.1349, -1.0034, -1.2599], [-1.1757, -1.0429, -1.2726]]				)

							# verify logits
							assert torch.allclose(logits[0, :3, :3]    ,      UpperCamelCase    ,      atol=1E-4				)

							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 __name__ == "__main__":
			_A     :      str   					=argparse.ArgumentParser()
			# Required parameters
			parser.add_argument(
			    '''--checkpoint_url''',
			    default='''https://dl.fbaipublicfiles.com/mae/visualize/mae_visualize_vit_base.pth''',
			    type=str,
			    help='''URL of the checkpoint you\'d like to convert.''',
			)
			parser.add_argument(
			    '''--pytorch_dump_folder_path''', default=None, type=str, help='''Path to the output PyTorch model directory.'''
			)

			_A     :      Tuple   					=parser.parse_args()
			convert_vit_mae_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path)

