2022-11-17 08:01:14 +00:00
|
|
|
import pytest
|
2023-01-05 08:39:55 +00:00
|
|
|
|
|
|
|
from colossalai.device import AlphaBetaProfiler
|
|
|
|
from colossalai.initialize import launch
|
|
|
|
from colossalai.logging import disable_existing_loggers
|
2023-04-06 06:51:35 +00:00
|
|
|
from colossalai.testing import parameterize, rerun_if_address_is_in_use, spawn
|
2023-01-05 08:39:55 +00:00
|
|
|
|
2022-11-17 08:01:14 +00:00
|
|
|
|
2023-04-06 06:51:35 +00:00
|
|
|
def check_alpha_beta(rank, world_size, port, physical_devices):
|
2023-01-05 08:39:55 +00:00
|
|
|
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-01-05 08:39:55 +00:00
|
|
|
profiler = AlphaBetaProfiler(physical_devices)
|
|
|
|
ab_dict = profiler.profile_ab()
|
|
|
|
for _, (alpha, beta) in ab_dict.items():
|
|
|
|
assert alpha > 0 and alpha < 1e-4 and beta > 0 and beta < 1e-10
|
2022-11-17 08:01:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip(reason="Skip because assertion fails for CI devices")
|
2023-01-05 08:39:55 +00:00
|
|
|
@pytest.mark.dist
|
2023-09-19 06:20:26 +00:00
|
|
|
@parameterize("physical_devices", [[0, 1, 2, 3], [0, 3]])
|
2023-01-05 08:39:55 +00:00
|
|
|
@rerun_if_address_is_in_use()
|
|
|
|
def test_profile_alpha_beta(physical_devices):
|
2023-04-06 06:51:35 +00:00
|
|
|
spawn(check_alpha_beta, 4, physical_devices=physical_devices)
|
2022-11-17 08:01:14 +00:00
|
|
|
|
|
|
|
|
2023-09-19 06:20:26 +00:00
|
|
|
if __name__ == "__main__":
|
2022-11-17 08:01:14 +00:00
|
|
|
test_profile_alpha_beta()
|