






'''simple docstring'''

import unittest

import numpy as np

from transformers import AlbertConfig, 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.albert.modeling_flax_albert import (
					    FlaxAlbertForMaskedLM,
					    FlaxAlbertForMultipleChoice,
					    FlaxAlbertForPreTraining,
					    FlaxAlbertForQuestionAnswering,
					    FlaxAlbertForSequenceClassification,
					    FlaxAlbertForTokenClassification,
					    FlaxAlbertModel,
					)






class        a_		(    unittest.TestCase       ):

		def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE=13    ,	_SCREAMING_SNAKE_CASE=7    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=99    ,	_SCREAMING_SNAKE_CASE=32    ,	_SCREAMING_SNAKE_CASE=5    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=37    ,	_SCREAMING_SNAKE_CASE="gelu"    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=512    ,	_SCREAMING_SNAKE_CASE=16    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=0.0_2    ,	_SCREAMING_SNAKE_CASE=4    ,	)						->   Union[str, Any]:



								"""simple docstring"""






								UpperCamelCase       						=      parent
								UpperCamelCase       						=      batch_size
								UpperCamelCase       						=      seq_length
								UpperCamelCase       						=      is_training
								UpperCamelCase       						=      use_attention_mask
								UpperCamelCase       						=      use_token_type_ids
								UpperCamelCase       						=      use_labels
								UpperCamelCase       						=      vocab_size
								UpperCamelCase       						=      hidden_size
								UpperCamelCase       						=      num_hidden_layers
								UpperCamelCase       						=      num_attention_heads
								UpperCamelCase       						=      intermediate_size
								UpperCamelCase       						=      hidden_act
								UpperCamelCase       						=      hidden_dropout_prob
								UpperCamelCase       						=      attention_probs_dropout_prob
								UpperCamelCase       						=      max_position_embeddings
								UpperCamelCase       						=      type_vocab_size
								UpperCamelCase       						=      type_sequence_label_size
								UpperCamelCase       						=      initializer_range
								UpperCamelCase       						=      num_choices

		def 						A__		(   self   )						->   str:



								"""simple docstring"""






								UpperCamelCase       						=      ids_tensor([self.batch_size, self.seq_length]    ,	self.vocab_size   )

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

								UpperCamelCase       						=      None
								if self.use_token_type_ids:
														UpperCamelCase       						=      ids_tensor([self.batch_size, self.seq_length]    ,	self.type_vocab_size   )

								UpperCamelCase       						=      AlbertConfig(
								    vocab_size=self.vocab_size    ,	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    ,	max_position_embeddings=self.max_position_embeddings    ,	type_vocab_size=self.type_vocab_size    ,	is_decoder=_SCREAMING_SNAKE_CASE    ,	initializer_range=self.initializer_range    ,	)

								return config, input_ids, token_type_ids, attention_mask


		def 						A__		(   self   )						->   Optional[int]:



								"""simple docstring"""






								UpperCamelCase       						=      self.prepare_config_and_inputs()
								UpperCamelCase						,UpperCamelCase						,UpperCamelCase						,UpperCamelCase       						=      config_and_inputs
								UpperCamelCase       						=      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
								return config, inputs_dict






@require_flax
class        a_		(    lowerCamelCase			, unittest.TestCase       ):
		lowercase  	=   (
		    (
		        FlaxAlbertModel,
		        FlaxAlbertForPreTraining,
		        FlaxAlbertForMaskedLM,
		        FlaxAlbertForMultipleChoice,
		        FlaxAlbertForQuestionAnswering,
		        FlaxAlbertForSequenceClassification,
		        FlaxAlbertForTokenClassification,
		        FlaxAlbertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)

		def 						A__		(   self   )						->   Dict:



								"""simple docstring"""






								UpperCamelCase       						=      FlaxAlbertModelTester(self   )


		@slow
		def 						A__		(   self   )						->   List[str]:



								"""simple docstring"""






								for model_class_name in self.all_model_classes:
														UpperCamelCase       						=      model_class_name.from_pretrained("""albert-base-v2"""   )
														UpperCamelCase       						=      model(np.ones((1, 1)   )   )
														self.assertIsNotNone(_SCREAMING_SNAKE_CASE   )






@require_flax
class        a_		(    unittest.TestCase       ):

		@slow
		def 						A__		(   self   )						->   Optional[int]:



								"""simple docstring"""






								UpperCamelCase       						=      FlaxAlbertModel.from_pretrained("""albert-base-v2"""   )
								UpperCamelCase       						=      np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]   )
								UpperCamelCase       						=      np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
								UpperCamelCase       						=      model(_SCREAMING_SNAKE_CASE    ,	attention_mask=_SCREAMING_SNAKE_CASE   )[0]
								UpperCamelCase       						=      (1, 11, 768)
								self.assertEqual(output.shape    ,	_SCREAMING_SNAKE_CASE   )
								UpperCamelCase       						=      np.array(
								    [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]   )

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








