mirror of https://github.com/hpcaitech/ColossalAI
Browse Source
* [Tensor] add some function to ColoTensor * torch.allclose * rm torch.addpull/878/head
Jiarui Fang
3 years ago
committed by
GitHub
4 changed files with 38 additions and 11 deletions
@ -0,0 +1,15 @@
|
||||
import torch |
||||
from colossalai.tensor import ColoTensor |
||||
from numpy import allclose |
||||
|
||||
|
||||
def test_tensor_indexing(): |
||||
torch_t = torch.randn(2, 3) |
||||
colo_t = ColoTensor.init_from_torch_tensor(torch_t) |
||||
assert allclose(torch_t[:, 1], colo_t[:, 1].torch_tensor()) |
||||
|
||||
|
||||
def test_lazy_init_tensor(): |
||||
lazy_t = ColoTensor(2, 3, dtype=torch.float32, requires_grad=True) |
||||
assert lazy_t._torch_tensor.numel() == 0 |
||||
assert lazy_t.numel() == 6 == lazy_t.torch_tensor().numel() |
Loading…
Reference in new issue