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


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

_A			:      Optional[Any]					      =				'''file'''







@pytest.fixture(scope="""session"""      )
def      UpperCamelCase_						(					snake_case_       :       Any      )					->     str:






 '''simple docstring'''

 __lowerCAmelCase											=						tmp_path_factory.mktemp("""data"""      ) / (FILE_PATH + """.zstd""")
 __lowerCAmelCase											=						bytes(_UpperCAmelCase						,		"""utf-8"""      )
 with zstd.open(_UpperCAmelCase						,		"""wb"""      ) as f:
  f.write(_UpperCAmelCase      )
 return path







@pytest.fixture
def      UpperCamelCase_						(					snake_case_       :       Union[str, Any]      )					->     List[Any]:






 '''simple docstring'''

 with open(os.path.join(tmpfs.local_root_dir						,		_UpperCAmelCase      )						,		"""w"""      ) as f:
  f.write(_UpperCAmelCase      )
 return FILE_PATH







@pytest.mark.parametrize("""compression_format"""						,		["""gzip""", """xz""", """zstd"""]      )
def      UpperCamelCase_						(					snake_case_       :       str						,		snake_case_       :       int						,		snake_case_       :       Optional[int]						,		snake_case_       :       Dict						,		snake_case_       :       Any						,		snake_case_       :       Dict      )					->     int:






 '''simple docstring'''

 __lowerCAmelCase											=						{"""gzip""": gz_file, """xz""": xz_file, """zstd""": zstd_path}
 __lowerCAmelCase											=						input_paths[compression_format]
 __lowerCAmelCase											=						tmp_path / """cache"""
 __lowerCAmelCase											=						DownloadConfig(cache_dir=_UpperCAmelCase						,		extract_compressed_file=_UpperCAmelCase      )
 __lowerCAmelCase											=						cached_path(_UpperCAmelCase						,		download_config=_UpperCAmelCase      )
 with open(_UpperCAmelCase      ) as f:
  __lowerCAmelCase											=						f.read()
 with open(_UpperCAmelCase      ) as f:
  __lowerCAmelCase											=						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_       :       str						,		snake_case_       :       List[str]						,		snake_case_       :       Dict						,		snake_case_       :       Optional[Any]						,		snake_case_       :       Tuple      )					->     List[Any]:






 '''simple docstring'''

 __lowerCAmelCase											=						"""custom_cache"""
 __lowerCAmelCase											=						"""custom_extracted_dir"""
 __lowerCAmelCase											=						tmp_path / """custom_extracted_path"""
 if default_extracted:
  __lowerCAmelCase											=						("""downloads""" if default_cache_dir else custom_cache_dir, """extracted""")
 else:
  monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_DIR"""						,		_UpperCAmelCase      )
  monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""						,		str(_UpperCAmelCase      )      )
  __lowerCAmelCase											=						custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

 __lowerCAmelCase											=						xz_file
 __lowerCAmelCase											=						(
     DownloadConfig(extract_compressed_file=_UpperCAmelCase      )
     if default_cache_dir
     else DownloadConfig(cache_dir=tmp_path / custom_cache_dir						,		extract_compressed_file=_UpperCAmelCase      )
 )
 __lowerCAmelCase											=						cached_path(_UpperCAmelCase						,		download_config=_UpperCAmelCase      )
 assert Path(_UpperCAmelCase      ).parent.parts[-2:] == expected







def      UpperCamelCase_						(					snake_case_       :       int      )					->     Any:






 '''simple docstring'''

 __lowerCAmelCase											=						str(Path(_UpperCAmelCase      ).resolve()      )
 assert cached_path(_UpperCAmelCase      ) == text_file
 # relative path
 __lowerCAmelCase											=						str(Path(_UpperCAmelCase      ).resolve().relative_to(Path(os.getcwd()      )      )      )
 assert cached_path(_UpperCAmelCase      ) == text_file







def      UpperCamelCase_						(					snake_case_       :       Optional[Any]      )					->     str:






 '''simple docstring'''

 __lowerCAmelCase											=						str(tmp_path.resolve() / """__missing_file__.txt"""      )
 with pytest.raises(_UpperCAmelCase      ):
  cached_path(_UpperCAmelCase      )
 # relative path
 __lowerCAmelCase											=						"""./__missing_file__.txt"""
 with pytest.raises(_UpperCAmelCase      ):
  cached_path(_UpperCAmelCase      )







def      UpperCamelCase_						(					snake_case_       :       Optional[int]      )					->     str:






 '''simple docstring'''

 __lowerCAmelCase											=						get_from_cache(f"""tmp://{tmpfs_file}"""      )
 with open(_UpperCAmelCase      ) as f:
  __lowerCAmelCase											=						f.read()
 assert output_file_content == FILE_CONTENT







