




"""simple docstring"""






import copy
import tempfile
import unittest

from transformers import MaMaaaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device
from transformers.utils import cached_property

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MaMaaaForConditionalGeneration, MaMaaaModel, MaMaaaTokenizer
				from transformers.models.mam_aaa.modeling_mam_aaa import MaMaaaDecoder, MaMaaaEncoder





def 							UpperCAmelCase		(		snake_case			:					Any      ,       snake_case			:					Tuple      ,       snake_case			:					Tuple      ,       snake_case			:					List[Any]=None      ,       snake_case			:					Dict=None      ,       snake_case			:					Optional[int]=None      ,       snake_case			:					str=None      ,       snake_case			:					Optional[int]=None      ,       ):
					if attention_mask is None:
										_lowerCAmelCase:List[str]									=  input_ids.ne(config.pad_token_id    )
					if decoder_attention_mask is None:
										_lowerCAmelCase:Optional[Any]									=  decoder_input_ids.ne(config.pad_token_id    )
					if head_mask is None:
										_lowerCAmelCase:Tuple									=  torch.ones(config.encoder_layers      ,       config.encoder_attention_heads      ,       device=snake_case    )
					if decoder_head_mask is None:
										_lowerCAmelCase:Dict									=  torch.ones(config.decoder_layers      ,       config.decoder_attention_heads      ,       device=snake_case    )
					if cross_attn_head_mask is None:
										_lowerCAmelCase:List[Any]									=  torch.ones(config.decoder_layers      ,       config.decoder_attention_heads      ,       device=snake_case    )
					return {
					    "input_ids": input_ids,
					    "decoder_input_ids": decoder_input_ids,
					    "attention_mask": attention_mask,
					    "decoder_attention_mask": attention_mask,
					    "head_mask": head_mask,
					    "decoder_head_mask": decoder_head_mask,
					    "cross_attn_head_mask": cross_attn_head_mask,
					}




