d2l-en
d2l-en copied to clipboard
Acceleration by Hybridization... But not actually accelerating for PyTorch
https://d2l.ai/chapter_computational-performance/hybridize.html#acceleration-by-hybridization
In the PyTorch tab:
net = get_net()
with Benchmark('Without torchscript'):
for i in range(1000): net(x)
net = torch.jit.script(net)
with Benchmark('With torchscript'):
for i in range(1000): net(x)
Without torchscript: 1.6357 sec
With torchscript: 1.6502 sec
I am reading that torchscript increased the time by 0.02.
I tried it out on my end, and get;
Without torchscript: 0.0580 sec
With torchscript: 0.0922 sec
Either i am getting the whole idea wrong, or torchscript isn't accelerating and
As is observed in the above results, after an nn.Sequential instance is scripted using the torch.jit.script function, computing performance is improved through the use of symbolic programming.
dosen't hold.
Thanks @GrandArth, this is also flagged in #1601. We'll probably update and improve the section here. Initially, the idea was to be consistent with mxnet hybridization and torchscript is the closest analogue.