Python Pytorch JIT类
JIT类的每个方法都符合吗?如果是这样,为什么JIT函数比类方法快一点? 请参阅下面的代码Python Pytorch JIT类,python,pytorch,Python,Pytorch,JIT类的每个方法都符合吗?如果是这样,为什么JIT函数比类方法快一点? 请参阅下面的代码 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.
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)
您能否提供您在跑步中实现的明确时间安排?