



import logging
import os
from dataclasses import dataclass, field
from typing import Dict, Optional

import datasets
import numpy as np
import tensorflow as tf

from transformers import (
    AutoConfig,
    AutoTokenizer,
    EvalPrediction,
    HfArgumentParser,
    PreTrainedTokenizer,
    TFAutoModelForSequenceClassification,
    TFTrainer,
    TFTrainingArguments,
)
from transformers.utils import logging as hf_logging


hf_logging.set_verbosity_info()
hf_logging.enable_default_handler()
hf_logging.enable_explicit_format()


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__ = None					,			):

				"""simple docstring"""


				lowercase__					:   List[str]													=					{}

				if train_file is not None:
								lowercase__					:   str													=					[train_file]
				if eval_file is not None:
								lowercase__					:   int													=					[eval_file]
				if test_file is not None:
								lowercase__					:   str													=					[test_file]

				lowercase__					:   List[Any]													=					datasets.load_dataset("csv"					,			data_files=lowerCamelCase__						)
				lowercase__					:   Optional[int]													=					list(ds[list(files.keys()						)[0]].features.keys()						)
				lowercase__					:   Optional[Any]													=					features_name.pop(lowerCamelCase__						)
				lowercase__					:   Dict													=					list(set(ds[list(files.keys()						)[0]][label_name]						)						)
				lowercase__					:   Optional[Any]													=					{label: i for i, label in enumerate(lowerCamelCase__						)}
				lowercase__					:   List[Any]													=					tokenizer.model_input_names
				lowercase__					:   int													=					{}

				if len(lowerCamelCase__						) == 1:
								for k in files.keys():
												lowercase__					:   int													=					ds[k].map(
												    lambda lowerCamelCase__						: tokenizer.batch_encode_plus(
												        example[features_name[0]]					,			truncation=lowerCamelCase__					,			max_length=lowerCamelCase__					,			padding="max_length"						)					,			batched=lowerCamelCase__					,			)
				elif len(lowerCamelCase__						) == 2:
								for k in files.keys():
												lowercase__					:   str													=					ds[k].map(
												    lambda lowerCamelCase__						: tokenizer.batch_encode_plus(
												        (example[features_name[0]], example[features_name[1]])					,			truncation=lowerCamelCase__					,			max_length=lowerCamelCase__					,			padding="max_length"					,			)					,			batched=lowerCamelCase__					,			)

				def gen_train():
								for ex in transformed_ds[datasets.Split.TRAIN]:
												lowercase__					:   Optional[int]													=					{k: v for k, v in ex.items() if k in input_names}
												lowercase__					:   str													=					labelaid[ex[label_name]]
												yield (d, label)

				def gen_val():
								for ex in transformed_ds[datasets.Split.VALIDATION]:
												lowercase__					:   List[Any]													=					{k: v for k, v in ex.items() if k in input_names}
												lowercase__					:   List[Any]													=					labelaid[ex[label_name]]
												yield (d, label)

				def gen_test():
								for ex in transformed_ds[datasets.Split.TEST]:
												lowercase__					:   Dict													=					{k: v for k, v in ex.items() if k in input_names}
												lowercase__					:   Any													=					labelaid[ex[label_name]]
												yield (d, label)

				lowercase__					:   int													=					(
				    tf.data.Dataset.from_generator(
				        lowerCamelCase__					,			({k: tf.intaa for k in input_names}, tf.intaa)					,			({k: tf.TensorShape([None]						) for k in input_names}, tf.TensorShape([]						))					,			)
				    if datasets.Split.TRAIN in transformed_ds
				    else None
				)

				if train_ds is not None:
								lowercase__					:   Optional[int]													=					train_ds.apply(tf.data.experimental.assert_cardinality(len(ds[datasets.Split.TRAIN]						)						)						)

				lowercase__					:   Any													=					(
				    tf.data.Dataset.from_generator(
				        lowerCamelCase__					,			({k: tf.intaa for k in input_names}, tf.intaa)					,			({k: tf.TensorShape([None]						) for k in input_names}, tf.TensorShape([]						))					,			)
				    if datasets.Split.VALIDATION in transformed_ds
				    else None
				)

				if val_ds is not None:
								lowercase__					:   Tuple													=					val_ds.apply(tf.data.experimental.assert_cardinality(len(ds[datasets.Split.VALIDATION]						)						)						)

				lowercase__					:   Optional[int]													=					(
				    tf.data.Dataset.from_generator(
				        lowerCamelCase__					,			({k: tf.intaa for k in input_names}, tf.intaa)					,			({k: tf.TensorShape([None]						) for k in input_names}, tf.TensorShape([]						))					,			)
				    if datasets.Split.TEST in transformed_ds
				    else None
				)

				if test_ds is not None:
								lowercase__					:   Tuple													=					test_ds.apply(tf.data.experimental.assert_cardinality(len(ds[datasets.Split.TEST]						)						)						)

				return train_ds, val_ds, test_ds, labelaid


