File size: 926 Bytes
7cbb55b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import torch
import time
from tensorly import tenalg

tenalg.set_backend("einsum")

from neuralop import get_model


# Read the configuration
from zencfg import make_config_from_cli
import sys

sys.path.insert(0, "../")
from config.test_config import TestConfig


config = make_config_from_cli(TestConfig)
print(config)
print(config.to_dict())
config = config.to_dict()

batch_size = config.data.batch_size
size = config.data.size

if torch.has_cuda:
    device = "cuda"
else:
    device = "cpu"

model = get_model(config)
model = model.to(device)

in_data = torch.randn(batch_size, 3, size, size).to(device)
print(model.__class__)
print(model)

t1 = time.time()
out = model(in_data)
t = time.time() - t1
print(f"Output of size {out.shape} in {t}.")

loss = out.sum()
loss.backward()

# Check for unused params
for name, param in model.named_parameters():
    if param.grad is None:
        print(f"Usused parameter {name}!")