2023-03-24 05:39:12 +00:00
|
|
|
from colossalai.cluster.device_mesh_manager import DeviceMeshInfo, DeviceMeshManager
|
|
|
|
from colossalai.initialize import launch
|
|
|
|
from colossalai.logging import disable_existing_loggers
|
2023-04-06 06:51:35 +00:00
|
|
|
from colossalai.testing import spawn
|
2023-03-24 05:39:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_device_mesh_manager(rank, world_size, port):
|
|
|
|
disable_existing_loggers()
|
2023-09-19 06:20:26 +00:00
|
|
|
launch(config={}, rank=rank, world_size=world_size, host="localhost", port=port, backend="nccl")
|
2023-03-24 05:39:12 +00:00
|
|
|
device_mesh_manager = DeviceMeshManager()
|
2023-05-15 09:20:56 +00:00
|
|
|
# TODO(ver217): this test is strictly relies on hardware, temporary skip it
|
|
|
|
# device_mesh_info_auto = DeviceMeshInfo(physical_ids=[0, 1, 2, 3],)
|
|
|
|
# device_mesh_auto = device_mesh_manager.create_device_mesh('0', device_mesh_info_auto)
|
|
|
|
# assert device_mesh_auto.shape == (2, 2)
|
|
|
|
# assert device_mesh_auto._logical_mesh_id.tolist() == [[0, 1], [2, 3]]
|
2023-03-24 05:39:12 +00:00
|
|
|
|
|
|
|
device_mesh_info_with_shape = DeviceMeshInfo(
|
|
|
|
physical_ids=[0, 1, 2, 3],
|
|
|
|
mesh_shape=(2, 2),
|
|
|
|
)
|
2023-09-19 06:20:26 +00:00
|
|
|
device_mesh_with_shape = device_mesh_manager.create_device_mesh("1", device_mesh_info_with_shape)
|
2023-03-24 05:39:12 +00:00
|
|
|
|
|
|
|
assert device_mesh_with_shape.shape == (2, 2)
|
|
|
|
assert device_mesh_with_shape._logical_mesh_id.tolist() == [[0, 1], [2, 3]]
|
|
|
|
|
|
|
|
|
|
|
|
def test_device_mesh_manager():
|
2023-04-06 06:51:35 +00:00
|
|
|
spawn(check_device_mesh_manager, 4)
|
2023-03-24 05:39:12 +00:00
|
|
|
|
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
if __name__ == "__main__":
|
2023-03-24 05:39:12 +00:00
|
|
|
test_device_mesh_manager()
|