test_sequence.py 1.07 KB
Newer Older
zbian's avatar
zbian committed
1
2
3
#!/usr/bin/env python
# -*- encoding: utf-8 -*-

Frank Lee's avatar
Frank Lee committed
4
5
6
import pytest
import torch
import torch.multiprocessing as mp
7
from colossalai.initialize import launch
Frank Lee's avatar
Frank Lee committed
8
from colossalai.logging import get_dist_logger
Frank Lee's avatar
Frank Lee committed
9
10
from checks_seq.check_layer_seq import *
from functools import partial
11
from colossalai.utils import free_port
Frank Lee's avatar
Frank Lee committed
12

zbian's avatar
zbian committed
13
14
15
16
17
18
19
20
21
22
23
24
25

CONFIG = dict(
    parallel=dict(
        pipeline=1,
        tensor=dict(mode='sequence', size=4)
    )
)


def check_layer():
    check_selfattention()


26
def run_check_sequence(rank, world_size, port):
zbian's avatar
zbian committed
27
    # init dist
Frank Lee's avatar
Frank Lee committed
28
    launch(config=CONFIG,
Frank Lee's avatar
Frank Lee committed
29
30
31
           rank=rank,
           world_size=world_size,
           host='localhost',
32
           port=port,
Frank Lee's avatar
Frank Lee committed
33
           backend='nccl')
Frank Lee's avatar
Frank Lee committed
34
    logger = get_dist_logger()
zbian's avatar
zbian committed
35
36
37
38
    logger.info('Distributed environment is initialzied.', ranks=[0])

    # check layers
    check_layer()
Frank Lee's avatar
Frank Lee committed
39
40
41
42
43
44
    torch.cuda.empty_cache()


@pytest.mark.dist
def test_sequence():
    world_size = 4
45
    run_func = partial(run_check_sequence, world_size=world_size, port=free_port())
Frank Lee's avatar
Frank Lee committed
46
    mp.spawn(run_func, nprocs=world_size)
zbian's avatar
zbian committed
47
48
49


if __name__ == '__main__':
Frank Lee's avatar
Frank Lee committed
50
    test_sequence()