@patch("""datasets.config.HF_DATASETS_OFFLINE"""						,		_UpperCAmelCase      )
def      UpperCamelCase_						(					)					->     Union[str, Any]:






 '''simple docstring'''

 with pytest.raises(_UpperCAmelCase      ):
  cached_path("""https://huggingface.co"""      )







@patch("""datasets.config.HF_DATASETS_OFFLINE"""						,		_UpperCAmelCase      )
def      UpperCamelCase_						(					snake_case_       :       Optional[int]      )					->     Tuple:






 '''simple docstring'''

 __lowerCAmelCase											=						tmp_path_factory.mktemp("""data"""      ) / """file.html"""
 with pytest.raises(_UpperCAmelCase      ):
  http_get("""https://huggingface.co"""						,		temp_file=_UpperCAmelCase      )
 with pytest.raises(_UpperCAmelCase      ):
  http_head("""https://huggingface.co"""      )







@patch("""datasets.config.HF_DATASETS_OFFLINE"""						,		_UpperCAmelCase      )
def      UpperCamelCase_						(					snake_case_       :       int      )					->     List[Any]:






 '''simple docstring'''

 __lowerCAmelCase											=						tmp_path_factory.mktemp("""data"""      ) / """file.html"""
 with pytest.raises(_UpperCAmelCase      ):
  ftp_get("""ftp://huggingface.co"""						,		temp_file=_UpperCAmelCase      )
 with pytest.raises(_UpperCAmelCase      ):
  ftp_head("""ftp://huggingface.co"""      )







@patch("""datasets.config.HF_DATASETS_OFFLINE"""						,		_UpperCAmelCase      )
def      UpperCamelCase_						(					snake_case_       :       List[str]      )					->     Dict:






 '''simple docstring'''

 __lowerCAmelCase											=						tmp_path_factory.mktemp("""data"""      ) / """file.html"""
 with pytest.raises(_UpperCAmelCase      ):
  fsspec_get("""s3://huggingface.co"""						,		temp_file=_UpperCAmelCase      )
 with pytest.raises(_UpperCAmelCase      ):
  fsspec_head("""s3://huggingface.co"""      )











import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()





def      __snake_case	(			_UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase   , _UpperCAmelCase				):
    # Initialise PyTorch model
    __a						       =				BigBirdConfig.from_json_file(_UpperCAmelCase				)
    print(f'Building PyTorch model from configuration: {config}'				)

    if is_trivia_qa:
        __a						       =				BigBirdForQuestionAnswering(_UpperCAmelCase				)
    else:
        __a						       =				BigBirdForPreTraining(_UpperCAmelCase				)

    # Load weights from tf checkpoint
    load_tf_weights_in_big_bird(_UpperCAmelCase   , _UpperCAmelCase   , is_trivia_qa=_UpperCAmelCase				)

    # Save pytorch-model
    print(f'Save PyTorch model to {pytorch_dump_path}'				)
    model.save_pretrained(_UpperCAmelCase				)


if __name__ == "__main__":
 __snake_case						:Tuple      		=     argparse.ArgumentParser()
 # Required parameters
 parser.add_argument(
     '''--tf_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
 )
 parser.add_argument(
     '''--big_bird_config_file''',
     default=None,
     type=str,
     required=True,
     help=(
         '''The config json file corresponding to the pre-trained BERT model. \n'''
         '''This specifies the model architecture.'''
     ),
 )
 parser.add_argument(
     '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
 )
 parser.add_argument(
     '''--is_trivia_qa''', action='''store_true''', help='''Whether to convert a model with a trivia_qa head.'''
 )
 __snake_case						:Any      		=     parser.parse_args()
 convert_tf_checkpoint_to_pytorch(
     args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
 )