class   a__			:





						def __init__(							self      :	Dict     ,a__      :	Optional[int]     ,a__      :	Union[str, Any]=13     ,a__      :	Optional[Any]=7     ,a__      :	Tuple=True     ,a__      :	Tuple=False     ,a__      :	Optional[int]=99     ,a__      :	List[str]=16     ,a__      :	Optional[int]=2     ,a__      :	Any=4     ,a__      :	Union[str, Any]=4     ,a__      :	int="relu"     ,a__      :	Union[str, Any]=0.1     ,a__      :	Optional[Any]=0.1     ,a__      :	Tuple=0.0     ,a__      :	Optional[int]=0.0     ,a__      :	List[str]=20     ,a__      :	Optional[Any]=2     ,a__      :	Optional[int]=1     ,a__      :	Tuple=0     ,)						->       Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  parent
											_lowerCAmelCase:str									=  batch_size
											_lowerCAmelCase:Union[str, Any]									=  seq_length
											_lowerCAmelCase:Optional[Any]									=  is_training
											_lowerCAmelCase:int									=  use_labels
											_lowerCAmelCase:Union[str, Any]									=  vocab_size
											_lowerCAmelCase:Optional[Any]									=  hidden_size
											_lowerCAmelCase:Tuple									=  num_hidden_layers
											_lowerCAmelCase:Optional[Any]									=  num_attention_heads
											_lowerCAmelCase:str									=  intermediate_size
											_lowerCAmelCase:str									=  hidden_act
											_lowerCAmelCase:Optional[Any]									=  hidden_dropout_prob
											_lowerCAmelCase:Any									=  attention_probs_dropout_prob
											_lowerCAmelCase:List[str]									=  encoder_layerdrop
											_lowerCAmelCase:Any									=  decoder_layerdrop
											_lowerCAmelCase:Union[str, Any]									=  max_position_embeddings
											_lowerCAmelCase:Dict									=  eos_token_id
											_lowerCAmelCase:Optional[int]									=  pad_token_id
											_lowerCAmelCase:Optional[int]									=  bos_token_id





						def       __UpperCamelCase     (							self      :	str)						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:int									=  ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size)
											_lowerCAmelCase:str									=  self.eos_token_id  # Eos Token
											_lowerCAmelCase:str									=  ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size)

											# we need to clamp the input ids here to avoid having pad token in between
											# this is because for M2M100 the position_ids are prepared such that
											# all pad tokens have pos id = 2 and rest are between 2..seq_length
											# and the seq_length here is seq_length - num_pad_tokens
											# but when using past, there is no way of knowing if the past input ids had
											# pad tokens in them, which results in incorrect seq_lenth and which in turn results in
											# position_ids being off by num_pad_tokens in past input
											_lowerCAmelCase:Any									=  input_ids.clamp(self.pad_token_id + 1)
											_lowerCAmelCase:Any									=  decoder_input_ids.clamp(self.pad_token_id + 1)

											_lowerCAmelCase:List[Any]									=  self.get_config()
											_lowerCAmelCase:str									=  prepare_mam_aaa_inputs_dict(a__     ,a__     ,a__)
											return config, inputs_dict





						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       Optional[Any]:




											"""simple docstring"""







											return MaMaaaConfig(
											    vocab_size=self.vocab_size     ,d_model=self.hidden_size     ,encoder_layers=self.num_hidden_layers     ,decoder_layers=self.num_hidden_layers     ,encoder_attention_heads=self.num_attention_heads     ,decoder_attention_heads=self.num_attention_heads     ,encoder_ffn_dim=self.intermediate_size     ,decoder_ffn_dim=self.intermediate_size     ,dropout=self.hidden_dropout_prob     ,attention_dropout=self.attention_probs_dropout_prob     ,encoder_layerdrop=self.encoder_layerdrop     ,decoder_layerdrop=self.decoder_layerdrop     ,max_position_embeddings=self.max_position_embeddings     ,eos_token_id=self.eos_token_id     ,bos_token_id=self.bos_token_id     ,pad_token_id=self.pad_token_id     ,)





						def       __UpperCamelCase     (							self      :	List[str])						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase							,   _lowerCAmelCase:Any									=  self.prepare_config_and_inputs()
											return config, inputs_dict





						def       __UpperCamelCase     (							self      :	Optional[Any]     ,a__      :	List[str]     ,a__      :	Tuple)						->       Any:




											"""simple docstring"""







											_lowerCAmelCase:Dict									=  MaMaaaModel(config=a__).get_decoder().to(a__).eval()
											_lowerCAmelCase:Optional[int]									=  inputs_dict['''input_ids''']
											_lowerCAmelCase:Any									=  inputs_dict['''attention_mask''']
											_lowerCAmelCase:Any									=  inputs_dict['''head_mask''']

											# first forward pass
											_lowerCAmelCase:int									=  model(a__     ,attention_mask=a__     ,head_mask=a__     ,use_cache=a__)

											_lowerCAmelCase							,   _lowerCAmelCase:int									=  outputs.to_tuple()

											# create hypothetical multiple next token and extent to next_input_ids
											_lowerCAmelCase:Optional[int]									=  ids_tensor((self.batch_size, 3)     ,config.vocab_size)
											_lowerCAmelCase:Union[str, Any]									=  ids_tensor((self.batch_size, 3)     ,2)

											# append to next input_ids and
											_lowerCAmelCase:Tuple									=  torch.cat([input_ids, next_tokens]     ,dim=-1)
											_lowerCAmelCase:str									=  torch.cat([attention_mask, next_attn_mask]     ,dim=-1)

											_lowerCAmelCase:List[str]									=  model(a__     ,attention_mask=a__)['''last_hidden_state''']
											_lowerCAmelCase:List[str]									=  model(a__     ,attention_mask=a__     ,past_key_values=a__)[
											    '''last_hidden_state'''
											]

											# select random slice
											_lowerCAmelCase:Dict									=  ids_tensor((1,)     ,output_from_past.shape[-1]).item()
											_lowerCAmelCase:Optional[Any]									=  output_from_no_past[:, -3:, random_slice_idx].detach()
											_lowerCAmelCase:int									=  output_from_past[:, :, random_slice_idx].detach()

											self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(a__     ,a__     ,atol=1E-2))







						def       __UpperCamelCase     (							self      :	Dict     ,a__      :	Optional[Any]     ,a__      :	List[str])						->       Tuple:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  MaMaaaModel(config=a__).to(a__).eval()
											_lowerCAmelCase:Any									=  model(**a__)

											_lowerCAmelCase:Tuple									=  outputs.encoder_last_hidden_state
											_lowerCAmelCase:List[str]									=  outputs.last_hidden_state

											with tempfile.TemporaryDirectory() as tmpdirname:
																_lowerCAmelCase:Any									=  model.get_encoder()
																encoder.save_pretrained(a__)
																_lowerCAmelCase:Optional[Any]									=  MaMaaaEncoder.from_pretrained(a__).to(a__)

											_lowerCAmelCase:Optional[int]									=  encoder(inputs_dict['''input_ids''']     ,attention_mask=inputs_dict['''attention_mask'''])[
											    0
											]

											self.parent.assertTrue((encoder_last_hidden_state_a - encoder_last_hidden_state).abs().max().item() < 1E-3)

											with tempfile.TemporaryDirectory() as tmpdirname:
																_lowerCAmelCase:Optional[Any]									=  model.get_decoder()
																decoder.save_pretrained(a__)
																_lowerCAmelCase:List[str]									=  MaMaaaDecoder.from_pretrained(a__).to(a__)

											_lowerCAmelCase:Optional[int]									=  decoder(
											    input_ids=inputs_dict['''decoder_input_ids''']     ,attention_mask=inputs_dict['''decoder_attention_mask''']     ,encoder_hidden_states=a__     ,encoder_attention_mask=inputs_dict['''attention_mask''']     ,)[0]

											self.parent.assertTrue((last_hidden_state_a - last_hidden_state).abs().max().item() < 1E-3)




