utils.py 628 Bytes
Newer Older
rusty1s's avatar
to csr  
rusty1s committed
1
import torch
YanbingJiang's avatar
YanbingJiang committed
2
3
import torch_scatter
from packaging import version
rusty1s's avatar
to csr  
rusty1s committed
4

rusty1s's avatar
rusty1s committed
5
6
reductions = ['sum', 'add', 'mean', 'min', 'max']

rusty1s's avatar
rusty1s committed
7
8
dtypes = [torch.half, torch.float, torch.double, torch.int, torch.long]
grad_dtypes = [torch.half, torch.float, torch.double]
rusty1s's avatar
to csr  
rusty1s committed
9

YanbingJiang's avatar
YanbingJiang committed
10
11
12
13
if version.parse(torch_scatter.__version__) > version.parse("2.0.9"):
    dtypes.append(torch.bfloat16)
    grad_dtypes.append(torch.bfloat16)

rusty1s's avatar
to csr  
rusty1s committed
14
devices = [torch.device('cpu')]
15
if torch.cuda.is_available():
rusty1s's avatar
rusty1s committed
16
    devices += [torch.device(f'cuda:{torch.cuda.current_device()}')]
rusty1s's avatar
to csr  
rusty1s committed
17
18


rusty1s's avatar
rusty1s committed
19
def tensor(x, dtype, device):
20
    return None if x is None else torch.tensor(x, dtype=dtype, device=device)