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

4
5
from functools import partial

zbian's avatar
zbian committed
6
import pytest
Frank Lee's avatar
Frank Lee committed
7
8
import torch
import torch.multiprocessing as mp
zbian's avatar
zbian committed
9
from colossalai.core import global_context as gpc
アマデウス's avatar
アマデウス committed
10
from colossalai.initialize import launch
11
12
from colossalai.utils import free_port

アマデウス's avatar
アマデウス committed
13
14
from checks_2d.check_layer_2d import *
from checks_2d.check_operation_2d import *
zbian's avatar
zbian committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

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


def check_operations():
    check_AB()
    check_ABT()
    check_ATB()


def check_layer():
    check_linear()
    check_layernorm()
アマデウス's avatar
アマデウス committed
36
    check_classifier()
zbian's avatar
zbian committed
37

38
def check_layer_and_operation(rank, world_size, port):
Frank Lee's avatar
Frank Lee committed
39
    launch(config=CONFIG,
Frank Lee's avatar
Frank Lee committed
40
41
42
           rank=rank,
           world_size=world_size,
           host='localhost',
43
           port=port,
Frank Lee's avatar
Frank Lee committed
44
45
           backend='nccl')

アマデウス's avatar
アマデウス committed
46
    # check_operations()
zbian's avatar
zbian committed
47
48
    check_layer()
    gpc.destroy()
Frank Lee's avatar
Frank Lee committed
49
50
51
52
53
54
    torch.cuda.empty_cache()


@pytest.mark.dist
def test_2d():
    world_size = 4
55
    run_func = partial(check_layer_and_operation, world_size=world_size, port=free_port())
Frank Lee's avatar
Frank Lee committed
56
    mp.spawn(run_func, nprocs=world_size)
zbian's avatar
zbian committed
57
58
59
60


if __name__ == '__main__':
    test_2d()