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

import pytest
Frank Lee's avatar
Frank Lee committed
5
6
import torch
import torch.multiprocessing as mp
zbian's avatar
zbian committed
7
8

from colossalai.core import global_context as gpc
Frank Lee's avatar
Frank Lee committed
9
from colossalai.initialize import launch, get_default_parser
Frank Lee's avatar
Frank Lee committed
10
11
from functools import partial
from checks_1d.check_layer_1d import *
zbian's avatar
zbian committed
12
13
14
15
16
17
18
19
20
21
22
23

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


Frank Lee's avatar
Frank Lee committed
24
25
26
27
28
29
30
31
def check_layer(rank, world_size):
    launch(config=CONFIG,
           rank=rank,
           world_size=world_size,
           host='localhost',
           port=29920,
           backend='nccl')

zbian's avatar
zbian committed
32
33
    check_linear_col()
    check_linear_row()
Frank Lee's avatar
Frank Lee committed
34
35
36
37
38
    check_attention()
    check_mlp()
    check_patch_embedding()
    check_embed()
    check_head()
zbian's avatar
zbian committed
39

Frank Lee's avatar
Frank Lee committed
40
41
42
    gpc.destroy()
    torch.cuda.empty_cache()

zbian's avatar
zbian committed
43
44

@pytest.mark.dist
Frank Lee's avatar
Frank Lee committed
45
def test_1d():
Frank Lee's avatar
Frank Lee committed
46
47
48
    world_size = 2
    run_func = partial(check_layer, world_size=world_size)
    mp.spawn(run_func, nprocs=world_size)
zbian's avatar
zbian committed
49
50
51


if __name__ == '__main__':
Frank Lee's avatar
Frank Lee committed
52
    test_1d()