[Bug] DeepSpeedDataSampler gates DP-group sampling on global_rank == 0 and broadcasts with raw src=0, crashing non-zero DP groups under 2D/3D parallelism

Aperta
#9,191 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start with deepspeed/runtime/data_pipeline/data_sampling/data_sampler.py, especially DeepSpeedDataSampler.__init__, get_new_cluster, get_next_global_batch, and load_state_dict. Trace how data_parallel_group, data_parallel_rank, and global_rank are used for cluster loading, state restoration, and distributed broadcasts. Extend tests/unit/runtime/test_data_efficiency.py with the multi-dimensional parallel setup described in the issue and verify that each DP group samples consistently without a missing-global-rank error.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

In deepspeed/runtime/data_pipeline/data_sampling/data_sampler.py (commit a695f646974c6c92da2a9028bbafde8bb28bad1e, present at HEAD), DeepSpeedDataSampler assumes that the leader of self.data_parallel_group is always global rank 0:

# deepspeed/runtime/data_pipeline/data_sampling/data_sampler.py:79-85, 178-227, 284-301, 354-358
# In __init__:
if self.global_rank == 0:
    self.data_clusters = []
    self.data_cluster_sizes = []
    ...

# In get_new_cluster:
if self.global_rank == 0:
    ...
    self.data_clusters.append(MMapIndexedDataset(cluster_path, skip_warmup=True))
    self.data_cluster_sizes.append(len(self.data_clusters[-1][0]))
dist.barrier(group=self.data_parallel_group)

# In get_next_global_batch:
if self.global_rank == 0:
    samples_per_cluster = self.sample_from_clusters()
    ...
    batch = torch.tensor(batch, device=get_accelerator().current_device_name(), dtype=torch.long).view(-1)
else:
    batch = torch.empty(self.global_batch_size,
                        device=get_accelerator().current_device_name(),
                        dtype=torch.long)
dist.broadcast(batch, 0, group=self.data_parallel_group)

Whenever any orthogonal parallelism dimension is enabled (TP > 1, PP > 1, or SP > 1), ranks with non-zero TP/PP/SP coordinates belong to a data_parallel_group that does not contain global rank 0 (for example, under TP=2, DP=2, DP group 0 is [0, 2] and DP group 1 is [1, 3]). On every non-zero DP group:

  1. dist.broadcast(batch, 0, group=self.data_parallel_group) (line 299) passes raw global rank 0 instead of dist.get_global_rank(self.data_parallel_group, 0), immediately raising ValueError: Global rank 0 is not part of group on the very first batch.
  2. self.global_rank == 0 in __init__ (lines 79, 93), get_new_cluster (line 178), get_next_global_batch (line 284), and load_state_dict (line 354) leaves self.data_clusters and self.data_cluster_sizes uninitialized on data_parallel_rank == 0 of every non-zero DP group.
  3. dist.barrier(group=self.data_parallel_group) at line 227 only synchronizes within each DP group rather than across the world, allowing non-zero DP groups to race past global rank 0 while cluster files are being written to shared disk.

Existing tests/unit/runtime/test_data_efficiency.py only tests single-group DP (TP=1, PP=1), where global rank 0 is present in the sole DP group.

Affected Location
  • Repository: deepspeedai/DeepSpeed (a695f646974c6c92da2a9028bbafde8bb28bad1e, present at HEAD)
  • File & lines:
    • deepspeed/runtime/data_pipeline/data_sampling/data_sampler.py:79-103,178-230,284-301,354-358 (DeepSpeedDataSampler.__init__, get_new_cluster, get_next_global_batch, load_state_dict)
Minimal Standalone Reproduction
import os
import torch.distributed as dist
from deepspeed.runtime.data_pipeline.data_sampling.data_sampler import DeepSpeedDataSampler

def worker(rank, cluster_dir):
    os.environ["RANK"] = str(rank)
    os.environ["WORLD_SIZE"] = "4"
    dist.init_process_group("gloo", rank=rank, world_size=4)
    # 2D parallelism: TP=2, DP=2 -> DP groups [0, 2] and [1, 3]
    dp_g0 = dist.new_group(ranks=[0, 2])
    dp_g1 = dist.new_group(ranks=[1, 3])
    my_dp_group = dp_g0 if rank in (0, 2) else dp_g1
    dp_rank = 0 if rank in (0, 1) else 1

    sampler = DeepSpeedDataSampler(
        data_efficiency_config=config,
        one_epoch_total_samples=20,
        micro_batch_size=2,
        data_parallel_rank=dp_rank,
        data_parallel_size=2,
        data_parallel_group=my_dp_group,
        gradient_accumulation_steps=1,
        global_rank=rank,
    )
    sampler.get_next_global_batch()

Observed behavior / output (4-process Gloo execution against verbatim DeepSpeedDataSampler):

  • Rank 0 (dp_rank=0, group [0, 2]): OK, sampler.batch = [16, 18, 3, 9]
  • Rank 2 (dp_rank=1, group [0, 2]): OK, sampler.batch = [16, 18, 3, 9]
  • Rank 1 (dp_rank=0, group [1, 3]): ValueError: Global rank 0 is not part of group <torch.distributed.distributed_c10d.ProcessGroup ...>
  • Rank 3 (dp_rank=1, group [1, 3]): ValueError: Global rank 0 is not part of group <torch.distributed.distributed_c10d.ProcessGroup ...>
Suggested Fix
  1. Gate per-DP-group cluster loading, batch sampling, and state restoration (__init__, get_next_global_batch, load_state_dict) on self.data_parallel_rank == 0 instead of self.global_rank == 0.
  2. In get_next_global_batch (line 299), pass the DP group's global rank 0 (dist.get_global_rank(self.data_parallel_group, 0)) to dist.broadcast(batch, src, group=self.data_parallel_group).
  3. In get_new_cluster, have global rank 0 write the shared .bin/.idx cluster files on disk, synchronize across the world (dist.barrier(), or a filesystem-safe world barrier) so non-zero DP groups never race file creation, and then let each DP group's data_parallel_rank == 0 open the finalized MMapIndexedDataset for deterministic DP sampling.
Lingua principale
Python
Stelle
43.4k
Fork
5.1k
Merge medio
5g 10h
PR unite (30g)
85

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepspeedai/DeepSpeed

Tutte le issue di deepspeedai/DeepSpeed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.