






import inspect
import unittest
import warnings
from math import ceil, floor

from transformers import LevitConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

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 transformers import (
							    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
							    MODEL_MAPPING,
							    LevitForImageClassification,
							    LevitForImageClassificationWithTeacher,
							    LevitModel,
							)
							from transformers.models.levit.modeling_levit import LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import LevitImageProcessor

class        lowerCAmelCase_				(      lowercase	):







				"""simple docstring"""




				def 				__a   ( self     :Optional[int]     ):
					UpperCamelCase__ :List[str]						=      self.config_class(**self.inputs_dict     )
					self.parent.assertTrue(hasattr(lowerCamelCase__  ,     """hidden_sizes"""     )     )
					self.parent.assertTrue(hasattr(lowerCamelCase__  ,     """num_attention_heads"""     )     )

class        lowerCAmelCase_				:







				"""simple docstring"""




				def __init__( self     :Dict  ,     lowerCamelCase__     :Optional[Any]  ,     lowerCamelCase__     :str=13  ,     lowerCamelCase__     :Dict=64  ,     lowerCamelCase__     :Dict=3  ,     lowerCamelCase__     :Union[str, Any]=3  ,     lowerCamelCase__     :Dict=2  ,     lowerCamelCase__     :Tuple=1  ,     lowerCamelCase__     :Tuple=16  ,     lowerCamelCase__     :int=[1_28, 2_56, 3_84]  ,     lowerCamelCase__     :int=[4, 6, 8]  ,     lowerCamelCase__     :Optional[Any]=[2, 3, 4]  ,     lowerCamelCase__     :int=[16, 16, 16]  ,     lowerCamelCase__     :List[Any]=0  ,     lowerCamelCase__     :List[Any]=[2, 2, 2]  ,     lowerCamelCase__     :List[Any]=[2, 2, 2]  ,     lowerCamelCase__     :Dict=0.02  ,     lowerCamelCase__     :Tuple=True  ,     lowerCamelCase__     :Any=True  ,     lowerCamelCase__     :int=2  ,     ):
					UpperCamelCase__ :Optional[Any]						=      parent
					UpperCamelCase__ :List[Any]						=      batch_size
					UpperCamelCase__ :Optional[int]						=      image_size
					UpperCamelCase__ :Any						=      num_channels
					UpperCamelCase__ :List[Any]						=      kernel_size
					UpperCamelCase__ :List[Any]						=      stride
					UpperCamelCase__ :Optional[Any]						=      padding
					UpperCamelCase__ :Optional[int]						=      hidden_sizes
					UpperCamelCase__ :Tuple						=      num_attention_heads
					UpperCamelCase__ :Optional[int]						=      depths
					UpperCamelCase__ :Dict						=      key_dim
					UpperCamelCase__ :Tuple						=      drop_path_rate
					UpperCamelCase__ :Optional[Any]						=      patch_size
					UpperCamelCase__ :Optional[Any]						=      attention_ratio
					UpperCamelCase__ :List[str]						=      mlp_ratio
					UpperCamelCase__ :int						=      initializer_range
					UpperCamelCase__ :List[Any]						=      [
					    ["""Subsample""", key_dim[0], hidden_sizes[0] // key_dim[0], 4, 2, 2],
					    ["""Subsample""", key_dim[0], hidden_sizes[1] // key_dim[0], 4, 2, 2],
					]
					UpperCamelCase__ :int						=      is_training
					UpperCamelCase__ :Union[str, Any]						=      use_labels
					UpperCamelCase__ :Optional[int]						=      num_labels
					UpperCamelCase__ :Any						=      initializer_range







				def 				__a   ( self     :str     ):
					UpperCamelCase__ :Tuple						=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

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

					UpperCamelCase__ :Optional[Any]						=      self.get_config()
					return config, pixel_values, labels







				def 				__a   ( self     :Union[str, Any]     ):
					return LevitConfig(
					    image_size=self.image_size  ,     num_channels=self.num_channels  ,     kernel_size=self.kernel_size  ,     stride=self.stride  ,     padding=self.padding  ,     patch_size=self.patch_size  ,     hidden_sizes=self.hidden_sizes  ,     num_attention_heads=self.num_attention_heads  ,     depths=self.depths  ,     key_dim=self.key_dim  ,     drop_path_rate=self.drop_path_rate  ,     mlp_ratio=self.mlp_ratio  ,     attention_ratio=self.attention_ratio  ,     initializer_range=self.initializer_range  ,     down_ops=self.down_ops  ,     )







				def 				__a   ( self     :List[str]  ,     lowerCamelCase__     :Any  ,     lowerCamelCase__     :Tuple  ,     lowerCamelCase__     :Tuple     ):
					UpperCamelCase__ :Any						=      LevitModel(config=lowerCamelCase__     )
					model.to(lowerCamelCase__     )
					model.eval()
					UpperCamelCase__ :List[str]						=      model(lowerCamelCase__     )
					UpperCamelCase__ :Tuple						=      (self.image_size, self.image_size)
					UpperCamelCase__				,		UpperCamelCase__ :List[Any]						=      image_size[0], image_size[1]
					for _ in range(4     ):
						UpperCamelCase__ :List[str]						=      floor(((height + 2 * self.padding - self.kernel_size) / self.stride) + 1     )
						UpperCamelCase__ :str						=      floor(((width + 2 * self.padding - self.kernel_size) / self.stride) + 1     )
					self.parent.assertEqual(
					    result.last_hidden_state.shape  ,     (self.batch_size, ceil(height / 4     ) * ceil(width / 4     ), self.hidden_sizes[-1])  ,     )







				def 				__a   ( self     :Dict  ,     lowerCamelCase__     :Optional[Any]  ,     lowerCamelCase__     :Optional[Any]  ,     lowerCamelCase__     :Optional[Any]     ):
					UpperCamelCase__ :Optional[Any]						=      self.num_labels
					UpperCamelCase__ :Union[str, Any]						=      LevitForImageClassification(lowerCamelCase__     )
					model.to(lowerCamelCase__     )
					model.eval()
					UpperCamelCase__ :List[Any]						=      model(lowerCamelCase__  ,     labels=lowerCamelCase__     )
					self.parent.assertEqual(result.logits.shape  ,     (self.batch_size, self.num_labels)     )







				def 				__a   ( self     :Optional[Any]     ):
					UpperCamelCase__ :str						=      self.prepare_config_and_inputs()
					UpperCamelCase__				,		UpperCamelCase__				,		UpperCamelCase__ :Tuple						=      config_and_inputs
					UpperCamelCase__ :Optional[int]						=      {"""pixel_values""": pixel_values}
					return config, inputs_dict

@require_torch
class        lowerCAmelCase_				(      lowercase						,      lowercase						,      unittest.TestCase	):







				"""simple docstring"""




				_snake_case				:   int        =			(
				    (LevitModel, LevitForImageClassification, LevitForImageClassificationWithTeacher)
				    if is_torch_available()
				    else ()
				)
				_snake_case				:   Union[str, Any]        =			(
				    {
				        """feature-extraction""": LevitModel,
				        """image-classification""": (LevitForImageClassification, LevitForImageClassificationWithTeacher),
				    }
				    if is_torch_available()
				    else {}
				)

				_snake_case				:   List[str]        =			False
				_snake_case				:   Dict        =			False
				_snake_case				:   Dict        =			False
				_snake_case				:   List[Any]        =			False
				_snake_case				:   Dict        =			False







				def 				__a   ( self     :Optional[int]     ):
					UpperCamelCase__ :Optional[Any]						=      LevitModelTester(self     )
					UpperCamelCase__ :int						=      ConfigTester(self  ,     config_class=lowerCamelCase__  ,     has_text_modality=lowerCamelCase__  ,     hidden_size=37     )







				def 				__a   ( self     :Optional[int]     ):
					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 				__a   ( self     :Union[str, Any]     ):
					return







				@unittest.skip(reason="""Levit does not use inputs_embeds"""     )
				def 				__a   ( self     :Union[str, Any]     ):
					pass







				@unittest.skip(reason="""Levit does not support input and output embeddings"""     )
				def 				__a   ( self     :Tuple     ):
					pass







				@unittest.skip(reason="""Levit does not output attentions"""     )
				def 				__a   ( self     :int     ):
					pass







				def 				__a   ( self     :Union[str, Any]     ):
					UpperCamelCase__				,		UpperCamelCase__ :str						=      self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						UpperCamelCase__ :List[str]						=      model_class(lowerCamelCase__     )
						UpperCamelCase__ :Any						=      inspect.signature(model.forward     )
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						UpperCamelCase__ :Tuple						=      [*signature.parameters.keys()]

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







				def 				__a   ( self     :int     ):
					def check_hidden_states_output(lowerCamelCase__     :Dict  ,     lowerCamelCase__     :Dict  ,     lowerCamelCase__     :str     ):
						UpperCamelCase__ :Dict						=      model_class(lowerCamelCase__     )
						model.to(lowerCamelCase__     )
						model.eval()

						with torch.no_grad():
							UpperCamelCase__ :Union[str, Any]						=      model(**self._prepare_for_class(lowerCamelCase__  ,     lowerCamelCase__     )     )

						UpperCamelCase__ :Optional[int]						=      outputs.hidden_states

						UpperCamelCase__ :Dict						=      len(self.model_tester.depths     ) + 1
						self.assertEqual(len(lowerCamelCase__     )  ,     lowerCamelCase__     )

						UpperCamelCase__ :int						=      (self.model_tester.image_size, self.model_tester.image_size)
						UpperCamelCase__				,		UpperCamelCase__ :Union[str, Any]						=      image_size[0], image_size[1]
						for _ in range(4     ):
							UpperCamelCase__ :Dict						=      floor(
							    (
							        (height + 2 * self.model_tester.padding - self.model_tester.kernel_size)
							        / self.model_tester.stride
							    )
							    + 1     )
							UpperCamelCase__ :Optional[int]						=      floor(
							    (
							        (width + 2 * self.model_tester.padding - self.model_tester.kernel_size)
							        / self.model_tester.stride
							    )
							    + 1     )
						# verify the first hidden states (first block)
						self.assertListEqual(
						    list(hidden_states[0].shape[-2:]     )  ,     [
						        height * width,
						        self.model_tester.hidden_sizes[0],
						    ]  ,     )

					UpperCamelCase__				,		UpperCamelCase__ :Tuple						=      self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						UpperCamelCase__ :int						=      True
						check_hidden_states_output(lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__     )

						# check that output_hidden_states also work using config
						del inputs_dict["output_hidden_states"]
						UpperCamelCase__ :Dict						=      True

						check_hidden_states_output(lowerCamelCase__  ,     lowerCamelCase__  ,     lowerCamelCase__     )







				@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""     )
				def 				__a   ( self     :Dict     ):
					pass







				def 				__a   ( self     :Dict  ,     lowerCamelCase__     :Optional[int]  ,     lowerCamelCase__     :List[str]  ,     lowerCamelCase__     :List[str]=False     ):
					UpperCamelCase__ :int						=      super()._prepare_for_class(lowerCamelCase__  ,     lowerCamelCase__  ,     return_labels=lowerCamelCase__     )

					if return_labels:
						if model_class.__name__ == "LevitForImageClassificationWithTeacher":
							del inputs_dict["labels"]

					return inputs_dict







				def 				__a   ( self     :Dict     ):
					UpperCamelCase__ :Tuple						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCamelCase__     )







				def 				__a   ( self     :Tuple     ):
					UpperCamelCase__ :List[Any]						=      self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*lowerCamelCase__     )







				def 				__a   ( self     :List[Any]     ):
					if not self.model_tester.is_training:
						return

					UpperCamelCase__				,		UpperCamelCase__ :List[str]						=      self.model_tester.prepare_config_and_inputs_for_common()
					UpperCamelCase__ :str						=      True

					for model_class in self.all_model_classes:
						# LevitForImageClassificationWithTeacher supports inference-only
						if (
						    model_class in get_values(lowerCamelCase__     )
						    or model_class.__name__ == "LevitForImageClassificationWithTeacher"
						):
							continue
						UpperCamelCase__ :str						=      model_class(lowerCamelCase__     )
						model.to(lowerCamelCase__     )
						model.train()
						UpperCamelCase__ :str						=      self._prepare_for_class(lowerCamelCase__  ,     lowerCamelCase__  ,     return_labels=lowerCamelCase__     )
						UpperCamelCase__ :Optional[Any]						=      model(**lowerCamelCase__     ).loss
						loss.backward()







				def 				__a   ( self     :Tuple     ):
					UpperCamelCase__				,		UpperCamelCase__ :Any						=      self.model_tester.prepare_config_and_inputs_for_common()
					if not self.model_tester.is_training:
						return

					UpperCamelCase__ :Union[str, Any]						=      False
					UpperCamelCase__ :Optional[int]						=      True

					for model_class in self.all_model_classes:
						if model_class in get_values(lowerCamelCase__     ) or not model_class.supports_gradient_checkpointing:
							continue
						# LevitForImageClassificationWithTeacher supports inference-only
						if model_class.__name__ == "LevitForImageClassificationWithTeacher":
							continue
						UpperCamelCase__ :Dict						=      model_class(lowerCamelCase__     )
						model.gradient_checkpointing_enable()
						model.to(lowerCamelCase__     )
						model.train()
						UpperCamelCase__ :Union[str, Any]						=      self._prepare_for_class(lowerCamelCase__  ,     lowerCamelCase__  ,     return_labels=lowerCamelCase__     )
						UpperCamelCase__ :Optional[int]						=      model(**lowerCamelCase__     ).loss
						loss.backward()







				def 				__a   ( self     :Optional[int]     ):
					UpperCamelCase__				,		UpperCamelCase__ :List[Any]						=      self.model_tester.prepare_config_and_inputs_for_common()

					UpperCamelCase__ :Dict						=      [
					    {"""title""": """multi_label_classification""", """num_labels""": 2, """dtype""": torch.float},
					    {"""title""": """single_label_classification""", """num_labels""": 1, """dtype""": torch.long},
					    {"""title""": """regression""", """num_labels""": 1, """dtype""": torch.float},
					]

					for model_class in self.all_model_classes:
						if (
						    model_class
						    not in [
						        *get_values(lowerCamelCase__     ),
						    ]
						    or model_class.__name__ == "LevitForImageClassificationWithTeacher"
						):
							continue

						for problem_type in problem_types:
							with self.subTest(msg=f"""Testing {model_class} with {problem_type["title"]}"""     ):
								UpperCamelCase__ :str						=      problem_type["""title"""]
								UpperCamelCase__ :Tuple						=      problem_type["""num_labels"""]

								UpperCamelCase__ :Dict						=      model_class(lowerCamelCase__     )
								model.to(lowerCamelCase__     )
								model.train()

								UpperCamelCase__ :List[str]						=      self._prepare_for_class(lowerCamelCase__  ,     lowerCamelCase__  ,     return_labels=lowerCamelCase__     )

								if problem_type["num_labels"] > 1:
									UpperCamelCase__ :Tuple						=      inputs["""labels"""].unsqueeze(1     ).repeat(1  ,     problem_type["""num_labels"""]     )

								UpperCamelCase__ :str						=      inputs["""labels"""].to(problem_type["""dtype"""]     )

								# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
								# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
								# they have the same size." which is a symptom something in wrong for the regression problem.
								# See https://github.com/huggingface/transformers/issues/11780
								with warnings.catch_warnings(record=lowerCamelCase__     ) as warning_list:
									UpperCamelCase__ :Dict						=      model(**lowerCamelCase__     ).loss
								for w in warning_list:
									if "Using a target size that is different to the input size" in str(w.message     ):
										raise ValueError(
										    f"""Something is going wrong in the regression problem: intercepted {w.message}"""     )

								loss.backward()







				@slow
				def 				__a   ( self     :Any     ):
					for model_name in LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						UpperCamelCase__ :Any						=      LevitModel.from_pretrained(lowerCamelCase__     )
						self.assertIsNotNone(lowerCamelCase__     )




