




'''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		:			Tuple     ,       lowercase		:			Optional[int]     ,       lowercase		:			Dict=13     ,       lowercase		:			List[Any]=7     ,       lowercase		:			Tuple=True     ,       lowercase		:			Optional[Any]=True     ,       lowercase		:			List[str]=True     ,       lowercase		:			str=True     ,       lowercase		:			Dict=99     ,       lowercase		:			Dict=32     ,       lowercase		:			Tuple=5     ,       lowercase		:			Optional[Any]=4     ,       lowercase		:			List[Any]=37     ,       lowercase		:			int="gelu"     ,       lowercase		:			List[str]=0.1     ,       lowercase		:			Optional[int]=0.1     ,       lowercase		:			Any=512     ,       lowercase		:			Optional[int]=16     ,       lowercase		:			Any=2     ,       lowercase		:			List[Any]=0.02     ,       lowercase		:			Optional[Any]=4     ,       ):



											'''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		:			Tuple       ):



											'''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     =	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_=lowercase     ,       )

											return config, input_ids, attention_mask







							def 					A   (			self		:			str       ):



											'''simple docstring'''

											UpperCAmelCase     =	self.prepare_config_and_inputs()
											UpperCAmelCase ,  UpperCAmelCase ,  UpperCAmelCase     =	config_and_inputs
											UpperCAmelCase     =	{'''input_ids''': input_ids, '''attention_mask''': attention_mask}
											return config, inputs_dict






@require_flax
class     _a						(			__a							,							unittest.TestCase				):
							__a       :  Dict            =      (
							    (
							        FlaxDistilBertModel,
							        FlaxDistilBertForMaskedLM,
							        FlaxDistilBertForMultipleChoice,
							        FlaxDistilBertForQuestionAnswering,
							        FlaxDistilBertForSequenceClassification,
							        FlaxDistilBertForTokenClassification,
							        FlaxDistilBertForQuestionAnswering,
							    )
							    if is_flax_available()
							    else ()
							)
							def 					A   (			self		:			Union[str, Any]       ):



											'''simple docstring'''

											UpperCAmelCase     =	FlaxDistilBertModelTester(self       )







							@slow
							def 					A   (			self		:			List[Any]       ):



											'''simple docstring'''

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






@require_flax
class     _a						(			unittest.TestCase				):
							@slow
							def 					A   (			self		:			Union[str, Any]       ):



											'''simple docstring'''

											UpperCAmelCase     =	FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''       )
											UpperCAmelCase     =	np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]       )
											UpperCAmelCase     =	np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
											UpperCAmelCase     =	model(lowercase     ,       attention_mask=lowercase       )[0]
											UpperCAmelCase     =	(1, 11, 768)
											self.assertEqual(output.shape     ,       lowercase       )
											UpperCAmelCase     =	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]     ,       lowercase     ,       atol=1E-4       )       )










'''simple docstring'''







from ...configuration_utils import PretrainedConfig
from ...utils import logging


A									=logging.get_logger(__name__)

A									={
    'alibaba-damo/mgp-str-base': 'https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json',
}


class     _a						(			__a				):
       __a       :  List[Any]            =      """mgp-str"""
       def __init__(			self		:			str     ,       lowercase		:			str=[32, 128]     ,       lowercase		:			Optional[Any]=4     ,       lowercase		:			Optional[Any]=3     ,       lowercase		:			Dict=27     ,       lowercase		:			Any=38     ,       lowercase		:			int=50_257     ,       lowercase		:			List[str]=30_522     ,       lowercase		:			Optional[int]=768     ,       lowercase		:			List[Any]=12     ,       lowercase		:			Tuple=12     ,       lowercase		:			Optional[int]=4.0     ,       lowercase		:			Union[str, Any]=True     ,       lowercase		:			str=False     ,       lowercase		:			str=1E-5     ,       lowercase		:			Dict=0.0     ,       lowercase		:			Dict=0.0     ,       lowercase		:			Tuple=0.0     ,       lowercase		:			str=False     ,       lowercase		:			Optional[Any]=0.02     ,       **lowercase		:			List[str]     ,       ):



           '''simple docstring'''

           super().__init__(**lowercase       )

           UpperCAmelCase     =	image_size
           UpperCAmelCase     =	patch_size
           UpperCAmelCase     =	num_channels
           UpperCAmelCase     =	max_token_length
           UpperCAmelCase     =	num_character_labels
           UpperCAmelCase     =	num_bpe_labels
           UpperCAmelCase     =	num_wordpiece_labels
           UpperCAmelCase     =	hidden_size
           UpperCAmelCase     =	num_hidden_layers
           UpperCAmelCase     =	num_attention_heads
           UpperCAmelCase     =	mlp_ratio
           UpperCAmelCase     =	distilled
           UpperCAmelCase     =	layer_norm_eps
           UpperCAmelCase     =	drop_rate
           UpperCAmelCase     =	qkv_bias
           UpperCAmelCase     =	attn_drop_rate
           UpperCAmelCase     =	drop_path_rate
           UpperCAmelCase     =	output_aa_attentions
           UpperCAmelCase     =	initializer_range