lowerCAmelCase__					  =  logging.getLogger(__name__)

@dataclass
class 				snake_case__:

					"""simple docstring"""






					lowercase_								=		field(metadata={"""help""": """Which column contains the label"""}      )
					lowercase_								=		field(default=_UpperCamelCase    ,      metadata={"""help""": """The path of the training file"""}      )
					lowercase_								=		field(default=_UpperCamelCase    ,      metadata={"""help""": """The path of the development file"""}      )
					lowercase_								=		field(default=_UpperCamelCase    ,      metadata={"""help""": """The path of the test file"""}      )
					lowercase_								=		field(
					    default=1_2_8    ,      metadata={
					        """help""": (
					            """The maximum total input sequence length after tokenization. Sequences longer """
					            """than this will be truncated, sequences shorter will be padded."""
					        )
					    }    ,      )
					lowercase_								=		field(
					    default=_UpperCamelCase    ,      metadata={"""help""": """Overwrite the cached training and evaluation sets"""}      )






@dataclass
class 				snake_case__:

					"""simple docstring"""






					lowercase_								=		field(
					    metadata={"""help""": """Path to pretrained model or model identifier from huggingface.co/models"""}      )
					lowercase_								=		field(
					    default=_UpperCamelCase    ,      metadata={"""help""": """Pretrained config name or path if not the same as model_name"""}      )
					lowercase_								=		field(
					    default=_UpperCamelCase    ,      metadata={"""help""": """Pretrained tokenizer name or path if not the same as model_name"""}      )
					lowercase_								=		field(default=_UpperCamelCase    ,      metadata={"""help""": """Set this flag to use fast tokenization."""}      )
					# If you want to tweak more attributes on your tokenizer, you should do it in a distinct script,
					# or just modify its tokenizer_config.json.
					lowercase_								=		field(
					    default=_UpperCamelCase    ,      metadata={"""help""": """Where do you want to store the pretrained models downloaded from huggingface.co"""}    ,      )






