




import argparse

import requests
import torch
from PIL import Image

from transformers import CLIPProcessor, GroupViTConfig, GroupViTModel

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str							)					-> Optional[Any]:
      # vision encoder
      if "img_encoder.pos_embed" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_encoder.pos_embed'			,			'vision_model.embeddings.position_embeddings'							)
      if "img_encoder.patch_embed.proj" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_encoder.patch_embed.proj'			,			'vision_model.embeddings.patch_embeddings.projection'							)
      if "img_encoder.patch_embed.norm" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_encoder.patch_embed.norm'			,			'vision_model.embeddings.layernorm'							)
      if "img_encoder.layers" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_encoder.layers'			,			'vision_model.encoder.stages'							)
      if "blocks" in name and "res" not in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('blocks'			,			'layers'							)
      if "attn" in name and "pre_assign" not in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('attn'			,			'self_attn'							)
      if "proj" in name and "self_attn" in name and "text" not in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('proj'			,			'out_proj'							)
      if "pre_assign_attn.attn.proj" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('pre_assign_attn.attn.proj'			,			'pre_assign_attn.attn.out_proj'							)
      if "norm1" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('norm1'			,			'layer_norm1'							)
      if "norm2" in name and "pre_assign" not in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('norm2'			,			'layer_norm2'							)
      if "img_encoder.norm" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_encoder.norm'			,			'vision_model.layernorm'							)
      # text encoder
      if "text_encoder.token_embedding" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('text_encoder.token_embedding'			,			'text_model.embeddings.token_embedding'							)
      if "text_encoder.positional_embedding" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('text_encoder.positional_embedding'			,			'text_model.embeddings.position_embedding.weight'							)
      if "text_encoder.transformer.resblocks." in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('text_encoder.transformer.resblocks.'			,			'text_model.encoder.layers.'							)
      if "ln_1" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('ln_1'			,			'layer_norm1'							)
      if "ln_2" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('ln_2'			,			'layer_norm2'							)
      if "c_fc" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('c_fc'			,			'fc1'							)
      if "c_proj" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('c_proj'			,			'fc2'							)
      if "text_encoder" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('text_encoder'			,			'text_model'							)
      if "ln_final" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('ln_final'			,			'final_layer_norm'							)
      # projection layers
      if "img_projector.linear_hidden." in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_projector.linear_hidden.'			,			'visual_projection.'							)
      if "img_projector.linear_out." in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('img_projector.linear_out.'			,			'visual_projection.3.'							)
      if "text_projector.linear_hidden" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('text_projector.linear_hidden'			,			'text_projection'							)
      if "text_projector.linear_out" in name:
            SCREAMING_SNAKE_CASE_							=			name.replace('text_projector.linear_out'			,			'text_projection.3'							)

      return name

def 					UpperCAmelCase_							(      __UpperCAmelCase						:	str			,			__UpperCAmelCase						:	List[str]							)					-> str:
      for key in orig_state_dict.copy().keys():
            SCREAMING_SNAKE_CASE_							=			orig_state_dict.pop(__UpperCAmelCase							)

            if "qkv" in key:
                  # weights and biases of the key, value and query projections of vision encoder's attention layers require special treatment:
                  # we need to split them up into separate matrices/vectors
                  SCREAMING_SNAKE_CASE_							=			key.split('.'							)
                  SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			int(key_split[2]							), int(key_split[4]							)
                  SCREAMING_SNAKE_CASE_							=			config.vision_config.hidden_size
                  if "weight" in key:
                        SCREAMING_SNAKE_CASE_							=			val[:dim, :]
                        SCREAMING_SNAKE_CASE_							=			val[dim : dim * 2, :]
                        SCREAMING_SNAKE_CASE_							=			val[-dim:, :]
                  else:
                        SCREAMING_SNAKE_CASE_							=			val[:dim]
                        SCREAMING_SNAKE_CASE_							=			val[dim : dim * 2]
                        SCREAMING_SNAKE_CASE_							=			val[-dim:]
            elif "in_proj" in key:
                  # weights and biases of the key, value and query projections of text encoder's attention layers require special treatment:
                  # we need to split them up into separate matrices/vectors
                  SCREAMING_SNAKE_CASE_							=			key.split('.'							)
                  SCREAMING_SNAKE_CASE_							=			int(key_split[3]							)
                  SCREAMING_SNAKE_CASE_							=			config.text_config.hidden_size
                  if "weight" in key:
                        SCREAMING_SNAKE_CASE_							=			val[:dim, :]
                        SCREAMING_SNAKE_CASE_							=			val[
                            dim : dim * 2, :
                        ]
                        SCREAMING_SNAKE_CASE_							=			val[-dim:, :]
                  else:
                        SCREAMING_SNAKE_CASE_							=			val[:dim]
                        SCREAMING_SNAKE_CASE_							=			val[dim : dim * 2]
                        SCREAMING_SNAKE_CASE_							=			val[-dim:]
            else:
                  SCREAMING_SNAKE_CASE_							=			rename_key(__UpperCAmelCase							)
                  # squeeze if necessary
                  if (
                      "text_projection.0" in new_name
                      or "text_projection.3" in new_name
                      or "visual_projection.0" in new_name
                      or "visual_projection.3" in new_name
                  ):
                        SCREAMING_SNAKE_CASE_							=			val.squeeze_()
                  else:
                        SCREAMING_SNAKE_CASE_							=			val

      return orig_state_dict

