mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-17 23:18:36 +00:00
[legacy] clean up legacy code (#4743)
* [legacy] remove outdated codes of pipeline (#4692) * [legacy] remove cli of benchmark and update optim (#4690) * [legacy] remove cli of benchmark and update optim * [doc] fix cli doc test * [legacy] fix engine clip grad norm * [legacy] remove outdated colo tensor (#4694) * [legacy] remove outdated colo tensor * [test] fix test import * [legacy] move outdated zero to legacy (#4696) * [legacy] clean up utils (#4700) * [legacy] clean up utils * [example] update examples * [legacy] clean up amp * [legacy] fix amp module * [legacy] clean up gpc (#4742) * [legacy] clean up context * [legacy] clean core, constants and global vars * [legacy] refactor initialize * [example] fix examples ci * [example] fix examples ci * [legacy] fix tests * [example] fix gpt example * [example] fix examples ci * [devops] fix ci installation * [example] fix examples ci
This commit is contained in:
41
tests/test_legacy/test_zero/test_commons.py
Normal file
41
tests/test_legacy/test_zero/test_commons.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import torch
|
||||
|
||||
import colossalai
|
||||
from colossalai.legacy.zero.gemini.tensor_utils import colo_model_data_tensor_move, colo_model_data_tensor_move_inline
|
||||
from colossalai.legacy.zero.sharded_param import ShardedTensor
|
||||
from colossalai.testing import rerun_if_address_is_in_use, spawn
|
||||
|
||||
|
||||
def run_tensor_move(rank, world_size, port):
|
||||
colossalai.legacy.launch(config={}, rank=0, world_size=world_size, host='localhost', port=port, backend='nccl')
|
||||
|
||||
src_t = torch.ones(2, 3).cuda()
|
||||
tgt_t = torch.zeros(2, 3)
|
||||
|
||||
colo_model_data_tensor_move(src_t, tgt_t)
|
||||
assert (torch.sum(tgt_t) == 6.0), f"{torch.sum(tgt_t.payload)} vs. 6.0"
|
||||
|
||||
src_t = torch.ones(2, 3)
|
||||
tgt_t = torch.zeros(2, 3).cuda().half()
|
||||
colo_model_data_tensor_move(src_t, tgt_t)
|
||||
# the src_t has been removed
|
||||
assert (src_t.numel() == 0)
|
||||
assert (torch.sum(tgt_t) == 6.0), f"{torch.sum(tgt_t.payload)} vs. 6.0"
|
||||
|
||||
src_t = ShardedTensor(torch.ones(2, 3))
|
||||
tgt_t = ShardedTensor(torch.zeros(2, 3).cuda().half())
|
||||
colo_model_data_tensor_move(src_t, tgt_t)
|
||||
assert (torch.sum(tgt_t.payload) == 6.0), f"{torch.sum(tgt_t.payload)} vs. 6.0"
|
||||
|
||||
assert (tgt_t.device.type == 'cuda')
|
||||
colo_model_data_tensor_move_inline(tgt_t, torch.device('cpu'))
|
||||
assert (tgt_t.device.type == 'cpu')
|
||||
|
||||
|
||||
@rerun_if_address_is_in_use()
|
||||
def test_tensor_move():
|
||||
spawn(run_tensor_move, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_tensor_move()
|
Reference in New Issue
Block a user