Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tensor] fix equal assert #1091

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions tests/test_tensor/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from colossalai.core import global_context as gpc
from colossalai.nn.optimizer import ColoOptimizer
from functools import partial
from _utils import set_seed
from _utils import tensor_equal, tensor_shard_equal, set_seed


def init_1d_row_linear(weight):
Expand Down Expand Up @@ -144,20 +144,8 @@ def run_1d_hybrid_tp(model_name):

with torch.no_grad():
# check param
for p1, p2 in zip(model.parameters(), model_torch.parameters()):
if p1.size() == p2.size():
assert torch.allclose(p1, p2)
else:
# TODO(jzy) Only check 1D spec. Need to be replaced by new DistSpec.
if p1.size(-1) < p2.size(-1): # col
world_size = p2.size(-1) // p1.size(-1)
split_p2 = torch.chunk(p2, world_size, dim=-1)[0]

elif p1.size(0) < p2.size(0): # row
world_size = p2.size(0) // p1.size(0)
split_p2 = torch.chunk(p2, world_size, dim=0)[0]

assert torch.allclose(p1, split_p2)
for p, torch_p in zip(model.parameters(), model_torch.parameters()):
assert tensor_shard_equal(torch_p, p)

if i > 5:
break
Expand Down Expand Up @@ -353,5 +341,5 @@ def _test_pretrain_load(world_size):
if __name__ == '__main__':
# test_model_parameters()
# test_colo_optimizer()
# test_model(4)
_test_pretrain_load(4)
test_model(4)
#_test_pretrain_load(4)
FrankLeeeee marked this conversation as resolved.
Show resolved Hide resolved