def  __lowerCamelCase (       ):

				"""simple docstring"""


				lowercase__					:   Union[str, Any]													=					HfArgumentParser((ModelArguments, DataTrainingArguments, TFTrainingArguments)						)
				lowercase__							,							lowercase__							,							lowercase__					:   List[str]													=					parser.parse_args_into_dataclasses()

				if (
				    os.path.exists(training_args.output_dir						)
				    and os.listdir(training_args.output_dir						)
				    and training_args.do_train
				    and not training_args.overwrite_output_dir
				):
								raise ValueError(
								    F"""Output directory ({training_args.output_dir}) already exists and is not empty. Use"""
								    " --overwrite_output_dir to overcome."						)

				# Setup logging
				logging.basicConfig(
				    format="%(asctime)s - %(levelname)s - %(name)s - %(message)s"					,			datefmt="%m/%d/%Y %H:%M:%S"					,			level=logging.INFO					,			)
				logger.info(
				    F"""n_replicas: {training_args.n_replicas}, distributed training: {bool(training_args.n_replicas > 1						)}, """
				    F"""16-bits training: {training_args.fpaa}"""						)
				logger.info(F"""Training/evaluation parameters {training_args}"""						)

				# Load pretrained model and tokenizer
				#
				# Distributed training:
				# The .from_pretrained methods guarantee that only one local process can concurrently
				# download model & vocab.

				lowercase__					:   Tuple													=					AutoTokenizer.from_pretrained(
				    model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path					,			cache_dir=model_args.cache_dir					,			)

				lowercase__							,							lowercase__							,							lowercase__							,							lowercase__					:   Optional[int]													=					get_tfds(
				    train_file=data_args.train_file					,			eval_file=data_args.dev_file					,			test_file=data_args.test_file					,			tokenizer=lowerCamelCase__					,			label_column_id=data_args.label_column_id					,			max_seq_length=data_args.max_seq_length					,			)

				lowercase__					:   List[str]													=					AutoConfig.from_pretrained(
				    model_args.config_name if model_args.config_name else model_args.model_name_or_path					,			num_labels=len(lowerCamelCase__						)					,			labelaid=lowerCamelCase__					,			idalabel={id: label for label, id in labelaid.items()}					,			finetuning_task="text-classification"					,			cache_dir=model_args.cache_dir					,			)

				with training_args.strategy.scope():
								lowercase__					:   Union[str, Any]													=					TFAutoModelForSequenceClassification.from_pretrained(
								    model_args.model_name_or_path					,			from_pt=bool(".bin" in model_args.model_name_or_path						)					,			config=lowerCamelCase__					,			cache_dir=model_args.cache_dir					,			)

				def compute_metrics(lowerCamelCase__						) -> Dict:
								lowercase__					:   Dict													=					np.argmax(p.predictions					,			axis=1						)

								return {"acc": (preds == p.label_ids).mean()}

				# Initialize our Trainer
				lowercase__					:   List[str]													=					TFTrainer(
				    model=lowerCamelCase__					,			args=lowerCamelCase__					,			train_dataset=lowerCamelCase__					,			eval_dataset=lowerCamelCase__					,			compute_metrics=lowerCamelCase__					,			)

				# Training
				if training_args.do_train:
								trainer.train()
								trainer.save_model()
								tokenizer.save_pretrained(training_args.output_dir						)

				# Evaluation
				lowercase__					:   Optional[Any]													=					{}
				if training_args.do_eval:
								logger.info("*** Evaluate ***"						)
								lowercase__					:   List[Any]													=					trainer.evaluate()
								lowercase__					:   int													=					os.path.join(training_args.output_dir					,			"eval_results.txt"						)

								with open(lowerCamelCase__					,			"w"						) as writer:
												logger.info("***** Eval results *****"						)

												for key, value in result.items():
																logger.info(F"""  {key} = {value}"""						)
																writer.write(F"""{key} = {value}\n"""						)

												results.update(lowerCamelCase__						)

				return results


if __name__ == "__main__":
				main()









import inspect
import unittest

import numpy as np

from transformers import BeitConfig
from transformers.testing_utils import require_flax, require_vision, slow
from transformers.utils import cached_property, is_flax_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor


if is_flax_available():
				import jax

				from transformers import FlaxBeitForImageClassification, FlaxBeitForMaskedImageModeling, FlaxBeitModel

if is_vision_available():
				from PIL import Image

				from transformers import BeitImageProcessor

