


from typing import Any, Dict, Optional

import torch
import torch.nn.functional as F
from torch import nn

from ..utils import maybe_allow_in_graph
from .activations import get_activation
from .attention_processor import Attention
from .embeddings import CombinedTimestepLabelEmbeddings






@maybe_allow_in_graph
class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase, lowerCamelCase, lowerCamelCase=0.0, lowerCamelCase = None, lowerCamelCase = "geglu", lowerCamelCase = None, lowerCamelCase = False, lowerCamelCase = False, lowerCamelCase = False, lowerCamelCase = False, lowerCamelCase = True, lowerCamelCase = "layer_norm", lowerCamelCase = False, )			->  Dict:




           """simple docstring"""

           super().__init__()
           _lowercase			:				Union[str, Any] 						=						only_cross_attention

           _lowercase			:				Union[str, Any] 						=						(num_embeds_ada_norm is not None) and norm_type == 'ada_norm_zero'
           _lowercase			:				List[str] 						=						(num_embeds_ada_norm is not None) and norm_type == 'ada_norm'

           if norm_type in ("ada_norm", "ada_norm_zero") and num_embeds_ada_norm is None:
               raise ValueError(
                   F'''`norm_type` is set to {norm_type}, but `num_embeds_ada_norm` is not defined. Please make sure to'''
                   F''' define `num_embeds_ada_norm` if setting `norm_type` to {norm_type}.''')

           # Define 3 blocks. Each block has its own normalization layer.
           # 1. Self-Attn
           if self.use_ada_layer_norm:
               _lowercase			:				Union[str, Any] 						=						AdaLayerNorm(lowerCamelCase, lowerCamelCase)
           elif self.use_ada_layer_norm_zero:
               _lowercase			:				List[str] 						=						AdaLayerNormZero(lowerCamelCase, lowerCamelCase)
           else:
               _lowercase			:				Tuple 						=						nn.LayerNorm(lowerCamelCase, elementwise_affine=lowerCamelCase)
           _lowercase			:				Optional[int] 						=						Attention(
               query_dim=lowerCamelCase, heads=lowerCamelCase, dim_head=lowerCamelCase, dropout=lowerCamelCase, bias=lowerCamelCase, cross_attention_dim=cross_attention_dim if only_cross_attention else None, upcast_attention=lowerCamelCase, )

           # 2. Cross-Attn
           if cross_attention_dim is not None or double_self_attention:
               # We currently only use AdaLayerNormZero for self attention where there will only be one attention block.
               # I.e. the number of returned modulation chunks from AdaLayerZero would not make sense if returned during
               # the second cross attention block.
               _lowercase			:				Dict 						=						(
                   AdaLayerNorm(lowerCamelCase, lowerCamelCase)
                   if self.use_ada_layer_norm
                   else nn.LayerNorm(lowerCamelCase, elementwise_affine=lowerCamelCase)
               )
               _lowercase			:				str 						=						Attention(
                   query_dim=lowerCamelCase, cross_attention_dim=cross_attention_dim if not double_self_attention else None, heads=lowerCamelCase, dim_head=lowerCamelCase, dropout=lowerCamelCase, bias=lowerCamelCase, upcast_attention=lowerCamelCase, )  # is self-attn if encoder_hidden_states is none
           else:
               _lowercase			:				Optional[int] 						=						None
               _lowercase			:				List[Any] 						=						None

           # 3. Feed-forward
           _lowercase			:				Dict 						=						nn.LayerNorm(lowerCamelCase, elementwise_affine=lowerCamelCase)
           _lowercase			:				Dict 						=						FeedForward(lowerCamelCase, dropout=lowerCamelCase, activation_fn=lowerCamelCase, final_dropout=lowerCamelCase)

           # let chunk size default to None
           _lowercase			:				Union[str, Any] 						=						None
           _lowercase			:				str 						=						0
       def      UpperCamelCase	(   self, lowerCamelCase, lowerCamelCase)			->  Tuple:




           """simple docstring"""

           _lowercase			:				Any 						=						chunk_size
           _lowercase			:				Union[str, Any] 						=						dim




       def      UpperCamelCase	(   self, lowerCamelCase, lowerCamelCase = None, lowerCamelCase = None, lowerCamelCase = None, lowerCamelCase = None, lowerCamelCase = None, lowerCamelCase = None, )			->  List[Any]:




           """simple docstring"""

           if self.use_ada_layer_norm:
               _lowercase			:				List[str] 						=						self.norma(lowerCamelCase, lowerCamelCase)
           elif self.use_ada_layer_norm_zero:
               _lowercase						,							_lowercase						,							_lowercase						,							_lowercase						,							_lowercase			:				Any 						=						self.norma(
                   lowerCamelCase, lowerCamelCase, lowerCamelCase, hidden_dtype=hidden_states.dtype)
           else:
               _lowercase			:				List[Any] 						=						self.norma(lowerCamelCase)

           _lowercase			:				List[Any] 						=						cross_attention_kwargs if cross_attention_kwargs is not None else {}

           _lowercase			:				Any 						=						self.attna(
               lowerCamelCase, encoder_hidden_states=encoder_hidden_states if self.only_cross_attention else None, attention_mask=lowerCamelCase, **lowerCamelCase, )
           if self.use_ada_layer_norm_zero:
               _lowercase			:				List[Any] 						=						gate_msa.unsqueeze(1) * attn_output
           _lowercase			:				List[Any] 						=						attn_output + hidden_states

           # 2. Cross-Attention
           if self.attna is not None:
               _lowercase			:				List[Any] 						=						(
                   self.norma(lowerCamelCase, lowerCamelCase) if self.use_ada_layer_norm else self.norma(lowerCamelCase)
               )

               _lowercase			:				Any 						=						self.attna(
                   lowerCamelCase, encoder_hidden_states=lowerCamelCase, attention_mask=lowerCamelCase, **lowerCamelCase, )
               _lowercase			:				Optional[int] 						=						attn_output + hidden_states

           # 3. Feed-forward
           _lowercase			:				List[str] 						=						self.norma(lowerCamelCase)

           if self.use_ada_layer_norm_zero:
               _lowercase			:				str 						=						norm_hidden_states * (1 + scale_mlp[:, None]) + shift_mlp[:, None]

           if self._chunk_size is not None:
               # "feed_forward_chunk_size" can be used to save memory
               if norm_hidden_states.shape[self._chunk_dim] % self._chunk_size != 0:
                   raise ValueError(
                       F'''`hidden_states` dimension to be chunked: {norm_hidden_states.shape[self._chunk_dim]} has to be divisible by chunk size: {self._chunk_size}. Make sure to set an appropriate `chunk_size` when calling `unet.enable_forward_chunking`.''')

               _lowercase			:				Optional[Any] 						=						norm_hidden_states.shape[self._chunk_dim] // self._chunk_size
               _lowercase			:				Optional[Any] 						=						torch.cat(
                   [self.ff(lowerCamelCase) for hid_slice in norm_hidden_states.chunk(lowerCamelCase, dim=self._chunk_dim)], dim=self._chunk_dim, )
           else:
               _lowercase			:				Union[str, Any] 						=						self.ff(lowerCamelCase)

           if self.use_ada_layer_norm_zero:
               _lowercase			:				List[str] 						=						gate_mlp.unsqueeze(1) * ff_output

           _lowercase			:				Tuple 						=						ff_output + hidden_states

           return hidden_states






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase = None, lowerCamelCase = 4, lowerCamelCase = 0.0, lowerCamelCase = "geglu", lowerCamelCase = False, )			->  Tuple:




           """simple docstring"""

           super().__init__()
           _lowercase			:				Optional[Any] 						=						int(dim * mult)
           _lowercase			:				Optional[Any] 						=						dim_out if dim_out is not None else dim

           if activation_fn == "gelu":
               _lowercase			:				Union[str, Any] 						=						GELU(lowerCamelCase, lowerCamelCase)
           if activation_fn == "gelu-approximate":
               _lowercase			:				Optional[Any] 						=						GELU(lowerCamelCase, lowerCamelCase, approximate='tanh')
           elif activation_fn == "geglu":
               _lowercase			:				str 						=						GEGLU(lowerCamelCase, lowerCamelCase)
           elif activation_fn == "geglu-approximate":
               _lowercase			:				Union[str, Any] 						=						ApproximateGELU(lowerCamelCase, lowerCamelCase)

           _lowercase			:				List[Any] 						=						nn.ModuleList([])
           # project in
           self.net.append(lowerCamelCase)
           # project dropout
           self.net.append(nn.Dropout(lowerCamelCase))
           # project out
           self.net.append(nn.Linear(lowerCamelCase, lowerCamelCase))
           # FF as used in Vision Transformer, MLP-Mixer, etc. have a final dropout
           if final_dropout:
               self.net.append(nn.Dropout(lowerCamelCase))




       def      UpperCamelCase	(   self, lowerCamelCase)			->  Optional[int]:




           """simple docstring"""

           for module in self.net:
               _lowercase			:				Union[str, Any] 						=						module(lowerCamelCase)
           return hidden_states






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase, lowerCamelCase = "none")			->  Optional[int]:




           """simple docstring"""

           super().__init__()
           _lowercase			:				Union[str, Any] 						=						nn.Linear(lowerCamelCase, lowerCamelCase)
           _lowercase			:				List[Any] 						=						approximate
       def      UpperCamelCase	(   self, lowerCamelCase)			->  Tuple:




           """simple docstring"""

           if gate.device.type != "mps":
               return F.gelu(lowerCamelCase, approximate=self.approximate)
           # mps: gelu is not implemented for float16
           return F.gelu(gate.to(dtype=torch.floataa), approximate=self.approximate).to(dtype=gate.dtype)




       def      UpperCamelCase	(   self, lowerCamelCase)			->  Tuple:




           """simple docstring"""

           _lowercase			:				Optional[int] 						=						self.proj(lowerCamelCase)
           _lowercase			:				Union[str, Any] 						=						self.gelu(lowerCamelCase)
           return hidden_states






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase)			->  int:




           """simple docstring"""

           super().__init__()
           _lowercase			:				Optional[Any] 						=						nn.Linear(lowerCamelCase, dim_out * 2)
       def      UpperCamelCase	(   self, lowerCamelCase)			->  Any:




           """simple docstring"""

           if gate.device.type != "mps":
               return F.gelu(lowerCamelCase)
           # mps: gelu is not implemented for float16
           return F.gelu(gate.to(dtype=torch.floataa)).to(dtype=gate.dtype)




       def      UpperCamelCase	(   self, lowerCamelCase)			->  Optional[int]:




           """simple docstring"""

           _lowercase						,							_lowercase			:				Tuple 						=						self.proj(lowerCamelCase).chunk(2, dim=-1)
           return hidden_states * self.gelu(lowerCamelCase)






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase)			->  Any:




           """simple docstring"""

           super().__init__()
           _lowercase			:				str 						=						nn.Linear(lowerCamelCase, lowerCamelCase)




       def      UpperCamelCase	(   self, lowerCamelCase)			->  Union[str, Any]:




           """simple docstring"""

           _lowercase			:				Optional[int] 						=						self.proj(lowerCamelCase)
           return x * torch.sigmoid(1.7_0_2 * x)






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase)			->  Tuple:




           """simple docstring"""

           super().__init__()
           _lowercase			:				int 						=						nn.Embedding(lowerCamelCase, lowerCamelCase)
           _lowercase			:				List[Any] 						=						nn.SiLU()
           _lowercase			:				Optional[Any] 						=						nn.Linear(lowerCamelCase, embedding_dim * 2)
           _lowercase			:				List[Any] 						=						nn.LayerNorm(lowerCamelCase, elementwise_affine=lowerCamelCase)




       def      UpperCamelCase	(   self, lowerCamelCase, lowerCamelCase)			->  Optional[Any]:




           """simple docstring"""

           _lowercase			:				List[str] 						=						self.linear(self.silu(self.emb(lowerCamelCase)))
           _lowercase						,							_lowercase			:				int 						=						torch.chunk(lowerCamelCase, 2)
           _lowercase			:				Optional[Any] 						=						self.norm(lowerCamelCase) * (1 + scale) + shift
           return x






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase)			->  Union[str, Any]:




           """simple docstring"""

           super().__init__()

           _lowercase			:				List[Any] 						=						CombinedTimestepLabelEmbeddings(lowerCamelCase, lowerCamelCase)

           _lowercase			:				Tuple 						=						nn.SiLU()
           _lowercase			:				Any 						=						nn.Linear(lowerCamelCase, 6 * embedding_dim, bias=lowerCamelCase)
           _lowercase			:				List[str] 						=						nn.LayerNorm(lowerCamelCase, elementwise_affine=lowerCamelCase, eps=1E-6)




       def      UpperCamelCase	(   self, lowerCamelCase, lowerCamelCase, lowerCamelCase, lowerCamelCase=None)			->  Dict:




           """simple docstring"""

           _lowercase			:				Optional[int] 						=						self.linear(self.silu(self.emb(lowerCamelCase, lowerCamelCase, hidden_dtype=lowerCamelCase)))
           _lowercase						,							_lowercase						,							_lowercase						,							_lowercase						,							_lowercase						,							_lowercase			:				List[str] 						=						emb.chunk(6, dim=1)
           _lowercase			:				Dict 						=						self.norm(lowerCamelCase) * (1 + scale_msa[:, None]) + shift_msa[:, None]
           return x, gate_msa, shift_mlp, scale_mlp, gate_mlp






