




import argparse

import tensorflow as tf
import torch

from transformers import BertConfig, BertForMaskedLM
from transformers.models.bert.modeling_bert import (
    BertIntermediate,
    BertLayer,
    BertOutput,
    BertPooler,
    BertSelfAttention,
    BertSelfOutput,
)
from transformers.utils import logging


logging.set_verbosity_info()

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str			,			__UpperCAmelCase						:	str			,			__UpperCAmelCase						:	str							)					-> Dict:
      def get_masked_lm_array(__UpperCAmelCase						:	str							):
            SCREAMING_SNAKE_CASE_							=			f"masked_lm/{name}/.ATTRIBUTES/VARIABLE_VALUE"
            SCREAMING_SNAKE_CASE_							=			tf.train.load_variable(__UpperCAmelCase			,			__UpperCAmelCase							)

            if "kernel" in name:
                  SCREAMING_SNAKE_CASE_							=			array.transpose()

            return torch.from_numpy(__UpperCAmelCase							)

      def get_encoder_array(__UpperCAmelCase						:	str							):
            SCREAMING_SNAKE_CASE_							=			f"encoder/{name}/.ATTRIBUTES/VARIABLE_VALUE"
            SCREAMING_SNAKE_CASE_							=			tf.train.load_variable(__UpperCAmelCase			,			__UpperCAmelCase							)

            if "kernel" in name:
                  SCREAMING_SNAKE_CASE_							=			array.transpose()

            return torch.from_numpy(__UpperCAmelCase							)

      def get_encoder_layer_array(__UpperCAmelCase						:	int			,			__UpperCAmelCase						:	str							):
            SCREAMING_SNAKE_CASE_							=			f"encoder/_transformer_layers/{layer_index}/{name}/.ATTRIBUTES/VARIABLE_VALUE"
            SCREAMING_SNAKE_CASE_							=			tf.train.load_variable(__UpperCAmelCase			,			__UpperCAmelCase							)

            if "kernel" in name:
                  SCREAMING_SNAKE_CASE_							=			array.transpose()

            return torch.from_numpy(__UpperCAmelCase							)

      def get_encoder_attention_layer_array(__UpperCAmelCase						:	int			,			__UpperCAmelCase						:	str			,			__UpperCAmelCase						:	Optional[Any]							):
            SCREAMING_SNAKE_CASE_							=			f"encoder/_transformer_layers/{layer_index}/_attention_layer/{name}/.ATTRIBUTES/VARIABLE_VALUE"
            SCREAMING_SNAKE_CASE_							=			tf.train.load_variable(__UpperCAmelCase			,			__UpperCAmelCase							)
            SCREAMING_SNAKE_CASE_							=			array.reshape(__UpperCAmelCase							)

            if "kernel" in name:
                  SCREAMING_SNAKE_CASE_							=			array.transpose()

            return torch.from_numpy(__UpperCAmelCase							)

      print(f"Loading model based on config from {config_path}..."							)
      SCREAMING_SNAKE_CASE_							=			BertConfig.from_json_file(__UpperCAmelCase							)
      SCREAMING_SNAKE_CASE_							=			BertForMaskedLM(__UpperCAmelCase							)

      # Layers
      for layer_index in range(0			,			config.num_hidden_layers							):
            SCREAMING_SNAKE_CASE_							=			model.bert.encoder.layer[layer_index]

            # Self-attention
            SCREAMING_SNAKE_CASE_							=			layer.attention.self

            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_query_dense/kernel'			,			self_attn.query.weight.data.shape							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_query_dense/bias'			,			self_attn.query.bias.data.shape							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_key_dense/kernel'			,			self_attn.key.weight.data.shape							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_key_dense/bias'			,			self_attn.key.bias.data.shape							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_value_dense/kernel'			,			self_attn.value.weight.data.shape							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_value_dense/bias'			,			self_attn.value.bias.data.shape							)

            # Self-attention Output
            SCREAMING_SNAKE_CASE_							=			layer.attention.output

            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_output_dense/kernel'			,			self_output.dense.weight.data.shape							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_attention_layer_array(
                __UpperCAmelCase			,			'_output_dense/bias'			,			self_output.dense.bias.data.shape							)

            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_attention_layer_norm/gamma'							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_attention_layer_norm/beta'							)

            # Intermediate
            SCREAMING_SNAKE_CASE_							=			layer.intermediate

            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_intermediate_dense/kernel'							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_intermediate_dense/bias'							)

            # Output
            SCREAMING_SNAKE_CASE_							=			layer.output

            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_output_dense/kernel'							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_output_dense/bias'							)

            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_output_layer_norm/gamma'							)
            SCREAMING_SNAKE_CASE_							=			get_encoder_layer_array(__UpperCAmelCase			,			'_output_layer_norm/beta'							)

      # Embeddings
      SCREAMING_SNAKE_CASE_							=			get_encoder_array('_position_embedding_layer/embeddings'							)
      SCREAMING_SNAKE_CASE_							=			get_encoder_array('_type_embedding_layer/embeddings'							)
      SCREAMING_SNAKE_CASE_							=			get_encoder_array('_embedding_norm_layer/gamma'							)
      SCREAMING_SNAKE_CASE_							=			get_encoder_array('_embedding_norm_layer/beta'							)

      # LM Head
      SCREAMING_SNAKE_CASE_							=			model.cls.predictions.transform

      SCREAMING_SNAKE_CASE_							=			get_masked_lm_array('dense/kernel'							)
      SCREAMING_SNAKE_CASE_							=			get_masked_lm_array('dense/bias'							)

      SCREAMING_SNAKE_CASE_							=			get_masked_lm_array('layer_norm/gamma'							)
      SCREAMING_SNAKE_CASE_							=			get_masked_lm_array('layer_norm/beta'							)

      SCREAMING_SNAKE_CASE_							=			get_masked_lm_array('embedding_table'							)

      # Pooling
      SCREAMING_SNAKE_CASE_							=			BertPooler(config=__UpperCAmelCase							)
      SCREAMING_SNAKE_CASE_							=			get_encoder_array('_pooler_layer/kernel'							)
      SCREAMING_SNAKE_CASE_							=			get_encoder_array('_pooler_layer/bias'							)

      # Export final model
      model.save_pretrained(__UpperCAmelCase							)

      # Integration test - should load without any errors ;)
      SCREAMING_SNAKE_CASE_							=			BertForMaskedLM.from_pretrained(__UpperCAmelCase							)
      print(new_model.eval()							)

      print('Model conversion was done sucessfully!'							)


