






"""simple docstring"""





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      a						(					unittest.TestCase		):






    def __init__(       self     :							List[Any]       ,						__SCREAMING_SNAKE_CASE     :							List[str]       ,						__SCREAMING_SNAKE_CASE     :							Tuple=13       ,						__SCREAMING_SNAKE_CASE     :							List[Any]=7       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]=True       ,						__SCREAMING_SNAKE_CASE     :							Tuple=True       ,						__SCREAMING_SNAKE_CASE     :							List[Any]=True       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]=True       ,						__SCREAMING_SNAKE_CASE     :							str=99       ,						__SCREAMING_SNAKE_CASE     :							Tuple=32       ,						__SCREAMING_SNAKE_CASE     :							List[str]=5       ,						__SCREAMING_SNAKE_CASE     :							Dict=4       ,						__SCREAMING_SNAKE_CASE     :							int=37       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]="gelu"       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]=0.1       ,						__SCREAMING_SNAKE_CASE     :							Any=0.1       ,						__SCREAMING_SNAKE_CASE     :							int=512       ,						__SCREAMING_SNAKE_CASE     :							List[str]=16       ,						__SCREAMING_SNAKE_CASE     :							List[str]=2       ,						__SCREAMING_SNAKE_CASE     :							int=0.02       ,						__SCREAMING_SNAKE_CASE     :							Union[str, Any]=4       ,						)     ->		List[Any]:
      lowerCamelCase_         =						parent
      lowerCamelCase_         =						batch_size
      lowerCamelCase_         =						seq_length
      lowerCamelCase_         =						is_training
      lowerCamelCase_         =						use_attention_mask
      lowerCamelCase_         =						use_token_type_ids
      lowerCamelCase_         =						use_labels
      lowerCamelCase_         =						vocab_size
      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_         =						max_position_embeddings
      lowerCamelCase_         =						type_vocab_size
      lowerCamelCase_         =						type_sequence_label_size
      lowerCamelCase_         =						initializer_range
      lowerCamelCase_         =						num_choices






    def    UpperCamelCase       (       self     :							Tuple					)     ->		Optional[Any]:
      lowerCamelCase_         =						ids_tensor([self.batch_size, self.seq_length]       ,						self.vocab_size					)

      lowerCamelCase_         =						None
      if self.use_attention_mask:
        lowerCamelCase_         =						random_attention_mask([self.batch_size, self.seq_length]					)

      lowerCamelCase_         =						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_=__SCREAMING_SNAKE_CASE       ,						)

      return config, input_ids, attention_mask






    def    UpperCamelCase       (       self     :							Optional[int]					)     ->		Union[str, Any]:
      lowerCamelCase_         =						self.prepare_config_and_inputs()
      lowerCamelCase_     ,	lowerCamelCase_     ,	lowerCamelCase_         =						config_and_inputs
      lowerCamelCase_         =						{'input_ids': input_ids, 'attention_mask': attention_mask}
      return config, inputs_dict






@require_flax
class      a						(					__SCREAMING_SNAKE_CASE  ,      unittest.TestCase		):
    SCREAMING_SNAKE_CASE						:     List[Any]						= (
        (
            FlaxDistilBertModel,
            FlaxDistilBertForMaskedLM,
            FlaxDistilBertForMultipleChoice,
            FlaxDistilBertForQuestionAnswering,
            FlaxDistilBertForSequenceClassification,
            FlaxDistilBertForTokenClassification,
            FlaxDistilBertForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )






    def    UpperCamelCase       (       self     :							int					)     ->		int:
      lowerCamelCase_         =						FlaxDistilBertModelTester(self					)






    @slow
    def    UpperCamelCase       (       self     :							Union[str, Any]					)     ->		int:
      for model_class_name in self.all_model_classes:
        lowerCamelCase_         =						model_class_name.from_pretrained('distilbert-base-uncased'					)
        lowerCamelCase_         =						model(np.ones((1, 1)					)					)
        self.assertIsNotNone(__SCREAMING_SNAKE_CASE					)






@require_flax
class      a						(					unittest.TestCase		):






    @slow
    def    UpperCamelCase       (       self     :							str					)     ->		int:
      lowerCamelCase_         =						FlaxDistilBertModel.from_pretrained('distilbert-base-uncased'					)
      lowerCamelCase_         =						np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]					)
      lowerCamelCase_         =						np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
      lowerCamelCase_         =						model(__SCREAMING_SNAKE_CASE       ,						attention_mask=__SCREAMING_SNAKE_CASE					)[0]
      lowerCamelCase_         =						(1, 11, 768)
      self.assertEqual(output.shape       ,						__SCREAMING_SNAKE_CASE					)
      lowerCamelCase_         =						np.array([[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]					)

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






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


SCREAMING_SNAKE_CASE							:Optional[Any]							 =				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE							:List[Any]							 =				{
    'hustvl/yolos-small': 'https://huggingface.co/hustvl/yolos-small/resolve/main/config.json',
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}





class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_					    =     "yolos"






	def __init__(       self					: Any							,A					: Optional[Any]=7_68							,A					: Dict=12							,A					: Any=12							,A					: str=30_72							,A					: Any="gelu"							,A					: str=0.0							,A					: List[str]=0.0							,A					: Dict=0.02							,A					: int=1E-12							,A					: Tuple=[5_12, 8_64]							,A					: List[Any]=16							,A					: str=3							,A					: str=True							,A					: Any=1_00							,A					: Dict=True							,A					: Dict=False							,A					: Tuple=1							,A					: Union[str, Any]=5							,A					: Optional[Any]=2							,A					: Union[str, Any]=5							,A					: int=2							,A					: int=0.1							,**A					: List[str]							,):
					super().__init__(**A )

					__A   			= hidden_size
					__A   			= num_hidden_layers
					__A   			= num_attention_heads
					__A   			= intermediate_size
					__A   			= hidden_act
					__A   			= hidden_dropout_prob
					__A   			= attention_probs_dropout_prob
					__A   			= initializer_range
					__A   			= layer_norm_eps
					__A   			= image_size
					__A   			= patch_size
					__A   			= num_channels
					__A   			= qkv_bias
					__A   			= num_detection_tokens
					__A   			= use_mid_position_embeddings
					__A   			= auxiliary_loss
					# Hungarian matcher
					__A   			= class_cost
					__A   			= bbox_cost
					__A   			= giou_cost
					# Loss coefficients
					__A   			= bbox_loss_coefficient
					__A   			= giou_loss_coefficient
					__A   			= eos_coefficient





class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_					    =     version.parse("1.11"  )






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






	@property
	def 				UpperCamelCase_  (       self					: List[Any] ):
					return 1E-4







	@property
	def 				UpperCamelCase_  (       self					: Optional[Any] ):
					return 12
