mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-05 19:13:01 +00:00
[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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user