class _lowerCamelCase(		nn.Module  ):
       def __init__(   self, lowerCamelCase, lowerCamelCase, lowerCamelCase, lowerCamelCase = None, lowerCamelCase = 1E-5)			->  Union[str, Any]:




           """simple docstring"""

           super().__init__()
           _lowercase			:				Optional[Any] 						=						num_groups
           _lowercase			:				Any 						=						eps

           if act_fn is None:
               _lowercase			:				Optional[Any] 						=						None
           else:
               _lowercase			:				Any 						=						get_activation(lowerCamelCase)

           _lowercase			:				int 						=						nn.Linear(lowerCamelCase, out_dim * 2)




       def      UpperCamelCase	(   self, lowerCamelCase, lowerCamelCase)			->  Optional[int]:




           """simple docstring"""

           if self.act:
               _lowercase			:				Optional[int] 						=						self.act(lowerCamelCase)
           _lowercase			:				Union[str, Any] 						=						self.linear(lowerCamelCase)
           _lowercase			:				Optional[Any] 						=						emb[:, :, None, None]
           _lowercase						,							_lowercase			:				Optional[Any] 						=						emb.chunk(2, dim=1)

           _lowercase			:				Any 						=						F.group_norm(lowerCamelCase, self.num_groups, eps=self.eps)
           _lowercase			:				Optional[Any] 						=						x * (1 + scale) + shift
           return x






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_( )       ->		Any:
    _lowercase			:				str 						=						10
    _lowercase			:				List[str] 						=						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'					),
        }					)
    _lowercase			:				Union[str, Any] 						=						datasets.Dataset.from_dict(
        {
            'tokens': [['foo'] * 5] * n,
            'labels': [[1] * 5] * n,
            'answers': [{'answer_start': [97], 'text': ['1976']}] * 10,
            'id': list(range(lowerCamelCase_					)					),
        }				,					features=lowerCamelCase_				,					)
    return dataset



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


