test_extract_alpha_beta.py 1.05 KB
Newer Older
1
2
3
4
5
import pytest

from colossalai.device import AlphaBetaProfiler
from colossalai.initialize import launch
from colossalai.logging import disable_existing_loggers
6
from colossalai.testing import parameterize, rerun_if_address_is_in_use, spawn
7
8


9
def check_extract_alpha_beta(rank, world_size, port, physical_devices):
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    disable_existing_loggers()
    launch(config={}, rank=rank, world_size=world_size, host='localhost', port=port, backend='nccl')
    profiler = AlphaBetaProfiler(physical_devices)

    mesh_alpha, mesh_beta = profiler.extract_alpha_beta_for_device_mesh()
    for alpha in mesh_alpha:
        assert alpha > 0 and alpha < 1e-3
    for beta in mesh_beta:
        assert beta > 0 and beta < 1e-10


@pytest.mark.skip(reason="Skip because assertion may fail for CI devices")
@pytest.mark.dist
@parameterize('physical_devices', [[0, 1, 2, 3], [0, 3]])
@rerun_if_address_is_in_use()
def test_profile_alpha_beta(physical_devices):
26
    spawn(check_extract_alpha_beta, 4, physical_devices=physical_devices)
27
28
29
30


if __name__ == '__main__':
    test_profile_alpha_beta()