'''simple docstring'''

import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


SCREAMING_SNAKE_CASE__											=     logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__											=     {
    'SenseTime/deformable-detr': 'https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json',
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}






class        a_		(    lowerCamelCase       ):
  lowercase  	=   """deformable_detr"""
  lowercase  	=   {
      """hidden_size""": """d_model""",
      """num_attention_heads""": """encoder_attention_heads""",
  }

  def __init__(   self    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=None    ,	_SCREAMING_SNAKE_CASE=3    ,	_SCREAMING_SNAKE_CASE=300    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=6    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=8    ,	_SCREAMING_SNAKE_CASE=6    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=8    ,	_SCREAMING_SNAKE_CASE=0.0    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE="relu"    ,	_SCREAMING_SNAKE_CASE=256    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.0    ,	_SCREAMING_SNAKE_CASE=0.0    ,	_SCREAMING_SNAKE_CASE=0.0_2    ,	_SCREAMING_SNAKE_CASE=1.0    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE="sine"    ,	_SCREAMING_SNAKE_CASE="resnet50"    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=300    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE=5    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE=5    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.2_5    ,	_SCREAMING_SNAKE_CASE=False    ,	**_SCREAMING_SNAKE_CASE    ,	)						->   List[str]:



        """simple docstring"""






        if backbone_config is not None and use_timm_backbone:
              raise ValueError("""You can't specify both `backbone_config` and `use_timm_backbone`."""   )

        if not use_timm_backbone:
              if backbone_config is None:
                    logger.info("""`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone."""   )
                    UpperCamelCase       						=      CONFIG_MAPPING["""resnet"""](out_features=["""stage4"""]   )
              elif isinstance(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   ):
                    UpperCamelCase       						=      backbone_config.get("""model_type"""   )
                    UpperCamelCase       						=      CONFIG_MAPPING[backbone_model_type]
                    UpperCamelCase       						=      config_class.from_dict(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      use_timm_backbone
        UpperCamelCase       						=      backbone_config
        UpperCamelCase       						=      num_channels
        UpperCamelCase       						=      num_queries
        UpperCamelCase       						=      max_position_embeddings
        UpperCamelCase       						=      d_model
        UpperCamelCase       						=      encoder_ffn_dim
        UpperCamelCase       						=      encoder_layers
        UpperCamelCase       						=      encoder_attention_heads
        UpperCamelCase       						=      decoder_ffn_dim
        UpperCamelCase       						=      decoder_layers
        UpperCamelCase       						=      decoder_attention_heads
        UpperCamelCase       						=      dropout
        UpperCamelCase       						=      attention_dropout
        UpperCamelCase       						=      activation_dropout
        UpperCamelCase       						=      activation_function
        UpperCamelCase       						=      init_std
        UpperCamelCase       						=      init_xavier_std
        UpperCamelCase       						=      encoder_layerdrop
        UpperCamelCase       						=      auxiliary_loss
        UpperCamelCase       						=      position_embedding_type
        UpperCamelCase       						=      backbone
        UpperCamelCase       						=      use_pretrained_backbone
        UpperCamelCase       						=      dilation
        # deformable attributes
        UpperCamelCase       						=      num_feature_levels
        UpperCamelCase       						=      encoder_n_points
        UpperCamelCase       						=      decoder_n_points
        UpperCamelCase       						=      two_stage
        UpperCamelCase       						=      two_stage_num_proposals
        UpperCamelCase       						=      with_box_refine
        if two_stage is True and with_box_refine is False:
              raise ValueError("""If two_stage is True, with_box_refine must be True."""   )
        # Hungarian matcher
        UpperCamelCase       						=      class_cost
        UpperCamelCase       						=      bbox_cost
        UpperCamelCase       						=      giou_cost
        # Loss coefficients
        UpperCamelCase       						=      mask_loss_coefficient
        UpperCamelCase       						=      dice_loss_coefficient
        UpperCamelCase       						=      bbox_loss_coefficient
        UpperCamelCase       						=      giou_loss_coefficient
        UpperCamelCase       						=      eos_coefficient
        UpperCamelCase       						=      focal_alpha
        UpperCamelCase       						=      disable_custom_kernels
        super().__init__(is_encoder_decoder=_SCREAMING_SNAKE_CASE    ,	**_SCREAMING_SNAKE_CASE   )

  @property
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        return self.encoder_attention_heads

  @property
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        return self.d_model


  def 						A__		(   self   )						->   Tuple:



        """simple docstring"""






        UpperCamelCase       						=      copy.deepcopy(self.__dict__   )
        if self.backbone_config is not None:
              UpperCamelCase       						=      self.backbone_config.to_dict()
        UpperCamelCase       						=      self.__class__.model_type
        return output
