[booster] added the plugin base and torch ddp plugin (#3180)

* [booster] added the plugin base and torch ddp plugin

* polish code

* polish code

* polish code
This commit is contained in:
Frank Lee
2023-03-21 17:39:30 +08:00
committed by GitHub
parent e5f668f280
commit e7f3bed2d3
8 changed files with 378 additions and 86 deletions

View File

@@ -1,13 +1,27 @@
import pytest
from functools import partial
import torch.multiprocessing as mp
import torch.nn as nn
from torchvision.models import resnet18
from colossalai.booster.accelerator import Accelerator
from colossalai.testing import parameterize, rerun_if_address_is_in_use
@pytest.mark.parametrize('device', ['cpu', 'cuda'])
def test_accelerator(device):
@parameterize('device', ['cpu', 'cuda'])
def run_accelerator(device):
acceleartor = Accelerator(device)
model = nn.Linear(8, 8)
model = acceleartor.configure_model(model)
assert next(model.parameters()).device.type == device
del model, acceleartor
def run_dist(rank):
run_accelerator()
@rerun_if_address_is_in_use()
def test_accelerator():
world_size = 1
run_func = partial(run_dist)
mp.spawn(run_func, nprocs=world_size)