Support datasets 5.1.0 shard-based streaming distribution to avoid read amplification at large DP scale

Open
#10,327 4 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@hjh0119 is already working on this.

Since Oct 10, 2026.

Assessment

This issue has not been assessed yet.

Description

enhancement
Checklist / 检查清单
  • I have searched existing issues, and this is a new feature request. / 我已经搜索过现有的 issues,确认这是一个新的 Feature Request。
Feature Request Description / Feature Request 描述
Description

我之前在分析 ms-swift 的 streaming 数据处理流程时,发现当前数据读取与预处理主要集中在 rank 0,再由 DataLoaderDispatcher 将batch 分发给其他 rank。随着 DP 并行度增加,rank 0 容易成为数据供给瓶颈。为解决这一问题,我在 Hugging Face datasets 提出了适用于 streaming dataset 的高效 source-shard 分片策略datasets issue #8253 该能力现已合入datasets 5.1.0。

希望 ms-swift 接入这一能力:让不同 DP rank 直接读取各自负责的 source shards,并在本 rank 内由 DataLoader workers 继续分配读取任务,以减少重复读取和 rank 0 的集中处理压力。

Proposed changes
  • 升级并验证依赖:适配 datasets 5.1.0。

  • 在预处理前划分数据:对 streaming 的 HF IterableDataset,在 encode 和 packing 包装之前调用 split_dataset_by_node(...,strategy="shards" | "examples"),使用 DP rank/world size,而非全局进程 rank/world size。

  • 调整 rank 间数据分发:为该模式增加 rank-local DataLoader 路径,不再由 rank 0 为所有 DP rank 读取并 scatter batch;模型并行场景仍需保持并行组内正确的 batch 共享。

  • 兼容 packing 与现有模式:优先落地普通 DDP、streaming、non-packing;随后处理 streaming packing 与 Megatron。暂不满足条件的场景继续使用现有 dispatcher 路径。

  • 保证训练语义:覆盖各 rank 提前耗尽、max_steps、shuffle seed/epoch、checkpoint resume,以及 shards 数量不足或负载不均时的行为。

Expected outcome

在具备足够 source shards 的 streaming 数据集上,各 DP rank 只读取分配给自己的 shards,shards数不足时,可按照example级别做数据划分,消除现有 rank 0 集中预处理的瓶颈。在我们的内部环境测试下,多dp并行度模式下,数据部分的处理吞吐可提升n倍。

Pull Request / Pull Request 信息

No response

Dominant language
Python
Stars
16.2k
Forks
1.8k
Avg merge
1d 14h
Merged PRs (30d)
68

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from modelscope/ms-swift

All issues in modelscope/ms-swift

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.