"""simple docstring"""






import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
							from transformers import WhisperFeatureExtractor, WhisperProcessor


__A         =				5_0_3_5_8
__A         =				5_0_3_6_2


@require_torch
@require_torchaudio
@require_sentencepiece
class 					UpperCAmelCase		(unittest.TestCase						):



				"""simple docstring"""

				def _snake_case    (     self							):
							lowercase__:     int      =   '''openai/whisper-small.en'''
							lowercase__:     List[str]      =   tempfile.mkdtemp()






				def _snake_case    (     self					,    **_UpperCAmelCase							):
							return WhisperTokenizer.from_pretrained(self.checkpoint					,    **_UpperCAmelCase							)






				def _snake_case    (     self					,    **_UpperCAmelCase							):
							return WhisperFeatureExtractor.from_pretrained(self.checkpoint					,    **_UpperCAmelCase							)






				def _snake_case    (     self							):
							shutil.rmtree(self.tmpdirname							)






				def _snake_case    (     self							):
							lowercase__:     Dict      =   self.get_tokenizer()
							lowercase__:     List[Any]      =   self.get_feature_extractor()

							lowercase__:     Dict      =   WhisperProcessor(tokenizer=_UpperCAmelCase					,    feature_extractor=_UpperCAmelCase							)

							processor.save_pretrained(self.tmpdirname							)
							lowercase__:     List[str]      =   WhisperProcessor.from_pretrained(self.tmpdirname							)

							self.assertEqual(processor.tokenizer.get_vocab()					,    tokenizer.get_vocab()							)
							self.assertIsInstance(processor.tokenizer					,    _UpperCAmelCase							)

							self.assertEqual(processor.feature_extractor.to_json_string()					,    feature_extractor.to_json_string()							)
							self.assertIsInstance(processor.feature_extractor					,    _UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Optional[Any]      =   WhisperProcessor(tokenizer=self.get_tokenizer()					,    feature_extractor=self.get_feature_extractor()							)
							processor.save_pretrained(self.tmpdirname							)

							lowercase__:     Tuple      =   self.get_tokenizer(bos_token='''(BOS)'''					,    eos_token='''(EOS)'''							)
							lowercase__:     Optional[Any]      =   self.get_feature_extractor(do_normalize=_UpperCAmelCase					,    padding_value=1.0							)

							lowercase__:     Dict      =   WhisperProcessor.from_pretrained(
							    self.tmpdirname					,    bos_token='''(BOS)'''					,    eos_token='''(EOS)'''					,    do_normalize=_UpperCAmelCase					,    padding_value=1.0							)

							self.assertEqual(processor.tokenizer.get_vocab()					,    tokenizer_add_kwargs.get_vocab()							)
							self.assertIsInstance(processor.tokenizer					,    _UpperCAmelCase							)

							self.assertEqual(processor.feature_extractor.to_json_string()					,    feature_extractor_add_kwargs.to_json_string()							)
							self.assertIsInstance(processor.feature_extractor					,    _UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Any      =   self.get_feature_extractor()
							lowercase__:     Optional[int]      =   self.get_tokenizer()

							lowercase__:     str      =   WhisperProcessor(tokenizer=_UpperCAmelCase					,    feature_extractor=_UpperCAmelCase							)

							lowercase__:     Optional[int]      =   floats_list((3, 1000)							)

							lowercase__:     int      =   feature_extractor(_UpperCAmelCase					,    return_tensors='''np'''							)
							lowercase__:     Any      =   processor(_UpperCAmelCase					,    return_tensors='''np'''							)

							for key in input_feat_extract.keys():
										self.assertAlmostEqual(input_feat_extract[key].sum()					,    input_processor[key].sum()					,    delta=1e-2							)






				def _snake_case    (     self							):
							lowercase__:     Any      =   self.get_feature_extractor()
							lowercase__:     Any      =   self.get_tokenizer()

							lowercase__:     Tuple      =   WhisperProcessor(tokenizer=_UpperCAmelCase					,    feature_extractor=_UpperCAmelCase							)

							lowercase__:     List[Any]      =   '''This is a test string'''

							lowercase__:     Dict      =   processor(text=_UpperCAmelCase							)

							lowercase__:     List[Any]      =   tokenizer(_UpperCAmelCase							)

							for key in encoded_tok.keys():
										self.assertListEqual(encoded_tok[key]					,    encoded_processor[key]							)






				def _snake_case    (     self							):
							lowercase__:     str      =   self.get_feature_extractor()
							lowercase__:     Dict      =   self.get_tokenizer()

							lowercase__:     Dict      =   WhisperProcessor(tokenizer=_UpperCAmelCase					,    feature_extractor=_UpperCAmelCase							)

							lowercase__:     Optional[int]      =   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

							lowercase__:     int      =   processor.batch_decode(_UpperCAmelCase							)
							lowercase__:     Union[str, Any]      =   tokenizer.batch_decode(_UpperCAmelCase							)

							self.assertListEqual(_UpperCAmelCase					,    _UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Tuple      =   self.get_feature_extractor()
							lowercase__:     Any      =   self.get_tokenizer()

							lowercase__:     Dict      =   WhisperProcessor(tokenizer=_UpperCAmelCase					,    feature_extractor=_UpperCAmelCase							)

							self.assertListEqual(
							    processor.model_input_names					,    feature_extractor.model_input_names					,    msg='''`processor` and `feature_extractor` model input names do not match'''					,    )






				def _snake_case    (     self							):
							lowercase__:     Optional[Any]      =   self.get_feature_extractor()
							lowercase__:     Dict      =   self.get_tokenizer()

							lowercase__:     Dict      =   WhisperProcessor(tokenizer=_UpperCAmelCase					,    feature_extractor=_UpperCAmelCase							)
							lowercase__:     Optional[int]      =   processor.get_decoder_prompt_ids(task='''transcribe'''					,    no_timestamps=_UpperCAmelCase							)

							self.assertIsInstance(_UpperCAmelCase					,    _UpperCAmelCase							)
							for ids in forced_decoder_ids:
										self.assertIsInstance(_UpperCAmelCase					,    (list, tuple)							)

							lowercase__:     Dict      =   [TRANSCRIBE, NOTIMESTAMPS]
							self.assertListEqual([ids[-1] for ids in forced_decoder_ids]					,    _UpperCAmelCase							)






				def _snake_case    (     self							):
							lowercase__:     Any      =   WhisperProcessor(tokenizer=self.get_tokenizer()					,    feature_extractor=self.get_feature_extractor()							)
							lowercase__:     Any      =   processor.get_prompt_ids('''Mr. Quilter'''							)
							lowercase__:     Any      =   processor.tokenizer.decode(_UpperCAmelCase							)

							self.assertListEqual(prompt_ids.tolist()					,    [50360, 1770, 13, 2264, 346, 353]							)
							self.assertEqual(_UpperCAmelCase					,    '''<|startofprev|> Mr. Quilter'''							)






				def _snake_case    (     self							):
							lowercase__:     int      =   WhisperProcessor(tokenizer=self.get_tokenizer()					,    feature_extractor=self.get_feature_extractor()							)
							lowercase__:     List[Any]      =   processor.get_prompt_ids(''''''							)
							lowercase__:     int      =   processor.tokenizer.decode(_UpperCAmelCase							)

							self.assertListEqual(prompt_ids.tolist()					,    [50360, 220]							)
							self.assertEqual(_UpperCAmelCase					,    '''<|startofprev|> '''							)






				def _snake_case    (     self							):
							lowercase__:     List[Any]      =   WhisperProcessor(tokenizer=self.get_tokenizer()					,    feature_extractor=self.get_feature_extractor()							)

							def _test_prompt_error_raised_helper(_UpperCAmelCase					,    _UpperCAmelCase							):
										with pytest.raises(_UpperCAmelCase							) as excinfo:
													processor.get_prompt_ids(_UpperCAmelCase							)
										lowercase__:     Optional[Any]      =   F"""Encountered text in the prompt corresponding to disallowed special token: {special_token}."""
										self.assertEqual(_UpperCAmelCase					,    str(excinfo.value							)							)

							_test_prompt_error_raised_helper('''<|startofprev|> test'''					,    '''<|startofprev|>'''							)
							_test_prompt_error_raised_helper('''test <|notimestamps|>'''					,    '''<|notimestamps|>'''							)
							_test_prompt_error_raised_helper('''test <|zh|> test <|transcribe|>'''					,    '''<|zh|>'''							)

"""simple docstring"""






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


__A         =				logging.get_logger(__name__)

__A         =				{
    "uw-madison/yoso-4096": "https://huggingface.co/uw-madison/yoso-4096/resolve/main/config.json",
    # See all YOSO models at https://huggingface.co/models?filter=yoso
}


class 					UpperCAmelCase		(_UpperCAmelCase						):



    """simple docstring"""

    _UpperCAmelCase			:Tuple							=				"yoso"






    def __init__(     self					,    _UpperCAmelCase=50265					,    _UpperCAmelCase=768					,    _UpperCAmelCase=12					,    _UpperCAmelCase=12					,    _UpperCAmelCase=3072					,    _UpperCAmelCase="gelu"					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=4096					,    _UpperCAmelCase=1					,    _UpperCAmelCase=0.02					,    _UpperCAmelCase=1e-1_2					,    _UpperCAmelCase="absolute"					,    _UpperCAmelCase=True					,    _UpperCAmelCase=9					,    _UpperCAmelCase=64					,    _UpperCAmelCase=None					,    _UpperCAmelCase=True					,    _UpperCAmelCase=True					,    _UpperCAmelCase=1					,    _UpperCAmelCase=0					,    _UpperCAmelCase=2					,    **_UpperCAmelCase					,    ):
       super().__init__(pad_token_id=_UpperCAmelCase					,    bos_token_id=_UpperCAmelCase					,    eos_token_id=_UpperCAmelCase					,    **_UpperCAmelCase							)

       lowercase__:     int      =   vocab_size
       lowercase__:     List[str]      =   max_position_embeddings
       lowercase__:     Tuple      =   hidden_size
       lowercase__:     Optional[Any]      =   num_hidden_layers
       lowercase__:     Optional[int]      =   num_attention_heads
       lowercase__:     List[Any]      =   intermediate_size
       lowercase__:     Union[str, Any]      =   hidden_act
       lowercase__:     int      =   hidden_dropout_prob
       lowercase__:     Optional[Any]      =   attention_probs_dropout_prob
       lowercase__:     List[Any]      =   initializer_range
       lowercase__:     Optional[Any]      =   type_vocab_size
       lowercase__:     int      =   layer_norm_eps
       lowercase__:     Optional[Any]      =   position_embedding_type
       lowercase__:     int      =   use_expectation
       lowercase__:     List[str]      =   hash_code_len
       lowercase__:     Union[str, Any]      =   num_hash
       lowercase__:     Any      =   conv_window
       lowercase__:     Dict      =   use_fast_hash
       lowercase__:     Dict      =   lsh_backward