class 				snake_case__(unittest.TestCase      ):

					"""simple docstring"""






					def __init__(							self :     List[Any]				,       SCREAMING_SNAKE_CASE :     Tuple				,       SCREAMING_SNAKE_CASE :     Optional[int]=100				,       SCREAMING_SNAKE_CASE :     Tuple=13				,       SCREAMING_SNAKE_CASE :     str=30				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=2				,       SCREAMING_SNAKE_CASE :     Tuple=3				,       SCREAMING_SNAKE_CASE :     List[Any]=True				,       SCREAMING_SNAKE_CASE :     int=True				,       SCREAMING_SNAKE_CASE :     Dict=32				,       SCREAMING_SNAKE_CASE :     str=5				,       SCREAMING_SNAKE_CASE :     Any=4				,       SCREAMING_SNAKE_CASE :     str=37				,       SCREAMING_SNAKE_CASE :     Any="gelu"				,       SCREAMING_SNAKE_CASE :     Tuple=0.1				,       SCREAMING_SNAKE_CASE :     Optional[Any]=0.1				,       SCREAMING_SNAKE_CASE :     Union[str, Any]=10				,       SCREAMING_SNAKE_CASE :     Dict=0.02				,       SCREAMING_SNAKE_CASE :     Any=3				,       ):
									lowercase__					:   Optional[int]													=					parent
									lowercase__					:   Optional[int]													=					vocab_size
									lowercase__					:   Dict													=					batch_size
									lowercase__					:   List[Any]													=					image_size
									lowercase__					:   List[Any]													=					patch_size
									lowercase__					:   Tuple													=					num_channels
									lowercase__					:   Any													=					is_training
									lowercase__					:   str													=					use_labels
									lowercase__					:   List[Any]													=					hidden_size
									lowercase__					:   Optional[int]													=					num_hidden_layers
									lowercase__					:   Dict													=					num_attention_heads
									lowercase__					:   Optional[int]													=					intermediate_size
									lowercase__					:   int													=					hidden_act
									lowercase__					:   str													=					hidden_dropout_prob
									lowercase__					:   Union[str, Any]													=					attention_probs_dropout_prob
									lowercase__					:   int													=					type_sequence_label_size
									lowercase__					:   Optional[int]													=					initializer_range

									# in BeiT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
									lowercase__					:   str													=					(image_size // patch_size) ** 2
									lowercase__					:   List[str]													=					num_patches + 1







					def 			snake_case					(							self :     Tuple					):
									lowercase__					:   List[Any]													=					floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

									lowercase__					:   Union[str, Any]													=					None
									if self.use_labels:
													lowercase__					:   List[Any]													=					ids_tensor([self.batch_size]				,       self.type_sequence_label_size					)

									lowercase__					:   int													=					BeitConfig(
									    vocab_size=self.vocab_size				,       image_size=self.image_size				,       patch_size=self.patch_size				,       num_channels=self.num_channels				,       hidden_size=self.hidden_size				,       num_hidden_layers=self.num_hidden_layers				,       num_attention_heads=self.num_attention_heads				,       intermediate_size=self.intermediate_size				,       hidden_act=self.hidden_act				,       hidden_dropout_prob=self.hidden_dropout_prob				,       attention_probs_dropout_prob=self.attention_probs_dropout_prob				,       is_decoder=SCREAMING_SNAKE_CASE				,       initializer_range=self.initializer_range				,       )

									return config, pixel_values, labels







					def 			snake_case					(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     List[str]				,       SCREAMING_SNAKE_CASE :     Dict				,       SCREAMING_SNAKE_CASE :     List[Any]					):
									lowercase__					:   Optional[Any]													=					FlaxBeitModel(config=SCREAMING_SNAKE_CASE					)
									lowercase__					:   Optional[int]													=					model(SCREAMING_SNAKE_CASE					)
									self.parent.assertEqual(result.last_hidden_state.shape				,       (self.batch_size, self.seq_length, self.hidden_size)					)







					def 			snake_case					(							self :     Union[str, Any]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     Tuple				,       SCREAMING_SNAKE_CASE :     List[str]					):
									lowercase__					:   int													=					FlaxBeitForMaskedImageModeling(config=SCREAMING_SNAKE_CASE					)
									lowercase__					:   Union[str, Any]													=					model(SCREAMING_SNAKE_CASE					)
									self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.seq_length - 1, self.vocab_size)					)







					def 			snake_case					(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     str				,       SCREAMING_SNAKE_CASE :     List[Any]				,       SCREAMING_SNAKE_CASE :     Any					):
									lowercase__					:   Tuple													=					self.type_sequence_label_size
									lowercase__					:   Optional[int]													=					FlaxBeitForImageClassification(config=SCREAMING_SNAKE_CASE					)
									lowercase__					:   str													=					model(SCREAMING_SNAKE_CASE					)
									self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.type_sequence_label_size)					)

									# test greyscale images
									lowercase__					:   int													=					1
									lowercase__					:   List[str]													=					FlaxBeitForImageClassification(SCREAMING_SNAKE_CASE					)

									lowercase__					:   int													=					floats_tensor([self.batch_size, 1, self.image_size, self.image_size]					)
									lowercase__					:   List[str]													=					model(SCREAMING_SNAKE_CASE					)







					def 			snake_case					(							self :     Any					):
									lowercase__					:   Optional[Any]													=					self.prepare_config_and_inputs()
									(
									    (
									    lowercase__
									)							,							(
									    lowercase__
									)							,							(
									    lowercase__
									)							,							
									)					:   str													=					config_and_inputs
									lowercase__					:   Dict													=					{"pixel_values": pixel_values}
									return config, inputs_dict






