





import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
      import torch


lowercase_          =		random.Random()




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE=1.0		,						_SCREAMING_SNAKE_CASE=None		,						_SCREAMING_SNAKE_CASE=None		)    ->       Union[str, Any]:
  if rng is None:
    lowercase__           =  global_rng

  lowercase__           =  []
  for batch_idx in range(shape[0]		):
    values.append([]		)
    for _ in range(shape[1]		):
      values[-1].append(rng.random() * scale		)

  return values
@require_torch
class     SCREAMING_SNAKE_CASE       (unittest.TestCase				):


   def __init__(   self      :    int      ,					a      :    str      ,					a      :    Any=7      ,					a      :    Any=400      ,					a      :    Optional[int]=2_000      ,					a      :    Optional[int]=1      ,					a      :    List[str]=0.0      ,					a      :    Any=16_000      ,					a      :    List[str]=True      ,					a      :    int=80      ,					a      :    List[Any]=16      ,					a      :    List[Any]=64      ,					a      :    Dict="hann_window"      ,					a      :    List[str]=80      ,					a      :    List[Any]=7_600      ,					a      :    Union[str, Any]=1E-1_0      ,					a      :    Dict=True      ,					)->       int:





     """simple docstring"""







     lowercase__           =  parent
     lowercase__           =  batch_size
     lowercase__           =  min_seq_length
     lowercase__           =  max_seq_length
     lowercase__           =  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
     lowercase__           =  feature_size
     lowercase__           =  padding_value
     lowercase__           =  sampling_rate
     lowercase__           =  do_normalize
     lowercase__           =  num_mel_bins
     lowercase__           =  hop_length
     lowercase__           =  win_length
     lowercase__           =  win_function
     lowercase__           =  fmin
     lowercase__           =  fmax
     lowercase__           =  mel_floor
     lowercase__           =  return_attention_mask


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[int]	)->       str:





     """simple docstring"""







     return {
         "feature_size": self.feature_size,
         "padding_value": self.padding_value,
         "sampling_rate": self.sampling_rate,
         "do_normalize": self.do_normalize,
         "num_mel_bins": self.num_mel_bins,
         "hop_length": self.hop_length,
         "win_length": self.win_length,
         "win_function": self.win_function,
         "fmin": self.fmin,
         "fmax": self.fmax,
         "mel_floor": self.mel_floor,
         "return_attention_mask": self.return_attention_mask,
     }


   def 	SCREAMING_SNAKE_CASE_							(   self      :    str      ,					a      :    Optional[int]=False      ,					a      :    List[Any]=False	)->       Union[str, Any]:





     """simple docstring"""







     def _flatten(a      :    Dict	):
       return list(itertools.chain(*a	)	)

     if equal_length:
       lowercase__           =  floats_list((self.batch_size, self.max_seq_length)	)
     else:
       # make sure that inputs increase in size
       lowercase__           =  [
           _flatten(floats_list((x, self.feature_size)	)	)
           for x in range(self.min_seq_length      ,					self.max_seq_length      ,					self.seq_length_diff	)
       ]

     if numpify:
       lowercase__           =  [np.asarray(a	) for x in speech_inputs]

     return speech_inputs


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]      ,					a      :    Optional[int]=False      ,					a      :    int=False	)->       int:





     """simple docstring"""







     if equal_length:
       lowercase__           =  [floats_list((self.max_seq_length, self.num_mel_bins)	) for _ in range(self.batch_size	)]
     else:
       # make sure that inputs increase in size
       lowercase__           =  [
           floats_list((x, self.num_mel_bins)	)
           for x in range(self.min_seq_length      ,					self.max_seq_length      ,					self.seq_length_diff	)
       ]

     if numpify:
       lowercase__           =  [np.asarray(a	) for x in speech_inputs]

     return speech_inputs






