Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/datasets/arrow_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ def save_to_disk(
num_shards: Optional[int] = None,
num_proc: Optional[int] = None,
storage_options: Optional[dict] = None,
flatten_indices: bool = True,
):
"""
Saves a dataset to a dataset directory, or in a filesystem using any implementation of `fsspec.spec.AbstractFileSystem`.
Expand Down Expand Up @@ -1611,10 +1612,13 @@ def save_to_disk(
total=len(self),
desc=f"Saving the dataset ({shards_done}/{num_shards} shards)",
)
# False avoids rebuilding the dataset and can significantly speed up save_to_disk for those cases.
dataset_for_sharding = self.flatten_indices() if (self._indices is not None and flatten_indices) else self

kwargs_per_job = (
{
"job_id": shard_idx,
"shard": self.shard(num_shards=num_shards, index=shard_idx, contiguous=True),
"shard": dataset_for_sharding.shard(num_shards=num_shards, index=shard_idx, contiguous=True),
"fpath": posixpath.join(dataset_path, f"data-{shard_idx:05d}-of-{num_shards:05d}.arrow"),
"storage_options": storage_options,
}
Expand Down
2 changes: 2 additions & 0 deletions src/datasets/dataset_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ def save_to_disk(
num_shards: Optional[dict[str, int]] = None,
num_proc: Optional[int] = None,
storage_options: Optional[dict] = None,
flatten_indices: bool = True,
):
"""
Saves a dataset dict to a filesystem using `fsspec.spec.AbstractFileSystem`.
Expand Down Expand Up @@ -1363,6 +1364,7 @@ def save_to_disk(
max_shard_size=max_shard_size,
num_proc=num_proc,
storage_options=storage_options,
flatten_indices=flatten_indices,
)

@staticmethod
Expand Down