






from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCamelCase    :      str  			=		logging.get_logger(__name__)

UpperCamelCase    :      str  			=		{
    'facebook/deit-base-distilled-patch16-224': (
        'https://huggingface.co/facebook/deit-base-patch16-224/resolve/main/config.json'
    ),
    # See all DeiT models at https://huggingface.co/models?filter=deit
}




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					'deit'






		def __init__(      self   ,_lowerCAmelCase=7_68   ,_lowerCAmelCase=12   ,_lowerCAmelCase=12   ,_lowerCAmelCase=30_72   ,_lowerCAmelCase="gelu"   ,_lowerCAmelCase=0.0   ,_lowerCAmelCase=0.0   ,_lowerCAmelCase=0.02   ,_lowerCAmelCase=1E-12   ,_lowerCAmelCase=2_24   ,_lowerCAmelCase=16   ,_lowerCAmelCase=3   ,_lowerCAmelCase=True   ,_lowerCAmelCase=16   ,**_lowerCAmelCase   ,):
								super().__init__(**_lowerCAmelCase       )

								lowerCamelCase__         =  hidden_size
								lowerCamelCase__         =  num_hidden_layers
								lowerCamelCase__         =  num_attention_heads
								lowerCamelCase__         =  intermediate_size
								lowerCamelCase__         =  hidden_act
								lowerCamelCase__         =  hidden_dropout_prob
								lowerCamelCase__         =  attention_probs_dropout_prob
								lowerCamelCase__         =  initializer_range
								lowerCamelCase__         =  layer_norm_eps
								lowerCamelCase__         =  image_size
								lowerCamelCase__         =  patch_size
								lowerCamelCase__         =  num_channels
								lowerCamelCase__         =  qkv_bias
								lowerCamelCase__         =  encoder_stride




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					version.parse('1.11'			)






		@property
		def 			UpperCamelCase_					(      self       ):
								return OrderedDict(
								    [
								        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
								    ]       )






		@property
		def 			UpperCamelCase_					(      self       ):
								return 1E-4









'''simple docstring'''







import json
from typing import Iterator, List, Union

from tokenizers import AddedToken, Regex, Tokenizer, decoders, normalizers, pre_tokenizers, trainers
from tokenizers.implementations.base_tokenizer import BaseTokenizer
from tokenizers.models import Unigram
from tokenizers.processors import TemplateProcessing




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		def __init__(      self   ,_lowerCAmelCase = "▁"   ,_lowerCAmelCase = True   ,_lowerCAmelCase = "<unk>"   ,_lowerCAmelCase = "</s>"   ,_lowerCAmelCase = "<pad>"   ,):
								lowerCamelCase__         =  {
								    """pad""": {"""id""": 0, """token""": pad_token},
								    """eos""": {"""id""": 1, """token""": eos_token},
								    """unk""": {"""id""": 2, """token""": unk_token},
								}

								lowerCamelCase__         =  [None] * len(self.special_tokens       )
								for token_dict in self.special_tokens.values():
														lowerCamelCase__         =  token_dict["""token"""]

								lowerCamelCase__         =  Tokenizer(Unigram()       )

								lowerCamelCase__         =  normalizers.Sequence(
								    [
								        normalizers.Nmt(),
								        normalizers.NFKC(),
								        normalizers.Replace(Regex(""" {2,}"""       )   ,""" """       ),
								        normalizers.Lowercase(),
								    ]       )
								lowerCamelCase__         =  pre_tokenizers.Sequence(
								    [
								        pre_tokenizers.Metaspace(replacement=_lowerCAmelCase   ,add_prefix_space=_lowerCAmelCase       ),
								        pre_tokenizers.Digits(individual_digits=_lowerCAmelCase       ),
								        pre_tokenizers.Punctuation(),
								    ]       )
								lowerCamelCase__         =  decoders.Metaspace(replacement=_lowerCAmelCase   ,add_prefix_space=_lowerCAmelCase       )

								lowerCamelCase__         =  TemplateProcessing(
								    single=F'''$A {self.special_tokens["eos"]["token"]}'''   ,special_tokens=[(self.special_tokens["""eos"""]["""token"""], self.special_tokens["""eos"""]["""id"""])]   ,)

								lowerCamelCase__         =  {
								    """model""": """SentencePieceUnigram""",
								    """replacement""": replacement,
								    """add_prefix_space""": add_prefix_space,
								}

								super().__init__(_lowerCAmelCase   ,_lowerCAmelCase       )






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase = 80_00   ,_lowerCAmelCase = True   ,):
								lowerCamelCase__         =  trainers.UnigramTrainer(
								    vocab_size=_lowerCAmelCase   ,special_tokens=self.special_tokens_list   ,show_progress=_lowerCAmelCase   ,)

								if isinstance(_lowerCAmelCase   ,_lowerCAmelCase       ):
														lowerCamelCase__         =  [files]
								self._tokenizer.train(_lowerCAmelCase   ,trainer=_lowerCAmelCase       )

								self.add_unk_id()






		def 			UpperCamelCase_					(      self   ,_lowerCAmelCase   ,_lowerCAmelCase = 80_00   ,_lowerCAmelCase = True   ,):
								lowerCamelCase__         =  trainers.UnigramTrainer(
								    vocab_size=_lowerCAmelCase   ,special_tokens=self.special_tokens_list   ,show_progress=_lowerCAmelCase   ,)

								self._tokenizer.train_from_iterator(_lowerCAmelCase   ,trainer=_lowerCAmelCase       )

								self.add_unk_id()






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  json.loads(self._tokenizer.to_str()       )

								lowerCamelCase__         =  self.special_tokens["""unk"""]["""id"""]

								lowerCamelCase__         =  Tokenizer.from_str(json.dumps(_lowerCAmelCase       )       )