@require_flax
class 				snake_case__(_UpperCamelCase    ,      unittest.TestCase      ):

					"""simple docstring"""






					lowercase_								=		(
					    (FlaxBeitModel, FlaxBeitForImageClassification, FlaxBeitForMaskedImageModeling) if is_flax_available() else ()
					)







					def 			snake_case					(							self :     Any					):
									lowercase__					:   List[Any]													=					FlaxBeitModelTester(self					)
									lowercase__					:   str													=					ConfigTester(self				,       config_class=SCREAMING_SNAKE_CASE				,       has_text_modality=SCREAMING_SNAKE_CASE				,       hidden_size=37					)







					def 			snake_case					(							self :     int					):
									self.config_tester.run_common_tests()







					def 			snake_case					(							self :     int					):
									lowercase__							,							lowercase__					:   Tuple													=					self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													lowercase__					:   List[str]													=					model_class(SCREAMING_SNAKE_CASE					)
													lowercase__					:   str													=					inspect.signature(model.__call__					)
													# signature.parameters is an OrderedDict => so arg_names order is deterministic
													lowercase__					:   Optional[int]													=					[*signature.parameters.keys()]

													lowercase__					:   str													=					["pixel_values"]
													self.assertListEqual(arg_names[:1]				,       SCREAMING_SNAKE_CASE					)







					def 			snake_case					(							self :     List[Any]					):
									lowercase__							,							lowercase__					:   Optional[Any]													=					self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													with self.subTest(model_class.__name__					):
																	lowercase__					:   Optional[int]													=					self._prepare_for_class(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					)
																	lowercase__					:   List[str]													=					model_class(SCREAMING_SNAKE_CASE					)

																	@jax.jit
																	def model_jitted(SCREAMING_SNAKE_CASE :     Optional[Any]				,       **SCREAMING_SNAKE_CASE :     List[Any]					):
																					return model(pixel_values=SCREAMING_SNAKE_CASE				,       **SCREAMING_SNAKE_CASE					)

																	with self.subTest("JIT Enabled"					):
																					lowercase__					:   Union[str, Any]													=					model_jitted(**SCREAMING_SNAKE_CASE					).to_tuple()

																	with self.subTest("JIT Disabled"					):
																					with jax.disable_jit():
																									lowercase__					:   Optional[int]													=					model_jitted(**SCREAMING_SNAKE_CASE					).to_tuple()

																	self.assertEqual(len(SCREAMING_SNAKE_CASE					)				,       len(SCREAMING_SNAKE_CASE					)					)
																	for jitted_output, output in zip(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):
																					self.assertEqual(jitted_output.shape				,       output.shape					)







					def 			snake_case					(							self :     Optional[int]					):
									lowercase__					:   Union[str, Any]													=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE					)







					def 			snake_case					(							self :     int					):
									lowercase__					:   List[Any]													=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE					)







					def 			snake_case					(							self :     Optional[Any]					):
									lowercase__					:   int													=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE					)







					@slow
					def 			snake_case					(							self :     Optional[int]					):
									for model_class_name in self.all_model_classes:
													lowercase__					:   Any													=					model_class_name.from_pretrained("microsoft/beit-base-patch16-224"					)
													lowercase__					:   Optional[int]													=					model(np.ones((1, 3, 224, 224)					)					)
													self.assertIsNotNone(SCREAMING_SNAKE_CASE					)






def  __lowerCamelCase (       ):

				"""simple docstring"""


				lowercase__					:   Dict													=					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
				return image

