'''simple docstring'''




import argparse
import collections

import torch
from flax import traverse_util
from tax import checkpoints

from transformers import TaConfig, TaEncoderModel, TaForConditionalGeneration
from transformers.utils import logging


logging.set_verbosity_info()




def 							lowerCamelCase			(   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      List[str]   ,   UpperCAmelCase__ :      str="attention"				)    ->   Tuple:
							lowercase_      :    str       		= params[F'''{prefix}/layers_{i}/{layer_name}/key/kernel''']
							lowercase_      :    Any       		= params[F'''{prefix}/layers_{i}/{layer_name}/out/kernel''']
							lowercase_      :    List[str]       		= params[F'''{prefix}/layers_{i}/{layer_name}/query/kernel''']
							lowercase_      :    int       		= params[F'''{prefix}/layers_{i}/{layer_name}/value/kernel''']
							return k, o, q, v




def 							lowerCamelCase			(   UpperCAmelCase__ :      Dict   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      List[Any]=False				)    ->   Optional[int]:
							if split_mlp_wi:
														lowercase_      :    List[str]       		= params[F'''{prefix}/layers_{i}/mlp/wi_0/kernel''']
														lowercase_      :    Dict       		= params[F'''{prefix}/layers_{i}/mlp/wi_1/kernel''']
														lowercase_      :    List[str]       		= (wi_a, wi_a)
							else:
														lowercase_      :    Any       		= params[F'''{prefix}/layers_{i}/mlp/wi/kernel''']

							lowercase_      :    List[Any]       		= params[F'''{prefix}/layers_{i}/mlp/wo/kernel''']
							return wi, wo




def 							lowerCamelCase			(   UpperCAmelCase__ :      List[Any]   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      Union[str, Any]   ,   UpperCAmelCase__ :      Dict				)    ->   Union[str, Any]:
							return params[F'''{prefix}/layers_{i}/{layer_name}/scale''']




