






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






      '''simple docstring'''

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




          '''simple docstring'''


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




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  Tuple    						=		ids_tensor([self.batch_size, self.seq_length]						,	self.vocab_size)

          SCREAMING_SNAKE_CASE_      :  List[str]    						=		None
          if self.use_attention_mask:
              SCREAMING_SNAKE_CASE_      :  Tuple    						=		random_attention_mask([self.batch_size, self.seq_length])

          SCREAMING_SNAKE_CASE_      :  str    						=		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_=UpperCamelCase__						,	)

          return config, input_ids, attention_mask



      def _SCREAMING_SNAKE_CASE (						self     :  List[str]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		self.prepare_config_and_inputs()
          SCREAMING_SNAKE_CASE_      :  str    						=		config_and_inputs
          SCREAMING_SNAKE_CASE_      :  int    						=		{"input_ids": input_ids, "attention_mask": attention_mask}
          return config, inputs_dict




@require_flax
class 							lowerCAmelCase__				(			__snake_case				,		unittest.TestCase ):






      '''simple docstring'''

      __UpperCamelCase	 =  (
          (
              FlaxDistilBertModel,
              FlaxDistilBertForMaskedLM,
              FlaxDistilBertForMultipleChoice,
              FlaxDistilBertForQuestionAnswering,
              FlaxDistilBertForSequenceClassification,
              FlaxDistilBertForTokenClassification,
              FlaxDistilBertForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )
      def _SCREAMING_SNAKE_CASE (						self     :  List[str]):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  int    						=		FlaxDistilBertModelTester(self)



      @slow
      def _SCREAMING_SNAKE_CASE (						self     :  Any):




          '''simple docstring'''


          for model_class_name in self.all_model_classes:
              SCREAMING_SNAKE_CASE_      :  Tuple    						=		model_class_name.from_pretrained('''distilbert-base-uncased''')
              SCREAMING_SNAKE_CASE_      :  str    						=		model(np.ones((1, 1)))
              self.assertIsNotNone(UpperCamelCase__)




@require_flax
class 							lowerCAmelCase__				(			unittest.TestCase ):






      '''simple docstring'''

      @slow
      def _SCREAMING_SNAKE_CASE (						self     :  Any):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased''')
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		model(UpperCamelCase__						,	attention_mask=UpperCamelCase__)[0]
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		(1, 11, 768)
          self.assertEqual(output.shape						,	UpperCamelCase__)
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		np.array([[[-0.16_39, 0.32_99, 0.16_48], [-0.17_46, 0.32_89, 0.17_10], [-0.18_84, 0.33_57, 0.18_10]]])

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





"""simple docstring"""


import copy
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional, Union





@dataclass
class     snake_case	:
				SCREAMING_SNAKE_CASE_   :      Optional[Union[str, Path]]         =  None
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      Optional[Dict]         =  None
				SCREAMING_SNAKE_CASE_   :      Optional[str]         =  None
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      bool         =  True
				SCREAMING_SNAKE_CASE_   :      Optional[int]         =  None
				SCREAMING_SNAKE_CASE_   :      int         =  1
				SCREAMING_SNAKE_CASE_   :      Optional[Union[str, bool]]         =  None
				SCREAMING_SNAKE_CASE_   :      bool         =  False
				SCREAMING_SNAKE_CASE_   :      Optional[Dict]         =  None
				SCREAMING_SNAKE_CASE_   :      Optional[str]         =  None

				def 							lowercase_     (	self							:				str)->   "DownloadConfig":



						'''simple docstring'''


						return self.__class__(**{k: copy.deepcopy(UpperCamelCase__) for k, v in self.__dict__.items()})