@require_torch
class   a__			(       UpperCamelCase_					,	UpperCamelCase_					,	UpperCamelCase_					,	unittest.TestCase  ):
						snake_case__             = (
						    (
						        MaMaaaModel,
						        MaMaaaForConditionalGeneration,
						    )
						    if is_torch_available()
						    else ()
						)
						snake_case__             = (MaMaaaForConditionalGeneration,) if is_torch_available() else ()
						snake_case__             = (
						    {
						        '''conversational''': MaMaaaForConditionalGeneration,
						        '''feature-extraction''': MaMaaaModel,
						        '''summarization''': MaMaaaForConditionalGeneration,
						        '''text2text-generation''': MaMaaaForConditionalGeneration,
						        '''translation''': MaMaaaForConditionalGeneration,
						    }
						    if is_torch_available()
						    else {}
						)
						snake_case__             = True
						snake_case__             = True
						snake_case__             = False
						snake_case__             = False





						def       __UpperCamelCase     (							self      :	Tuple     ,a__      :	Dict     ,a__      :	List[Any]     ,a__      :	Optional[Any]     ,a__      :	Tuple     ,a__      :	List[Any])						->       Optional[Any]:




											"""simple docstring"""







											if pipeline_test_casse_name == "TranslationPipelineTests":
																# Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`.
																# `M2M100Config` was never used in pipeline tests: cannot create a simple tokenizer.
																return True

											return False





						def       __UpperCamelCase     (							self      :	Tuple)						->       Dict:




											"""simple docstring"""







											_lowerCAmelCase:str									=  MaMaaaModelTester(self)
											_lowerCAmelCase:Optional[Any]									=  ConfigTester(self     ,config_class=a__)





						def       __UpperCamelCase     (							self      :	Dict)						->       str:




											"""simple docstring"""







											self.config_tester.run_common_tests()





						def       __UpperCamelCase     (							self      :	str)						->       Dict:




											"""simple docstring"""







											_lowerCAmelCase							,   _lowerCAmelCase:Dict									=  self.model_tester.prepare_config_and_inputs()
											for model_class in self.all_model_classes:
																_lowerCAmelCase:List[Any]									=  model_class(a__)

																with tempfile.TemporaryDirectory() as tmpdirname:
																					model.save_pretrained(a__)
																					_lowerCAmelCase							,   _lowerCAmelCase:int									=  model_class.from_pretrained(a__     ,output_loading_info=a__)
																self.assertEqual(info['''missing_keys''']     ,[])





						def       __UpperCamelCase     (							self      :	int)						->       List[str]:




											"""simple docstring"""







											_lowerCAmelCase:Union[str, Any]									=  self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_decoder_model_past_large_inputs(*a__)





						def       __UpperCamelCase     (							self      :	Any)						->       Dict:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  self.model_tester.prepare_config_and_inputs_for_common()
											self.model_tester.check_encoder_decoder_model_standalone(*a__)





						def       __UpperCamelCase     (							self      :	List[str])						->       Any:




											"""simple docstring"""







											_lowerCAmelCase							,   _lowerCAmelCase:Optional[int]									=  self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in (MaMaaaModel, MaMaaaForConditionalGeneration):
																_lowerCAmelCase:Optional[int]									=  model_class(a__)
																model.to(a__)
																model.eval()

																_lowerCAmelCase:Optional[int]									=  copy.deepcopy(self._prepare_for_class(a__     ,a__))

																if not self.is_encoder_decoder:
																					_lowerCAmelCase:List[Any]									=  inputs['''input_ids''']
																					del inputs["input_ids"]
																else:
																					_lowerCAmelCase:int									=  inputs['''input_ids''']
																					_lowerCAmelCase:Union[str, Any]									=  inputs.get('''decoder_input_ids'''     ,a__)
																					del inputs["input_ids"]
																					inputs.pop('''decoder_input_ids'''     ,a__)

																_lowerCAmelCase:Tuple									=  model.get_input_embeddings()
																if not self.is_encoder_decoder:
																					_lowerCAmelCase:Tuple									=  wte(a__)
																else:
																					_lowerCAmelCase:int									=  wte(a__)
																					_lowerCAmelCase:Tuple									=  wte(a__)

																with torch.no_grad():
																					model(**a__)[0]







						def       __UpperCamelCase     (							self      :	Dict)						->       Optional[int]:




											"""simple docstring"""







											_lowerCAmelCase							,   _lowerCAmelCase:Any									=  self.model_tester.prepare_config_and_inputs()
											_lowerCAmelCase:Dict									=  input_dict['''input_ids''']
											_lowerCAmelCase:Tuple									=  input_ids.ne(1).to(a__)
											_lowerCAmelCase:Dict									=  MaMaaaForConditionalGeneration(a__).eval().to(a__)
											if torch_device == "cuda":
																model.half()
											model.generate(a__     ,attention_mask=a__)
											model.generate(num_beams=4     ,do_sample=a__     ,early_stopping=a__     ,num_return_sequences=3)





