2022-06-15 07:27:51 +00:00
|
|
|
import torch
|
|
|
|
from colossalai.fx.proxy import ColoProxy
|
2022-07-06 08:15:16 +00:00
|
|
|
import pytest
|
2022-06-15 07:27:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_coloproxy():
|
|
|
|
# create a dummy node only for testing purpose
|
|
|
|
model = torch.nn.Linear(10, 10)
|
|
|
|
gm = torch.fx.symbolic_trace(model)
|
|
|
|
node = list(gm.graph.nodes)[0]
|
|
|
|
|
|
|
|
# create proxy
|
|
|
|
proxy = ColoProxy(node=node)
|
2022-07-06 06:03:13 +00:00
|
|
|
proxy.meta_data = torch.empty(4, 2, device='meta')
|
2022-06-15 07:27:51 +00:00
|
|
|
|
|
|
|
assert len(proxy) == 4
|
|
|
|
assert proxy.shape[0] == 4 and proxy.shape[1] == 2
|
|
|
|
assert proxy.dim() == 2
|
|
|
|
assert proxy.dtype == torch.float32
|
|
|
|
assert proxy.size(0) == 4
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-07-06 08:15:16 +00:00
|
|
|
test_coloproxy()
|