mindspore-ai / mindspore-ai/hyper-parallel

[RFC]多维并行的随机状态管理

Open
#287 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
53
Forks
63
Avg merge
23h 45m
Merged PRs (30d)
63

Description

当前发现的问题

当用户没有手动设置随机状态时(manual_seed()),DTensor的op_random操作会在op_dispatch里创建默认的OffsetBasedRNGTracker(显式执行),此时会执行platform.broadcast(rng_state, 0)操作,多个stage场景下会有问题。

业界情况调研

pytorch也有类似问题:在pp场景进行 lazy_init RNGTracker时,会出现卡死问题
具体说明:https://github.com/pytorch/pytorch/pull/141223
解决办法:手动调用manual_seed方法,不同stage设置不同的seed
image.png

例如torchtitan做法:初始化的时候会将不同的stage设置不同的seed
image.png

扩展

pytorch针对这个问题的讨论:https://github.com/pytorch/pytorch/issues/140301,
问题如下:

  1. 当前没有考虑PP场景
  2. 实现过于复杂
  3. 用户设置的seed有可能被覆盖(根据不同场景(TP\DP等)自动执行操作)

提出的解决办法:

  1. 扩展接口 torch.distributed.manual_seed(seed, sharded_groups=[pp, tp, fsdp]) 感知到DeviceMesh及并行分布
  2. 全局只创建一个RNG tracker对象,统一管理

结果:没有被采纳,设计初衷和DTensor违背

hyper解决办法

补齐Dtensor下的manual_seed方法,在pp场景,当前需要用户显式调用manual_seed方法,不同的stage设置不同的seed。
后续:统一在集群拉起阶段(init_dist)由框架自动拉起,类似torchtitan。

schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 153
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/153

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by reading the DTensor op_random and op_dispatch paths, especially the default OffsetBasedRNGTracker and its platform.broadcast(rng_state, 0) call. Review the linked PyTorch discussions and the torchtitan approach. Done should include a DTensor manual_seed implementation that supports distinct seeds for pipeline-parallel stages; the issue does not name tests or files to update.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.