



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,
)


__UpperCAmelCase          =       '''\
    Text data.
    Second line of data.'''

__UpperCAmelCase          =       '''file'''
@pytest.fixture(scope='session'	)
def 		UpperCamelCase	(   snake_case__       :    Tuple	)	->     int:
   UpperCamelCase    :  List[Any]							=	tmp_path_factory.mktemp('data'	) / (FILE_PATH + '.zstd')
   UpperCamelCase    :  Tuple							=	bytes(snake_case__       ,     'utf-8'	)
   with zstd.open(snake_case__       ,     'wb'	) as f:
      f.write(snake_case__	)
   return path
@pytest.fixture
def 		UpperCamelCase	(   snake_case__       :    List[Any]	)	->     Tuple:
   with open(os.path.join(tmpfs.local_root_dir       ,     snake_case__	)       ,     'w'	) as f:
      f.write(snake_case__	)
   return FILE_PATH
@pytest.mark.parametrize('compression_format'       ,     ['gzip', 'xz', 'zstd']	)
def 		UpperCamelCase	(   snake_case__       :    Union[str, Any]       ,     snake_case__       :    List[str]       ,     snake_case__       :    List[str]       ,     snake_case__       :    str       ,     snake_case__       :    Optional[int]       ,     snake_case__       :    int	)	->     Union[str, Any]:
   UpperCamelCase    :  Any							=	{'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_path}
   UpperCamelCase    :  int							=	input_paths[compression_format]
   UpperCamelCase    :  str							=	tmp_path / 'cache'
   UpperCamelCase    :  int							=	DownloadConfig(cache_dir=snake_case__       ,     extract_compressed_file=snake_case__	)
   UpperCamelCase    :  Tuple							=	cached_path(snake_case__       ,     download_config=snake_case__	)
   with open(snake_case__	) as f:
      UpperCamelCase    :  Optional[Any]							=	f.read()
   with open(snake_case__	) as f:
      UpperCamelCase    :  Optional[Any]							=	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 		UpperCamelCase	(   snake_case__       :    Optional[Any]       ,     snake_case__       :    Union[str, Any]       ,     snake_case__       :    Tuple       ,     snake_case__       :    List[Any]       ,     snake_case__       :    Tuple	)	->     int:
   UpperCamelCase    :  List[str]							=	'custom_cache'
   UpperCamelCase    :  str							=	'custom_extracted_dir'
   UpperCamelCase    :  int							=	tmp_path / 'custom_extracted_path'
   if default_extracted:
      UpperCamelCase    :  List[Any]							=	('downloads' if default_cache_dir else custom_cache_dir, 'extracted')
   else:
      monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_DIR'       ,     snake_case__	)
      monkeypatch.setattr('datasets.config.EXTRACTED_DATASETS_PATH'       ,     str(snake_case__	)	)
      UpperCamelCase    :  Union[str, Any]							=	custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

   UpperCamelCase    :  str							=	xz_file
   UpperCamelCase    :  List[str]							=	(
       DownloadConfig(extract_compressed_file=snake_case__	)
       if default_cache_dir
       else DownloadConfig(cache_dir=tmp_path / custom_cache_dir       ,     extract_compressed_file=snake_case__	)
   )
   UpperCamelCase    :  List[str]							=	cached_path(snake_case__       ,     download_config=snake_case__	)
   assert Path(snake_case__	).parent.parts[-2:] == expected
def 		UpperCamelCase	(   snake_case__       :    int	)	->     str:
   # absolute path
   UpperCamelCase    :  Tuple							=	str(Path(snake_case__	).resolve()	)
   assert cached_path(snake_case__	) == text_file
   # relative path
   UpperCamelCase    :  Tuple							=	str(Path(snake_case__	).resolve().relative_to(Path(os.getcwd()	)	)	)
   assert cached_path(snake_case__	) == text_file
def 		UpperCamelCase	(   snake_case__       :    int	)	->     Any:
   # absolute path
   UpperCamelCase    :  Optional[int]							=	str(tmp_path.resolve() / '__missing_file__.txt'	)
   with pytest.raises(snake_case__	):
      cached_path(snake_case__	)
   # relative path
   UpperCamelCase    :  List[str]							=	'./__missing_file__.txt'
   with pytest.raises(snake_case__	):
      cached_path(snake_case__	)
def 		UpperCamelCase	(   snake_case__       :    Union[str, Any]	)	->     Any:
   UpperCamelCase    :  Tuple							=	get_from_cache(F"""tmp://{tmpfs_file}"""	)
   with open(snake_case__	) as f:
      UpperCamelCase    :  Optional[int]							=	f.read()
   assert output_file_content == FILE_CONTENT
@patch('datasets.config.HF_DATASETS_OFFLINE'       ,     snake_case__	)
def 		UpperCamelCase	(   )	->     Tuple:
   with pytest.raises(snake_case__	):
      cached_path('https://huggingface.co'	)
@patch('datasets.config.HF_DATASETS_OFFLINE'       ,     snake_case__	)
def 		UpperCamelCase	(   snake_case__       :    List[Any]	)	->     Dict:
   UpperCamelCase    :  Any							=	tmp_path_factory.mktemp('data'	) / 'file.html'
   with pytest.raises(snake_case__	):
      http_get('https://huggingface.co'       ,     temp_file=snake_case__	)
   with pytest.raises(snake_case__	):
      http_head('https://huggingface.co'	)
@patch('datasets.config.HF_DATASETS_OFFLINE'       ,     snake_case__	)
def 		UpperCamelCase	(   snake_case__       :    Union[str, Any]	)	->     List[str]:
   UpperCamelCase    :  List[Any]							=	tmp_path_factory.mktemp('data'	) / 'file.html'
   with pytest.raises(snake_case__	):
      ftp_get('ftp://huggingface.co'       ,     temp_file=snake_case__	)
   with pytest.raises(snake_case__	):
      ftp_head('ftp://huggingface.co'	)


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








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


__UpperCAmelCase          =       logging.get_logger(__name__)

__UpperCAmelCase          =       {
    '''facebook/s2t-wav2vec2-large-en-de''': (
        '''https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'''
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}



class 				lowerCAmelCase_		(  a__							):
       UpperCAmelCase__				:					Optional[Any]        =  "speech_to_text_2"
       UpperCAmelCase__				:					List[Any]        =  ["past_key_values"]
       UpperCAmelCase__				:					Any        =  {"num_attention_heads": "decoder_attention_heads", "hidden_size": "d_model"}
       def __init__(			self,			SCREAMING_SNAKE_CASE_=1_0000,			SCREAMING_SNAKE_CASE_=6,			SCREAMING_SNAKE_CASE_=2048,			SCREAMING_SNAKE_CASE_=4,			SCREAMING_SNAKE_CASE_=0.0,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_="relu",			SCREAMING_SNAKE_CASE_=256,			SCREAMING_SNAKE_CASE_=0.1,			SCREAMING_SNAKE_CASE_=0.0,			SCREAMING_SNAKE_CASE_=0.0,			SCREAMING_SNAKE_CASE_=0.02,			SCREAMING_SNAKE_CASE_=2,			SCREAMING_SNAKE_CASE_=True,			SCREAMING_SNAKE_CASE_=1,			SCREAMING_SNAKE_CASE_=0,			SCREAMING_SNAKE_CASE_=2,			SCREAMING_SNAKE_CASE_=1024,			**SCREAMING_SNAKE_CASE_,			)     ->		int:
          UpperCamelCase    :  Optional[int]							=	vocab_size
          UpperCamelCase    :  List[str]							=	d_model
          UpperCamelCase    :  List[str]							=	decoder_ffn_dim
          UpperCamelCase    :  Optional[Any]							=	decoder_layers
          UpperCamelCase    :  Any							=	decoder_attention_heads
          UpperCamelCase    :  Tuple							=	dropout
          UpperCamelCase    :  str							=	attention_dropout
          UpperCamelCase    :  str							=	activation_dropout
          UpperCamelCase    :  Union[str, Any]							=	activation_function
          UpperCamelCase    :  Optional[int]							=	init_std
          UpperCamelCase    :  Tuple							=	decoder_layerdrop
          UpperCamelCase    :  Dict							=	use_cache
          UpperCamelCase    :  Any							=	decoder_layers
          UpperCamelCase    :  Union[str, Any]							=	scale_embedding  # scale factor will be sqrt(d_model) if True
          UpperCamelCase    :  Union[str, Any]							=	max_target_positions

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