if __name__ == "__main__":
   lowerCamelCase__ :   Dict					=							argparse.ArgumentParser()
   parser.add_argument(
       '--tf_checkpoint_path', type=str, required=True, help='Path to the TensorFlow Token Dropping checkpoint path.'
   )
   parser.add_argument(
       '--bert_config_file',
       type=str,
       required=True,
       help='The config json file corresponding to the BERT model. This specifies the model architecture.',
   )
   parser.add_argument(
       '--pytorch_dump_path',
       type=str,
       required=True,
       help='Path to the output PyTorch model.',
   )
   lowerCamelCase__ :   Optional[int]					=							parser.parse_args()
   convert_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)





import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      )					-> str:
      SCREAMING_SNAKE_CASE_							=			10
      SCREAMING_SNAKE_CASE_							=			datasets.Features(
          {
              'tokens': datasets.Sequence(datasets.Value('string'							)							),
              'labels': datasets.Sequence(datasets.ClassLabel(names=['negative', 'positive']							)							),
              'answers': datasets.Sequence(
                  {
                      'text': datasets.Value('string'							),
                      'answer_start': datasets.Value('int32'							),
                  }							),
              'id': datasets.Value('int64'							),
          }							)
      SCREAMING_SNAKE_CASE_							=			datasets.Dataset.from_dict(
          {
              'tokens': [['foo'] * 5] * n,
              'labels': [[1] * 5] * n,
              'answers': [{'answer_start': [97], 'text': ['1976']}] * 10,
              'id': list(range(__UpperCAmelCase							)							),
          }			,			features=__UpperCAmelCase			,			)
      return dataset

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Tuple			,			__UpperCAmelCase						:	str							)					-> int:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'file.arrow'							)
      dataset.map(cache_file_name=__UpperCAmelCase							)
      return filename


# FILE_CONTENT + files


