reorgnize colotensor directory (#1062)

* reorgnize colotensor directory

* polish code
This commit is contained in:
Jiarui Fang
2022-06-03 18:04:22 +08:00
committed by GitHub
parent 3d10be33bd
commit a00644079e
25 changed files with 130 additions and 66 deletions

View File

@@ -0,0 +1,12 @@
import torch
from typing import Union, Optional
from colossalai.tensor import ColoTensor
GeneralTensor = Union[ColoTensor, torch.Tensor]
Number = Union[int, float]
def convert_to_colo_tensor(tensor: Optional[GeneralTensor]) -> Optional[ColoTensor]:
if tensor is not None and not isinstance(tensor, ColoTensor):
tensor = ColoTensor.from_torch_tensor(tensor)
return tensor