'''simple docstring'''




import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


_lowercase		:				List[str]	       =		'''\
    Text data.
    Second line of data.'''

_lowercase		:				Optional[int]	       =		'''file'''




@pytest.fixture(scope="""session"""				)
def 				lowerCamelCase			(   UpperCAmelCase__ :      Tuple				)    ->   Dict:
							lowercase_      :    Optional[int]       		= tmp_path_factory.mktemp("""data"""				) / (FILE_PATH + '.zstd')
							lowercase_      :    Union[str, Any]       		= bytes(_lowercase   ,   """utf-8"""				)
							with zstd.open(_lowercase   ,   """wb"""				) as f:
														f.write(_lowercase				)
							return path




@pytest.fixture
def 				lowerCamelCase			(   UpperCAmelCase__ :      int				)    ->   Any:
							with open(os.path.join(tmpfs.local_root_dir   ,   _lowercase				)   ,   """w"""				) as f:
														f.write(_lowercase				)
							return FILE_PATH




@pytest.mark.parametrize("""compression_format"""   ,   ["""gzip""", """xz""", """zstd"""]				)
def 				lowerCamelCase			(   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      Union[str, Any]   ,   UpperCAmelCase__ :      Tuple   ,   UpperCAmelCase__ :      Union[str, Any]   ,   UpperCAmelCase__ :      str   ,   UpperCAmelCase__ :      str				)    ->   Any:
							lowercase_      :    Any       		= {'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
							lowercase_      :    List[Any]       		= input_paths[compression_format]
							lowercase_      :    Union[str, Any]       		= tmp_path / 'cache'
							lowercase_      :    Union[str, Any]       		= DownloadConfig(cache_dir=_lowercase   ,   extract_compressed_file=_lowercase				)
							lowercase_      :    Optional[int]       		= cached_path(_lowercase   ,   download_config=_lowercase				)
							with open(_lowercase				) as f:
														lowercase_      :    List[str]       		= f.read()
							with open(_lowercase				) as f:
														lowercase_      :    Optional[int]       		= f.read()
							assert extracted_file_content == expected_file_content




@pytest.mark.parametrize("""default_extracted"""   ,   [True, False]				)
@pytest.mark.parametrize("""default_cache_dir"""   ,   [True, False]				)
def 				lowerCamelCase			(   UpperCAmelCase__ :      List[Any]   ,   UpperCAmelCase__ :      Optional[int]   ,   UpperCAmelCase__ :      Union[str, Any]   ,   UpperCAmelCase__ :      Optional[Any]   ,   UpperCAmelCase__ :      str				)    ->   Tuple:
							lowercase_      :    Optional[Any]       		= 'custom_cache'
							lowercase_      :    Tuple       		= 'custom_extracted_dir'
							lowercase_      :    List[str]       		= tmp_path / 'custom_extracted_path'
							if default_extracted:
														lowercase_      :    Union[str, Any]       		= ('downloads' if default_cache_dir else custom_cache_dir, 'extracted')
							else:
														monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_DIR"""   ,   _lowercase				)
														monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""   ,   str(_lowercase				)				)
														lowercase_      :    List[Any]       		= custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

							lowercase_      :    List[Any]       		= xz_file
							lowercase_      :    Any       		= (
							    DownloadConfig(extract_compressed_file=_lowercase				)
							    if default_cache_dir
							    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir   ,   extract_compressed_file=_lowercase				)
							)
							lowercase_      :    Tuple       		= cached_path(_lowercase   ,   download_config=_lowercase				)
							assert Path(_lowercase				).parent.parts[-2:] == expected




def 				lowerCamelCase			(   UpperCAmelCase__ :      Union[str, Any]				)    ->   Union[str, Any]:
							# absolute path
							lowercase_      :    Tuple       		= str(Path(_lowercase				).resolve()				)
							assert cached_path(_lowercase				) == text_file
							# relative path
							lowercase_      :    Dict       		= str(Path(_lowercase				).resolve().relative_to(Path(os.getcwd()				)				)				)
							assert cached_path(_lowercase				) == text_file




def 				lowerCamelCase			(   UpperCAmelCase__ :      int				)    ->   Union[str, Any]:
							# absolute path
							lowercase_      :    List[Any]       		= str(tmp_path.resolve() / """__missing_file__.txt"""				)
							with pytest.raises(_lowercase				):
														cached_path(_lowercase				)
							# relative path
							lowercase_      :    Tuple       		= './__missing_file__.txt'
							with pytest.raises(_lowercase				):
														cached_path(_lowercase				)




def 				lowerCamelCase			(   UpperCAmelCase__ :      Optional[int]				)    ->   Tuple:
							lowercase_      :    List[Any]       		= get_from_cache(F'''tmp://{tmpfs_file}'''				)
							with open(_lowercase				) as f:
														lowercase_      :    Optional[Any]       		= f.read()
							assert output_file_content == FILE_CONTENT




@patch("""datasets.config.HF_DATASETS_OFFLINE"""   ,   _lowercase				)
def 				lowerCamelCase			(   )    ->   Dict:
							with pytest.raises(_lowercase				):
														cached_path("""https://huggingface.co"""				)




@patch("""datasets.config.HF_DATASETS_OFFLINE"""   ,   _lowercase				)
def 				lowerCamelCase			(   UpperCAmelCase__ :      Any				)    ->   List[str]:
							lowercase_      :    Dict       		= tmp_path_factory.mktemp("""data"""				) / 'file.html'
							with pytest.raises(_lowercase				):
														http_get("""https://huggingface.co"""   ,   temp_file=_lowercase				)
							with pytest.raises(_lowercase				):
														http_head("""https://huggingface.co"""				)




@patch("""datasets.config.HF_DATASETS_OFFLINE"""   ,   _lowercase				)
def 				lowerCamelCase			(   UpperCAmelCase__ :      Union[str, Any]				)    ->   Optional[Any]:
							lowercase_      :    str       		= tmp_path_factory.mktemp("""data"""				) / 'file.html'
							with pytest.raises(_lowercase				):
														ftp_get("""ftp://huggingface.co"""   ,   temp_file=_lowercase				)
							with pytest.raises(_lowercase				):
														ftp_head("""ftp://huggingface.co"""				)




@patch("""datasets.config.HF_DATASETS_OFFLINE"""   ,   _lowercase				)
def 				lowerCamelCase			(   UpperCAmelCase__ :      Any				)    ->   List[str]:
							lowercase_      :    Optional[int]       		= tmp_path_factory.mktemp("""data"""				) / 'file.html'
							with pytest.raises(_lowercase				):
														fsspec_get("""s3://huggingface.co"""   ,   temp_file=_lowercase				)
							with pytest.raises(_lowercase				):
														fsspec_head("""s3://huggingface.co"""				)






'''simple docstring'''




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


_lowercase		:				Optional[Any]	       =		logging.get_logger(__name__)

_lowercase		:				Union[str, Any]	       =		{
    "facebook/s2t-small-librispeech-asr": (
        "https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class 					__magic_name__		(					_UpperCAmelCase):
			UpperCamelCase__       = '''speech_to_text'''
			UpperCamelCase__       = ['''past_key_values''']
			UpperCamelCase__       = {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







			def __init__(			self       :						str       ,    lowercase_       :						Optional[int]=10000       ,    lowercase_       :						int=12       ,    lowercase_       :						Any=2048       ,    lowercase_       :						Any=4       ,    lowercase_       :						Dict=6       ,    lowercase_       :						Any=2048       ,    lowercase_       :						List[str]=4       ,    lowercase_       :						str=0.0       ,    lowercase_       :						str=0.0       ,    lowercase_       :						Union[str, Any]=True       ,    lowercase_       :						List[Any]=True       ,    lowercase_       :						int="relu"       ,    lowercase_       :						str=256       ,    lowercase_       :						int=0.1       ,    lowercase_       :						int=0.0       ,    lowercase_       :						str=0.0       ,    lowercase_       :						Optional[int]=0.02       ,    lowercase_       :						str=2       ,    lowercase_       :						Union[str, Any]=True       ,    lowercase_       :						Any=1       ,    lowercase_       :						Dict=0       ,    lowercase_       :						List[str]=2       ,    lowercase_       :						List[Any]=6000       ,    lowercase_       :						Tuple=1024       ,    lowercase_       :						str=2       ,    lowercase_       :						Any=(5, 5)       ,    lowercase_       :						Union[str, Any]=1024       ,    lowercase_       :						Dict=80       ,    lowercase_       :						List[Any]=1       ,    **lowercase_       :						int       ,    ):
										lowercase_      :    List[Any]       		= vocab_size
										lowercase_      :    str       		= d_model
										lowercase_      :    List[Any]       		= encoder_ffn_dim
										lowercase_      :    str       		= encoder_layers
										lowercase_      :    Dict       		= encoder_attention_heads
										lowercase_      :    str       		= decoder_ffn_dim
										lowercase_      :    int       		= decoder_layers
										lowercase_      :    Any       		= decoder_attention_heads
										lowercase_      :    Any       		= dropout
										lowercase_      :    Dict       		= attention_dropout
										lowercase_      :    Optional[int]       		= activation_dropout
										lowercase_      :    Any       		= activation_function
										lowercase_      :    Union[str, Any]       		= init_std
										lowercase_      :    str       		= encoder_layerdrop
										lowercase_      :    Optional[int]       		= decoder_layerdrop
										lowercase_      :    Dict       		= use_cache
										lowercase_      :    Union[str, Any]       		= encoder_layers
										lowercase_      :    Tuple       		= scale_embedding  # scale factor will be sqrt(d_model) if True
										lowercase_      :    Dict       		= max_source_positions
										lowercase_      :    Optional[int]       		= max_target_positions
										lowercase_      :    Tuple       		= num_conv_layers
										lowercase_      :    Tuple       		= list(lowercase_					)
										lowercase_      :    Union[str, Any]       		= conv_channels
										lowercase_      :    str       		= input_feat_per_channel
										lowercase_      :    str       		= input_channels

										if len(self.conv_kernel_sizes					) != self.num_conv_layers:
																	raise ValueError(
																	    """Configuration for convolutional module is incorrect. """
																	    """It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` """
																	    f'''but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes					)}`, '''
																	    f'''`config.num_conv_layers = {self.num_conv_layers}`.'''					)

										super().__init__(
										    pad_token_id=lowercase_       ,    bos_token_id=lowercase_       ,    eos_token_id=lowercase_       ,    is_encoder_decoder=lowercase_       ,    decoder_start_token_id=lowercase_       ,    **lowercase_       ,    )