def 							UpperCAmelCase		(		snake_case			:					Tuple    ):
					return torch.tensor(snake_case      ,       dtype=torch.long      ,       device=snake_case    )


UpperCamelCase__						=			1e-4





@require_torch
@require_sentencepiece
@require_tokenizers
@slow
class   a__			(       unittest.TestCase  ):





						@cached_property
						def       __UpperCamelCase     (							self      :	List[Any])						->       Optional[Any]:




											"""simple docstring"""







											return MaMaaaTokenizer.from_pretrained('''facebook/m2m100_418M''')





						def       __UpperCamelCase     (							self      :	List[str])						->       Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:List[Any]									=  MaMaaaModel.from_pretrained('''facebook/m2m100_418M''').to(a__)
											_lowerCAmelCase:Union[str, Any]									=  _long_tensor([[12_8028, 98, 12, 3_0527, 2732, 159, 7755, 6_1904, 3_9144, 38, 2]])
											_lowerCAmelCase:List[Any]									=  _long_tensor([[2, 12_8028, 98, 12, 3_0527, 2732, 159, 7755, 6_1904, 3_9144, 38]])
											_lowerCAmelCase:Optional[Any]									=  prepare_mam_aaa_inputs_dict(model.config     ,a__     ,a__)
											with torch.no_grad():
																_lowerCAmelCase:Optional[Any]									=  model(**a__)[0]
											_lowerCAmelCase:Union[str, Any]									=  torch.Size((1, 11, 1024))
											self.assertEqual(output.shape     ,a__)
											# change to expected output here
											_lowerCAmelCase:List[Any]									=  torch.tensor(
											    [[-0.7780, -0.1676, 0.1038], [-6.7556, -1.3992, 0.0567], [-7.5383, -0.5920, -0.2779]]     ,device=a__)
											self.assertTrue(torch.allclose(output[:, :3, :3]     ,a__     ,atol=a__))





						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       List[str]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[int]									=  MaMaaaForConditionalGeneration.from_pretrained('''facebook/m2m100_418M''').to(a__)

											# change to intended input
											_lowerCAmelCase:Union[str, Any]									=  _long_tensor([[12_8028, 98, 12, 3_0527, 2732, 159, 7755, 6_1904, 3_9144, 38, 2]])
											_lowerCAmelCase:List[str]									=  _long_tensor([[2, 12_8028, 98, 12, 3_0527, 2732, 159, 7755, 6_1904, 3_9144, 38]])
											_lowerCAmelCase:List[str]									=  prepare_mam_aaa_inputs_dict(model.config     ,a__     ,a__)
											with torch.no_grad():
																_lowerCAmelCase:int									=  model(**a__)[0]
											_lowerCAmelCase:str									=  torch.Size((1, 11, model.config.vocab_size))
											self.assertEqual(output.shape     ,a__)
											# change to expected output here
											_lowerCAmelCase:Optional[int]									=  torch.tensor(
											    [[-1.0448, -1.0411, 3.7992], [-3.2191, -3.2386, -1.3451], [-3.6210, -3.5993, 0.4925]]     ,device=a__)
											self.assertTrue(torch.allclose(output[:, :3, :3]     ,a__     ,atol=a__))







						def       __UpperCamelCase     (							self      :	Dict)						->       Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  MaMaaaForConditionalGeneration.from_pretrained('''facebook/m2m100_418M''').to(a__)
											_lowerCAmelCase:Union[str, Any]									=  MaMaaaTokenizer.from_pretrained('''facebook/m2m100_418M'''     ,src_lang='''fr'''     ,tgt_lang='''en''')

											_lowerCAmelCase:Optional[Any]									=  [
											    '''L\'affaire NSA souligne l\'absence totale de débat sur le renseignement''',
											    '''Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.''',
											    '''Lorsque François Hollande téléphone à Barack Obama ou quand le ministre des affaires étrangères Laurent'''
											    ''' Fabius convoque l\'ambassadeur des Etats-Unis, ils réagissent à une vraie découverte, qui est celle de'''
											    ''' l\'ampleur de la surveillance américaine sur l\'ensemble des communications en France.''',
											]

											# The below article tests that we don't add any hypotheses outside of the top n_beams
											_lowerCAmelCase:List[Any]									=  tokenizer(a__     ,padding=a__     ,return_tensors='''pt''')

											_lowerCAmelCase:Any									=  model.generate(
											    input_ids=dct['''input_ids'''].to(a__)     ,attention_mask=dct['''attention_mask'''].to(a__)     ,num_beams=5     ,forced_bos_token_id=tokenizer.get_lang_id('''en''')     ,)

											_lowerCAmelCase:Union[str, Any]									=  [
											    '''The NSA case highlights the total absence of intelligence debate''',
											    '''I think there are two levels of response from the French government.''',
											    '''When François Hollande calls Barack Obama or when Foreign Minister Laurent Fabius calls the U.S.'''
											    ''' Ambassador, they respond to a real discovery, which is that of the scale of U.S. surveillance on all'''
											    ''' communications in France.''',
											]

											_lowerCAmelCase:Union[str, Any]									=  tokenizer.batch_decode(
											    hypotheses_batch.tolist()     ,clean_up_tokenization_spaces=a__     ,skip_special_tokens=a__)
											assert generated == expected_en












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




											"""simple docstring"""







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





						def       __UpperCamelCase     (							self      :	List[str])						->       int:




											"""simple docstring"""







											_lowerCAmelCase:int									=  ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size)

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

											_lowerCAmelCase:Dict									=  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_=a__     ,)

											return config, input_ids, attention_mask







						def       __UpperCamelCase     (							self      :	Any)						->       Any:




											"""simple docstring"""







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