lowerCamelCase__ :   List[Any]					=							'\\n    Text data.\n    Second line of data.'

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Any							)					-> List[str]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt'
      SCREAMING_SNAKE_CASE_							=			FILE_CONTENT
      with open(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase							)
      return filename

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict							)					-> List[str]:
      import bza

      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.bz2'
      SCREAMING_SNAKE_CASE_							=			bytes(__UpperCAmelCase			,			'utf-8'							)
      with bza.open(__UpperCAmelCase			,			'wb'							) as f:
            f.write(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[Any]							)					-> Any:
      import gzip

      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'file.txt.gz'							)
      SCREAMING_SNAKE_CASE_							=			bytes(__UpperCAmelCase			,			'utf-8'							)
      with gzip.open(__UpperCAmelCase			,			'wb'							) as f:
            f.write(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[str]							)					-> int:
      if datasets.config.LZ4_AVAILABLE:
            import lza.frame

            SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.lz4'
            SCREAMING_SNAKE_CASE_							=			bytes(__UpperCAmelCase			,			'utf-8'							)
            with lza.frame.open(__UpperCAmelCase			,			'wb'							) as f:
                  f.write(__UpperCAmelCase							)
            return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[Any]			,			__UpperCAmelCase						:	Union[str, Any]							)					-> Any:
      if datasets.config.PY7ZR_AVAILABLE:
            import pyazr

            SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.7z'
            with pyazr.SevenZipFile(__UpperCAmelCase			,			'w'							) as archive:
                  archive.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
            return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict			,			__UpperCAmelCase						:	str							)					-> str:
      import tarfile

      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.tar'
      with tarfile.TarFile(__UpperCAmelCase			,			'w'							) as f:
            f.add(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str							)					-> List[Any]:
      import lzma

      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.xz'
      SCREAMING_SNAKE_CASE_							=			bytes(__UpperCAmelCase			,			'utf-8'							)
      with lzma.open(__UpperCAmelCase			,			'wb'							) as f:
            f.write(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict			,			__UpperCAmelCase						:	Dict							)					-> str:
      import zipfile

      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict							)					-> Any:
      if datasets.config.ZSTANDARD_AVAILABLE:
            import zstandard as zstd

            SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.txt.zst'
            SCREAMING_SNAKE_CASE_							=			bytes(__UpperCAmelCase			,			'utf-8'							)
            with zstd.open(__UpperCAmelCase			,			'wb'							) as f:
                  f.write(__UpperCAmelCase							)
            return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	int							)					-> List[Any]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'file.xml'
      SCREAMING_SNAKE_CASE_							=			textwrap.dedent(
          '\\n    <?xml version="1.0" encoding="UTF-8" ?>\n    <tmx version="1.4">\n      <header segtype="sentence" srclang="ca" />\n      <body>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 1</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 1</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 2</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 2</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 3</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 3</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 4</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 4</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang="ca"><seg>Contingut 5</seg></tuv>\n          <tuv xml:lang="en"><seg>Content 5</seg></tuv>\n        </tu>\n      </body>\n    </tmx>'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase							)
      return filename


lowerCamelCase__ :   Optional[Any]					=							[
    {'col_1': '0', 'col_2': 0, 'col_3': 0.0},
    {'col_1': '1', 'col_2': 1, 'col_3': 1.0},
    {'col_1': '2', 'col_2': 2, 'col_3': 2.0},
    {'col_1': '3', 'col_2': 3, 'col_3': 3.0},
]
lowerCamelCase__ :   Dict					=							[
    {'col_1': '4', 'col_2': 4, 'col_3': 4.0},
    {'col_1': '5', 'col_2': 5, 'col_3': 5.0},
]
lowerCamelCase__ :   Optional[int]					=							{
    'col_1': ['0', '1', '2', '3'],
    'col_2': [0, 1, 2, 3],
    'col_3': [0.0, 1.0, 2.0, 3.0],
}

lowerCamelCase__ :   List[Any]					=							[
    {'col_3': 0.0, 'col_1': '0', 'col_2': 0},
    {'col_3': 1.0, 'col_1': '1', 'col_2': 1},
]

