[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

Đang mở
#9,191 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, pytorch

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
Python
Star
43.3k
Fork
5.1k
Merge trung bình
5 ngày 10 giờ
Pull request đã merge (30 ngày)
85

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của deepspeedai/DeepSpeed

Tất cả issue của deepspeedai/DeepSpeed

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.