@require_vision
@require_flax
class 				snake_case__(unittest.TestCase      ):

					"""simple docstring"""






					@cached_property
					def 			snake_case					(							self :     int					):
									return BeitImageProcessor.from_pretrained("microsoft/beit-base-patch16-224"					) if is_vision_available() else None







					@slow
					def 			snake_case					(							self :     Union[str, Any]					):
									lowercase__					:   Tuple													=					FlaxBeitForMaskedImageModeling.from_pretrained("microsoft/beit-base-patch16-224-pt22k"					)

									lowercase__					:   int													=					self.default_image_processor
									lowercase__					:   Union[str, Any]													=					prepare_img()
									lowercase__					:   str													=					image_processor(images=SCREAMING_SNAKE_CASE				,       return_tensors="np"					).pixel_values

									# prepare bool_masked_pos
									lowercase__					:   Optional[Any]													=					np.ones((1, 196)				,       dtype=SCREAMING_SNAKE_CASE					)

									# forward pass
									lowercase__					:   Any													=					model(pixel_values=SCREAMING_SNAKE_CASE				,       bool_masked_pos=SCREAMING_SNAKE_CASE					)
									lowercase__					:   Tuple													=					outputs.logits

									# verify the logits
									lowercase__					:   List[str]													=					(1, 196, 8_192)
									self.assertEqual(logits.shape				,       SCREAMING_SNAKE_CASE					)

									lowercase__					:   Dict													=					np.array(
									    [[-3.2_437, 0.5_072, -13.9_174], [-3.2_456, 0.4_948, -13.9_401], [-3.2_033, 0.5_121, -13.8_550]]					)

									self.assertTrue(np.allclose(logits[bool_masked_pos][:3, :3]				,       SCREAMING_SNAKE_CASE				,       atol=1E-2					)					)







					@slow
					def 			snake_case					(							self :     Any					):
									lowercase__					:   Union[str, Any]													=					FlaxBeitForImageClassification.from_pretrained("microsoft/beit-base-patch16-224"					)

									lowercase__					:   Tuple													=					self.default_image_processor
									lowercase__					:   List[Any]													=					prepare_img()
									lowercase__					:   Optional[Any]													=					image_processor(images=SCREAMING_SNAKE_CASE				,       return_tensors="np"					)

									# forward pass
									lowercase__					:   str													=					model(**SCREAMING_SNAKE_CASE					)
									lowercase__					:   Dict													=					outputs.logits

									# verify the logits
									lowercase__					:   List[str]													=					(1, 1_000)
									self.assertEqual(logits.shape				,       SCREAMING_SNAKE_CASE					)

									lowercase__					:   Tuple													=					np.array([-1.2_385, -1.0_987, -1.0_108]					)

									self.assertTrue(np.allclose(logits[0, :3]				,       SCREAMING_SNAKE_CASE				,       atol=1E-4					)					)

									lowercase__					:   str													=					281
									self.assertEqual(logits.argmax(-1					).item()				,       SCREAMING_SNAKE_CASE					)







					@slow
					def 			snake_case					(							self :     str					):
									lowercase__					:   List[Any]													=					FlaxBeitForImageClassification.from_pretrained("microsoft/beit-large-patch16-224-pt22k-ft22k"					)

									lowercase__					:   Dict													=					self.default_image_processor
									lowercase__					:   Dict													=					prepare_img()
									lowercase__					:   List[Any]													=					image_processor(images=SCREAMING_SNAKE_CASE				,       return_tensors="np"					)

									# forward pass
									lowercase__					:   Union[str, Any]													=					model(**SCREAMING_SNAKE_CASE					)
									lowercase__					:   Optional[Any]													=					outputs.logits

									# verify the logits
									lowercase__					:   int													=					(1, 21_841)
									self.assertEqual(logits.shape				,       SCREAMING_SNAKE_CASE					)

									lowercase__					:   str													=					np.array([1.6_881, -0.2_787, 0.5_901]					)

									self.assertTrue(np.allclose(logits[0, :3]				,       SCREAMING_SNAKE_CASE				,       atol=1E-4					)					)

									lowercase__					:   Union[str, Any]													=					2_396
									self.assertEqual(logits.argmax(-1					).item()				,       SCREAMING_SNAKE_CASE					)




