Is every method of Jit Class complied? If so why the JIT function is little faster than the class method?
import torch
import time
@torch.jit.script
class Test:
def __init__(self):
pass
def calc(self, input: torch.Tensor) -> torch.Tensor:
return 1.0 / torch.exp(input)
@torch.jit.script
def calc(a):
return 1.0 / torch.exp(a)
for i in range(5):
test = Test()
start = time.time()
a = torch.zeros(6000, 200)
for j in range(1000):
a = test.calc(a)
print(time.time() - start)
for i in range(5):
start = time.time()
a = torch.zeros(6000, 200)
for j in range(1000):
a = calc(a)
print(time.time() - start)