def 							lowerCamelCase			(   UpperCAmelCase__ :      dict   ,   *, UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      bool				)    ->   int:
							lowercase_      :    List[Any]       		= traverse_util.flatten_dict(variables["""target"""]				)
							lowercase_      :    str       		= {"""/""".join(UpperCAmelCase__				): v for k, v in old.items()}

							# v1.1 models have a gated GeLU with wi_0 and wi_1 instead of wi
							lowercase_      :    List[str]       		= """encoder/layers_0/mlp/wi_0/kernel""" in old
							print("""Split MLP:"""   ,   UpperCAmelCase__				)

							lowercase_      :    Optional[Any]       		= collections.OrderedDict()

							# Shared embeddings.
							lowercase_      :    List[Any]       		= old["""token_embedder/embedding"""]

							# Encoder.
							for i in range(UpperCAmelCase__				):
														# Block i, layer 0 (Self Attention).
														lowercase_      :    List[Any]       		= tax_layer_norm_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """encoder"""   ,   """pre_attention_layer_norm"""				)
														lowercase_		,		lowercase_		,		lowercase_		,		lowercase_      :    Tuple       		= tax_attention_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """encoder"""   ,   """attention"""				)
														lowercase_      :    str       		= layer_norm
														lowercase_      :    Optional[int]       		= k.T
														lowercase_      :    Optional[Any]       		= o.T
														lowercase_      :    Dict       		= q.T
														lowercase_      :    int       		= v.T

														# Block i, layer 1 (MLP).
														lowercase_      :    Any       		= tax_layer_norm_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """encoder"""   ,   """pre_mlp_layer_norm"""				)
														lowercase_		,		lowercase_      :    str       		= tax_mlp_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """encoder"""   ,   UpperCAmelCase__				)
														lowercase_      :    Union[str, Any]       		= layer_norm
														if split_mlp_wi:
																					lowercase_      :    Tuple       		= wi[0].T
																					lowercase_      :    List[Any]       		= wi[1].T
														else:
																					lowercase_      :    List[Any]       		= wi.T
														lowercase_      :    Union[str, Any]       		= wo.T

							lowercase_      :    Dict       		= old[
							    """encoder/relpos_bias/rel_embedding"""
							].T
							lowercase_      :    Optional[Any]       		= old["""encoder/encoder_norm/scale"""]

							if not is_encoder_only:
														# Decoder.
														for i in range(UpperCAmelCase__				):
																					# Block i, layer 0 (Self Attention).
																					lowercase_      :    Optional[Any]       		= tax_layer_norm_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decoder"""   ,   """pre_self_attention_layer_norm"""				)
																					lowercase_		,		lowercase_		,		lowercase_		,		lowercase_      :    int       		= tax_attention_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decoder"""   ,   """self_attention"""				)
																					lowercase_      :    List[str]       		= layer_norm
																					lowercase_      :    Optional[int]       		= k.T
																					lowercase_      :    Any       		= o.T
																					lowercase_      :    List[str]       		= q.T
																					lowercase_      :    int       		= v.T

																					# Block i, layer 1 (Cross Attention).
																					lowercase_      :    str       		= tax_layer_norm_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decoder"""   ,   """pre_cross_attention_layer_norm"""				)
																					lowercase_		,		lowercase_		,		lowercase_		,		lowercase_      :    Dict       		= tax_attention_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decoder"""   ,   """encoder_decoder_attention"""				)
																					lowercase_      :    Dict       		= layer_norm
																					lowercase_      :    Union[str, Any]       		= k.T
																					lowercase_      :    Dict       		= o.T
																					lowercase_      :    str       		= q.T
																					lowercase_      :    Dict       		= v.T

																					# Block i, layer 2 (MLP).
																					lowercase_      :    Dict       		= tax_layer_norm_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decoder"""   ,   """pre_mlp_layer_norm"""				)
																					lowercase_		,		lowercase_      :    List[str]       		= tax_mlp_lookup(UpperCAmelCase__   ,   UpperCAmelCase__   ,   """decoder"""   ,   UpperCAmelCase__				)
																					lowercase_      :    int       		= layer_norm
																					if split_mlp_wi:
																												lowercase_      :    Union[str, Any]       		= wi[0].T
																												lowercase_      :    Union[str, Any]       		= wi[1].T
																					else:
																												lowercase_      :    List[Any]       		= wi.T
																					lowercase_      :    int       		= wo.T

														lowercase_      :    Dict       		= old["""decoder/decoder_norm/scale"""]
														lowercase_      :    Dict       		= old[
														    """decoder/relpos_bias/rel_embedding"""
														].T

														# LM Head (only in v1.1 checkpoints, in v1.0 embeddings are used instead)
														if "decoder/logits_dense/kernel" in old:
																					lowercase_      :    List[Any]       		= old["""decoder/logits_dense/kernel"""].T

							return new




def 							lowerCamelCase			(   UpperCAmelCase__ :      Optional[int]   ,   UpperCAmelCase__ :      bool				)    ->   int:
							lowercase_      :    List[Any]       		= collections.OrderedDict([(k, torch.from_numpy(v.copy()				)) for (k, v) in converted_params.items()]				)

							# Add what is missing.
							if "encoder.embed_tokens.weight" not in state_dict:
														lowercase_      :    Any       		= state_dict["""shared.weight"""]

							if not is_encoder_only:
														if "decoder.embed_tokens.weight" not in state_dict:
																					lowercase_      :    Union[str, Any]       		= state_dict["""shared.weight"""]

														if "lm_head.weight" not in state_dict:  # For old 1.0 models.
																					print("""Using shared word embeddings as lm_head."""				)
																					lowercase_      :    Union[str, Any]       		= state_dict["""shared.weight"""]

							return state_dict




def 							lowerCamelCase			(   UpperCAmelCase__ :      int   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      Dict   ,   UpperCAmelCase__ :      Optional[int]				)    ->   Any:
							lowercase_      :    str       		= checkpoints.load_tax_checkpoint(UpperCAmelCase__				)
							lowercase_      :    str       		= convert_tax_to_pytorch(UpperCAmelCase__   ,   num_layers=config.num_layers   ,   is_encoder_only=UpperCAmelCase__				)
							lowercase_      :    Optional[Any]       		= make_state_dict(UpperCAmelCase__   ,   UpperCAmelCase__				)
							model.load_state_dict(UpperCAmelCase__   ,   strict=UpperCAmelCase__				)




def 							lowerCamelCase			(   UpperCAmelCase__ :      Optional[Any]   ,   UpperCAmelCase__ :      List[str]   ,   UpperCAmelCase__ :      Optional[Any]   ,   UpperCAmelCase__ :      bool = False				)    ->   List[str]:
							lowercase_      :    Dict       		= TaConfig.from_json_file(UpperCAmelCase__				)
							print(F'''Building PyTorch model from configuration: {config}'''				)
							# Non-v1.1 checkpoints could also use T5Model, but this works for all.
							# The v1.0 checkpoints will simply have an LM head that is the word embeddings.
							if is_encoder_only:
														lowercase_      :    Optional[int]       		= TaEncoderModel(UpperCAmelCase__				)
							else:
														lowercase_      :    Dict       		= TaForConditionalGeneration(UpperCAmelCase__				)

							# Load weights from tf checkpoint
							load_tax_weights_in_ta(UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__   ,   UpperCAmelCase__				)

							# Save pytorch-model
							print(F'''Save PyTorch model to {pytorch_dump_path}'''				)
							model.save_pretrained(UpperCAmelCase__				)

							# Verify that we can load the checkpoint.
							model.from_pretrained(UpperCAmelCase__				)
							print("""Done"""				)


if __name__ == "__main__":
						_lowercase		:				Optional[int]	       =		argparse.ArgumentParser(description="Converts a native T5X checkpoint into a PyTorch checkpoint.")
						# Required parameters
						parser.add_argument(
						    "--t5x_checkpoint_path", default=None, type=str, required=True, help="Path to the T5X checkpoint."
						)
						parser.add_argument(
						    "--config_file",
						    default=None,
						    type=str,
						    required=True,
						    help="The config json file corresponding to the pre-trained T5 model.\nThis specifies the model architecture.",
						)
						parser.add_argument(
						    "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
						)
						parser.add_argument(
						    "--is_encoder_only", action="store_true", help="Check if the model is encoder-decoder model", default=False
						)
						_lowercase		:				Optional[int]	       =		parser.parse_args()
						convert_tax_checkpoint_to_pytorch(
						    args.tax_checkpoint_path, args.config_file, args.pytorch_dump_path, args.is_encoder_only
						)






'''simple docstring'''




import inspect
import unittest

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

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch
						from torch import nn

						from transformers import BitBackbone, BitForImageClassification, BitImageProcessor, BitModel
						from transformers.models.bit.modeling_bit import BIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image





class 					__magic_name__		:







			def __init__(			self       :						Tuple       ,    lowercase_       :						Tuple       ,    lowercase_       :						Any=3       ,    lowercase_       :						int=32       ,    lowercase_       :						str=3       ,    lowercase_       :						int=10       ,    lowercase_       :						Any=[8, 16, 32, 64]       ,    lowercase_       :						Tuple=[1, 1, 2, 1]       ,    lowercase_       :						Any=True       ,    lowercase_       :						int=True       ,    lowercase_       :						Any="relu"       ,    lowercase_       :						List[Any]=3       ,    lowercase_       :						Tuple=None       ,    lowercase_       :						Union[str, Any]=["stage2", "stage3", "stage4"]       ,    lowercase_       :						Optional[int]=[2, 3, 4]       ,    lowercase_       :						List[str]=1       ,    ):
										lowercase_      :    Any       		= parent
										lowercase_      :    str       		= batch_size
										lowercase_      :    Any       		= image_size
										lowercase_      :    Optional[Any]       		= num_channels
										lowercase_      :    Any       		= embeddings_size
										lowercase_      :    Union[str, Any]       		= hidden_sizes
										lowercase_      :    Any       		= depths
										lowercase_      :    Dict       		= is_training
										lowercase_      :    Tuple       		= use_labels
										lowercase_      :    str       		= hidden_act
										lowercase_      :    Optional[Any]       		= num_labels
										lowercase_      :    Tuple       		= scope
										lowercase_      :    Any       		= len(lowercase_					)
										lowercase_      :    Optional[Any]       		= out_features
										lowercase_      :    Tuple       		= out_indices
										lowercase_      :    str       		= num_groups







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[Any]					):
										lowercase_      :    int       		= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

										lowercase_      :    List[Any]       		= None
										if self.use_labels:
																	lowercase_      :    List[str]       		= ids_tensor([self.batch_size]       ,    self.num_labels					)

										lowercase_      :    int       		= self.get_config()

										return config, pixel_values, labels







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Union[str, Any]					):
										return BitConfig(
										    num_channels=self.num_channels       ,    embeddings_size=self.embeddings_size       ,    hidden_sizes=self.hidden_sizes       ,    depths=self.depths       ,    hidden_act=self.hidden_act       ,    num_labels=self.num_labels       ,    out_features=self.out_features       ,    out_indices=self.out_indices       ,    num_groups=self.num_groups       ,    )







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Union[str, Any]       ,    lowercase_       :						int       ,    lowercase_       :						List[str]       ,    lowercase_       :						List[str]					):
										lowercase_      :    Optional[int]       		= BitModel(config=lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    List[Any]       		= model(lowercase_					)
										self.parent.assertEqual(
										    result.last_hidden_state.shape       ,    (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)       ,    )







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]       ,    lowercase_       :						Tuple       ,    lowercase_       :						Optional[int]       ,    lowercase_       :						List[Any]					):
										lowercase_      :    Union[str, Any]       		= self.num_labels
										lowercase_      :    Tuple       		= BitForImageClassification(lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    Any       		= model(lowercase_       ,    labels=lowercase_					)
										self.parent.assertEqual(result.logits.shape       ,    (self.batch_size, self.num_labels)					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]       ,    lowercase_       :						Union[str, Any]       ,    lowercase_       :						List[Any]       ,    lowercase_       :						Optional[int]					):
										lowercase_      :    Any       		= BitBackbone(config=lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    Dict       		= model(lowercase_					)

										# verify feature maps
										self.parent.assertEqual(len(result.feature_maps					)       ,    len(config.out_features					)					)
										self.parent.assertListEqual(list(result.feature_maps[0].shape					)       ,    [self.batch_size, self.hidden_sizes[1], 4, 4]					)

										# verify channels
										self.parent.assertEqual(len(model.channels					)       ,    len(config.out_features					)					)
										self.parent.assertListEqual(model.channels       ,    config.hidden_sizes[1:]					)

										# verify backbone works with out_features=None
										lowercase_      :    List[str]       		= None
										lowercase_      :    Dict       		= BitBackbone(config=lowercase_					)
										model.to(lowercase_					)
										model.eval()
										lowercase_      :    Tuple       		= model(lowercase_					)

										# verify feature maps
										self.parent.assertEqual(len(result.feature_maps					)       ,    1					)
										self.parent.assertListEqual(list(result.feature_maps[0].shape					)       ,    [self.batch_size, self.hidden_sizes[-1], 1, 1]					)

										# verify channels
										self.parent.assertEqual(len(model.channels					)       ,    1					)
										self.parent.assertListEqual(model.channels       ,    [config.hidden_sizes[-1]]					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										lowercase_      :    Optional[int]       		= self.prepare_config_and_inputs()
										lowercase_		,		lowercase_		,		lowercase_      :    Optional[Any]       		= config_and_inputs
										lowercase_      :    Any       		= {"""pixel_values""": pixel_values}
										return config, inputs_dict





@require_torch
class 					__magic_name__		(					_UpperCAmelCase,  _UpperCAmelCase,  unittest.TestCase):
			UpperCamelCase__       = (BitModel, BitForImageClassification, BitBackbone) if is_torch_available() else ()
			UpperCamelCase__       = (
			    {'''feature-extraction''': BitModel, '''image-classification''': BitForImageClassification}
			    if is_torch_available()
			    else {}
			)

			UpperCamelCase__       = False
			UpperCamelCase__       = False
			UpperCamelCase__       = False
			UpperCamelCase__       = False
			UpperCamelCase__       = False







			def 			SCREAMING_SNAKE_CASE_  (			self       :						str					):
										lowercase_      :    int       		= BitModelTester(self					)
										lowercase_      :    Optional[int]       		= ConfigTester(self       ,    config_class=lowercase_       ,    has_text_modality=lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										self.create_and_test_config_common_properties()
										self.config_tester.create_and_test_config_to_json_string()
										self.config_tester.create_and_test_config_to_json_file()
										self.config_tester.create_and_test_config_from_and_save_pretrained()
										self.config_tester.create_and_test_config_with_num_labels()
										self.config_tester.check_config_can_be_init_without_params()
										self.config_tester.check_config_arguments_init()







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[str]					):
										return







			@unittest.skip(reason="""Bit does not output attentions"""					)
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										pass







			@unittest.skip(reason="""Bit does not use inputs_embeds"""					)
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										pass







			@unittest.skip(reason="""Bit does not support input and output embeddings"""					)
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[int]					):
										pass







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Dict					):
										lowercase_		,		lowercase_      :    Optional[int]       		= self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																	lowercase_      :    Optional[Any]       		= model_class(lowercase_					)
																	lowercase_      :    Union[str, Any]       		= inspect.signature(model.forward					)
																	# signature.parameters is an OrderedDict => so arg_names order is deterministic
																	lowercase_      :    Union[str, Any]       		= [*signature.parameters.keys()]

																	lowercase_      :    Optional[int]       		= ["""pixel_values"""]
																	self.assertListEqual(arg_names[:1]       ,    lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										lowercase_      :    int       		= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Tuple					):
										lowercase_      :    Any       		= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_backbone(*lowercase_					)







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Any					):
										lowercase_		,		lowercase_      :    int       		= self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																	lowercase_      :    List[Any]       		= model_class(config=lowercase_					)
																	for name, module in model.named_modules():
																								if isinstance(lowercase_       ,    (nn.BatchNormad, nn.GroupNorm)					):
																															self.assertTrue(
																															    torch.all(module.weight == 1					)       ,    msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''       ,    )
																															self.assertTrue(
																															    torch.all(module.bias == 0					)       ,    msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''       ,    )







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										def check_hidden_states_output(lowercase_       :						Optional[int]       ,    lowercase_       :						int       ,    lowercase_       :						int					):
																	lowercase_      :    Optional[Any]       		= model_class(lowercase_					)
																	model.to(lowercase_					)
																	model.eval()

																	with torch.no_grad():
																								lowercase_      :    List[Any]       		= model(**self._prepare_for_class(lowercase_       ,    lowercase_					)					)

																	lowercase_      :    str       		= outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																	lowercase_      :    Optional[int]       		= self.model_tester.num_stages
																	self.assertEqual(len(lowercase_					)       ,    expected_num_stages + 1					)

																	# Bit's feature maps are of shape (batch_size, num_channels, height, width)
																	self.assertListEqual(
																	    list(hidden_states[0].shape[-2:]					)       ,    [self.model_tester.image_size // 4, self.model_tester.image_size // 4]       ,    )

										lowercase_		,		lowercase_      :    List[Any]       		= self.model_tester.prepare_config_and_inputs_for_common()
										lowercase_      :    Dict       		= ["""preactivation""", """bottleneck"""]
										for model_class in self.all_model_classes:
																	for layer_type in layers_type:
																								lowercase_      :    Union[str, Any]       		= layer_type
																								lowercase_      :    Optional[Any]       		= True
																								check_hidden_states_output(lowercase_       ,    lowercase_       ,    lowercase_					)

																								# check that output_hidden_states also work using config
																								del inputs_dict["output_hidden_states"]
																								lowercase_      :    Union[str, Any]       		= True

																								check_hidden_states_output(lowercase_       ,    lowercase_       ,    lowercase_					)







			@unittest.skip(reason="""Bit does not use feedforward chunking"""					)
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Tuple					):
										pass







			def 			SCREAMING_SNAKE_CASE_  (			self       :						Optional[Any]					):
										lowercase_      :    Tuple       		= self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*lowercase_					)







			@slow
			def 			SCREAMING_SNAKE_CASE_  (			self       :						Tuple					):
										for model_name in BIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowercase_      :    List[str]       		= BitModel.from_pretrained(lowercase_					)
																	self.assertIsNotNone(lowercase_					)




def 							lowerCamelCase			(   )    ->   Optional[Any]:
							lowercase_      :    List[str]       		= Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""				)
							return image





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







			@cached_property
			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[str]					):
										return (
										    BitImageProcessor.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]					) if is_vision_available() else None
										)







			@slow
			def 			SCREAMING_SNAKE_CASE_  (			self       :						int					):
										lowercase_      :    List[str]       		= BitForImageClassification.from_pretrained(BIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]					).to(lowercase_					)

										lowercase_      :    int       		= self.default_image_processor
										lowercase_      :    List[Any]       		= prepare_img()
										lowercase_      :    Dict       		= image_processor(images=lowercase_       ,    return_tensors="""pt"""					).to(lowercase_					)

										# forward pass
										with torch.no_grad():
																	lowercase_      :    str       		= model(**lowercase_					)

										# verify the logits
										lowercase_      :    Optional[int]       		= torch.Size((1, 1000)					)
										self.assertEqual(outputs.logits.shape       ,    lowercase_					)

										lowercase_      :    Union[str, Any]       		= torch.tensor([[-0.65_26, -0.52_63, -1.43_98]]					).to(lowercase_					)

										self.assertTrue(torch.allclose(outputs.logits[0, :3]       ,    lowercase_       ,    atol=1E-4					)					)





@require_torch
class 					__magic_name__		(					_UpperCAmelCase,  unittest.TestCase):
			UpperCamelCase__       = (BitBackbone,) if is_torch_available() else ()
			UpperCamelCase__       = BitConfig

			UpperCamelCase__       = False







			def 			SCREAMING_SNAKE_CASE_  (			self       :						List[Any]					):
										lowercase_      :    Union[str, Any]       		= BitModelTester(self					)





