Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/arrow/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/arrow/__pycache__/arrow.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/__pycache__/audiofolder.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/audiofolder.py +67 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/cache/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/cache/__pycache__/cache.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/csv/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/csv/__pycache__/csv.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/folder_based_builder/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/folder_based_builder/__pycache__/folder_based_builder.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/__pycache__/generator.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/generator.py +33 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/__pycache__/imagefolder.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/imagefolder.py +103 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/json/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/json/__pycache__/json.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/__pycache__/pandas.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/pandas.py +65 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/__pycache__/parquet.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/parquet.py +109 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pdffolder/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pdffolder/__pycache__/pdffolder.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/spark/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/spark/__pycache__/spark.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/sql/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/sql/__pycache__/sql.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/__pycache__/text.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/text.py +112 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/videofolder/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/videofolder/__pycache__/videofolder.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__pycache__/__init__.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__pycache__/_tenbin.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__pycache__/webdataset.cpython-310.pyc +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/_tenbin.py +285 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/webdataset.py +350 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/xml/__init__.py +0 -0
- data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/xml/__pycache__/__init__.cpython-310.pyc +0 -0
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/arrow/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (205 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/arrow/__pycache__/arrow.cpython-310.pyc
ADDED
|
Binary file (3.48 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/__pycache__/audiofolder.cpython-310.pyc
ADDED
|
Binary file (1.38 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/audiofolder/audiofolder.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
from ..folder_based_builder import folder_based_builder
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
logger = datasets.utils.logging.get_logger(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class AudioFolderConfig(folder_based_builder.FolderBasedBuilderConfig):
|
| 10 |
+
"""Builder Config for AudioFolder."""
|
| 11 |
+
|
| 12 |
+
drop_labels: bool = None
|
| 13 |
+
drop_metadata: bool = None
|
| 14 |
+
|
| 15 |
+
def __post_init__(self):
|
| 16 |
+
super().__post_init__()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class AudioFolder(folder_based_builder.FolderBasedBuilder):
|
| 20 |
+
BASE_FEATURE = datasets.Audio
|
| 21 |
+
BASE_COLUMN_NAME = "audio"
|
| 22 |
+
BUILDER_CONFIG_CLASS = AudioFolderConfig
|
| 23 |
+
EXTENSIONS: list[str] # definition at the bottom of the script
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Obtained with:
|
| 27 |
+
# ```
|
| 28 |
+
# import soundfile as sf
|
| 29 |
+
#
|
| 30 |
+
# AUDIO_EXTENSIONS = [f".{format.lower()}" for format in sf.available_formats().keys()]
|
| 31 |
+
#
|
| 32 |
+
# # .opus decoding is supported if libsndfile >= 1.0.31:
|
| 33 |
+
# AUDIO_EXTENSIONS.extend([".opus"])
|
| 34 |
+
# ```
|
| 35 |
+
# We intentionally do not run this code on launch because:
|
| 36 |
+
# (1) Soundfile is an optional dependency, so importing it in global namespace is not allowed
|
| 37 |
+
# (2) To ensure the list of supported extensions is deterministic
|
| 38 |
+
AUDIO_EXTENSIONS = [
|
| 39 |
+
".aiff",
|
| 40 |
+
".au",
|
| 41 |
+
".avr",
|
| 42 |
+
".caf",
|
| 43 |
+
".flac",
|
| 44 |
+
".htk",
|
| 45 |
+
".svx",
|
| 46 |
+
".mat4",
|
| 47 |
+
".mat5",
|
| 48 |
+
".mpc2k",
|
| 49 |
+
".ogg",
|
| 50 |
+
".paf",
|
| 51 |
+
".pvf",
|
| 52 |
+
".raw",
|
| 53 |
+
".rf64",
|
| 54 |
+
".sd2",
|
| 55 |
+
".sds",
|
| 56 |
+
".ircam",
|
| 57 |
+
".voc",
|
| 58 |
+
".w64",
|
| 59 |
+
".wav",
|
| 60 |
+
".nist",
|
| 61 |
+
".wavex",
|
| 62 |
+
".wve",
|
| 63 |
+
".xi",
|
| 64 |
+
".mp3",
|
| 65 |
+
".opus",
|
| 66 |
+
]
|
| 67 |
+
AudioFolder.EXTENSIONS = AUDIO_EXTENSIONS
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/cache/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (205 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/cache/__pycache__/cache.cpython-310.pyc
ADDED
|
Binary file (6.34 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/csv/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (203 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/csv/__pycache__/csv.cpython-310.pyc
ADDED
|
Binary file (7.06 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/folder_based_builder/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (220 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/folder_based_builder/__pycache__/folder_based_builder.cpython-310.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (209 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/__pycache__/generator.cpython-310.pyc
ADDED
|
Binary file (1.79 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/generator/generator.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
from typing import Callable, Optional
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@dataclass
|
| 8 |
+
class GeneratorConfig(datasets.BuilderConfig):
|
| 9 |
+
generator: Optional[Callable] = None
|
| 10 |
+
gen_kwargs: Optional[dict] = None
|
| 11 |
+
features: Optional[datasets.Features] = None
|
| 12 |
+
split: datasets.NamedSplit = datasets.Split.TRAIN
|
| 13 |
+
|
| 14 |
+
def __post_init__(self):
|
| 15 |
+
super().__post_init__()
|
| 16 |
+
if self.generator is None:
|
| 17 |
+
raise ValueError("generator must be specified")
|
| 18 |
+
|
| 19 |
+
if self.gen_kwargs is None:
|
| 20 |
+
self.gen_kwargs = {}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Generator(datasets.GeneratorBasedBuilder):
|
| 24 |
+
BUILDER_CONFIG_CLASS = GeneratorConfig
|
| 25 |
+
|
| 26 |
+
def _info(self):
|
| 27 |
+
return datasets.DatasetInfo(features=self.config.features)
|
| 28 |
+
|
| 29 |
+
def _split_generators(self, dl_manager):
|
| 30 |
+
return [datasets.SplitGenerator(name=self.config.split, gen_kwargs=self.config.gen_kwargs)]
|
| 31 |
+
|
| 32 |
+
def _generate_examples(self, **gen_kwargs):
|
| 33 |
+
yield from enumerate(self.config.generator(**gen_kwargs))
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/__pycache__/imagefolder.cpython-310.pyc
ADDED
|
Binary file (1.58 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/imagefolder/imagefolder.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
from ..folder_based_builder import folder_based_builder
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
logger = datasets.utils.logging.get_logger(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class ImageFolderConfig(folder_based_builder.FolderBasedBuilderConfig):
|
| 10 |
+
"""BuilderConfig for ImageFolder."""
|
| 11 |
+
|
| 12 |
+
drop_labels: bool = None
|
| 13 |
+
drop_metadata: bool = None
|
| 14 |
+
|
| 15 |
+
def __post_init__(self):
|
| 16 |
+
super().__post_init__()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class ImageFolder(folder_based_builder.FolderBasedBuilder):
|
| 20 |
+
BASE_FEATURE = datasets.Image
|
| 21 |
+
BASE_COLUMN_NAME = "image"
|
| 22 |
+
BUILDER_CONFIG_CLASS = ImageFolderConfig
|
| 23 |
+
EXTENSIONS: list[str] # definition at the bottom of the script
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Obtained with:
|
| 27 |
+
# ```
|
| 28 |
+
# import PIL.Image
|
| 29 |
+
# IMAGE_EXTENSIONS = []
|
| 30 |
+
# PIL.Image.init()
|
| 31 |
+
# for ext, format in PIL.Image.EXTENSION.items():
|
| 32 |
+
# if format in PIL.Image.OPEN:
|
| 33 |
+
# IMAGE_EXTENSIONS.append(ext[1:])
|
| 34 |
+
# ```
|
| 35 |
+
# We intentionally do not run this code on launch because:
|
| 36 |
+
# (1) Pillow is an optional dependency, so importing Pillow in global namespace is not allowed
|
| 37 |
+
# (2) To ensure the list of supported extensions is deterministic
|
| 38 |
+
IMAGE_EXTENSIONS = [
|
| 39 |
+
".blp",
|
| 40 |
+
".bmp",
|
| 41 |
+
".dib",
|
| 42 |
+
".bufr",
|
| 43 |
+
".cur",
|
| 44 |
+
".pcx",
|
| 45 |
+
".dcx",
|
| 46 |
+
".dds",
|
| 47 |
+
".ps",
|
| 48 |
+
".eps",
|
| 49 |
+
".fit",
|
| 50 |
+
".fits",
|
| 51 |
+
".fli",
|
| 52 |
+
".flc",
|
| 53 |
+
".ftc",
|
| 54 |
+
".ftu",
|
| 55 |
+
".gbr",
|
| 56 |
+
".gif",
|
| 57 |
+
".grib",
|
| 58 |
+
# ".h5", # may contain zero or several images
|
| 59 |
+
# ".hdf", # may contain zero or several images
|
| 60 |
+
".png",
|
| 61 |
+
".apng",
|
| 62 |
+
".jp2",
|
| 63 |
+
".j2k",
|
| 64 |
+
".jpc",
|
| 65 |
+
".jpf",
|
| 66 |
+
".jpx",
|
| 67 |
+
".j2c",
|
| 68 |
+
".icns",
|
| 69 |
+
".ico",
|
| 70 |
+
".im",
|
| 71 |
+
".iim",
|
| 72 |
+
".tif",
|
| 73 |
+
".tiff",
|
| 74 |
+
".jfif",
|
| 75 |
+
".jpe",
|
| 76 |
+
".jpg",
|
| 77 |
+
".jpeg",
|
| 78 |
+
".mpg",
|
| 79 |
+
".mpeg",
|
| 80 |
+
".msp",
|
| 81 |
+
".pcd",
|
| 82 |
+
".pxr",
|
| 83 |
+
".pbm",
|
| 84 |
+
".pgm",
|
| 85 |
+
".ppm",
|
| 86 |
+
".pnm",
|
| 87 |
+
".psd",
|
| 88 |
+
".bw",
|
| 89 |
+
".rgb",
|
| 90 |
+
".rgba",
|
| 91 |
+
".sgi",
|
| 92 |
+
".ras",
|
| 93 |
+
".tga",
|
| 94 |
+
".icb",
|
| 95 |
+
".vda",
|
| 96 |
+
".vst",
|
| 97 |
+
".webp",
|
| 98 |
+
".wmf",
|
| 99 |
+
".emf",
|
| 100 |
+
".xbm",
|
| 101 |
+
".xpm",
|
| 102 |
+
]
|
| 103 |
+
ImageFolder.EXTENSIONS = IMAGE_EXTENSIONS
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/json/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (204 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/json/__pycache__/json.cpython-310.pyc
ADDED
|
Binary file (5.89 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (206 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/__pycache__/pandas.cpython-310.pyc
ADDED
|
Binary file (2.92 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pandas/pandas.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
import warnings
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import pyarrow as pa
|
| 8 |
+
|
| 9 |
+
import datasets
|
| 10 |
+
from datasets.table import table_cast
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@dataclass
|
| 14 |
+
class PandasConfig(datasets.BuilderConfig):
|
| 15 |
+
"""BuilderConfig for Pandas."""
|
| 16 |
+
|
| 17 |
+
features: Optional[datasets.Features] = None
|
| 18 |
+
|
| 19 |
+
def __post_init__(self):
|
| 20 |
+
super().__post_init__()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Pandas(datasets.ArrowBasedBuilder):
|
| 24 |
+
BUILDER_CONFIG_CLASS = PandasConfig
|
| 25 |
+
|
| 26 |
+
def _info(self):
|
| 27 |
+
warnings.warn(
|
| 28 |
+
"The Pandas builder is deprecated and will be removed in the next major version of datasets.",
|
| 29 |
+
FutureWarning,
|
| 30 |
+
)
|
| 31 |
+
return datasets.DatasetInfo(features=self.config.features)
|
| 32 |
+
|
| 33 |
+
def _split_generators(self, dl_manager):
|
| 34 |
+
"""We handle string, list and dicts in datafiles"""
|
| 35 |
+
if not self.config.data_files:
|
| 36 |
+
raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}")
|
| 37 |
+
data_files = dl_manager.download_and_extract(self.config.data_files)
|
| 38 |
+
if isinstance(data_files, (str, list, tuple)):
|
| 39 |
+
files = data_files
|
| 40 |
+
if isinstance(files, str):
|
| 41 |
+
files = [files]
|
| 42 |
+
# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
|
| 43 |
+
files = [dl_manager.iter_files(file) for file in files]
|
| 44 |
+
return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": files})]
|
| 45 |
+
splits = []
|
| 46 |
+
for split_name, files in data_files.items():
|
| 47 |
+
if isinstance(files, str):
|
| 48 |
+
files = [files]
|
| 49 |
+
# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
|
| 50 |
+
files = [dl_manager.iter_files(file) for file in files]
|
| 51 |
+
splits.append(datasets.SplitGenerator(name=split_name, gen_kwargs={"files": files}))
|
| 52 |
+
return splits
|
| 53 |
+
|
| 54 |
+
def _cast_table(self, pa_table: pa.Table) -> pa.Table:
|
| 55 |
+
if self.config.features is not None:
|
| 56 |
+
# more expensive cast to support nested features with keys in a different order
|
| 57 |
+
# allows str <-> int/float or str to Audio for example
|
| 58 |
+
pa_table = table_cast(pa_table, self.config.features.arrow_schema)
|
| 59 |
+
return pa_table
|
| 60 |
+
|
| 61 |
+
def _generate_tables(self, files):
|
| 62 |
+
for i, file in enumerate(itertools.chain.from_iterable(files)):
|
| 63 |
+
with open(file, "rb") as f:
|
| 64 |
+
pa_table = pa.Table.from_pandas(pd.read_pickle(f))
|
| 65 |
+
yield i, self._cast_table(pa_table)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (207 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/__pycache__/parquet.cpython-310.pyc
ADDED
|
Binary file (4.51 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/parquet/parquet.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
from dataclasses import dataclass
|
| 3 |
+
from typing import Optional, Union
|
| 4 |
+
|
| 5 |
+
import pyarrow as pa
|
| 6 |
+
import pyarrow.dataset as ds
|
| 7 |
+
import pyarrow.parquet as pq
|
| 8 |
+
|
| 9 |
+
import datasets
|
| 10 |
+
from datasets.table import table_cast
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
logger = datasets.utils.logging.get_logger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class ParquetConfig(datasets.BuilderConfig):
|
| 18 |
+
"""BuilderConfig for Parquet."""
|
| 19 |
+
|
| 20 |
+
batch_size: Optional[int] = None
|
| 21 |
+
columns: Optional[list[str]] = None
|
| 22 |
+
features: Optional[datasets.Features] = None
|
| 23 |
+
filters: Optional[Union[ds.Expression, list[tuple], list[list[tuple]]]] = None
|
| 24 |
+
|
| 25 |
+
def __post_init__(self):
|
| 26 |
+
super().__post_init__()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class Parquet(datasets.ArrowBasedBuilder):
|
| 30 |
+
BUILDER_CONFIG_CLASS = ParquetConfig
|
| 31 |
+
|
| 32 |
+
def _info(self):
|
| 33 |
+
if (
|
| 34 |
+
self.config.columns is not None
|
| 35 |
+
and self.config.features is not None
|
| 36 |
+
and set(self.config.columns) != set(self.config.features)
|
| 37 |
+
):
|
| 38 |
+
raise ValueError(
|
| 39 |
+
"The columns and features argument must contain the same columns, but got ",
|
| 40 |
+
f"{self.config.columns} and {self.config.features}",
|
| 41 |
+
)
|
| 42 |
+
return datasets.DatasetInfo(features=self.config.features)
|
| 43 |
+
|
| 44 |
+
def _split_generators(self, dl_manager):
|
| 45 |
+
"""We handle string, list and dicts in datafiles"""
|
| 46 |
+
if not self.config.data_files:
|
| 47 |
+
raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}")
|
| 48 |
+
dl_manager.download_config.extract_on_the_fly = True
|
| 49 |
+
data_files = dl_manager.download_and_extract(self.config.data_files)
|
| 50 |
+
splits = []
|
| 51 |
+
for split_name, files in data_files.items():
|
| 52 |
+
if isinstance(files, str):
|
| 53 |
+
files = [files]
|
| 54 |
+
# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
|
| 55 |
+
files = [dl_manager.iter_files(file) for file in files]
|
| 56 |
+
# Infer features if they are stored in the arrow schema
|
| 57 |
+
if self.info.features is None:
|
| 58 |
+
for file in itertools.chain.from_iterable(files):
|
| 59 |
+
with open(file, "rb") as f:
|
| 60 |
+
self.info.features = datasets.Features.from_arrow_schema(pq.read_schema(f))
|
| 61 |
+
break
|
| 62 |
+
splits.append(datasets.SplitGenerator(name=split_name, gen_kwargs={"files": files}))
|
| 63 |
+
if self.config.columns is not None and set(self.config.columns) != set(self.info.features):
|
| 64 |
+
self.info.features = datasets.Features(
|
| 65 |
+
{col: feat for col, feat in self.info.features.items() if col in self.config.columns}
|
| 66 |
+
)
|
| 67 |
+
return splits
|
| 68 |
+
|
| 69 |
+
def _cast_table(self, pa_table: pa.Table) -> pa.Table:
|
| 70 |
+
if self.info.features is not None:
|
| 71 |
+
# more expensive cast to support nested features with keys in a different order
|
| 72 |
+
# allows str <-> int/float or str to Audio for example
|
| 73 |
+
pa_table = table_cast(pa_table, self.info.features.arrow_schema)
|
| 74 |
+
return pa_table
|
| 75 |
+
|
| 76 |
+
def _generate_tables(self, files):
|
| 77 |
+
if self.config.features is not None and self.config.columns is not None:
|
| 78 |
+
if sorted(field.name for field in self.info.features.arrow_schema) != sorted(self.config.columns):
|
| 79 |
+
raise ValueError(
|
| 80 |
+
f"Tried to load parquet data with columns '{self.config.columns}' with mismatching features '{self.info.features}'"
|
| 81 |
+
)
|
| 82 |
+
filter_expr = (
|
| 83 |
+
pq.filters_to_expression(self.config.filters)
|
| 84 |
+
if isinstance(self.config.filters, list)
|
| 85 |
+
else self.config.filters
|
| 86 |
+
)
|
| 87 |
+
for file_idx, file in enumerate(itertools.chain.from_iterable(files)):
|
| 88 |
+
with open(file, "rb") as f:
|
| 89 |
+
parquet_fragment = ds.ParquetFileFormat().make_fragment(f)
|
| 90 |
+
if parquet_fragment.row_groups:
|
| 91 |
+
batch_size = self.config.batch_size or parquet_fragment.row_groups[0].num_rows
|
| 92 |
+
try:
|
| 93 |
+
for batch_idx, record_batch in enumerate(
|
| 94 |
+
parquet_fragment.to_batches(
|
| 95 |
+
batch_size=batch_size,
|
| 96 |
+
columns=self.config.columns,
|
| 97 |
+
filter=filter_expr,
|
| 98 |
+
batch_readahead=0,
|
| 99 |
+
fragment_readahead=0,
|
| 100 |
+
)
|
| 101 |
+
):
|
| 102 |
+
pa_table = pa.Table.from_batches([record_batch])
|
| 103 |
+
# Uncomment for debugging (will print the Arrow table size and elements)
|
| 104 |
+
# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
|
| 105 |
+
# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
|
| 106 |
+
yield f"{file_idx}_{batch_idx}", self._cast_table(pa_table)
|
| 107 |
+
except ValueError as e:
|
| 108 |
+
logger.error(f"Failed to read file '{file}' with error {type(e)}: {e}")
|
| 109 |
+
raise
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pdffolder/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (209 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/pdffolder/__pycache__/pdffolder.cpython-310.pyc
ADDED
|
Binary file (1.17 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/spark/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (205 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/spark/__pycache__/spark.cpython-310.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/sql/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (203 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/sql/__pycache__/sql.cpython-310.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (204 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/__pycache__/text.cpython-310.pyc
ADDED
|
Binary file (4.21 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/text/text.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
from dataclasses import dataclass
|
| 3 |
+
from io import StringIO
|
| 4 |
+
from typing import Optional
|
| 5 |
+
|
| 6 |
+
import pyarrow as pa
|
| 7 |
+
|
| 8 |
+
import datasets
|
| 9 |
+
from datasets.features.features import require_storage_cast
|
| 10 |
+
from datasets.table import table_cast
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
logger = datasets.utils.logging.get_logger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@dataclass
|
| 17 |
+
class TextConfig(datasets.BuilderConfig):
|
| 18 |
+
"""BuilderConfig for text files."""
|
| 19 |
+
|
| 20 |
+
features: Optional[datasets.Features] = None
|
| 21 |
+
encoding: str = "utf-8"
|
| 22 |
+
encoding_errors: Optional[str] = None
|
| 23 |
+
chunksize: int = 10 << 20 # 10MB
|
| 24 |
+
keep_linebreaks: bool = False
|
| 25 |
+
sample_by: str = "line"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Text(datasets.ArrowBasedBuilder):
|
| 29 |
+
BUILDER_CONFIG_CLASS = TextConfig
|
| 30 |
+
|
| 31 |
+
def _info(self):
|
| 32 |
+
return datasets.DatasetInfo(features=self.config.features)
|
| 33 |
+
|
| 34 |
+
def _split_generators(self, dl_manager):
|
| 35 |
+
"""The `data_files` kwarg in load_dataset() can be a str, List[str], Dict[str,str], or Dict[str,List[str]].
|
| 36 |
+
|
| 37 |
+
If str or List[str], then the dataset returns only the 'train' split.
|
| 38 |
+
If dict, then keys should be from the `datasets.Split` enum.
|
| 39 |
+
"""
|
| 40 |
+
if not self.config.data_files:
|
| 41 |
+
raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}")
|
| 42 |
+
dl_manager.download_config.extract_on_the_fly = True
|
| 43 |
+
data_files = dl_manager.download_and_extract(self.config.data_files)
|
| 44 |
+
splits = []
|
| 45 |
+
for split_name, files in data_files.items():
|
| 46 |
+
if isinstance(files, str):
|
| 47 |
+
files = [files]
|
| 48 |
+
files = [dl_manager.iter_files(file) for file in files]
|
| 49 |
+
splits.append(datasets.SplitGenerator(name=split_name, gen_kwargs={"files": files}))
|
| 50 |
+
return splits
|
| 51 |
+
|
| 52 |
+
def _cast_table(self, pa_table: pa.Table) -> pa.Table:
|
| 53 |
+
if self.config.features is not None:
|
| 54 |
+
schema = self.config.features.arrow_schema
|
| 55 |
+
if all(not require_storage_cast(feature) for feature in self.config.features.values()):
|
| 56 |
+
# cheaper cast
|
| 57 |
+
pa_table = pa_table.cast(schema)
|
| 58 |
+
else:
|
| 59 |
+
# more expensive cast; allows str <-> int/float or str to Audio for example
|
| 60 |
+
pa_table = table_cast(pa_table, schema)
|
| 61 |
+
return pa_table
|
| 62 |
+
else:
|
| 63 |
+
return pa_table.cast(pa.schema({"text": pa.string()}))
|
| 64 |
+
|
| 65 |
+
def _generate_tables(self, files):
|
| 66 |
+
pa_table_names = list(self.config.features) if self.config.features is not None else ["text"]
|
| 67 |
+
for file_idx, file in enumerate(itertools.chain.from_iterable(files)):
|
| 68 |
+
# open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
|
| 69 |
+
with open(file, encoding=self.config.encoding, errors=self.config.encoding_errors) as f:
|
| 70 |
+
if self.config.sample_by == "line":
|
| 71 |
+
batch_idx = 0
|
| 72 |
+
while True:
|
| 73 |
+
batch = f.read(self.config.chunksize)
|
| 74 |
+
if not batch:
|
| 75 |
+
break
|
| 76 |
+
batch += f.readline() # finish current line
|
| 77 |
+
# StringIO.readlines, by default splits only on "\n" (and keeps line breaks)
|
| 78 |
+
batch = StringIO(batch).readlines()
|
| 79 |
+
if not self.config.keep_linebreaks:
|
| 80 |
+
batch = [line.rstrip("\n") for line in batch]
|
| 81 |
+
pa_table = pa.Table.from_arrays([pa.array(batch)], names=pa_table_names)
|
| 82 |
+
# Uncomment for debugging (will print the Arrow table size and elements)
|
| 83 |
+
# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
|
| 84 |
+
# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
|
| 85 |
+
yield (file_idx, batch_idx), self._cast_table(pa_table)
|
| 86 |
+
batch_idx += 1
|
| 87 |
+
elif self.config.sample_by == "paragraph":
|
| 88 |
+
batch_idx = 0
|
| 89 |
+
batch = ""
|
| 90 |
+
while True:
|
| 91 |
+
new_batch = f.read(self.config.chunksize)
|
| 92 |
+
if not new_batch:
|
| 93 |
+
break
|
| 94 |
+
batch += new_batch
|
| 95 |
+
batch += f.readline() # finish current line
|
| 96 |
+
batch = batch.split("\n\n")
|
| 97 |
+
pa_table = pa.Table.from_arrays(
|
| 98 |
+
[pa.array([example for example in batch[:-1] if example])], names=pa_table_names
|
| 99 |
+
)
|
| 100 |
+
# Uncomment for debugging (will print the Arrow table size and elements)
|
| 101 |
+
# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
|
| 102 |
+
# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
|
| 103 |
+
yield (file_idx, batch_idx), self._cast_table(pa_table)
|
| 104 |
+
batch_idx += 1
|
| 105 |
+
batch = batch[-1]
|
| 106 |
+
if batch:
|
| 107 |
+
pa_table = pa.Table.from_arrays([pa.array([batch])], names=pa_table_names)
|
| 108 |
+
yield (file_idx, batch_idx), self._cast_table(pa_table)
|
| 109 |
+
elif self.config.sample_by == "document":
|
| 110 |
+
text = f.read()
|
| 111 |
+
pa_table = pa.Table.from_arrays([pa.array([text])], names=pa_table_names)
|
| 112 |
+
yield file_idx, self._cast_table(pa_table)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/videofolder/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (211 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/videofolder/__pycache__/videofolder.cpython-310.pyc
ADDED
|
Binary file (1.24 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (210 Bytes). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__pycache__/_tenbin.cpython-310.pyc
ADDED
|
Binary file (8.85 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/__pycache__/webdataset.cpython-310.pyc
ADDED
|
Binary file (7.24 kB). View file
|
|
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/_tenbin.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# Copyright (c) 2017-2021 NVIDIA CORPORATION. All rights reserved.
|
| 3 |
+
# This file coems from the WebDataset library.
|
| 4 |
+
# See the LICENSE file for licensing terms (BSD-style).
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
Binary tensor encodings for PyTorch and NumPy.
|
| 9 |
+
|
| 10 |
+
This defines efficient binary encodings for tensors. The format is 8 byte
|
| 11 |
+
aligned and can be used directly for computations when transmitted, say,
|
| 12 |
+
via RDMA. The format is supported by WebDataset with the `.ten` filename
|
| 13 |
+
extension. It is also used by Tensorcom, Tensorcom RDMA, and can be used
|
| 14 |
+
for fast tensor storage with LMDB and in disk files (which can be memory
|
| 15 |
+
mapped)
|
| 16 |
+
|
| 17 |
+
Data is encoded as a series of chunks:
|
| 18 |
+
|
| 19 |
+
- magic number (int64)
|
| 20 |
+
- length in bytes (int64)
|
| 21 |
+
- bytes (multiple of 64 bytes long)
|
| 22 |
+
|
| 23 |
+
Arrays are a header chunk followed by a data chunk.
|
| 24 |
+
Header chunks have the following structure:
|
| 25 |
+
|
| 26 |
+
- dtype (int64)
|
| 27 |
+
- 8 byte array name
|
| 28 |
+
- ndim (int64)
|
| 29 |
+
- dim[0]
|
| 30 |
+
- dim[1]
|
| 31 |
+
- ...
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
import struct
|
| 35 |
+
import sys
|
| 36 |
+
|
| 37 |
+
import numpy as np
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def bytelen(a):
|
| 41 |
+
"""Determine the length of a in bytes."""
|
| 42 |
+
if hasattr(a, "nbytes"):
|
| 43 |
+
return a.nbytes
|
| 44 |
+
elif isinstance(a, (bytearray, bytes)):
|
| 45 |
+
return len(a)
|
| 46 |
+
else:
|
| 47 |
+
raise ValueError(a, "cannot determine nbytes")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def bytedata(a):
|
| 51 |
+
"""Return a the raw data corresponding to a."""
|
| 52 |
+
if isinstance(a, (bytearray, bytes, memoryview)):
|
| 53 |
+
return a
|
| 54 |
+
elif hasattr(a, "data"):
|
| 55 |
+
return a.data
|
| 56 |
+
else:
|
| 57 |
+
raise ValueError(a, "cannot return bytedata")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# tables for converting between long/short NumPy dtypes
|
| 61 |
+
|
| 62 |
+
long_to_short = """
|
| 63 |
+
float16 f2
|
| 64 |
+
float32 f4
|
| 65 |
+
float64 f8
|
| 66 |
+
int8 i1
|
| 67 |
+
int16 i2
|
| 68 |
+
int32 i4
|
| 69 |
+
int64 i8
|
| 70 |
+
uint8 u1
|
| 71 |
+
uint16 u2
|
| 72 |
+
unit32 u4
|
| 73 |
+
uint64 u8
|
| 74 |
+
""".strip()
|
| 75 |
+
long_to_short = [x.split() for x in long_to_short.split("\n")]
|
| 76 |
+
long_to_short = {x[0]: x[1] for x in long_to_short}
|
| 77 |
+
short_to_long = {v: k for k, v in long_to_short.items()}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def check_acceptable_input_type(data, allow64):
|
| 81 |
+
"""Check that the data has an acceptable type for tensor encoding.
|
| 82 |
+
|
| 83 |
+
:param data: array
|
| 84 |
+
:param allow64: allow 64 bit types
|
| 85 |
+
"""
|
| 86 |
+
for a in data:
|
| 87 |
+
if a.dtype.name not in long_to_short:
|
| 88 |
+
raise ValueError("unsupported dataypte")
|
| 89 |
+
if not allow64 and a.dtype.name not in ["float64", "int64", "uint64"]:
|
| 90 |
+
raise ValueError("64 bit datatypes not allowed unless explicitly enabled")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def str64(s):
|
| 94 |
+
"""Convert a string to an int64."""
|
| 95 |
+
s = s + "\0" * (8 - len(s))
|
| 96 |
+
s = s.encode("ascii")
|
| 97 |
+
return struct.unpack("@q", s)[0]
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def unstr64(i):
|
| 101 |
+
"""Convert an int64 to a string."""
|
| 102 |
+
b = struct.pack("@q", i)
|
| 103 |
+
return b.decode("ascii").strip("\0")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def check_infos(data, infos, required_infos=None):
|
| 107 |
+
"""Verify the info strings."""
|
| 108 |
+
if required_infos is False or required_infos is None:
|
| 109 |
+
return data
|
| 110 |
+
if required_infos is True:
|
| 111 |
+
return data, infos
|
| 112 |
+
if not isinstance(required_infos, (tuple, list)):
|
| 113 |
+
raise ValueError("required_infos must be tuple or list")
|
| 114 |
+
for required, actual in zip(required_infos, infos):
|
| 115 |
+
raise ValueError(f"actual info {actual} doesn't match required info {required}")
|
| 116 |
+
return data
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def encode_header(a, info=""):
|
| 120 |
+
"""Encode an array header as a byte array."""
|
| 121 |
+
if a.ndim >= 10:
|
| 122 |
+
raise ValueError("too many dimensions")
|
| 123 |
+
if a.nbytes != np.prod(a.shape) * a.itemsize:
|
| 124 |
+
raise ValueError("mismatch between size and shape")
|
| 125 |
+
if a.dtype.name not in long_to_short:
|
| 126 |
+
raise ValueError("unsupported array type")
|
| 127 |
+
header = [str64(long_to_short[a.dtype.name]), str64(info), len(a.shape)] + list(a.shape)
|
| 128 |
+
return bytedata(np.array(header, dtype="i8"))
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def decode_header(h):
|
| 132 |
+
"""Decode a byte array into an array header."""
|
| 133 |
+
h = np.frombuffer(h, dtype="i8")
|
| 134 |
+
if unstr64(h[0]) not in short_to_long:
|
| 135 |
+
raise ValueError("unsupported array type")
|
| 136 |
+
dtype = np.dtype(short_to_long[unstr64(h[0])])
|
| 137 |
+
info = unstr64(h[1])
|
| 138 |
+
rank = int(h[2])
|
| 139 |
+
shape = tuple(h[3 : 3 + rank])
|
| 140 |
+
return shape, dtype, info
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def encode_list(l, infos=None): # noqa: E741
|
| 144 |
+
"""Given a list of arrays, encode them into a list of byte arrays."""
|
| 145 |
+
if infos is None:
|
| 146 |
+
infos = [""]
|
| 147 |
+
else:
|
| 148 |
+
if len(l) != len(infos):
|
| 149 |
+
raise ValueError(f"length of list {l} must muatch length of infos {infos}")
|
| 150 |
+
result = []
|
| 151 |
+
for i, a in enumerate(l):
|
| 152 |
+
header = encode_header(a, infos[i % len(infos)])
|
| 153 |
+
result += [header, bytedata(a)]
|
| 154 |
+
return result
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def decode_list(l, infos=False): # noqa: E741
|
| 158 |
+
"""Given a list of byte arrays, decode them into arrays."""
|
| 159 |
+
result = []
|
| 160 |
+
infos0 = []
|
| 161 |
+
for header, data in zip(l[::2], l[1::2]):
|
| 162 |
+
shape, dtype, info = decode_header(header)
|
| 163 |
+
a = np.frombuffer(data, dtype=dtype, count=np.prod(shape)).reshape(*shape)
|
| 164 |
+
result += [a]
|
| 165 |
+
infos0 += [info]
|
| 166 |
+
return check_infos(result, infos0, infos)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
magic_str = "~TenBin~"
|
| 170 |
+
magic = str64(magic_str)
|
| 171 |
+
magic_bytes = unstr64(magic).encode("ascii")
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def roundup(n, k=64):
|
| 175 |
+
"""Round up to the next multiple of 64."""
|
| 176 |
+
return k * ((n + k - 1) // k)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def encode_chunks(l): # noqa: E741
|
| 180 |
+
"""Encode a list of chunks into a single byte array, with lengths and magics.."""
|
| 181 |
+
size = sum(16 + roundup(b.nbytes) for b in l)
|
| 182 |
+
result = bytearray(size)
|
| 183 |
+
offset = 0
|
| 184 |
+
for b in l:
|
| 185 |
+
result[offset : offset + 8] = magic_bytes
|
| 186 |
+
offset += 8
|
| 187 |
+
result[offset : offset + 8] = struct.pack("@q", b.nbytes)
|
| 188 |
+
offset += 8
|
| 189 |
+
result[offset : offset + bytelen(b)] = b
|
| 190 |
+
offset += roundup(bytelen(b))
|
| 191 |
+
return result
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def decode_chunks(buf):
|
| 195 |
+
"""Decode a byte array into a list of chunks."""
|
| 196 |
+
result = []
|
| 197 |
+
offset = 0
|
| 198 |
+
total = bytelen(buf)
|
| 199 |
+
while offset < total:
|
| 200 |
+
if magic_bytes != buf[offset : offset + 8]:
|
| 201 |
+
raise ValueError("magic bytes mismatch")
|
| 202 |
+
offset += 8
|
| 203 |
+
nbytes = struct.unpack("@q", buf[offset : offset + 8])[0]
|
| 204 |
+
offset += 8
|
| 205 |
+
b = buf[offset : offset + nbytes]
|
| 206 |
+
offset += roundup(nbytes)
|
| 207 |
+
result.append(b)
|
| 208 |
+
return result
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def encode_buffer(l, infos=None): # noqa: E741
|
| 212 |
+
"""Encode a list of arrays into a single byte array."""
|
| 213 |
+
if not isinstance(l, list):
|
| 214 |
+
raise ValueError("requires list")
|
| 215 |
+
return encode_chunks(encode_list(l, infos=infos))
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def decode_buffer(buf, infos=False):
|
| 219 |
+
"""Decode a byte array into a list of arrays."""
|
| 220 |
+
return decode_list(decode_chunks(buf), infos=infos)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def write_chunk(stream, buf):
|
| 224 |
+
"""Write a byte chunk to the stream with magics, length, and padding."""
|
| 225 |
+
nbytes = bytelen(buf)
|
| 226 |
+
stream.write(magic_bytes)
|
| 227 |
+
stream.write(struct.pack("@q", nbytes))
|
| 228 |
+
stream.write(bytedata(buf))
|
| 229 |
+
padding = roundup(nbytes) - nbytes
|
| 230 |
+
if padding > 0:
|
| 231 |
+
stream.write(b"\0" * padding)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def read_chunk(stream):
|
| 235 |
+
"""Read a byte chunk from a stream with magics, length, and padding."""
|
| 236 |
+
magic = stream.read(8)
|
| 237 |
+
if magic == b"":
|
| 238 |
+
return None
|
| 239 |
+
if magic != magic_bytes:
|
| 240 |
+
raise ValueError("magic number does not match")
|
| 241 |
+
nbytes = stream.read(8)
|
| 242 |
+
nbytes = struct.unpack("@q", nbytes)[0]
|
| 243 |
+
if nbytes < 0:
|
| 244 |
+
raise ValueError("negative nbytes")
|
| 245 |
+
data = stream.read(nbytes)
|
| 246 |
+
padding = roundup(nbytes) - nbytes
|
| 247 |
+
if padding > 0:
|
| 248 |
+
stream.read(padding)
|
| 249 |
+
return data
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def write(stream, l, infos=None): # noqa: E741
|
| 253 |
+
"""Write a list of arrays to a stream, with magics, length, and padding."""
|
| 254 |
+
for chunk in encode_list(l, infos=infos):
|
| 255 |
+
write_chunk(stream, chunk)
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def read(stream, n=sys.maxsize, infos=False):
|
| 259 |
+
"""Read a list of arrays from a stream, with magics, length, and padding."""
|
| 260 |
+
chunks = []
|
| 261 |
+
for _ in range(n):
|
| 262 |
+
header = read_chunk(stream)
|
| 263 |
+
if header is None:
|
| 264 |
+
break
|
| 265 |
+
data = read_chunk(stream)
|
| 266 |
+
if data is None:
|
| 267 |
+
raise ValueError("premature EOF")
|
| 268 |
+
chunks += [header, data]
|
| 269 |
+
return decode_list(chunks, infos=infos)
|
| 270 |
+
|
| 271 |
+
|
| 272 |
+
def save(fname, *args, infos=None, nocheck=False):
|
| 273 |
+
"""Save a list of arrays to a file, with magics, length, and padding."""
|
| 274 |
+
if not nocheck and not fname.endswith(".ten"):
|
| 275 |
+
raise ValueError("file name should end in .ten")
|
| 276 |
+
with open(fname, "wb") as stream:
|
| 277 |
+
write(stream, args, infos=infos)
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
def load(fname, infos=False, nocheck=False):
|
| 281 |
+
"""Read a list of arrays from a file, with magics, length, and padding."""
|
| 282 |
+
if not nocheck and not fname.endswith(".ten"):
|
| 283 |
+
raise ValueError("file name should end in .ten")
|
| 284 |
+
with open(fname, "rb") as stream:
|
| 285 |
+
return read(stream, infos=infos)
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/webdataset/webdataset.py
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
from itertools import islice
|
| 5 |
+
from typing import Any, Callable
|
| 6 |
+
|
| 7 |
+
import fsspec
|
| 8 |
+
import numpy as np
|
| 9 |
+
import pyarrow as pa
|
| 10 |
+
|
| 11 |
+
import datasets
|
| 12 |
+
from datasets.features.features import cast_to_python_objects
|
| 13 |
+
from datasets.utils.file_utils import SINGLE_FILE_COMPRESSION_EXTENSION_TO_PROTOCOL, xbasename
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
logger = datasets.utils.logging.get_logger(__name__)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class WebDataset(datasets.GeneratorBasedBuilder):
|
| 20 |
+
DEFAULT_WRITER_BATCH_SIZE = 100
|
| 21 |
+
IMAGE_EXTENSIONS: list[str] # definition at the bottom of the script
|
| 22 |
+
AUDIO_EXTENSIONS: list[str] # definition at the bottom of the script
|
| 23 |
+
VIDEO_EXTENSIONS: list[str] # definition at the bottom of the script
|
| 24 |
+
DECODERS: dict[str, Callable[[Any], Any]] # definition at the bottom of the script
|
| 25 |
+
NUM_EXAMPLES_FOR_FEATURES_INFERENCE = 5
|
| 26 |
+
|
| 27 |
+
@classmethod
|
| 28 |
+
def _get_pipeline_from_tar(cls, tar_path, tar_iterator):
|
| 29 |
+
current_example = {}
|
| 30 |
+
fs: fsspec.AbstractFileSystem = fsspec.filesystem("memory")
|
| 31 |
+
streaming_download_manager = datasets.StreamingDownloadManager()
|
| 32 |
+
for filename, f in tar_iterator:
|
| 33 |
+
example_key, field_name = base_plus_ext(filename)
|
| 34 |
+
if example_key is None:
|
| 35 |
+
continue
|
| 36 |
+
if current_example and current_example["__key__"] != example_key:
|
| 37 |
+
# reposition some keys in last position
|
| 38 |
+
current_example["__key__"] = current_example.pop("__key__")
|
| 39 |
+
current_example["__url__"] = current_example.pop("__url__")
|
| 40 |
+
yield current_example
|
| 41 |
+
current_example = {}
|
| 42 |
+
current_example["__key__"] = example_key
|
| 43 |
+
current_example["__url__"] = tar_path
|
| 44 |
+
current_example[field_name.lower()] = f.read()
|
| 45 |
+
if field_name.split(".")[-1] in SINGLE_FILE_COMPRESSION_EXTENSION_TO_PROTOCOL:
|
| 46 |
+
fs.write_bytes(filename, current_example[field_name.lower()])
|
| 47 |
+
extracted_file_path = streaming_download_manager.extract(f"memory://{filename}")
|
| 48 |
+
with fsspec.open(extracted_file_path) as f:
|
| 49 |
+
current_example[field_name.lower()] = f.read()
|
| 50 |
+
fs.delete(filename)
|
| 51 |
+
data_extension = xbasename(extracted_file_path).split(".")[-1]
|
| 52 |
+
else:
|
| 53 |
+
data_extension = field_name.split(".")[-1]
|
| 54 |
+
if data_extension in cls.DECODERS:
|
| 55 |
+
current_example[field_name] = cls.DECODERS[data_extension](current_example[field_name])
|
| 56 |
+
if current_example:
|
| 57 |
+
yield current_example
|
| 58 |
+
|
| 59 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 60 |
+
return datasets.DatasetInfo()
|
| 61 |
+
|
| 62 |
+
def _split_generators(self, dl_manager):
|
| 63 |
+
"""We handle string, list and dicts in datafiles"""
|
| 64 |
+
# Download the data files
|
| 65 |
+
if not self.config.data_files:
|
| 66 |
+
raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}")
|
| 67 |
+
data_files = dl_manager.download(self.config.data_files)
|
| 68 |
+
splits = []
|
| 69 |
+
for split_name, tar_paths in data_files.items():
|
| 70 |
+
if isinstance(tar_paths, str):
|
| 71 |
+
tar_paths = [tar_paths]
|
| 72 |
+
tar_iterators = [dl_manager.iter_archive(tar_path) for tar_path in tar_paths]
|
| 73 |
+
splits.append(
|
| 74 |
+
datasets.SplitGenerator(
|
| 75 |
+
name=split_name, gen_kwargs={"tar_paths": tar_paths, "tar_iterators": tar_iterators}
|
| 76 |
+
)
|
| 77 |
+
)
|
| 78 |
+
if not self.info.features:
|
| 79 |
+
# Get one example to get the feature types
|
| 80 |
+
pipeline = self._get_pipeline_from_tar(tar_paths[0], tar_iterators[0])
|
| 81 |
+
first_examples = list(islice(pipeline, self.NUM_EXAMPLES_FOR_FEATURES_INFERENCE))
|
| 82 |
+
if any(example.keys() != first_examples[0].keys() for example in first_examples):
|
| 83 |
+
raise ValueError(
|
| 84 |
+
"The TAR archives of the dataset should be in WebDataset format, "
|
| 85 |
+
"but the files in the archive don't share the same prefix or the same types."
|
| 86 |
+
)
|
| 87 |
+
pa_tables = [
|
| 88 |
+
pa.Table.from_pylist(cast_to_python_objects([example], only_1d_for_numpy=True))
|
| 89 |
+
for example in first_examples
|
| 90 |
+
]
|
| 91 |
+
inferred_arrow_schema = pa.concat_tables(pa_tables, promote_options="default").schema
|
| 92 |
+
features = datasets.Features.from_arrow_schema(inferred_arrow_schema)
|
| 93 |
+
|
| 94 |
+
# Set Image types
|
| 95 |
+
for field_name in first_examples[0]:
|
| 96 |
+
extension = field_name.rsplit(".", 1)[-1]
|
| 97 |
+
if extension in self.IMAGE_EXTENSIONS:
|
| 98 |
+
features[field_name] = datasets.Image()
|
| 99 |
+
# Set Audio types
|
| 100 |
+
for field_name in first_examples[0]:
|
| 101 |
+
extension = field_name.rsplit(".", 1)[-1]
|
| 102 |
+
if extension in self.AUDIO_EXTENSIONS:
|
| 103 |
+
features[field_name] = datasets.Audio()
|
| 104 |
+
# Set Video types
|
| 105 |
+
for field_name in first_examples[0]:
|
| 106 |
+
extension = field_name.rsplit(".", 1)[-1]
|
| 107 |
+
if extension in self.VIDEO_EXTENSIONS:
|
| 108 |
+
features[field_name] = datasets.Video()
|
| 109 |
+
self.info.features = features
|
| 110 |
+
|
| 111 |
+
return splits
|
| 112 |
+
|
| 113 |
+
def _generate_examples(self, tar_paths, tar_iterators):
|
| 114 |
+
image_field_names = [
|
| 115 |
+
field_name for field_name, feature in self.info.features.items() if isinstance(feature, datasets.Image)
|
| 116 |
+
]
|
| 117 |
+
audio_field_names = [
|
| 118 |
+
field_name for field_name, feature in self.info.features.items() if isinstance(feature, datasets.Audio)
|
| 119 |
+
]
|
| 120 |
+
all_field_names = list(self.info.features.keys())
|
| 121 |
+
for tar_idx, (tar_path, tar_iterator) in enumerate(zip(tar_paths, tar_iterators)):
|
| 122 |
+
for example_idx, example in enumerate(self._get_pipeline_from_tar(tar_path, tar_iterator)):
|
| 123 |
+
for field_name in all_field_names:
|
| 124 |
+
if field_name not in example:
|
| 125 |
+
example[field_name] = None
|
| 126 |
+
for field_name in image_field_names + audio_field_names:
|
| 127 |
+
if example[field_name] is not None:
|
| 128 |
+
example[field_name] = {
|
| 129 |
+
"path": example["__key__"] + "." + field_name,
|
| 130 |
+
"bytes": example[field_name],
|
| 131 |
+
}
|
| 132 |
+
yield f"{tar_idx}_{example_idx}", example
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# Source: https://github.com/webdataset/webdataset/blob/87bd5aa41602d57f070f65a670893ee625702f2f/webdataset/tariterators.py#L25
|
| 136 |
+
def base_plus_ext(path):
|
| 137 |
+
"""Split off all file extensions.
|
| 138 |
+
|
| 139 |
+
Returns base, allext.
|
| 140 |
+
"""
|
| 141 |
+
match = re.match(r"^((?:.*/|)[^.]+)[.]([^/]*)$", path)
|
| 142 |
+
if not match:
|
| 143 |
+
return None, None
|
| 144 |
+
return match.group(1), match.group(2)
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
# Obtained with:
|
| 148 |
+
# ```
|
| 149 |
+
# import PIL.Image
|
| 150 |
+
# IMAGE_EXTENSIONS = []
|
| 151 |
+
# PIL.Image.init()
|
| 152 |
+
# for ext, format in PIL.Image.EXTENSION.items():
|
| 153 |
+
# if format in PIL.Image.OPEN:
|
| 154 |
+
# IMAGE_EXTENSIONS.append(ext[1:])
|
| 155 |
+
# ```
|
| 156 |
+
# We intentionally do not run this code on launch because:
|
| 157 |
+
# (1) Pillow is an optional dependency, so importing Pillow in global namespace is not allowed
|
| 158 |
+
# (2) To ensure the list of supported extensions is deterministic
|
| 159 |
+
IMAGE_EXTENSIONS = [
|
| 160 |
+
"blp",
|
| 161 |
+
"bmp",
|
| 162 |
+
"dib",
|
| 163 |
+
"bufr",
|
| 164 |
+
"cur",
|
| 165 |
+
"pcx",
|
| 166 |
+
"dcx",
|
| 167 |
+
"dds",
|
| 168 |
+
"ps",
|
| 169 |
+
"eps",
|
| 170 |
+
"fit",
|
| 171 |
+
"fits",
|
| 172 |
+
"fli",
|
| 173 |
+
"flc",
|
| 174 |
+
"ftc",
|
| 175 |
+
"ftu",
|
| 176 |
+
"gbr",
|
| 177 |
+
"gif",
|
| 178 |
+
"grib",
|
| 179 |
+
"h5",
|
| 180 |
+
"hdf",
|
| 181 |
+
"png",
|
| 182 |
+
"apng",
|
| 183 |
+
"jp2",
|
| 184 |
+
"j2k",
|
| 185 |
+
"jpc",
|
| 186 |
+
"jpf",
|
| 187 |
+
"jpx",
|
| 188 |
+
"j2c",
|
| 189 |
+
"icns",
|
| 190 |
+
"ico",
|
| 191 |
+
"im",
|
| 192 |
+
"iim",
|
| 193 |
+
"tif",
|
| 194 |
+
"tiff",
|
| 195 |
+
"jfif",
|
| 196 |
+
"jpe",
|
| 197 |
+
"jpg",
|
| 198 |
+
"jpeg",
|
| 199 |
+
"mpg",
|
| 200 |
+
"mpeg",
|
| 201 |
+
"msp",
|
| 202 |
+
"pcd",
|
| 203 |
+
"pxr",
|
| 204 |
+
"pbm",
|
| 205 |
+
"pgm",
|
| 206 |
+
"ppm",
|
| 207 |
+
"pnm",
|
| 208 |
+
"psd",
|
| 209 |
+
"bw",
|
| 210 |
+
"rgb",
|
| 211 |
+
"rgba",
|
| 212 |
+
"sgi",
|
| 213 |
+
"ras",
|
| 214 |
+
"tga",
|
| 215 |
+
"icb",
|
| 216 |
+
"vda",
|
| 217 |
+
"vst",
|
| 218 |
+
"webp",
|
| 219 |
+
"wmf",
|
| 220 |
+
"emf",
|
| 221 |
+
"xbm",
|
| 222 |
+
"xpm",
|
| 223 |
+
]
|
| 224 |
+
WebDataset.IMAGE_EXTENSIONS = IMAGE_EXTENSIONS
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
# Obtained with:
|
| 228 |
+
# ```
|
| 229 |
+
# import soundfile as sf
|
| 230 |
+
#
|
| 231 |
+
# AUDIO_EXTENSIONS = [f".{format.lower()}" for format in sf.available_formats().keys()]
|
| 232 |
+
#
|
| 233 |
+
# # .opus decoding is supported if libsndfile >= 1.0.31:
|
| 234 |
+
# AUDIO_EXTENSIONS.extend([".mp3", ".opus"])
|
| 235 |
+
# ```
|
| 236 |
+
# We intentionally do not run this code on launch because:
|
| 237 |
+
# (1) Soundfile is an optional dependency, so importing it in global namespace is not allowed
|
| 238 |
+
# (2) To ensure the list of supported extensions is deterministic
|
| 239 |
+
AUDIO_EXTENSIONS = [
|
| 240 |
+
"aiff",
|
| 241 |
+
"au",
|
| 242 |
+
"avr",
|
| 243 |
+
"caf",
|
| 244 |
+
"flac",
|
| 245 |
+
"htk",
|
| 246 |
+
"svx",
|
| 247 |
+
"mat4",
|
| 248 |
+
"mat5",
|
| 249 |
+
"mpc2k",
|
| 250 |
+
"ogg",
|
| 251 |
+
"paf",
|
| 252 |
+
"pvf",
|
| 253 |
+
"raw",
|
| 254 |
+
"rf64",
|
| 255 |
+
"sd2",
|
| 256 |
+
"sds",
|
| 257 |
+
"ircam",
|
| 258 |
+
"voc",
|
| 259 |
+
"w64",
|
| 260 |
+
"wav",
|
| 261 |
+
"nist",
|
| 262 |
+
"wavex",
|
| 263 |
+
"wve",
|
| 264 |
+
"xi",
|
| 265 |
+
"mp3",
|
| 266 |
+
"opus",
|
| 267 |
+
]
|
| 268 |
+
WebDataset.AUDIO_EXTENSIONS = AUDIO_EXTENSIONS
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
# TODO: initial list, we should check the compatibility of other formats
|
| 272 |
+
VIDEO_EXTENSIONS = [
|
| 273 |
+
".mkv",
|
| 274 |
+
".mp4",
|
| 275 |
+
".avi",
|
| 276 |
+
".mpeg",
|
| 277 |
+
".mov",
|
| 278 |
+
]
|
| 279 |
+
WebDataset.VIDEO_EXTENSIONS = VIDEO_EXTENSIONS
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def text_loads(data: bytes):
|
| 283 |
+
return data.decode("utf-8")
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def tenbin_loads(data: bytes):
|
| 287 |
+
from . import _tenbin
|
| 288 |
+
|
| 289 |
+
return _tenbin.decode_buffer(data)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
def msgpack_loads(data: bytes):
|
| 293 |
+
import msgpack
|
| 294 |
+
|
| 295 |
+
return msgpack.unpackb(data)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def npy_loads(data: bytes):
|
| 299 |
+
import numpy.lib.format
|
| 300 |
+
|
| 301 |
+
stream = io.BytesIO(data)
|
| 302 |
+
return numpy.lib.format.read_array(stream, allow_pickle=False)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def npz_loads(data: bytes):
|
| 306 |
+
return np.load(io.BytesIO(data), allow_pickle=False)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def cbor_loads(data: bytes):
|
| 310 |
+
import cbor
|
| 311 |
+
|
| 312 |
+
return cbor.loads(data)
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def torch_loads(data: bytes):
|
| 316 |
+
import torch
|
| 317 |
+
|
| 318 |
+
return torch.load(io.BytesIO(data), weights_only=True)
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
# Obtained by checking `decoders` in `webdataset.autodecode`
|
| 322 |
+
# and removing unsafe extension decoders.
|
| 323 |
+
# Removed Pickle decoders:
|
| 324 |
+
# - "pyd": lambda data: pickle.loads(data)
|
| 325 |
+
# - "pickle": lambda data: pickle.loads(data)
|
| 326 |
+
# Modified NumPy decoders to fix CVE-2019-6446 (add allow_pickle=False and weights_only=True):
|
| 327 |
+
# - "npy": npy_loads,
|
| 328 |
+
# - "npz": lambda data: np.load(io.BytesIO(data)),
|
| 329 |
+
# - "pth": lambda data: torch_loads(data)
|
| 330 |
+
DECODERS = {
|
| 331 |
+
"txt": text_loads,
|
| 332 |
+
"text": text_loads,
|
| 333 |
+
"transcript": text_loads,
|
| 334 |
+
"cls": int,
|
| 335 |
+
"cls2": int,
|
| 336 |
+
"index": int,
|
| 337 |
+
"inx": int,
|
| 338 |
+
"id": int,
|
| 339 |
+
"json": json.loads,
|
| 340 |
+
"jsn": json.loads,
|
| 341 |
+
"ten": tenbin_loads,
|
| 342 |
+
"tb": tenbin_loads,
|
| 343 |
+
"mp": msgpack_loads,
|
| 344 |
+
"msg": msgpack_loads,
|
| 345 |
+
"npy": npy_loads,
|
| 346 |
+
"npz": npz_loads,
|
| 347 |
+
"cbor": cbor_loads,
|
| 348 |
+
"pth": torch_loads,
|
| 349 |
+
}
|
| 350 |
+
WebDataset.DECODERS = DECODERS
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/xml/__init__.py
ADDED
|
File without changes
|
data/tefig/envs/olmes-eval/lib/python3.10/site-packages/datasets/packaged_modules/xml/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (203 Bytes). View file
|
|
|