datasets icon indicating copy to clipboard operation
datasets copied to clipboard

concatenate_datasets drops the split_dataset_by_node split, so every rank gets all the data

Open hzmsh opened this issue 1 month ago • 1 comments

Describe the bug

If you call split_dataset_by_node on iterable datasets and then concatenate them with concatenate_datasets, the result is no longer split: every rank iterates over the full data of all inputs.

There is no error. In distributed training, each rank silently trains on the same data, so every example is seen world_size times per epoch.

interleave_datasets (#7868, fixed in #7992) and .skip() (#8568) had the same problem and now keep the split. concatenate_datasets doesn't yet. Both axis=0 and axis=1 are affected.

Steps to reproduce the bug

from datasets import Dataset, concatenate_datasets, interleave_datasets
from datasets.distributed import split_dataset_by_node

a = Dataset.from_dict({"i": [0, 1, 2, 3]}).to_iterable_dataset(num_shards=2)
b = Dataset.from_dict({"i": [10, 11, 12, 13]}).to_iterable_dataset(num_shards=2)

for rank in range(2):
    a_rank = split_dataset_by_node(a, rank=rank, world_size=2)
    b_rank = split_dataset_by_node(b, rank=rank, world_size=2)
    print(f"rank {rank}")
    print("  concatenate:", [x["i"] for x in concatenate_datasets([a_rank, b_rank])])
    print("  interleave: ", [x["i"] for x in interleave_datasets([a_rank, b_rank])])

Output with datasets 5.1.0 and on main at 9e7496a4d:

rank 0
  concatenate: [0, 1, 2, 3, 10, 11, 12, 13]
  interleave:  [0, 10, 1]
rank 1
  concatenate: [0, 1, 2, 3, 10, 11, 12, 13]
  interleave:  [2, 12, 3]

Both ranks get all 8 rows from concatenate_datasets. interleave_datasets correctly gives each rank only its own rows.

Expected behavior

rank 0
  concatenate: [0, 1, 10, 11]
rank 1
  concatenate: [2, 3, 12, 13]

This is also what you get with split_dataset_by_node(concatenate_datasets([a, b]), rank, 2).

The cause: _concatenate_iterable_datasets in src/datasets/iterable_dataset.py doesn't pass distributed= to the IterableDataset it returns, while _interleave_iterable_datasets does (and checks that all inputs are split the same way).

I have a fix with tests ready and will open a PR shortly.

Environment info

  • datasets version: 5.1.0 (also reproduced on main at 9e7496a4d)
  • Platform: Windows-10-10.0.26200-SP0
  • Python version: 3.11.3
  • huggingface_hub version: 2.2.0
  • PyArrow version: 26.0.0
  • Pandas version: 3.0.6
  • fsspec version: 2026.7.0

hzmsh avatar Oct 14 '26 04:10 hzmsh

#self-assign

hzmsh avatar Oct 14 '26 04:10 hzmsh