mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-05-16 04:10:14 +00:00
* [legacy] remove outdated codes of pipeline (#4692) * [legacy] remove cli of benchmark and update optim (#4690) * [legacy] remove cli of benchmark and update optim * [doc] fix cli doc test * [legacy] fix engine clip grad norm * [legacy] remove outdated colo tensor (#4694) * [legacy] remove outdated colo tensor * [test] fix test import * [legacy] move outdated zero to legacy (#4696) * [legacy] clean up utils (#4700) * [legacy] clean up utils * [example] update examples * [legacy] clean up amp * [legacy] fix amp module * [legacy] clean up gpc (#4742) * [legacy] clean up context * [legacy] clean core, constants and global vars * [legacy] refactor initialize * [example] fix examples ci * [example] fix examples ci * [legacy] fix tests * [example] fix gpt example * [example] fix examples ci * [devops] fix ci installation * [example] fix examples ci
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import pytest
|
|
import torch
|
|
import torch.distributed as dist
|
|
from torch.distributed import ReduceOp
|
|
|
|
from colossalai.device.device_mesh import DeviceMesh
|
|
from colossalai.initialize import launch
|
|
from colossalai.testing import rerun_if_address_is_in_use, spawn
|
|
|
|
|
|
def check_layer(rank, world_size, port):
|
|
launch(config={}, rank=rank, world_size=world_size, host='localhost', port=port, backend='nccl')
|
|
|
|
physical_mesh_id = torch.arange(0, 4)
|
|
assert rank == dist.get_rank()
|
|
|
|
tensor_to_check = torch.tensor([2, 2, 2, 2]).cuda()
|
|
mesh_shape = (2, 2)
|
|
# [[0, 1,
|
|
# [2, 3]]
|
|
device_mesh = DeviceMesh(physical_mesh_id, mesh_shape, init_process_group=True)
|
|
|
|
for axis in range(len(mesh_shape)):
|
|
tensor = torch.ones(4).cuda()
|
|
pg = device_mesh.get_process_group(axis=axis)
|
|
dist.all_reduce(tensor, op=ReduceOp.SUM, group=pg)
|
|
assert tensor.equal(tensor_to_check)
|
|
|
|
|
|
@pytest.mark.dist
|
|
@rerun_if_address_is_in_use()
|
|
def test_logical_pg():
|
|
spawn(check_layer, 4)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test_logical_pg()
|