2022-10-18 08:31:22 +00:00
|
|
|
import pytest
|
|
|
|
import torch
|
|
|
|
|
|
|
|
import colossalai
|
2023-04-06 06:51:35 +00:00
|
|
|
from colossalai.testing import rerun_if_address_is_in_use, spawn
|
|
|
|
from colossalai.utils import get_current_device
|
2023-04-04 05:48:16 +00:00
|
|
|
from colossalai.zero.gemini.chunk import init_chunk_manager, search_chunk_configuration
|
2022-10-18 08:31:22 +00:00
|
|
|
from tests.components_to_test.registry import non_distributed_component_funcs
|
|
|
|
|
|
|
|
|
|
|
|
def exam_search_chunk_size():
|
|
|
|
world_size = torch.distributed.get_world_size()
|
|
|
|
|
|
|
|
get_components_func = non_distributed_component_funcs.get_callable('gpt2')
|
|
|
|
model_builder, train_dataloader, test_dataloader, optimizer_class, criterion = get_components_func()
|
|
|
|
|
|
|
|
# make sure torch_model and model has the same parameter values
|
2023-08-24 01:29:25 +00:00
|
|
|
model = model_builder()
|
2023-01-28 06:35:25 +00:00
|
|
|
config_dict, *_ = search_chunk_configuration(model,
|
2023-06-25 05:34:15 +00:00
|
|
|
search_range_m=1,
|
|
|
|
search_interval=16,
|
|
|
|
min_chunk_size_m=0,
|
2023-01-28 06:35:25 +00:00
|
|
|
filter_exlarge_params=True)
|
2022-10-18 08:31:22 +00:00
|
|
|
|
|
|
|
for key in config_dict:
|
|
|
|
chunk_size = config_dict[key]['chunk_size']
|
2023-08-24 01:29:25 +00:00
|
|
|
if world_size == 1 or True:
|
2022-10-18 08:31:22 +00:00
|
|
|
assert chunk_size == 31616
|
|
|
|
else:
|
|
|
|
assert chunk_size == 1024
|
|
|
|
|
|
|
|
|
2023-01-28 06:35:25 +00:00
|
|
|
def exam_chunk_manager():
|
|
|
|
world_size = torch.distributed.get_world_size()
|
|
|
|
|
|
|
|
get_components_func = non_distributed_component_funcs.get_callable('gpt2')
|
|
|
|
model_builder, train_dataloader, test_dataloader, optimizer_class, criterion = get_components_func()
|
|
|
|
|
2023-08-24 01:29:25 +00:00
|
|
|
sharded_ddp_model = model_builder()
|
2023-01-28 06:35:25 +00:00
|
|
|
chunk_manager = init_chunk_manager(sharded_ddp_model,
|
|
|
|
get_current_device(),
|
|
|
|
hidden_dim=16,
|
2023-06-25 05:34:15 +00:00
|
|
|
search_range_m=1,
|
|
|
|
min_chunk_size_m=0,
|
2023-01-28 06:35:25 +00:00
|
|
|
filter_exlarge_params=True,
|
|
|
|
strict_ddp_flag=True)
|
|
|
|
config_dict = chunk_manager.dp_degree_chunk_size_dict
|
|
|
|
assert len(config_dict) == 1
|
|
|
|
assert config_dict[world_size] == 31616
|
|
|
|
|
|
|
|
|
2022-10-18 08:31:22 +00:00
|
|
|
def run_dist(rank, world_size, port):
|
|
|
|
colossalai.launch(config={}, rank=rank, world_size=world_size, host='localhost', port=port, backend='nccl')
|
|
|
|
exam_search_chunk_size()
|
2023-01-28 06:35:25 +00:00
|
|
|
exam_chunk_manager()
|
2022-10-18 08:31:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.dist
|
|
|
|
@pytest.mark.parametrize('world_size', [1, 4])
|
|
|
|
@rerun_if_address_is_in_use()
|
|
|
|
def test_search(world_size):
|
2023-04-06 06:51:35 +00:00
|
|
|
spawn(run_dist, world_size)
|
2022-10-18 08:31:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_search(4)
|