





'''simple docstring'''

import itertools
import random
import unittest

import numpy as np

from transformers import ASTFeatureExtractor
from transformers.testing_utils import require_torch, require_torchaudio
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


lowercase__						:			str       =				random.Random()

if is_torch_available():
   import torch







def 					a__				(				lowercase					:     Optional[int],					lowercase					:     List[str]=1.0,					lowercase					:     Tuple=None,					lowercase					:     Optional[int]=None      )		->		Optional[Any]:





     """simple docstring"""

     if rng is None:
          _UpperCamelCase				    =       global_rng

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

     return values
class 				__lowerCAmelCase     (    unittest.TestCase ):






       """simple docstring"""





       def __init__(							self   :		Union[str, Any]       , lowerCAmelCase__   :		Dict       , lowerCAmelCase__   :		int=7       , lowerCAmelCase__   :		Tuple=400       , lowerCAmelCase__   :		Tuple=2000       , lowerCAmelCase__   :		Optional[int]=1       , lowerCAmelCase__   :		List[Any]=0.0       , lowerCAmelCase__   :		Dict=16000       , lowerCAmelCase__   :		List[Any]=True       , lowerCAmelCase__   :		Tuple=True       , )    ->     Dict:

            '''simple docstring'''




            _UpperCamelCase				    =       parent
            _UpperCamelCase				    =       batch_size
            _UpperCamelCase				    =       min_seq_length
            _UpperCamelCase				    =       max_seq_length
            _UpperCamelCase				    =       (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
            _UpperCamelCase				    =       feature_size
            _UpperCamelCase				    =       padding_value
            _UpperCamelCase				    =       sampling_rate
            _UpperCamelCase				    =       return_attention_mask
            _UpperCamelCase				    =       do_normalize





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

            '''simple docstring'''




            return {
                "feature_size": self.feature_size,
                "padding_value": self.padding_value,
                "sampling_rate": self.sampling_rate,
                "return_attention_mask": self.return_attention_mask,
                "do_normalize": self.do_normalize,
            }







       def snake_case__						(							self   :		List[Any]       , lowerCAmelCase__   :		str=False       , lowerCAmelCase__   :		Optional[int]=False     )    ->     Any:

            '''simple docstring'''




            def _flatten(lowerCAmelCase__   :		Tuple     ):
                 return list(itertools.chain(*A_     )     )

            if equal_length:
                 _UpperCamelCase				    =       floats_list((self.batch_size, self.max_seq_length)     )
            else:
                 # make sure that inputs increase in size
                 _UpperCamelCase				    =       [
                     _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:
                 _UpperCamelCase				    =       [np.asarray(A_     ) for x in speech_inputs]

            return speech_inputs

@require_torch
@require_torchaudio
class 				__lowerCAmelCase     (    __snake_case						,						unittest.TestCase ):






       """simple docstring"""
       _snake_case	:     Optional[Any]										=    ASTFeatureExtractor





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

            '''simple docstring'''




            _UpperCamelCase				    =       ASTFeatureExtractionTester(self     )





       def snake_case__						(							self   :		str     )    ->     Tuple:

            '''simple docstring'''




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

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

            # Test batched
            _UpperCamelCase				    =       feat_extract(A_       , padding=A_       , return_tensors='''np'''     ).input_values
            _UpperCamelCase				    =       feat_extract(A_       , padding=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.
            _UpperCamelCase				    =       [floats_list((1, x)     )[0] for x in (800, 800, 800)]
            _UpperCamelCase				    =       np.asarray(A_     )
            _UpperCamelCase				    =       feat_extract(A_       , return_tensors='''np'''     ).input_values
            _UpperCamelCase				    =       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     )     )





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

            '''simple docstring'''




            import torch

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

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





       def snake_case__						(							self   :		Dict       , lowerCAmelCase__   :		Tuple     )    ->     Optional[int]:

            '''simple docstring'''




            from datasets import load_dataset

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

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







       @require_torch
       def snake_case__						(							self   :		Tuple     )    ->     Any:

            '''simple docstring'''




            _UpperCamelCase				    =       torch.tensor(
                [-0.9894, -1.2776, -0.9066, -1.2776, -0.9349, -1.2609, -1.0386, -1.2776,
                 -1.1561, -1.2776, -1.2052, -1.2723, -1.2190, -1.2132, -1.2776, -1.1133,
                 -1.1953, -1.1343, -1.1584, -1.2203, -1.1770, -1.2474, -1.2381, -1.1936,
                 -0.9270, -0.8317, -0.8049, -0.7706, -0.7565, -0.7869]     )
            # fmt: on

            _UpperCamelCase				    =       self._load_datasamples(1     )
            _UpperCamelCase				    =       ASTFeatureExtractor()
            _UpperCamelCase				    =       feature_extractor(A_       , return_tensors='''pt'''     ).input_values
            self.assertEquals(input_values.shape       , (1, 1024, 128)     )
            self.assertTrue(torch.allclose(input_values[0, 0, :30]       , A_       , atol=1e-4     )     )










import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
__lowerCamelCase       :     str   =     """src/transformers"""


# This is to make sure the transformers module imported is the one in the repo.
__lowerCamelCase       :     Tuple   =     direct_transformers_import(PATH_TO_TRANSFORMERS)

__lowerCamelCase       :     List[str]   =     transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
__lowerCamelCase       :     Optional[Any]   =     re.compile(r"""\[(.+?)\]\((https://huggingface\.co/.+?)\)""")


__lowerCamelCase       :     List[str]   =     {
    """DecisionTransformerConfig""",
    """EncoderDecoderConfig""",
    """MusicgenConfig""",
    """RagConfig""",
    """SpeechEncoderDecoderConfig""",
    """TimmBackboneConfig""",
    """VisionEncoderDecoderConfig""",
    """VisionTextDualEncoderConfig""",
    """LlamaConfig""",
}



def 		A_				(     _lowerCAmelCase     )						-> List[str]:
 UpperCamelCase	:					Optional[Any]       	=   None

 # source code of `config_class`
 UpperCamelCase	:					Tuple       	=   inspect.getsource(_lowerCAmelCase     )
 UpperCamelCase	:					Optional[Any]       	=   _re_checkpoint.findall(_lowerCAmelCase     )

 # Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
 # For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
 for ckpt_name, ckpt_link in checkpoints:
  # allow the link to end with `/`
  if ckpt_link.endswith("/"     ):
   UpperCamelCase	:					Dict       	=   ckpt_link[:-1]

  # verify the checkpoint name corresponds to the checkpoint link
  UpperCamelCase	:					Any       	=   F"""https://huggingface.co/{ckpt_name}"""
  if ckpt_link == ckpt_link_from_name:
   UpperCamelCase	:					List[Any]       	=   ckpt_name
   break

 return checkpoint



def 		A_				(     )						-> List[str]:
 UpperCamelCase	:					Optional[int]       	=   []

 for config_class in list(CONFIG_MAPPING.values()     ):
  # Skip deprecated models
  if "models.deprecated" in config_class.__module__:
   continue
  UpperCamelCase	:					Union[str, Any]       	=   get_checkpoint_from_config_class(_lowerCAmelCase     )

  UpperCamelCase	:					Optional[int]       	=   config_class.__name__
  if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
   configs_without_checkpoint.append(_lowerCAmelCase     )

 if len(_lowerCAmelCase     ) > 0:
  UpperCamelCase	:					Any       	=   "\n".join(sorted(_lowerCAmelCase     )     )
  raise ValueError(F"""The following configurations don't contain any valid checkpoint:\n{message}"""     )


if __name__ == "__main__":
    check_config_docstrings_have_checkpoints()