def 					UpperCAmelCase_							(      )					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			'http://images.cocodataset.org/val2017/000000039769.jpg'
      SCREAMING_SNAKE_CASE_							=			Image.open(requests.get(__UpperCAmelCase			,			stream=__UpperCAmelCase							).raw							)
      return im

@torch.no_grad()
def 					UpperCAmelCase_							(      __UpperCAmelCase						:	Any			,			__UpperCAmelCase						:	List[str]			,			__UpperCAmelCase						:	Any="groupvit-gcc-yfcc"			,			__UpperCAmelCase						:	Dict=False							)					-> List[str]:
      SCREAMING_SNAKE_CASE_							=			GroupViTConfig()
      SCREAMING_SNAKE_CASE_							=			GroupViTModel(__UpperCAmelCase							).eval()

      SCREAMING_SNAKE_CASE_							=			torch.load(__UpperCAmelCase			,			map_location='cpu'							)['model']
      SCREAMING_SNAKE_CASE_							=			convert_state_dict(__UpperCAmelCase			,			__UpperCAmelCase							)
      SCREAMING_SNAKE_CASE_						, SCREAMING_SNAKE_CASE_							=			model.load_state_dict(__UpperCAmelCase			,			strict=__UpperCAmelCase							)
      assert missing_keys == ["text_model.embeddings.position_ids"]
      assert (unexpected_keys == ["multi_label_logit_scale"]) or (len(__UpperCAmelCase							) == 0)

      # verify result
      SCREAMING_SNAKE_CASE_							=			CLIPProcessor.from_pretrained('openai/clip-vit-base-patch32'							)
      SCREAMING_SNAKE_CASE_							=			prepare_img()
      SCREAMING_SNAKE_CASE_							=			processor(text=['a photo of a cat', 'a photo of a dog']			,			images=__UpperCAmelCase			,			padding=__UpperCAmelCase			,			return_tensors='pt'							)

      with torch.no_grad():
            SCREAMING_SNAKE_CASE_							=			model(**__UpperCAmelCase							)

      if model_name == "groupvit-gcc-yfcc":
            SCREAMING_SNAKE_CASE_							=			torch.tensor([[1_3.3_5_2_3, 6.3_6_2_9]]							)
      elif model_name == "groupvit-gcc-redcaps":
            SCREAMING_SNAKE_CASE_							=			torch.tensor([[1_6.1_8_7_3, 8.6_2_3_0]]							)
      else:
            raise ValueError(f"Model name {model_name} not supported."							)
      assert torch.allclose(outputs.logits_per_image			,			__UpperCAmelCase			,			atol=1E-3							)

      processor.save_pretrained(__UpperCAmelCase							)
      model.save_pretrained(__UpperCAmelCase							)
      print('Successfully saved processor and model to'			,			__UpperCAmelCase							)

      if push_to_hub:
            print('Pushing to the hub...'							)
            processor.push_to_hub(__UpperCAmelCase			,			organization='nielsr'							)
            model.push_to_hub(__UpperCAmelCase			,			organization='nielsr'							)


if __name__ == "__main__":
   lowerCamelCase__ :   int					=							argparse.ArgumentParser()
   parser.add_argument(
       '--pytorch_dump_folder_path', default=None, type=str, help='Path to dump the processor and PyTorch model.'
   )
   parser.add_argument('--checkpoint_path', default=None, type=str, help='Path to GroupViT checkpoint')
   parser.add_argument(
       '--model_name',
       default='groupvit-gccy-fcc',
       type=str,
       help='Name of the model. Expecting either \'groupvit-gcc-yfcc\' or \'groupvit-gcc-redcaps\'',
   )
   parser.add_argument(
       '--push_to_hub',
       action='store_true',
       help='Whether or not to push the converted model and processor to the 🤗 hub using the provided `model_name`.',
   )
   lowerCamelCase__ :   Dict					=							parser.parse_args()

   convert_groupvit_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.model_name, args.push_to_hub)





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