def 				A		(					)		-> str:
	UpperCamelCase__ :int						=      Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
	return image




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







				"""simple docstring"""




				@cached_property
				def 				__a   ( self     :Any     ):
					return LevitImageProcessor.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]     )







				@slow
				def 				__a   ( self     :Tuple     ):
					UpperCamelCase__ :Any						=      LevitForImageClassificationWithTeacher.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]     ).to(
					    lowerCamelCase__     )

					UpperCamelCase__ :Optional[Any]						=      self.default_image_processor
					UpperCamelCase__ :Union[str, Any]						=      prepare_img()
					UpperCamelCase__ :str						=      image_processor(images=lowerCamelCase__  ,     return_tensors="""pt"""     ).to(lowerCamelCase__     )

					# forward pass
					with torch.no_grad():
						UpperCamelCase__ :List[str]						=      model(**lowerCamelCase__     )

					# verify the logits
					UpperCamelCase__ :str						=      torch.Size((1, 10_00)     )
					self.assertEqual(outputs.logits.shape  ,     lowerCamelCase__     )

					UpperCamelCase__ :Tuple						=      torch.tensor([1.0448, -0.3745, -1.8317]     ).to(lowerCamelCase__     )

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




import unittest

import numpy as np

from transformers import DistilBertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
			import jax.numpy as jnp

			from transformers.models.distilbert.modeling_flax_distilbert import (
			    FlaxDistilBertForMaskedLM,
			    FlaxDistilBertForMultipleChoice,
			    FlaxDistilBertForQuestionAnswering,
			    FlaxDistilBertForSequenceClassification,
			    FlaxDistilBertForTokenClassification,
			    FlaxDistilBertModel,
			)