# FILE_CONTENT + files


SCREAMING_SNAKE_CASE			: str				   =					"\\n    Text data.\n    Second line of data."



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		Tuple:
    import bza

    _lowercase			:				Any 						=						tmp_path_factory.mktemp('data'					) / 'file.txt.bz2'
    _lowercase			:				Optional[Any] 						=						bytes(lowerCamelCase_				,					'utf-8'					)
    with bza.open(lowerCamelCase_				,					'wb'					) as f:
        f.write(lowerCamelCase_					)
    return path



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

    _lowercase			:				Optional[int] 						=						str(tmp_path_factory.mktemp('data'					) / 'file.txt.gz'					)
    _lowercase			:				Optional[int] 						=						bytes(lowerCamelCase_				,					'utf-8'					)
    with gzip.open(lowerCamelCase_				,					'wb'					) as f:
        f.write(lowerCamelCase_					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		str:
    if datasets.config.LZ4_AVAILABLE:
        import lza.frame

        _lowercase			:				Any 						=						tmp_path_factory.mktemp('data'					) / 'file.txt.lz4'
        _lowercase			:				Optional[Any] 						=						bytes(lowerCamelCase_				,					'utf-8'					)
        with lza.frame.open(lowerCamelCase_				,					'wb'					) as f:
            f.write(lowerCamelCase_					)
        return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		str:
    if datasets.config.PY7ZR_AVAILABLE:
        import pyazr

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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		List[str]:
    import tarfile

    _lowercase			:				Optional[Any] 						=						tmp_path_factory.mktemp('data'					) / 'file.txt.tar'
    with tarfile.TarFile(lowerCamelCase_				,					'w'					) as f:
        f.add(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		str:
    import lzma

    _lowercase			:				Optional[Any] 						=						tmp_path_factory.mktemp('data'					) / 'file.txt.xz'
    _lowercase			:				int 						=						bytes(lowerCamelCase_				,					'utf-8'					)
    with lzma.open(lowerCamelCase_				,					'wb'					) as f:
        f.write(lowerCamelCase_					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		str:
    import zipfile

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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		Optional[Any]:
    if datasets.config.ZSTANDARD_AVAILABLE:
        import zstandard as zstd

        _lowercase			:				Optional[Any] 						=						tmp_path_factory.mktemp('data'					) / 'file.txt.zst'
        _lowercase			:				Dict 						=						bytes(lowerCamelCase_				,					'utf-8'					)
        with zstd.open(lowerCamelCase_				,					'wb'					) as f:
            f.write(lowerCamelCase_					)
        return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		str:
    _lowercase			:				Union[str, Any] 						=						tmp_path_factory.mktemp('data'					) / 'file.xml'
    _lowercase			:				Optional[Any] 						=						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(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_					)
    return filename


SCREAMING_SNAKE_CASE			: Dict				   =					[
    {"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},
]
SCREAMING_SNAKE_CASE			: Dict				   =					[
    {"col_1": "4", "col_2": 4, "col_3": 4.0},
    {"col_1": "5", "col_2": 5, "col_3": 5.0},
]
SCREAMING_SNAKE_CASE			: Optional[Any]				   =					{
    "col_1": ["0", "1", "2", "3"],
    "col_2": [0, 1, 2, 3],
    "col_3": [0.0, 1.0, 2.0, 3.0],
}

SCREAMING_SNAKE_CASE			: Tuple				   =					[
    {"col_3": 0.0, "col_1": "0", "col_2": 0},
    {"col_3": 1.0, "col_1": "1", "col_2": 1},
]

SCREAMING_SNAKE_CASE			: 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_( )       ->		List[str]:
    return DATA_DICT_OF_LISTS



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		Dict:
    _lowercase			:				Optional[int] 						=						datasets.Dataset.from_dict(lowerCamelCase_					)
    _lowercase			:				List[Any] 						=						str(tmp_path_factory.mktemp('data'					) / 'dataset.arrow'					)
    dataset.map(cache_file_name=lowerCamelCase_					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		str:
    _lowercase			:				List[str] 						=						str(tmp_path_factory.mktemp('data'					) / 'dataset.sqlite'					)
    with contextlib.closing(sqlitea.connect(lowerCamelCase_					)					) as con:
        _lowercase			:				Union[str, Any] 						=						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_( lowerCamelCase_					)       ->		Dict:
    _lowercase			:				List[str] 						=						str(tmp_path_factory.mktemp('data'					) / 'dataset.csv'					)
    with open(lowerCamelCase_				,					'w'				,					newline=''					) as f:
        _lowercase			:				Tuple 						=						csv.DictWriter(lowerCamelCase_				,					fieldnames=['col_1', 'col_2', 'col_3']					)
        writer.writeheader()
        for item in DATA:
            writer.writerow(lowerCamelCase_					)
    return path



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		Any:
    import bza

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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		Optional[int]:
    _lowercase			:				Optional[Any] 						=						tmp_path_factory.mktemp('data'					) / 'dataset.csv.zip'
    with zipfile.ZipFile(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
        f.write(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
    return path



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



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



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		Optional[Any]:
    _lowercase			:				Optional[Any] 						=						str(tmp_path_factory.mktemp('data'					) / 'dataset.json'					)
    _lowercase			:				List[Any] 						=						{'data': DATA}
    with open(lowerCamelCase_				,					'w'					) as f:
        json.dump(lowerCamelCase_				,					lowerCamelCase_					)
    return path



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



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		Dict:
    _lowercase			:				Dict 						=						str(tmp_path_factory.mktemp('data'					) / 'dataset2.jsonl'					)
    with open(lowerCamelCase_				,					'w'					) as f:
        for item in DATA:
            f.write(json.dumps(lowerCamelCase_					) + '\n'					)
    return path



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



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		Optional[Any]:
    import gzip

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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_					)       ->		Dict:
    import gzip

    _lowercase			:				Optional[int] 						=						str(tmp_path_factory.mktemp('data'					) / 'dataset.jsonl.gz'					)
    with open(lowerCamelCase_				,					'rb'					) as orig_file:
        with gzip.open(lowerCamelCase_				,					'wb'					) as zipped_file:
            zipped_file.writelines(lowerCamelCase_					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		List[str]:
    _lowercase			:				Any 						=						tmp_path_factory.mktemp('data'					) / 'dataset.jsonl.zip'
    with zipfile.ZipFile(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
        f.write(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		str:
    _lowercase			:				str 						=						tmp_path_factory.mktemp('data'					) / 'dataset_nested.jsonl.zip'
    with zipfile.ZipFile(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_				,					arcname=os.path.join('nested'				,					os.path.basename(lowerCamelCase_					)					)					)
    return path



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		Optional[int]:
    _lowercase			:				Tuple 						=						tmp_path_factory.mktemp('data'					) / 'dataset.jsonl.tar'
    with tarfile.TarFile(lowerCamelCase_				,					'w'					) as f:
        f.add(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
        f.add(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		Any:
    _lowercase			:				str 						=						tmp_path_factory.mktemp('data'					) / 'dataset_nested.jsonl.tar'
    with tarfile.TarFile(lowerCamelCase_				,					'w'					) as f:
        f.add(lowerCamelCase_				,					arcname=os.path.join('nested'				,					os.path.basename(lowerCamelCase_					)					)					)
    return path



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



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



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		Any:
    _lowercase			:				Optional[Any] 						=						tmp_path_factory.mktemp('data'					) / 'dataset.text.zip'
    with zipfile.ZipFile(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
        f.write(lowerCamelCase_				,					arcname=os.path.basename(lowerCamelCase_					)					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		Dict:
    _lowercase			:				List[Any] 						=						tmp_path_factory.mktemp('data'					) / 'dataset_with_dir.text.zip'
    with zipfile.ZipFile(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_				,					arcname=os.path.join('main_dir'				,					os.path.basename(lowerCamelCase_					)					)					)
        f.write(lowerCamelCase_				,					arcname=os.path.join('main_dir'				,					os.path.basename(lowerCamelCase_					)					)					)
    return path



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_				,					lowerCamelCase_				,					lowerCamelCase_					)       ->		str:
    _lowercase			:				Any 						=						tmp_path_factory.mktemp('data'					) / 'dataset.ext.zip'
    with zipfile.ZipFile(lowerCamelCase_				,					'w'					) as f:
        f.write(lowerCamelCase_				,					arcname=os.path.basename('unsupported.ext'					)					)
        f.write(lowerCamelCase_				,					arcname=os.path.basename('unsupported_2.ext'					)					)
    return path



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( )       ->		Dict:
    return os.path.join('tests'				,					'features'				,					'data'				,					'test_image_rgb.jpg'					)



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



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



@pytest.fixture(scope='session'					)
def 							UpperCamelCase_( lowerCamelCase_					)       ->		Optional[Any]:
    _lowercase			:				str 						=						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


