[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

オープン
#9,191 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, pytorch

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
Python
スター
43.3k
フォーク
5.1k
平均マージ
5日 10時間
マージ済み PR(30日)
85

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

deepspeedai/DeepSpeed のほかの issue

deepspeedai/DeepSpeed の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。