class 						lowercase    (							unittest.TestCase):
						'''simple docstring'''


						def __init__(  self    :				int       ,	snake_case    :				Optional[Any]       ,	snake_case    :				Optional[Any]=13       ,	snake_case    :				str=7       ,	snake_case    :				Optional[Any]=True       ,	snake_case    :				int=True       ,	snake_case    :				str=True       ,	snake_case    :				List[str]=True       ,	snake_case    :				Optional[Any]=99       ,	snake_case    :				Optional[int]=32       ,	snake_case    :				Optional[int]=5       ,	snake_case    :				Optional[Any]=4       ,	snake_case    :				Optional[Any]=37       ,	snake_case    :				str="gelu"       ,	snake_case    :				List[str]=0.1       ,	snake_case    :				List[str]=0.1       ,	snake_case    :				int=512       ,	snake_case    :				Union[str, Any]=16       ,	snake_case    :				Optional[Any]=2       ,	snake_case    :				int=0.02       ,	snake_case    :				str=4       ,	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Tuple						=				parent
											SCREAMING_SNAKE_CASE							:     str						=				batch_size
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				seq_length
											SCREAMING_SNAKE_CASE							:     int						=				is_training
											SCREAMING_SNAKE_CASE							:     List[str]						=				use_attention_mask
											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				use_token_type_ids
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				use_labels
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				vocab_size
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				hidden_size
											SCREAMING_SNAKE_CASE							:     Any						=				num_hidden_layers
											SCREAMING_SNAKE_CASE							:     Tuple						=				num_attention_heads
											SCREAMING_SNAKE_CASE							:     Any						=				intermediate_size
											SCREAMING_SNAKE_CASE							:     Tuple						=				hidden_act
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				hidden_dropout_prob
											SCREAMING_SNAKE_CASE							:     str						=				attention_probs_dropout_prob
											SCREAMING_SNAKE_CASE							:     Tuple						=				max_position_embeddings
											SCREAMING_SNAKE_CASE							:     Any						=				type_vocab_size
											SCREAMING_SNAKE_CASE							:     List[Any]						=				type_sequence_label_size
											SCREAMING_SNAKE_CASE							:     Tuple						=				initializer_range
											SCREAMING_SNAKE_CASE							:     List[str]						=				num_choices







						def       lowerCamelCase_				(  self    :				List[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size	)

											SCREAMING_SNAKE_CASE							:     Optional[int]						=				None
											if self.use_attention_mask:
																SCREAMING_SNAKE_CASE							:     Any						=				random_attention_mask([self.batch_size, self.seq_length]	)

											SCREAMING_SNAKE_CASE							:     Tuple						=				DistilBertConfig(
											    vocab_size=self.vocab_size       ,	dim=self.hidden_size       ,	n_layers=self.num_hidden_layers       ,	n_heads=self.num_attention_heads       ,	hidden_dim=self.intermediate_size       ,	hidden_act=self.hidden_act       ,	dropout=self.hidden_dropout_prob       ,	attention_dropout=self.attention_probs_dropout_prob       ,	max_position_embeddings=self.max_position_embeddings       ,	initializer_range=self.initializer_range       ,	tie_weights_=snake_case       ,	)

											return config, input_ids, attention_mask







						def       lowerCamelCase_				(  self    :				int	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Tuple						=				self.prepare_config_and_inputs()
											SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     Optional[int]						=				config_and_inputs
											SCREAMING_SNAKE_CASE							:     int						=				{'input_ids': input_ids, 'attention_mask': attention_mask}
											return config, inputs_dict


@require_flax
class 						lowercase    (							SCREAMING_SNAKE_CASE_      ,    unittest.TestCase):
						'''simple docstring'''


						UpperCAmelCase			:		int		=		(
						    (
						        FlaxDistilBertModel,
						        FlaxDistilBertForMaskedLM,
						        FlaxDistilBertForMultipleChoice,
						        FlaxDistilBertForQuestionAnswering,
						        FlaxDistilBertForSequenceClassification,
						        FlaxDistilBertForTokenClassification,
						        FlaxDistilBertForQuestionAnswering,
						    )
						    if is_flax_available()
						    else ()
						)







						def       lowerCamelCase_				(  self    :				Optional[int]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     str						=				FlaxDistilBertModelTester(self	)







						@slow
						def       lowerCamelCase_				(  self    :				Any	):



											'''simple docstring'''


											for model_class_name in self.all_model_classes:
																SCREAMING_SNAKE_CASE							:     Dict						=				model_class_name.from_pretrained('distilbert-base-uncased'	)
																SCREAMING_SNAKE_CASE							:     Dict						=				model(np.ones((1, 1)	)	)
																self.assertIsNotNone(snake_case	)


@require_flax
class 						lowercase    (							unittest.TestCase):
						'''simple docstring'''


						@slow
						def       lowerCamelCase_				(  self    :				Tuple	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     List[Any]						=				FlaxDistilBertModel.from_pretrained('distilbert-base-uncased'	)
											SCREAMING_SNAKE_CASE							:     List[str]						=				np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]	)
											SCREAMING_SNAKE_CASE							:     Dict						=				np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
											SCREAMING_SNAKE_CASE							:     str						=				model(snake_case       ,	attention_mask=snake_case	)[0]
											SCREAMING_SNAKE_CASE							:     int						=				(1, 11, 768)
											self.assertEqual(output.shape       ,	snake_case	)
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				np.array([[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]]	)

											self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]       ,	snake_case       ,	atol=1E-4	)	)