-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from chengzeyi/dev_batch_parallel
Dev batch parallel
- Loading branch information
Showing
8 changed files
with
174 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import math | ||
|
||
import torch.distributed as dist | ||
|
||
import para_attn.primitives as DP | ||
|
||
|
||
def init_context_parallel_mesh( | ||
device_type=None, *, mesh=None, max_batch_dim_size=None, max_ulysses_dim_size=None, max_ring_dim_size=None | ||
): | ||
if mesh is not None: | ||
return mesh | ||
|
||
assert device_type is not None, "device must be provided if mesh is not provided" | ||
|
||
world_size = DP.get_world_size() | ||
if max_batch_dim_size is None: | ||
batch_dim_size = 1 | ||
else: | ||
batch_dim_size = math.gcd(world_size, max_batch_dim_size) | ||
|
||
attn_world_size = world_size // batch_dim_size | ||
|
||
assert not ( | ||
max_ulysses_dim_size is not None and max_ring_dim_size is not None | ||
), "Only one of max_ulysses_dim_size and max_ring_dim_size can be set" | ||
|
||
if max_ulysses_dim_size is None: | ||
if max_ring_dim_size is None: | ||
ring_dim_size = 1 | ||
else: | ||
ring_dim_size = math.gcd(attn_world_size, max_ring_dim_size) | ||
ulysses_dim_size = attn_world_size // ring_dim_size | ||
else: | ||
ulysses_dim_size = math.gcd(attn_world_size, max_ulysses_dim_size) | ||
ring_dim_size = attn_world_size // ulysses_dim_size | ||
|
||
mesh_shape = (batch_dim_size, ulysses_dim_size, ring_dim_size) | ||
return dist.init_device_mesh(device_type, mesh_shape, mesh_dim_names=("batch", "ulysses", "ring")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.