lowerCamelCase__ :   List[Any]					=							[
    {'col_1': 's0', 'col_2': 0, 'col_3': 0.0},
    {'col_1': 's1', 'col_2': 1, 'col_3': 1.0},
    {'col_1': 's2', 'col_2': 2, 'col_3': 2.0},
    {'col_1': 's3', 'col_2': 3, 'col_3': 3.0},
]

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      )					-> Tuple:
      return DATA_DICT_OF_LISTS

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[Any]							)					-> Union[str, Any]:
      SCREAMING_SNAKE_CASE_							=			datasets.Dataset.from_dict(__UpperCAmelCase							)
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.arrow'							)
      dataset.map(cache_file_name=__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[str]							)					-> List[str]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.sqlite'							)
      with contextlib.closing(sqlitea.connect(__UpperCAmelCase							)							) as con:
            SCREAMING_SNAKE_CASE_							=			con.cursor()
            cur.execute('CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)'							)
            for item in DATA:
                  cur.execute('INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)'			,			tuple(item.values()							)							)
            con.commit()
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[int]							)					-> str:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.csv'							)
      with open(__UpperCAmelCase			,			'w'			,			newline=''							) as f:
            SCREAMING_SNAKE_CASE_							=			csv.DictWriter(__UpperCAmelCase			,			fieldnames=['col_1', 'col_2', 'col_3']							)
            writer.writeheader()
            for item in DATA:
                  writer.writerow(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Tuple							)					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset2.csv'							)
      with open(__UpperCAmelCase			,			'w'			,			newline=''							) as f:
            SCREAMING_SNAKE_CASE_							=			csv.DictWriter(__UpperCAmelCase			,			fieldnames=['col_1', 'col_2', 'col_3']							)
            writer.writeheader()
            for item in DATA:
                  writer.writerow(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str			,			__UpperCAmelCase						:	Tuple							)					-> str:
      import bza

      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.csv.bz2'
      with open(__UpperCAmelCase			,			'rb'							) as f:
            SCREAMING_SNAKE_CASE_							=			f.read()
      # data = bytes(FILE_CONTENT, "utf-8")
      with bza.open(__UpperCAmelCase			,			'wb'							) as f:
            f.write(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict			,			__UpperCAmelCase						:	List[str]			,			__UpperCAmelCase						:	str							)					-> Optional[int]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.csv.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[Any]			,			__UpperCAmelCase						:	int			,			__UpperCAmelCase						:	str							)					-> Any:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.csv.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(csv_path.replace('.csv'			,			'.CSV'							)							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(csva_path.replace('.csv'			,			'.CSV'							)							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	int			,			__UpperCAmelCase						:	Tuple			,			__UpperCAmelCase						:	List[Any]							)					-> Union[str, Any]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset_with_dir.csv.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.join('main_dir'			,			os.path.basename(__UpperCAmelCase							)							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.join('main_dir'			,			os.path.basename(__UpperCAmelCase							)							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[str]							)					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.parquet'							)
      SCREAMING_SNAKE_CASE_							=			pa.schema(
          {
              'col_1': pa.string(),
              'col_2': pa.intaa(),
              'col_3': pa.floataa(),
          }							)
      with open(__UpperCAmelCase			,			'wb'							) as f:
            SCREAMING_SNAKE_CASE_							=			pq.ParquetWriter(__UpperCAmelCase			,			schema=__UpperCAmelCase							)
            SCREAMING_SNAKE_CASE_							=			pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(__UpperCAmelCase							)							)] for k in DATA[0]}			,			schema=__UpperCAmelCase							)
            writer.write_table(__UpperCAmelCase							)
            writer.close()
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Tuple							)					-> Any:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.json'							)
      SCREAMING_SNAKE_CASE_							=			{'data': DATA}
      with open(__UpperCAmelCase			,			'w'							) as f:
            json.dump(__UpperCAmelCase			,			__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Union[str, Any]							)					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.json'							)
      SCREAMING_SNAKE_CASE_							=			{'data': DATA_DICT_OF_LISTS}
      with open(__UpperCAmelCase			,			'w'							) as f:
            json.dump(__UpperCAmelCase			,			__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict							)					-> List[str]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.jsonl'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in DATA:
                  f.write(json.dumps(__UpperCAmelCase							) + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[Any]							)					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset2.jsonl'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in DATA:
                  f.write(json.dumps(__UpperCAmelCase							) + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[Any]							)					-> List[Any]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset_312.jsonl'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in DATA_312:
                  f.write(json.dumps(__UpperCAmelCase							) + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[Any]							)					-> List[Any]:
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset-str.jsonl'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in DATA_STR:
                  f.write(json.dumps(__UpperCAmelCase							) + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Union[str, Any]			,			__UpperCAmelCase						:	List[str]							)					-> Union[str, Any]:
      import gzip

      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.txt.gz'							)
      with open(__UpperCAmelCase			,			'rb'							) as orig_file:
            with gzip.open(__UpperCAmelCase			,			'wb'							) as zipped_file:
                  zipped_file.writelines(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str			,			__UpperCAmelCase						:	Optional[Any]							)					-> List[str]:
      import gzip

      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.jsonl.gz'							)
      with open(__UpperCAmelCase			,			'rb'							) as orig_file:
            with gzip.open(__UpperCAmelCase			,			'wb'							) as zipped_file:
                  zipped_file.writelines(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Union[str, Any]			,			__UpperCAmelCase						:	Optional[Any]			,			__UpperCAmelCase						:	Dict							)					-> Optional[int]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.jsonl.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[Any]			,			__UpperCAmelCase						:	Any			,			__UpperCAmelCase						:	List[str]			,			__UpperCAmelCase						:	List[str]							)					-> Optional[int]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset_nested.jsonl.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.join('nested'			,			os.path.basename(__UpperCAmelCase							)							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[str]			,			__UpperCAmelCase						:	Optional[Any]			,			__UpperCAmelCase						:	str							)					-> Any:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset_with_dir.jsonl.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.join('main_dir'			,			os.path.basename(__UpperCAmelCase							)							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.join('main_dir'			,			os.path.basename(__UpperCAmelCase							)							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[Any]			,			__UpperCAmelCase						:	List[Any]			,			__UpperCAmelCase						:	Tuple							)					-> Dict:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.jsonl.tar'
      with tarfile.TarFile(__UpperCAmelCase			,			'w'							) as f:
            f.add(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
            f.add(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[int]			,			__UpperCAmelCase						:	Optional[int]			,			__UpperCAmelCase						:	Optional[Any]			,			__UpperCAmelCase						:	List[Any]							)					-> List[str]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset_nested.jsonl.tar'
      with tarfile.TarFile(__UpperCAmelCase			,			'w'							) as f:
            f.add(__UpperCAmelCase			,			arcname=os.path.join('nested'			,			os.path.basename(__UpperCAmelCase							)							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Optional[Any]							)					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			['0', '1', '2', '3']
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset.txt'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in data:
                  f.write(item + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict							)					-> Any:
      SCREAMING_SNAKE_CASE_							=			['0', '1', '2', '3']
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset2.txt'							)
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in data:
                  f.write(item + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	List[Any]							)					-> int:
      SCREAMING_SNAKE_CASE_							=			['0', '1', '2', '3']
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.abc'
      with open(__UpperCAmelCase			,			'w'							) as f:
            for item in data:
                  f.write(item + '\n'							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Any			,			__UpperCAmelCase						:	Dict			,			__UpperCAmelCase						:	Dict							)					-> Union[str, Any]:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.text.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Tuple			,			__UpperCAmelCase						:	int			,			__UpperCAmelCase						:	Optional[int]							)					-> Any:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset_with_dir.text.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.join('main_dir'			,			os.path.basename(__UpperCAmelCase							)							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.join('main_dir'			,			os.path.basename(__UpperCAmelCase							)							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Union[str, Any]			,			__UpperCAmelCase						:	Any			,			__UpperCAmelCase						:	Union[str, Any]							)					-> Dict:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.ext.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename('unsupported.ext'							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.basename('unsupported_2.ext'							)							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Union[str, Any]							)					-> Dict:
      SCREAMING_SNAKE_CASE_							=			'\n'.join(['First', 'Second\u2029with Unicode new line', 'Third']							)
      SCREAMING_SNAKE_CASE_							=			str(tmp_path_factory.mktemp('data'							) / 'dataset_with_unicode_new_lines.txt'							)
      with open(__UpperCAmelCase			,			'w'			,			encoding='utf-8'							) as f:
            f.write(__UpperCAmelCase							)
      return path

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      )					-> List[Any]:
      return os.path.join('tests'			,			'features'			,			'data'			,			'test_image_rgb.jpg'							)

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      )					-> Tuple:
      return os.path.join('tests'			,			'features'			,			'data'			,			'test_audio_44100.wav'							)

@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Dict			,			__UpperCAmelCase						:	Dict							)					-> int:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data'							) / 'dataset.img.zip'
      with zipfile.ZipFile(__UpperCAmelCase			,			'w'							) as f:
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							)							)
            f.write(__UpperCAmelCase			,			arcname=os.path.basename(__UpperCAmelCase							).replace('.jpg'			,			'2.jpg'							)							)
      return path





@pytest.fixture(scope='session'							)
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str							)					-> Dict:
      SCREAMING_SNAKE_CASE_							=			tmp_path_factory.mktemp('data_dir'							)

      (data_dir / "subdir").mkdir()
      with open(data_dir / 'subdir' / 'train.txt'			,			'w'							) as f:
            f.write('foo\n' * 10							)
      with open(data_dir / 'subdir' / 'test.txt'			,			'w'							) as f:
            f.write('bar\n' * 10							)
      # hidden file
      with open(data_dir / 'subdir' / '.test.txt'			,			'w'							) as f:
            f.write('bar\n' * 10							)

      # hidden directory
      (data_dir / ".subdir").mkdir()
      with open(data_dir / '.subdir' / 'train.txt'			,			'w'							) as f:
            f.write('foo\n' * 10							)
      with open(data_dir / '.subdir' / 'test.txt'			,			'w'							) as f:
            f.write('bar\n' * 10							)

      return data_dir