@require_torch
class     SCREAMING_SNAKE_CASE       (UpperCAmelCase      ,     unittest.TestCase				):
   _UpperCamelCase   :		str			 =	SpeechTaFeatureExtractor


   def 	SCREAMING_SNAKE_CASE_							(   self      :    int	)->       int:





     """simple docstring"""







     lowercase__           =  SpeechTaFeatureExtractionTester(self	)


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





     """simple docstring"""







     self.assertTrue(np.all(np.mean(a      ,					axis=0	) < 1E-3	)	)
     self.assertTrue(np.all(np.abs(np.var(a      ,					axis=0	) - 1	) < 1E-3	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       Any:





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     # create three inputs of length 800, 1000, and 1200
     lowercase__           =  [floats_list((1, x)	)[0] for x in range(800      ,					1_400      ,					200	)]
     lowercase__           =  [np.asarray(a	) for speech_input in speech_inputs]

     # Test not batched input
     lowercase__           =  feat_extract(speech_inputs[0]      ,					return_tensors='np'	).input_values
     lowercase__           =  feat_extract(np_speech_inputs[0]      ,					return_tensors='np'	).input_values
     self.assertTrue(np.allclose(a      ,					a      ,					atol=1E-3	)	)

     # Test batched
     lowercase__           =  feat_extract(a      ,					return_tensors='np'	).input_values
     lowercase__           =  feat_extract(a      ,					return_tensors='np'	).input_values
     for enc_seq_a, enc_seq_a in zip(a      ,					a	):
       self.assertTrue(np.allclose(a      ,					a      ,					atol=1E-3	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple	)->       Optional[int]:





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     lowercase__           =  [floats_list((1, x)	)[0] for x in range(800      ,					1_400      ,					200	)]

     lowercase__           =  ['longest', 'max_length', 'do_not_pad']
     lowercase__           =  [None, 1_600, None]
     for max_length, padding in zip(a      ,					a	):
       lowercase__           =  feat_extract(a      ,					padding=a      ,					max_length=a      ,					return_tensors='np'	)
       lowercase__           =  processed.input_values

       self._check_zero_mean_unit_variance(input_values[0][:800]	)
       self.assertTrue(input_values[0][800:].sum() < 1E-6	)
       self._check_zero_mean_unit_variance(input_values[1][:1_000]	)
       self.assertTrue(input_values[0][1_000:].sum() < 1E-6	)
       self._check_zero_mean_unit_variance(input_values[2][:1_200]	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       str:





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     lowercase__           =  range(800      ,					1_400      ,					200	)
     lowercase__           =  [floats_list((1, x)	)[0] for x in lengths]

     lowercase__           =  ['longest', 'max_length', 'do_not_pad']
     lowercase__           =  [None, 1_600, None]

     for max_length, padding in zip(a      ,					a	):
       lowercase__           =  feat_extract(a      ,					max_length=a      ,					padding=a	)
       lowercase__           =  processed.input_values

       self._check_zero_mean_unit_variance(input_values[0][:800]	)
       self._check_zero_mean_unit_variance(input_values[1][:1_000]	)
       self._check_zero_mean_unit_variance(input_values[2][:1_200]	)


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





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     lowercase__           =  [floats_list((1, x)	)[0] for x in range(800      ,					1_400      ,					200	)]
     lowercase__           =  feat_extract(
         a      ,					truncation=a      ,					max_length=1_000      ,					padding='max_length'      ,					return_tensors='np'	)
     lowercase__           =  processed.input_values

     self._check_zero_mean_unit_variance(input_values[0, :800]	)
     self._check_zero_mean_unit_variance(input_values[1]	)
     self._check_zero_mean_unit_variance(input_values[2]	)


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





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     lowercase__           =  [floats_list((1, x)	)[0] for x in range(800      ,					1_400      ,					200	)]
     lowercase__           =  feat_extract(
         a      ,					truncation=a      ,					max_length=1_000      ,					padding='longest'      ,					return_tensors='np'	)
     lowercase__           =  processed.input_values

     self._check_zero_mean_unit_variance(input_values[0, :800]	)
     self._check_zero_mean_unit_variance(input_values[1, :1_000]	)
     self._check_zero_mean_unit_variance(input_values[2]	)

     # make sure that if max_length < longest -> then pad to max_length
     self.assertTrue(input_values.shape == (3, 1_000)	)

     lowercase__           =  [floats_list((1, x)	)[0] for x in range(800      ,					1_400      ,					200	)]
     lowercase__           =  feat_extract(
         a      ,					truncation=a      ,					max_length=2_000      ,					padding='longest'      ,					return_tensors='np'	)
     lowercase__           =  processed.input_values

     self._check_zero_mean_unit_variance(input_values[0, :800]	)
     self._check_zero_mean_unit_variance(input_values[1, :1_000]	)
     self._check_zero_mean_unit_variance(input_values[2]	)

     # make sure that if max_length > longest -> then pad to longest
     self.assertTrue(input_values.shape == (3, 1_200)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       Optional[Any]:





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     lowercase__           =  np.random.rand(100	).astype(np.floataa	)
     lowercase__           =  np_speech_inputs.tolist()

     for inputs in [py_speech_inputs, np_speech_inputs]:
       lowercase__           =  feature_extractor.pad([{'input_values': inputs}]      ,					return_tensors='np'	)
       self.assertTrue(np_processed.input_values.dtype == np.floataa	)
       lowercase__           =  feature_extractor.pad([{'input_values': inputs}]      ,					return_tensors='pt'	)
       self.assertTrue(pt_processed.input_values.dtype == torch.floataa	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
     # create three inputs of length 800, 1000, and 1200
     lowercase__           =  [floats_list((1, x)	)[0] for x in range(800      ,					1_400      ,					200	)]
     lowercase__           =  [np.asarray(a	) for speech_input in speech_inputs]

     # Test feature size
     lowercase__           =  feature_extractor(audio_target=a      ,					padding=a      ,					return_tensors='np'	).input_values
     self.assertTrue(input_values.ndim == 3	)
     self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins	)

     # Test not batched input
     lowercase__           =  feature_extractor(speech_inputs[0]      ,					return_tensors='np'	).input_values
     lowercase__           =  feature_extractor(np_speech_inputs[0]      ,					return_tensors='np'	).input_values
     self.assertTrue(np.allclose(a      ,					a      ,					atol=1E-3	)	)

     # Test batched
     lowercase__           =  feature_extractor(a      ,					return_tensors='np'	).input_values
     lowercase__           =  feature_extractor(a      ,					return_tensors='np'	).input_values
     for enc_seq_a, enc_seq_a in zip(a      ,					a	):
       self.assertTrue(np.allclose(a      ,					a      ,					atol=1E-3	)	)

     # Test 2-D numpy arrays are batched.
     lowercase__           =  [floats_list((1, x)	)[0] for x in (800, 800, 800)]
     lowercase__           =  np.asarray(a	)
     lowercase__           =  feature_extractor(a      ,					return_tensors='np'	).input_values
     lowercase__           =  feature_extractor(a      ,					return_tensors='np'	).input_values
     for enc_seq_a, enc_seq_a in zip(a      ,					a	):
       self.assertTrue(np.allclose(a      ,					a      ,					atol=1E-3	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    int	)->       int:





     """simple docstring"""







     lowercase__           =  self.feat_extract_tester.prepare_inputs_for_target()
     lowercase__           =  self.feature_extraction_class(**self.feat_extract_dict	)
     lowercase__           =  feat_extract.model_input_names[0]

     lowercase__           =  BatchFeature({input_name: speech_inputs}	)

     self.assertTrue(all(len(a	) == len(a	) for x, y in zip(a      ,					processed_features[input_name]	)	)	)

     lowercase__           =  self.feat_extract_tester.prepare_inputs_for_target(equal_length=a	)
     lowercase__           =  BatchFeature({input_name: speech_inputs}      ,					tensor_type='np'	)

     lowercase__           =  processed_features[input_name]

     if len(batch_features_input.shape	) < 3:
       lowercase__           =  batch_features_input[:, :, None]

     self.assertTrue(
         batch_features_input.shape
         == (self.feat_extract_tester.batch_size, len(speech_inputs[0]	), self.feat_extract_tester.num_mel_bins)	)


   @require_torch
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       str:





     """simple docstring"""







     lowercase__           =  self.feat_extract_tester.prepare_inputs_for_target(equal_length=a	)
     lowercase__           =  self.feature_extraction_class(**self.feat_extract_dict	)
     lowercase__           =  feat_extract.model_input_names[0]

     lowercase__           =  BatchFeature({input_name: speech_inputs}      ,					tensor_type='pt'	)

     lowercase__           =  processed_features[input_name]

     if len(batch_features_input.shape	) < 3:
       lowercase__           =  batch_features_input[:, :, None]

     self.assertTrue(
         batch_features_input.shape
         == (self.feat_extract_tester.batch_size, len(speech_inputs[0]	), self.feat_extract_tester.num_mel_bins)	)


   @require_torch
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[int]	)->       Optional[int]:





     """simple docstring"""







     lowercase__           =  self.feature_extraction_class(**self.feat_extract_dict	)
     lowercase__           =  self.feat_extract_tester.prepare_inputs_for_target()
     lowercase__           =  feat_extract.model_input_names[0]

     lowercase__           =  BatchFeature({input_name: speech_inputs}	)

     lowercase__           =  feat_extract.num_mel_bins  # hack!

     lowercase__           =  feat_extract.pad(a      ,					padding='longest'      ,					return_tensors='np'	)[input_name]
     lowercase__           =  feat_extract.pad(a      ,					padding='longest'      ,					return_tensors='pt'	)[input_name]

     self.assertTrue(abs(input_np.astype(np.floataa	).sum() - input_pt.numpy().astype(np.floataa	).sum()	) < 1E-2	)


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





     """simple docstring"""







     lowercase__           =  self.feat_extract_dict
     lowercase__           =  True
     lowercase__           =  self.feature_extraction_class(**a	)
     lowercase__           =  self.feat_extract_tester.prepare_inputs_for_target()
     lowercase__           =  [len(a	) for x in speech_inputs]
     lowercase__           =  feat_extract.model_input_names[0]

     lowercase__           =  BatchFeature({input_name: speech_inputs}	)

     lowercase__           =  feat_extract.num_mel_bins  # hack!

     lowercase__           =  feat_extract.pad(a      ,					padding='longest'      ,					return_tensors='np'	)
     self.assertIn('attention_mask'      ,					a	)
     self.assertListEqual(list(processed.attention_mask.shape	)      ,					list(processed[input_name].shape[:2]	)	)
     self.assertListEqual(processed.attention_mask.sum(-1	).tolist()      ,					a	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       Tuple:





     """simple docstring"""







     lowercase__           =  self.feat_extract_dict
     lowercase__           =  True
     lowercase__           =  self.feature_extraction_class(**a	)
     lowercase__           =  self.feat_extract_tester.prepare_inputs_for_target()
     lowercase__           =  [len(a	) for x in speech_inputs]
     lowercase__           =  feat_extract.model_input_names[0]

     lowercase__           =  BatchFeature({input_name: speech_inputs}	)
     lowercase__           =  min(a	)

     lowercase__           =  feat_extract.num_mel_bins  # hack!

     lowercase__           =  feat_extract.pad(
         a      ,					padding='max_length'      ,					max_length=a      ,					truncation=a      ,					return_tensors='np'	)
     self.assertIn('attention_mask'      ,					a	)
     self.assertListEqual(
         list(processed_pad.attention_mask.shape	)      ,					[processed_pad[input_name].shape[0], max_length]	)
     self.assertListEqual(
         processed_pad.attention_mask[:, :max_length].sum(-1	).tolist()      ,					[max_length for x in speech_inputs]	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    str      ,					a      :    Dict	)->       int:





     """simple docstring"""







     from datasets import load_dataset

     lowercase__           =  load_dataset('hf-internal-testing/librispeech_asr_dummy'      ,					'clean'      ,					split='validation'	)
     # automatic decoding with librispeech
     lowercase__           =  ds.sort('id'	).select(range(a	)	)[:num_samples]['audio']

     return [x["array"] for x in speech_samples]


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





     """simple docstring"""







     lowercase__           =  torch.tensor(
         [2.3_8_0_4E-0_3, 2.0_7_5_2E-0_3, 1.9_8_3_6E-0_3, 2.1_0_5_7E-0_3, 1.6_1_7_4E-0_3,
          3.0_5_1_8E-0_4, 9.1_5_5_3E-0_5, 3.3_5_6_9E-0_4, 9.7_6_5_6E-0_4, 1.8_3_1_1E-0_3,
          2.0_1_4_2E-0_3, 2.1_0_5_7E-0_3, 1.7_3_9_5E-0_3, 4.5_7_7_6E-0_4, -3.9_6_7_3E-0_4,
          4.5_7_7_6E-0_4, 1.0_0_7_1E-0_3, 9.1_5_5_3E-0_5, 4.8_8_2_8E-0_4, 1.1_5_9_7E-0_3,
          7.3_2_4_2E-0_4, 9.4_6_0_4E-0_4, 1.8_0_0_5E-0_3, 1.8_3_1_1E-0_3, 8.8_5_0_1E-0_4,
          4.2_7_2_5E-0_4, 4.8_8_2_8E-0_4, 7.3_2_4_2E-0_4, 1.0_9_8_6E-0_3, 2.1_0_5_7E-0_3]	)
     # fmt: on

     lowercase__           =  self._load_datasamples(1	)
     lowercase__           =  SpeechTaFeatureExtractor()
     lowercase__           =  feature_extractor(a      ,					return_tensors='pt'	).input_values
     self.assertEquals(input_values.shape      ,					(1, 93_680)	)
     self.assertTrue(torch.allclose(input_values[0, :30]      ,					a      ,					atol=1E-6	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       Dict:





     """simple docstring"""







     lowercase__           =  torch.tensor(
         [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
          -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
          -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
          -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]	)
     # fmt: on

     lowercase__           =  self._load_datasamples(1	)
     lowercase__           =  SpeechTaFeatureExtractor()
     lowercase__           =  feature_extractor(audio_target=a      ,					return_tensors='pt'	).input_values
     self.assertEquals(input_values.shape      ,					(1, 366, 80)	)
     self.assertTrue(torch.allclose(input_values[0, 0, :30]      ,					a      ,					atol=1E-4	)	)









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


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





     """simple docstring"""







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


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





     """simple docstring"""







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

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

     lowercase__           =  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 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]	)->       Any:





     """simple docstring"""







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






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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       List[str]:





     """simple docstring"""







     lowercase__           =  FlaxDistilBertModelTester(self	)


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





     """simple docstring"""







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






@require_flax
class     SCREAMING_SNAKE_CASE       (unittest.TestCase				):


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





     """simple docstring"""







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


