Introduce Megatron-style parallel state management #7726
+3,284
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR, authored by @hahaha3210, introduces
ParallelState, a class that manages process groups for an arbitrary combination of parallel strategies including TP, EP, PP and DP.As is discussed in #7680, the primary approach is borrowing the process group creation logic from https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/core/parallel_state.py but encapsulating the states (i.e., process groups, ranks and world sizes) into a class. This design enables the coexistence of multiple, independent parallelism configurations within a single process, which is particularly valuable in scenarios involving multiple models, such as in reinforcement learning (RL) workflows. Objects of
ParallelStatecan be created prior to calls todeepspeed.initializeso that process groups are available to custom modules, such asUlyssesSPAttentionHF, at an early stage.Compatibility of
ParallelStateand current process group management facilities (includingdeepspeed.runtime.sequence_parallel.parallel_state_spanddeepspeed.utils.groups) is tested bytest_mpu.py.Opens
ParallelStatefrom a config object rather than specifying different parallel dimensions explicitly.parallel_state_deepspeed.pynecessary? If so, is there a better way to implement more concisely its APIs sharing similar code patterns?ProcessGroupNCCL.optionsfromtorch.distributed, and that is not provided bydeepspeed.commtoday. Should we introduce that todeepspeed.comm, or make the format-checking script allowing that specific use oftorch.distributed?