@require_flax
class   a__			(       UpperCamelCase_					,	unittest.TestCase  ):
						snake_case__             = (
						    (
						        FlaxDistilBertModel,
						        FlaxDistilBertForMaskedLM,
						        FlaxDistilBertForMultipleChoice,
						        FlaxDistilBertForQuestionAnswering,
						        FlaxDistilBertForSequenceClassification,
						        FlaxDistilBertForTokenClassification,
						        FlaxDistilBertForQuestionAnswering,
						    )
						    if is_flax_available()
						    else ()
						)





						def       __UpperCamelCase     (							self      :	str)						->       Dict:




											"""simple docstring"""







											_lowerCAmelCase:str									=  FlaxDistilBertModelTester(self)







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




											"""simple docstring"""







											for model_class_name in self.all_model_classes:
																_lowerCAmelCase:List[str]									=  model_class_name.from_pretrained('''distilbert-base-uncased''')
																_lowerCAmelCase:Tuple									=  model(np.ones((1, 1)))
																self.assertIsNotNone(a__)




@require_flax
class   a__			(       unittest.TestCase  ):





						@slow
						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Any									=  FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased''')
											_lowerCAmelCase:Optional[int]									=  np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
											_lowerCAmelCase:Tuple									=  np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
											_lowerCAmelCase:List[str]									=  model(a__     ,attention_mask=a__)[0]
											_lowerCAmelCase:List[str]									=  (1, 11, 768)
											self.assertEqual(output.shape     ,a__)
											_lowerCAmelCase: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]     ,a__     ,atol=1E-4))






