2023-03-20 05:59:24 +00:00
|
|
|
import torch.nn as nn
|
|
|
|
|
|
|
|
from colossalai.booster.accelerator import Accelerator
|
2023-04-06 06:51:35 +00:00
|
|
|
from colossalai.testing import clear_cache_before_run, parameterize
|
2023-03-20 05:59:24 +00:00
|
|
|
|
|
|
|
|
2023-04-06 06:51:35 +00:00
|
|
|
@clear_cache_before_run()
|
2023-03-21 09:39:30 +00:00
|
|
|
@parameterize('device', ['cpu', 'cuda'])
|
2023-04-06 06:51:35 +00:00
|
|
|
def test_accelerator(device):
|
2023-05-11 08:30:58 +00:00
|
|
|
accelerator = Accelerator(device)
|
2023-03-20 05:59:24 +00:00
|
|
|
model = nn.Linear(8, 8)
|
2023-05-11 08:30:58 +00:00
|
|
|
model = accelerator.configure_model(model)
|
2023-03-20 05:59:24 +00:00
|
|
|
assert next(model.parameters()).device.type == device
|
2023-05-11 08:30:58 +00:00
|
|
|
del model, accelerator
|